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

Last change on this file since 949 was 943, checked in by aslmd, 12 years ago

clean and organized UTIL/PYTHON folder

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