source: trunk/UTIL/PYTHON/mcd/examples/dustdevil.py @ 1074

Last change on this file since 1074 was 1007, checked in by aslmd, 11 years ago

UTIL PYTHON. various updates on example + mcd + plot scripts. nothing major.

  • Property svn:executable set to *
File size: 8.3 KB
Line 
1#! /usr/bin/env python
2
3from mcd import mcd
4from myplot import maplatlon
5import numpy as np
6import matplotlib.pyplot as mpl
7
8from math import isnan
9
10from ppplot import writeascii
11
12
13dafile = "/home/aymeric/Work/submitted/coauthorship/2012reiss/reiss_data.txt"
14
15yorgl = np.loadtxt(dafile)
16yorgl = np.transpose(yorgl)
17ddwind = yorgl[5]
18ddwinddir = yorgl[6]
19ddwinderror = yorgl[9]
20
21ddheight = yorgl[7]
22ddheighterror = yorgl[8]
23
24#ddheight = yorgl[7]*0. + 10.
25#ddheighterror = yorgl[8]*0. + 0.5
26
27stddev = np.std(ddwind[np.where(ddwind != -999.)])
28print stddev
29
30## missing points are NaN
31ind = np.where(ddwind == -999.) ; ddwind[ind] = np.NaN
32print "1. wind not available", yorgl[0][ind]
33ind = np.where(ddheight == -999.) ; ddwind[ind] = np.NaN
34print "1. height not available", yorgl[0][ind]
35## no data point with rel error more than x%
36#ind = np.where(100. * ddwinderror / ddwinddir > 5.)
37#there was an error here!
38tol = 50.
39ind = np.where(100. * ddwinderror / ddwind > tol) ; ddwind[ind] = np.NaN
40print "2. error on wind too large"
41print yorgl[0][ind]
42print ddwinderror[ind]
43ind = np.where(100. * ddheighterror / ddheight > tol) ; ddwind[ind] = np.NaN
44print "3. error on height too large"
45print yorgl[0][ind]
46print ddheighterror[ind]
47## one record is doubtful according to Reiss
48ind = np.where( yorgl[0] == 3 ) ; ddwind[ind] = np.NaN #; ddwinddir[ind] = np.NaN ; ddwinderror[ind] = np.NaN
49print "4. doubtful", yorgl[0][ind]
50
51#exit()
52
53## constant_heights
54#for heights in [20.,100.,500.,1000.,2000.,5000.,7000.,10000.,20000.]:
55for heights in [10.]:
56
57## multiple_obsheight
58#for heights in [0.1,0.2,0.5,0.75,1.0,1.5,2.0,10.]:
59
60 query = mcd()
61 mcdwind = [] ; mcdwindle = [] ; mcdwindhe = [] ; mcdangle = [] ; mcdanglele = [] ; mcdanglehe = [] 
62
63 for i in yorgl[0]:
64
65   if not isnan(ddwind[i-1]):
66    query.lat = yorgl[1][i-1]
67    query.lon = yorgl[2][i-1]
68    query.xdate = yorgl[3][i-1]
69    query.loct = yorgl[4][i-1]
70
71    query.xz = ddheight[i-1] #ddheight is really the one that works best
72
73    ## constant_heights
74    query.xz = heights
75
76    ## multiple_obsheight
77    #query.xz = ddheight[i-1]*heights
78
79    query.update() ; uu = query.zonwind ; vv = query.merwind
80    if uu == -999. or vv == -999.: 
81       speed = np.NaN ; speedmin = np.NaN ; speedmax = np.NaN
82       angle = np.NaN ; anglemin = np.NaN ; anglemax = np.NaN
83    else:
84       speed = np.sqrt(uu*uu+vv*vv) ; speedmin = speed ; speedmax = speed
85
86       angle = 90. - np.arctan2(vv,uu) * 180. / np.pi
87       if angle < 0.: angle = angle + 360.
88
89       #query.xzs = max(ddheight[i-1] - 2.*ddheighterror[i-1],10.)
90       #query.xze = ddheight[i-1] + 2.*ddheighterror[i-1]
91       query.xzs = max(query.xz - 0.1*query.xz,10.)
92       query.xze = query.xz + 0.1*query.xz
93
94       query.profile()
95       tab = np.sqrt(query.zonwindtab*query.zonwindtab + query.merwindtab*query.merwindtab)
96       tab2 = 90. - np.arctan2(query.merwindtab,query.zonwindtab) * 180. / np.pi
97       tab2[np.where(tab2 < 0.)] = tab2[np.where(tab2 < 0.)] + 360.
98       speedmin = min(tab)
99       speedmax = max(tab)
100       anglemin = min(tab2)-5.
101       anglemax = max(tab2)+5.
102       if anglemin < 0.: anglemin = angle - (anglemax - angle)
103       print int(i), speed, speedmin, speedmax
104       print int(i), angle, anglemin, anglemax
105   else:
106    #print "removed ",i,ddwinderror[i-1],ddheighterror[i-1]
107    speed = -999. ; speedmin = -1000. ; speedmax = -998. ; angle = -999. ; anglemin = -1000. ; anglemax = -998.
108
109   mcdwind.append(speed)
110   mcdwindle.append(speed-speedmin)
111   mcdwindhe.append(speedmax-speed)
112   mcdangle.append(angle)
113   mcdanglele.append(angle-anglemin)
114   mcdanglehe.append(anglemax-angle)
115
116 mcdwind = np.array(mcdwind)
117 mcdwindle = np.array(mcdwindle)
118 mcdwindhe = np.array(mcdwindhe)
119
120 mcdangle = np.array(mcdangle)
121 mcdanglele = np.array(mcdanglele)
122 mcdanglehe = np.array(mcdanglehe)
123
124
125 mpl.figure(figsize=(12,10))
126 mpl.plot([0,30], [stddev,stddev+30], 'g--')
127 mpl.plot([0,30], [-stddev,-stddev+30], 'g--')
128 mpl.plot([0,30], [0,30], 'g-')
129
130 writeascii(field=mcdwind,absc=ddwind,name=str(heights)+'.txt')
131
132
133 mpl.errorbar(mcdwind, ddwind, yerr=[ddwinderror,ddwinderror], xerr=[mcdwindle,mcdwindhe], fmt='bo')
134# mpl.xlim(xmin=0.,xmax=17.)
135# mpl.ylim(ymin=0.,ymax=30.)
136 mpl.xlim(xmin=0.,xmax=30.)
137 mpl.ylim(ymin=0.,ymax=30.)
138
139
140 mpl.xlabel('MCD horizontal wind speed (m/s)')
141 mpl.ylabel('Dust devil observed drift speed (m/s)')
142
143
144 for i in yorgl[0]:
145    ## on multiplie stddev par 1.2 de facon a enlever les points tres au bord
146    ##  qui sont in si on considere l error bar
147    if abs(ddwind[i-1] - mcdwind[i-1]) > stddev*1.2:
148        mpl.annotate(str(int(i)), xy=(mcdwind[i-1], ddwind[i-1]), xytext=(10,2), 
149            textcoords='offset points', ha='center', va='bottom' )#,
150            #bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3),
151            #arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=-0.3',
152            #color='red'))
153
154
155 #mpl.show()
156 mpl.savefig("speed"+str(heights)+".eps")
157 mpl.savefig("speed"+str(heights)+".png")
158 ##mpl.savefig("comp4.eps")
159 ##mpl.savefig("comp4.png")
160
161 ddwinddirerror = mcdanglele*0. + 15.
162
163 mpl.figure(figsize=(12,10))
164 mpl.errorbar(mcdangle,ddwinddir,yerr=[ddwinddirerror,ddwinddirerror],xerr=[mcdanglele,mcdanglehe],fmt='bo')
165 mpl.plot(mcdangle,ddwinddir,'bo')
166 mpl.xlim(xmin=0.,xmax=360.)
167 mpl.ylim(ymin=0.,ymax=360.)
168
169 mpl.xlabel('MCD horizontal wind orientation (deg)')
170 mpl.ylabel('Dust devil observed drift orientation (deg)')
171
172
173 stddev2 = 50.  ## voir e.g. 8 9 10
174 mpl.plot([0,360], [stddev2,stddev2+360], 'g--')
175 mpl.plot([0,360], [-stddev2,-stddev2+360], 'g--')
176 mpl.plot([0,360], [0,360], 'g-')
177
178
179 for i in yorgl[0]:
180    ## on multiplie stddev par 1.2 de facon a enlever les points tres au bord
181    ##  qui sont in si on considere l error bar
182    if abs(ddwinddir[i-1] - mcdangle[i-1]) > stddev2*1.2:
183        mpl.annotate(str(int(i)), xy=(mcdangle[i-1], ddwinddir[i-1]), xytext=(10,2),
184            textcoords='offset points', ha='center', va='bottom')#,
185            #bbox=dict(boxstyle='round,pad=0.2', fc='yellow', alpha=0.3),
186            #arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=-0.3',
187            #color='red'))
188
189 ##xytext=(18,30)
190
191 #mpl.show()
192 mpl.savefig("angle"+str(heights)+".eps")
193 mpl.savefig("angle"+str(heights)+".png")
194 #mpl.savefig("comp3.eps")
195 #mpl.savefig("comp3.png")
196
197#exit()
198#
199#
200#dd = mcd()
201#
202#
203#
204#
205#
206##dd.zkey = 4
207##dd.xzs = 600.
208##dd.xze = 0.1
209##dd.profile()
210##dd.plot1d(["t","p"])
211##mpl.show()
212##exit()
213#
214### CASE 1
215#dd.lat   = -14.6584
216#dd.lon   = 175.54
217#dd.xdate = 265.278792
218#dd.loct  = 14.8487
219#dd.xz    = 130.4
220#
221#dd.update()
222#dd.printmcd()
223#
224#dd.lats  = -5. 
225#dd.late  = -25.
226#dd.lons  = 160.
227#dd.lone  = 190.
228#dd.map2d(["wind"],incwind=True,fixedlt=True)
229### il y a un piege pour les cartes locales il faut fixedlt=True
230#mpl.savefig("case1.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
231#
232### CASE 2
233#dd.lat   = -68.6125
234#dd.lon   = 11.4303
235#dd.xdate = 286.507293
236#dd.loct  = 15.129030
237#dd.xz    = 872.8
238##dd.xz    = 10000.0
239#
240#dd.update()
241#dd.printmcd()
242#
243#dd.lats  = -75.
244#dd.late  = -60.
245#dd.lons  = 0.
246#dd.lone  = 20.
247#dd.map2d(["wind"],incwind=True,fixedlt=True)
248#mpl.savefig("case2.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
249#
250###3    25,1306 314,4842        60,8946 14,9971 30,89575722     232     250,217961736111
251#
252### CASE 3
253#dd.lat   = 25.1306
254#dd.lon   = 314.4842
255#dd.xdate = 60.8946
256#dd.loct  = 14.9971
257#dd.xz    = 250.218
258#
259#dd.update()
260#dd.printmcd()
261#
262###4    35,564  199,486 60,5883 14,9949 12,2972688101353        125     895,247012611329
263#
264### CASE 4
265#dd.lat   = 35.564
266#dd.lon   = 199.486
267#dd.xdate = 60.5883
268#dd.loct  = 14.9949
269#dd.xz    = 895.247
270#
271#dd.update()
272#dd.printmcd()
273#
274###5    68,346  234,396 142,828 15,1777 13,4079899322222        83      1128,06581216829
275###6    68,316  234,462 142,828 15,1819 16,1939071396022        85      582,624074786015
276###7    68,302  234,144 142,828 15,1607 17,3354121022885        112     262,299040101764
277#
278### CASE 5
279#dd.lat   = 68.32
280#dd.lon   = 234.3
281#dd.xdate = 142.828
282#dd.loct  = 15.2
283#
284#dd.xz    = 1128.066
285#dd.update()
286#dd.printmcd()
287#
288#dd.xz    = 582.624
289#dd.update()
290#dd.printmcd()
291#
292#dd.xz    = 262.299
293#dd.update()
294#dd.printmcd()
295#
296#
297###19   27,055  129,614 13,5818 14,444  42,6488205391137        302     1395,96076100437
298#
299### CASE 19
300#dd.lat   = 27.055
301#dd.lon   = 129.614
302#dd.xdate = 13.5818
303#dd.loct  = 14.444
304#
305#dd.xz    = 1395.961
306#dd.update()
307#dd.printmcd()
308#
309#dd.lats  = 20.
310#dd.late  = 30.
311#dd.lons  = 125.
312#dd.lone  = 135.
313#dd.map2d(["wind"],incwind=True,fixedlt=True)
314#mpl.savefig("case19.png",dpi=110,bbox_inches='tight',pad_inches=0.4)
315#
316#
Note: See TracBrowser for help on using the repository browser.