Changeset 724
- Timestamp:
- Jul 16, 2012, 11:15:30 PM (12 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/myplot.py
r721 r724 645 645 print "WARNING: domain plot artificially centered on lat,lon 0,0" 646 646 elif typefile in ['gcm','earthgcm','ecmwf']: 647 #### n est ce pas nc.variables ? 647 648 if "longitude" in nc.dimensions: dalon = "longitude" 648 649 elif "lon" in nc.dimensions: dalon = "lon" 650 else: dalon = "nothing" 649 651 if "latitude" in nc.dimensions: dalat = "latitude" 650 652 elif "lat" in nc.dimensions: dalat = "lat" 653 else: dalat = "nothing" 651 654 [lon2d,lat2d] = getcoord2d(nc,nlat=dalat,nlon=dalon,is1d=True) 652 655 elif typefile in ['geo']: … … 657 660 def getcoord2d (nc,nlat='XLAT',nlon='XLONG',is1d=False): 658 661 import numpy as np 659 if is1d: 660 lat = nc.variables[nlat][:] 661 lon = nc.variables[nlon][:] 662 if nlon == "nothing" or nlat == "nothing": 663 print "NO LAT LON FIELDS. I AM TRYING MY BEST. I ASSUME GLOBAL FIELD." 664 lon = np.linspace(-180.,180.,getdimfromvar(nc)[-1]) 665 lat = np.linspace(-90.,90.,getdimfromvar(nc)[-2]) 662 666 [lon2d,lat2d] = np.meshgrid(lon,lat) 663 667 else: 664 lat = nc.variables[nlat][0,:,:] 665 lon = nc.variables[nlon][0,:,:] 666 [lon2d,lat2d] = [lon,lat] 668 if is1d: 669 lat = nc.variables[nlat][:] 670 lon = nc.variables[nlon][:] 671 [lon2d,lat2d] = np.meshgrid(lon,lat) 672 else: 673 lat = nc.variables[nlat][0,:,:] 674 lon = nc.variables[nlon][0,:,:] 675 [lon2d,lat2d] = [lon,lat] 667 676 return lon2d,lat2d 677 678 ## Author: AS 679 def getdimfromvar (nc): 680 varinfile = nc.variables.keys() 681 dim = nc.variables[varinfile[-1]].shape ## usually the last variable is 4D or 3D 682 return dim 668 683 669 684 ## FROM COOKBOOK http://www.scipy.org/Cookbook/SignalSmooth -
trunk/UTIL/PYTHON/planetoplot.py
r721 r724 80 80 zoomset,getcoorddef,getwinddef,whatkindfile,reducefield,bounds,getstralt,getfield,smooth,nolow,\ 81 81 getname,localtime,check_localtime,polarinterv,getsindex,define_axis,determineplot,readslices,bidimfind,getlschar,hole_bounds,\ 82 windamplitude,slopeamplitude,deltat0t1,enrichment_factor 82 windamplitude,slopeamplitude,deltat0t1,enrichment_factor,getdimfromvar 83 83 from mymath import deg,max,min,mean,get_tsat,writeascii,fig2data,fig2img 84 84 import matplotlib as mpl … … 184 184 if slon is not None: sslon = slon 185 185 if slat is not None: sslat = slat 186 ### LAT 187 if "latitude" in nc.variables: lat = nc.variables["latitude"][:] 188 elif "lat" in nc.variables: lat = nc.variables["lat"][:] 189 ### LON 190 if "longitude" in nc.variables: lon = nc.variables["longitude"][:] 191 elif "lon" in nc.variables: lon = nc.variables["lon"][:] 186 ### LAT : done in getcoorddef 187 lat = lat2d[0,:] 188 ### LON : done in getcoorddef 189 lon = lon2d[:,0] 192 190 ### ALT 193 191 if "altitude" in nc.variables: vert = nc.variables["altitude"][:] … … 195 193 elif "lev" in nc.variables: vert = nc.variables["lev"][:] 196 194 elif "presnivs" in nc.variables: vert = nc.variables["presnivs"][:] 197 else: vert = [0.] 195 else: 196 print "No altitude found. Try to build a simple axis." 197 dadim = getdimfromvar(nc) 198 if len(dadim) == 4: print "-- 4D field. Assume z is dim 2." ; vert = np.arange(dadim[-3]) 199 elif len(dadim) == 3: print "-- 3D field. Assume z is dim 1." ; vert = [0.] 200 else: errormess("-- 2D or 1D field. Unclear. Stop.") 201 #else: vert = [0.] 198 202 ### AIRE (to weight means with the area) 199 203 if "aire" in nc.variables: area = nc.variables["aire"][:,:] … … 203 207 elif "time" in nc.variables: time = nc.variables["time"][:] 204 208 elif "time_counter" in nc.variables: time = nc.variables["time_counter"][:]/86400. #### time counter cinverstion from s-> days 205 else: time = [0.] #errormess("no time axis found.") 209 else: 210 print "No time found. Try to build a simple axis. Assume t is dim 1." 211 dadim = getdimfromvar(nc) 212 if len(dadim) == 4: time = np.arange(dadim[-4]) 213 elif len(dadim) == 3: time = np.arange(dadim[-3]) 214 else: errormess("-- I am sorry this is 2D or 1D field. I failed.") 215 #else: time = [0.] #errormess("no time axis found.") 206 216 if axtime in ["ls"]: 207 217 print "converting to Ls ..."
Note: See TracChangeset
for help on using the changeset viewer.