1 tplarson 1.1 import matplotlib.pyplot as plt
2 from matplotlib import animation
3 import numpy as np
4 import sosh
5 import sys
6 import os
7
8 nargs=len(sys.argv)
9 #print(sys.argv)
10 if (nargs > 1):
11 for i in range(1, nargs):
12 exec(sys.argv[i])
13
14 try:
15 freqscale
16 except:
|
17 tplarson 1.2 freqscale=1.0/3
|
18 tplarson 1.1
19 try:
20 dpi
21 except:
22 dpi = 300
23
24 try:
25 nframes
26 except:
27 nframes = 64
28
29 try:
|
30 tplarson 1.2 colorshift
|
31 tplarson 1.1 except:
|
32 tplarson 1.2 colorshift=0
33
34 try:
35 animate
36 except:
37 animate=1
38
39 try:
40 show
41 except:
42 show=1
|
43 tplarson 1.1
44 try:
45 rsurf
46 except:
47 rsurf=1.0
48
49 try:
50 pixels
51 except:
52 pixels=1000
53
54 try:
55 figsize
56 except:
57 figsize=5
58
|
59 tplarson 1.2 sosh.nframes=nframes
60 sosh.dpi=dpi
61 sosh.icolshift=colorshift
62
|
63 tplarson 1.1 sosh.loadmodel()
64
65 #(phi,theta)=sosh.image2sphere(xpixels=pixels,ypixels=pixels,bangle=bangle)
66 (r, theta) = sosh.image2rtheta(xpixels=pixels,ypixels=pixels)
67 x=np.cos(theta)
|
68 tplarson 1.2 phi=0.0*theta
|
69 tplarson 1.1 (nx,ny)=x.shape
70 if (rsurf < 1.0):
71 newind = (r <= rsurf)
72 r.mask = np.logical_not(newindex)
73
|
74 tplarson 1.2 #modeparms=np.loadtxt('mdi.average.modes')
|
75 tplarson 1.1 # use model values instead of measured values
|
76 tplarson 1.2 #modeparms=np.loadtxt('model.surface.modes')
77 #lmod=modeparms[:,0]
78 #nmod=modeparms[:,1]
|
79 tplarson 1.1
80 arrlist={}
81 lmaxlist={}
82 varlist={}
83
84 rlist=[]
85 tlist=[]
86 plist=[]
87 freqlist=[]
88 amplist=[]
89 rclist=[]
90 hclist=[]
91
92 interval = 1.0/25
|
93 tplarson 1.2 maxsave=0.0
|
94 tplarson 1.1
95 #Animation function to call
|
96 tplarson 1.2 def calcsumt(i):
97
|
98 tplarson 1.1 sumr=0.0
99 sumt=0.0
100 sump=0.0
|
101 tplarson 1.2 plotvar=sosh.plotvar
102
103 if plotvar in ['Vr','Vmag','Vsq']:
104 for k in range(nmodes):
105 sumr += freqlist[k]*rclist[k]*rlist[k]*np.exp(-1.0j*2*np.pi*freqlist[k]*freqscale*float(i) / np.float(nframes))
106 if plotvar in ['Vt', 'Vh', 'Vmag','Vsq']:
107 for k in range(nmodes):
108 sumt += freqlist[k]*hclist[k]*tlist[k]*np.exp(-1.0j*2*np.pi*freqlist[k]*freqscale*float(i) / np.float(nframes))
109 if plotvar in ['Vt', 'Vh', 'Vmag','Vsq']:
110 for k in range(nmodes):
111 sump += freqlist[k]*hclist[k]*plist[k]*np.exp(-1.0j*2*np.pi*freqlist[k]*freqscale*float(i) / np.float(nframes))
112
113 if plotvar in ['Vh', 'Vmag', 'Vsq']:
114 vh2=np.square(sumt.real) + np.square(sump.real)
115 if plotvar in ['Vmag', 'Vsq']:
116 v2=np.square(sumr.real) + vh2
|
117 tplarson 1.1
118 if (plotvar == 'Vr'):
119 d=sumr.real
120 if (plotvar == 'Vt'):
121 d=sumt.real
122 if (plotvar == 'Vp'):
123 d=sump.real
124 if (plotvar == 'Vh'):
125 d=np.sqrt(vh2)
126 if (plotvar == 'Vmag'):
127 d=np.sqrt(v2)
128 if (plotvar == 'Vsq'):
129 d=v2
130
|
131 tplarson 1.2 return d
132
133 def sumanimate(i):
134
135 d=calcsumt(i)
136 global maxsave
137 mn,mx=d.min(),d.max()
138 maxabs=np.abs([mn,mx]).max()
139 if (maxabs > maxsave):
140 maxsave=maxabs
141 # print("new max=%f"%maxabs, end=" ", flush=True)
142
|
143 tplarson 1.1 im.set_data(d)
144 fig.canvas.draw()
|
145 tplarson 1.2 return maxabs
|
146 tplarson 1.1
147 sosh.animate=sumanimate
|
148 tplarson 1.2 sosh.calcimage=calcsumt
|
149 tplarson 1.1 sosh.isave=0
150
|
151 tplarson 1.2
|
152 tplarson 1.1 print("You may enter 'q' to quit or 'c' to change parameters.")
153 instr=sosh.catchc("Enter number of modes: ",2)
154 if (instr == 'q'):
155 sys.exit()
156 nmodes=int(instr)
157 for i in range(nmodes):
158 print("MODE #%i" % (i+1))
159
160 (l,m,n)=sosh.querylmn()
161 if l == -1:
162 sys.exit()
|
163 tplarson 1.2 ntest = sosh.modeln[l==sosh.modell]
|
164 tplarson 1.1 while (n not in ntest):
165 print("That n was not modelled for that l. Modelled values are in the range %i to %i. Try again." \
166 % (ntest.min(),ntest.max()))
167 (l,m,n)=sosh.querylmn()
|
168 tplarson 1.2 ntest = sosh.modeln[l==sosh.modell]
|
169 tplarson 1.1
170 signedm=m
171 m=np.abs(m)
172 if m not in lmaxlist.keys() or l > lmaxlist[m]:
173 lmaxlist[m]=l
174 plm=np.ma.array(np.zeros((nx,ny,l-m+1)))
175 dplm=np.ma.array(np.zeros((nx,ny,l-m+1)))
176 (y,dy)=sosh.setplm(l,m,x,plm,dplm)
177 arrlist[m]=(plm,dplm)
178 print("Spherical harmonic calculated and saved.")
179 else:
180 (plm,dplm)=arrlist[m]
181 (y,dy)=(plm[...,l-m],dplm[...,l-m])
182 print("Spherical harmonic retrieved.")
183
184 if (m > 0):
|
185 tplarson 1.2 phi[:,int(nx/2):nx]=(np.pi/4)/m
186 phi[:,0:int(nx/2)]=(np.pi/4)/m + np.pi
|
187 tplarson 1.1 else:
|
188 tplarson 1.2 phi=0.0*theta
|
189 tplarson 1.1 ylm=y*np.exp(1.0j*signedm*phi)
190 dylmt=-np.sin(theta)*dy*np.exp(1.0j*signedm*phi)
|
191 tplarson 1.2 dylmp=1.0j*signedm*y*np.exp(1.0j*signedm*phi)
|
192 tplarson 1.1
193 rlist.append(ylm)
194 tlist.append(dylmt)
195 plist.append(dylmp/np.sin(theta))
196
197 xir, xih = sosh.getradial(l,n)
198 fr=np.interp(r,sosh.rmesh,xir*np.sqrt(sosh.rho))
199 fh=np.interp(r,sosh.rmesh,xih*np.sqrt(sosh.rho))
200
|
201 tplarson 1.2 idx = ((sosh.modeln == n) & (sosh.modell == l))
202 freq = sosh.modelnu[idx]/1000.0
203 # ind = ((l==lmod) & (n==nmod))
204 # freq = float(modeparms[ind,2])/1000.0
|
205 tplarson 1.1 rclist.append(fr)
206 hclist.append(fh)
207 freqlist.append(freq)
|
208 tplarson 1.2 print("Scaled frequency = %f." % (freq*freqscale))
|
209 tplarson 1.1
210 # if using measured mode parameters, this would
211 # allow you to compute frequency as a function of m
212 # from the fitted a-coefficients
213 # ai=np.append([0.0],modeparms[ind,12:18]/1000)
214 # pols=sosh.apols(l,6)
215 # fx=np.matmul(pols,ai)
216 # freq=modeparms[ind,2]+fx
217 # freqlist.append(freq[l+signedm]*freqscale)
218 # amplist.append(modeparms[ind,3])
219
220 sumr=0.0
221 sumt=0.0
222 sump=0.0
223 for i in range(nmodes):
224 sumr += rclist[i]*rlist[i]*freqlist[i]
225 sumt += hclist[i]*tlist[i]*freqlist[i]
226 sump += hclist[i]*plist[i]*freqlist[i]
227
228 vh2=(np.square(sumt.real) + np.square(sump.real))
229 v2=(np.square(sumr.real) + vh2)
230 tplarson 1.1
231 varlist['Vr']=sumr.real
232 varlist['Vt']=sumt.real
233 varlist['Vp']=sump.real
234 varlist['Vh']=np.sqrt(vh2)
235 varlist['Vmag']=np.sqrt(v2)
236 varlist['Vsq']=v2
237
238 while True:
239
240 var=varlist[sosh.plotvar]
|
241 tplarson 1.2 maxsave=0.0
|
242 tplarson 1.1
243 fig,im = sosh.drawfigure(var, fsize=figsize)
244 if (sosh.isave != 0):
|
245 tplarson 1.2 sosh.savefigure(ianimate=animate, label='_interior')
246 if (show != 0):
247 if (animate != 0):
248 anim = animation.FuncAnimation(fig, sumanimate, frames=nframes, interval=interval)
249 plt.show()
|
250 tplarson 1.1
251 print()
252 c=sosh.queryplotparms()
253 if (c == 'q'):
254 break
255
256
257
|