Changeset 184 for trunk/MESOSCALE/PLOT/PYTHON/mylib
- Timestamp:
- Jul 1, 2011, 5:14:38 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MESOSCALE/PLOT/PYTHON/mylib/myplot.py
r181 r184 35 35 return wlon,wlat 36 36 37 def getproj (nc): 38 map_proj = getattr(nc, 'MAP_PROJ') 39 cen_lat = getattr(nc, 'CEN_LAT') 40 if map_proj == 2: 41 if cen_lat > 10.: 42 proj="npstere" 43 print "NP stereographic polar domain" 44 else: 45 proj="spstere" 46 print "SP stereographic polar domain" 47 elif map_proj == 1: 48 print "lambert projection domain" 49 proj="lcc" 50 elif map_proj == 3: 51 print "mercator projection" 52 proj="merc" 53 return proj 54 37 55 def ptitle (name): 38 56 from matplotlib.pyplot import title … … 43 61 import numpy as np 44 62 return [[np.min(lon2d),np.max(lon2d)],[np.min(lat2d),np.max(lat2d)]] 63 64 def wrfinterv (lon2d,lat2d): 65 nx = len(lon2d[0,:])-1 66 ny = len(lon2d[:,0])-1 67 return [[lon2d[0,0],lon2d[nx,ny]],[lat2d[0,0],lat2d[nx,ny]]] 45 68 46 69 def makeplotpngres (filename,res,pad_inches_value=0.25,folder='',disp=True): … … 58 81 return 59 82 60 def getcoord2d (nc,nlat='XLAT',nlon='XLONG'): 61 import numpy as np 62 lat = nc.variables[nlat][0,:,:] 63 lon = nc.variables[nlon][0,:,:] 64 if np.array(lat).ndim != 2: [lon2d,lat2d] = np.meshgrid(lon,lat) 65 else: [lon2d,lat2d] = [lon,lat] 66 return lon2d,lat2d 83 def dumpbdy (field): 84 nx = len(field[0,:])-1 85 ny = len(field[:,0])-1 86 return field[5:ny-5,5:nx-5] 87 88 def getcoord2d (nc,nlat='XLAT',nlon='XLONG',is1d=False): 89 import numpy as np 90 if is1d: 91 lat = nc.variables[nlat][:] 92 lon = nc.variables[nlon][:] 93 [lon2d,lat2d] = np.meshgrid(lon,lat) 94 else: 95 lat = nc.variables[nlat][0,:,:] 96 lon = nc.variables[nlon][0,:,:] 97 [lon2d,lat2d] = [lon,lat] 98 return lon2d,lat2d 67 99 68 100 def smooth (field, coeff): … … 94 126 return improc 95 127 96 def vectorfield (u, v, x, y, stride=3, scale=15., factor=250., color='black', csmooth=1): 97 ## scale regle la reference du vecteur 98 ## factor regle toutes les longueurs (dont la reference). l'AUGMENTER pour raccourcir les vecteurs. 99 import matplotlib.pyplot as plt 100 import numpy as np 101 posx = np.max(x)*0.90 102 posy = np.mean(y) 103 u = smooth(u,csmooth) 104 v = smooth(v,csmooth) 105 q = plt.quiver( x[::stride,::stride],\ 106 y[::stride,::stride],\ 107 u[::stride,::stride],\ 108 v[::stride,::stride],\ 109 angles='xy',color=color,\ 110 scale=factor,width=0.003 ) 111 if color=='white': kcolor='black' 112 elif color=='yellow': kcolor=color 113 else: kcolor=color 114 p = plt.quiverkey(q,posx,posy,scale,\ 115 str(int(scale)),coordinates='data',color=kcolor) 116 return p 128 def vectorfield (u, v, x, y, stride=3, scale=15., factor=250., color='black', csmooth=1, key=True): 129 ## scale regle la reference du vecteur 130 ## factor regle toutes les longueurs (dont la reference). l'AUGMENTER pour raccourcir les vecteurs. 131 import matplotlib.pyplot as plt 132 import numpy as np 133 posx = np.max(x) + np.std(x) / 3. ## pb pour les domaines globaux ... 134 posy = np.mean(y) 135 #posx = np.min(x) 136 #posy = np.max(x) 137 u = smooth(u,csmooth) 138 v = smooth(v,csmooth) 139 widthvec = 0.005 #0.003 140 q = plt.quiver( x[::stride,::stride],\ 141 y[::stride,::stride],\ 142 u[::stride,::stride],\ 143 v[::stride,::stride],\ 144 angles='xy',color=color,\ 145 scale=factor,width=widthvec ) 146 if color=='white': kcolor='black' 147 elif color=='yellow': kcolor=color 148 else: kcolor=color 149 if key: p = plt.quiverkey(q,posx,posy,scale,\ 150 str(int(scale)),coordinates='data',color=kcolor) 151 return 117 152 118 153 def display (name): 119 from osimport system120 121 154 from os import system 155 system("display "+name+" > /dev/null 2> /dev/null &") 156 return name 122 157 123 158 def findstep (wlon): 124 steplon = int((wlon[1]-wlon[0])/3.) 125 step = 60. 126 if steplon < 60.: step = 30. 127 if steplon < 30.: step = 15. 128 if steplon < 15.: step = 10. 129 if steplon < 10.: step = 5. 130 if steplon < 5.: step = 1. 159 steplon = int((wlon[1]-wlon[0])/4.) #3 160 step = 120. 161 while step > steplon and step > 15. : step = step / 2. 162 if step <= 15.: 163 while step > steplon and step > 5. : step = step - 5. 164 if step <= 5.: 165 while step > steplon and step > 1. : step = step - 1. 166 if step <= 1.: 167 step = 1. 131 168 return step 132 169 … … 137 174 meanlon = 0.5*(wlon[0]+wlon[1]) 138 175 meanlat = 0.5*(wlat[0]+wlat[1]) 176 if wlat[0] >= 80.: blat = 40. 177 elif wlat[0] <= -80.: blat = -40. 178 else: blat = wlat[0] 139 179 h = 2000. 140 if char == "cyl": m = Basemap(projection='cyl',llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1]) 141 elif char == "moll": m = Basemap(projection='moll',lon_0=meanlon) 142 elif char == "ortho": m = Basemap(projection='ortho',lon_0=meanlon,lat_0=meanlat) 143 elif char == "lcc": m = Basemap(projection='lcc',lat_1=meanlat,lat_0=meanlat,lon_0=meanlon,\ 180 radius = 3397200 181 if char == "cyl": m = Basemap(rsphere=radius,projection='cyl',\ 144 182 llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1]) 145 elif char == "npstere": m = Basemap(projection='npstere', boundinglat=wlat[0], lon_0=0.) 146 elif char == "spstere": m = Basemap(projection='spstere', boundinglat=wlat[0], lon_0=0.) 147 elif char == "nsper": m = Basemap(projection='nsper',lon_0=meanlon,lat_0=meanlat,satellite_height=h*1000.) 148 fontsizemer = int(mpl.rcParams['font.size']*2./3.) 149 if char in ["cyl","lcc"]: step = findstep(wlon) 150 else: step = 10. 183 elif char == "moll": m = Basemap(rsphere=radius,projection='moll',lon_0=meanlon) 184 elif char == "ortho": m = Basemap(rsphere=radius,projection='ortho',lon_0=meanlon,lat_0=meanlat) 185 elif char == "lcc": m = Basemap(rsphere=radius,projection='lcc',lat_1=meanlat,lat_0=meanlat,lon_0=meanlon,\ 186 llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1]) 187 elif char == "npstere": m = Basemap(rsphere=radius,projection='npstere', boundinglat=blat, lon_0=0.) 188 elif char == "spstere": m = Basemap(rsphere=radius,projection='spstere', boundinglat=blat, lon_0=0.) 189 elif char == "nsper": m = Basemap(rsphere=radius,projection='nsper',lon_0=meanlon,lat_0=meanlat,satellite_height=h*1000.) 190 elif char == "merc": m = Basemap(rsphere=radius,projection='merc',lat_ts=0.,\ 191 llcrnrlat=wlat[0],urcrnrlat=wlat[1],llcrnrlon=wlon[0],urcrnrlon=wlon[1]) 192 fontsizemer = int(mpl.rcParams['font.size']*3./4.) 193 if char in ["cyl","lcc","merc"]: step = findstep(wlon) 194 else: step = 10. 151 195 m.drawmeridians(np.r_[-180.:180.:step*2.], labels=[0,0,0,1], color='grey', fontsize=fontsizemer) 152 196 m.drawparallels(np.r_[-90.:90.:step], labels=[1,0,0,0], color='grey', fontsize=fontsizemer)
Note: See TracChangeset
for help on using the changeset viewer.