Changeset 350 for trunk/MESOSCALE/LMD_MM_MARS
- Timestamp:
- Nov 6, 2011, 9:28:12 PM (13 years ago)
- Location:
- trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON/gcm.py
r349 r350 26 26 parser.add_option('-s', '--stride', action='store',dest='stride', type="int", default=3, help='stride vectors (def=3)') 27 27 parser.add_option('-v', '--var', action='append',dest='var', type="string", default=None, help='variable color-shaded (append)') 28 parser.add_option('-n', '--num', action='store',dest='numplot', type="int", default= 2,help='plot number (def=2)(<0: plot LT -*numplot*)')28 parser.add_option('-n', '--num', action='store',dest='numplot', type="int", default=None, help='plot number (def=2)(<0: plot LT -*numplot*)') 29 29 parser.add_option('-i', '--interp', action='store',dest='interp', type="int", default=None, help='interpolation (2: p, 3: z-amr, 4:z-als)') 30 30 parser.add_option('-c', '--color', action='store',dest='colorb', type="string", default="def", help='change colormap (nobar: no colorbar)') … … 138 138 ############# 139 139 ### Main call 140 name = planetoplot (zenamefiles, int(zelevel),\140 name = planetoplot (zenamefiles,nvert=int(zelevel),vertmode=opt.interp,\ 141 141 proj=opt.proj,back=opt.back,target=opt.target,stride=opt.stride,var=zevar,\ 142 142 numplot=opt.numplot,colorb=opt.colorb,winds=opt.winds,\ -
trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON/meso.py
r349 r350 26 26 parser.add_option('-s', '--stride', action='store',dest='stride', type="int", default=3, help='stride vectors (def=3)') 27 27 parser.add_option('-v', '--var', action='append',dest='var', type="string", default=None, help='variable color-shaded (append)') 28 parser.add_option('-n', '--num', action='store',dest='numplot', type="int", default= 2,help='plot number (def=2)(<0: plot LT -*numplot*)')28 parser.add_option('-n', '--num', action='store',dest='numplot', type="int", default=None, help='plot number (def=2)(<0: plot LT -*numplot*)') 29 29 parser.add_option('-i', '--interp', action='store',dest='interp', type="int", default=None, help='interpolation (2: p, 3: z-amr, 4:z-als)') 30 30 parser.add_option('-c', '--color', action='store',dest='colorb', type="string", default="def", help='change colormap (nobar: no colorbar)') … … 133 133 ############# 134 134 ### Main call 135 name = planetoplot (zefile, int(zelevel),\135 name = planetoplot (zefile,nvert=int(zelevel),vertmode=opt.interp,\ 136 136 proj=opt.proj,back=opt.back,target=opt.target,stride=opt.stride,var=argvar,\ 137 137 numplot=opt.numplot,colorb=opt.colorb,winds=opt.winds,\ -
trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON/myplot.py
r349 r350 68 68 output = input 69 69 error = False 70 ### this is needed to cope the case where d4,d3,d2,d1 are single integers and not arrays70 #### this is needed to cope the case where d4,d3,d2,d1 are single integers and not arrays 71 71 if d4 is not None and not isinstance(d4, np.ndarray): d4=[d4] 72 72 if d3 is not None and not isinstance(d3, np.ndarray): d3=[d3] … … 77 77 if d2 >= shape[0]: error = True 78 78 elif d1 >= shape[1]: error = True 79 elif d1 is not None and d2 is not None: output = input[d2,d1]80 elif d1 is not None: output = input[:,d1]81 elif d2 is not None: output = input[d2,:]79 elif d1 is not None and d2 is not None: output = mean(input[d2,:],axis=0); output = mean(output[d1],axis=0) 80 elif d1 is not None: output = mean(input[:,d1],axis=1) 81 elif d2 is not None: output = mean(input[d2,:],axis=0) 82 82 elif dimension == 3: 83 83 if max(d4) >= shape[0]: error = True 84 84 elif max(d2) >= shape[1]: error = True 85 85 elif max(d1) >= shape[2]: error = True 86 elif d4 is not None and d2 is not None and d1 is not None: output = input[d4,d2,d1] 86 elif d4 is not None and d2 is not None and d1 is not None: 87 output = mean(input[d4,:,:],axis=0); output = mean(output[d2,:],axis=0); output = mean(output[d1],axis=0) 87 88 elif d4 is not None and d2 is not None: output = mean(input[d4,:,:],axis=0); output=mean(output[d2,:],axis=0) 88 89 elif d4 is not None and d1 is not None: output = mean(input[d4,:,:],axis=0); output=mean(output[:,d1],axis=1) … … 96 97 elif max(d2) >= shape[2]: error = True 97 98 elif max(d1) >= shape[3]: error = True 98 elif d4 is not None and d3 is not None and d2 is not None and d1 is not None: output = input[d4,d3,d2,d1] 99 elif d4 is not None and d3 is not None and d2 is not None: output = input[d4,d3,d2,:] 100 elif d4 is not None and d3 is not None and d1 is not None: output = input[d4,d3,:,d1] 101 elif d4 is not None and d2 is not None and d1 is not None: output = input[d4,:,d2,d1] 102 elif d3 is not None and d2 is not None and d1 is not None: output = input[:,d3,d2,d1] 99 elif d4 is not None and d3 is not None and d2 is not None and d1 is not None: 100 output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[d2,:],axis=0); output = mean(output[d1],axis=0) 101 elif d4 is not None and d3 is not None and d2 is not None: 102 output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[d2,:],axis=0) 103 elif d4 is not None and d3 is not None and d1 is not None: 104 output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0); output = mean(output[:,d1],axis=1) 105 elif d4 is not None and d2 is not None and d1 is not None: 106 output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1) 107 elif d3 is not None and d2 is not None and d1 is not None: 108 output = mean(input[:,d3,:,:],axis=1); output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1) 103 109 elif d4 is not None and d3 is not None: output = mean(input[d4,:,:,:],axis=0); output = mean(output[d3,:,:],axis=0) 104 110 elif d4 is not None and d2 is not None: output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,d2,:],axis=1) … … 107 113 elif d3 is not None and d1 is not None: output = mean(input[:,d3,:,:],axis=1); output = mean(output[:,:,d1],axis=0) 108 114 elif d2 is not None and d1 is not None: output = mean(input[:,:,d2,:],axis=2); output = mean(output[:,:,d1],axis=2) 109 elif d1 is not None: output = input[:,:,:,d1]110 elif d2 is not None: output = input[:,:,d2,:]111 elif d3 is not None: output = input[:,d3,:,:]112 elif d4 is not None: output = input[d4,:,:,:]115 elif d1 is not None: output = mean(input[:,:,:,d1],axis=3) 116 elif d2 is not None: output = mean(input[:,:,d2,:],axis=2) 117 elif d3 is not None: output = mean(input[:,d3,:,:],axis=1) 118 elif d4 is not None: output = mean(input[d4,:,:,:],axis=0) 113 119 dimension = np.array(output).ndim 114 120 shape = np.array(output).shape … … 801 807 shape = what_I_plot.shape 802 808 if indextime is None: 809 print "axis is time" 803 810 x = time 804 811 count = count+1 805 812 if indexlon is None: 813 print "axis is lon" 806 814 if count == 0: x = lon 807 815 else: y = lon 808 816 count = count+1 809 817 if indexlat is None: 818 print "axis is lat" 810 819 if count == 0: x = lat 811 820 else: y = lat 812 821 count = count+1 813 822 if indexvert is None and dim0 is 4: 823 print "axis is vert" 814 824 if vertmode == 0: # vertical axis is as is (GCM grid) 815 825 if count == 0: x=range(len(vert)) … … 822 832 x = array(x) 823 833 y = array(y) 834 print "what_I_plot.shape", what_I_plot.shape 835 print "x.shape, y.shape", x.shape, y.shape 824 836 if len(shape) == 1: 825 if shape != len(x): 837 print shape[0] 838 if shape[0] != len(x): 826 839 print "WARNING HERE !!!" 827 840 x = y -
trunk/MESOSCALE/LMD_MM_MARS/SRC/PYTHON/planetoplot.py
r349 r350 7 7 8 8 def planetoplot (namefiles,\ 9 vertmode,\ 9 nvert=0,\ 10 vertmode=0,\ 10 11 proj=None,\ 11 12 back=None,\ 12 13 target=None, 13 14 stride=3,\ 14 numplot= 2,\15 numplot=None,\ 15 16 var=None,\ 16 17 colorb="def",\ … … 59 60 if not isinstance(namefiles, np.ndarray): namefiles = [namefiles] 60 61 zelen = len(namefiles) 61 numplot = zelen*nslices62 if numplot == None: numplot = zelen*nslices 62 63 print "len(namefiles), nslices, numplot: ", zelen, nslices, numplot 63 64 all_var = [[]]*zelen … … 97 98 ########################################################## 98 99 if typefile == "gcm": 99 lat = nc.variables["latitude"][:] 100 lat = nc.variables["latitude"][:] 100 101 lon = nc.variables["longitude"][:] 101 102 time = nc.variables["Time"][:] 102 103 vert = nc.variables["altitude"][:] 103 #if firstfile: 104 # lat0 = lat 105 #elif len(lat0) != len(lat): 106 # errormess("Not the same latitude lengths !", [len(lat0), len(lat)]) 107 #elif sum((lat == lat0) == False) != 0: 108 # errormess("Not the same latitudes !", [lat,lat0]) 109 ## Faire d'autre checks sur les compatibilites entre fichiers!! 104 elif typefile in ['meso','mesoapi']: 105 if mapmode == 0: 106 if var in ['PHTOT','W']: vertdim='BOTTOM-TOP_PATCH_END_STAG' 107 else: vertdim='BOTTOM-TOP_PATCH_END_UNSTAG' 108 if var in ['V']: latdim='SOUTH-NORTH_PATCH_END_STAG' 109 else: latdim='SOUTH-NORTH_PATCH_END_UNSTAG' 110 if var in ['U']: londim='WEST-EAST_PATCH_END_STAG' 111 else: londim='WEST-EAST_PATCH_END_UNSTAG' 112 lon = np.arange(0,getattr(nc,londim),1) 113 lat = np.arange(0,getattr(nc,latdim),1) 114 vert = np.arange(0,getattr(nc,vertdim),1) 115 time = np.arange(0,len(nc.variables["Times"]),1) 116 #if firstfile: 117 # lat0 = lat 118 #elif len(lat0) != len(lat): 119 # errormess("Not the same latitude lengths !", [len(lat0), len(lat)]) 120 #elif sum((lat == lat0) == False) != 0: 121 # errormess("Not the same latitudes !", [lat,lat0]) 122 ## Faire d'autre checks sur les compatibilites entre fichiers!! 110 123 ########################################################## 111 124 … … 122 135 ### Name for title and graphics save file 123 136 basename = getname(var=var,winds=winds,anomaly=anomaly) 124 basename = basename + getstralt(nc, vertmode) ## can be moved elsewhere for a more generic routine137 basename = basename + getstralt(nc,nvert) ## can be moved elsewhere for a more generic routine 125 138 126 139 print "var, var2: ", var, var2 … … 179 192 180 193 #################################################################### 181 if typefile in ['mesoapi','meso']: 182 indexlon = None 183 indexlat = None 184 indexvert = vertmode 185 indextime = itime 186 nlon = 1 187 nlat = 1 188 nvert = 1 189 ntime = 1 190 index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%len(namefiles) 191 print "index lon,lat,vert,time", max(indexlon), max(indexlat), max(indexvert), max(indextime) 192 elif typefile in ['gcm']: 194 if typefile in ['meso','mesoapi'] and mapmode == 1: 195 indextime = itime 196 indexlon = None 197 indexlat = None 198 indexvert = nvert ## ou svert ??? 199 nlon = 1 200 nlat = 1 201 nvert = 1 202 ntime = 1 203 else: 193 204 ## get all indexes to be taken into account for this subplot and then reduce field 194 205 ## We plot 1) all lon slices 2) all lat slices 3) all vert slices 4) all time slices and then go to the next slice 195 #print "(nplot-1)%nlon", (nplot-1)%nlon196 206 indexlon = getsindex(slon,(nplot-1)%nlon,lon) 197 print "indexlon", indexlon198 207 indexlat = getsindex(slat,((nplot-1)//nlon)%nlat,lat) 199 208 indexvert = getsindex(svert,((nplot-1)//(nlon*nlat))%nvert,vert) 200 209 indextime = getsindex(stime,((nplot-1)//(nlon*nlat*nvert))%ntime,time) 201 index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%len(namefiles) 202 #print "index lon,lat,vert,time", max(indexlon), max(indexlat), max(indexvert), max(indextime) 210 index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%len(namefiles) 211 print nlon, nlat, nvert, ntime 212 print slon, slat, svert, stime 213 print index_f 214 print "index lon,lat,vert,time", max(indexlon), max(indexlat), max(indexvert), max(indextime) 203 215 #################################################################### 204 216 … … 208 220 #what_I_plot = what_I_plot*mult 209 221 if not error: 210 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) 222 if mapmode == 1: 223 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) 211 224 zevmin, zevmax = calculate_bounds(what_I_plot) 212 225 zelevels = np.linspace(zevmin,zevmax,num=ndiv+1) #20) … … 214 227 if mapmode == 0: 215 228 x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\ 216 indextime,what_I_plot.shape, len(all_var [index_f].shape),vertmode)229 indextime,what_I_plot.shape, len(all_var2[index_f].shape),vertmode) 217 230 ### If we plot a 2-D field 218 231 if len(what_I_plot.shape) is 2: … … 221 234 ### If we plot a 1-D field 222 235 elif len(what_I_plot.shape) is 1: 223 plot( x,y,what_I_plot, zelevels, colors='g', linewidths = 0.33 ) #colors='w' )# , alpha=0.5)236 plot(what_I_plot,x) 224 237 else: 225 238 errormess("There is an error in reducing field !") … … 239 252 # fvar = str(mult) + "*" + var 240 253 ### 241 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) 254 if mapmode == 1: 255 if typefile in ['mesoapi','meso']: what_I_plot = dumpbdy(what_I_plot,6) 256 elif mapmode == 0: 257 what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\ 258 indextime,what_I_plot, len(all_var[index_f].shape),vertmode) 242 259 zevmin, zevmax = calculate_bounds(what_I_plot,vmin=vmin,vmax=vmax) 243 260 if colorb in ["def","nobar"]: palette = get_cmap(name=defcolorb(fvar.upper())) 244 261 else: palette = get_cmap(name=colorb) 245 ### If we plot a 2-D field262 ##### 2D field 246 263 if len(what_I_plot.shape) is 2: 247 if mapmode == 0:248 what_I_plot, x, y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\249 indextime,what_I_plot, len(all_var[index_f].shape),vertmode)250 264 if not tile: 251 265 if not hole: what_I_plot = bounds(what_I_plot,zevmin,zevmax) 252 266 #zelevels = np.linspace(zevmin*(1. + 1.e-7),zevmax*(1. - 1.e-7)) #,num=20) 253 print "what_I_plot.shape", what_I_plot.shape 254 print "x.shape, y.shape", x.shape, y.shape 255 zelevels = np.linspace(zevmin,zevmax,num=ndiv+1) 267 zelevels = np.linspace(zevmin,zevmax)#,num=ndiv+1) 256 268 #contourf(what_I_plot, zelevels, cmap = palette ) 257 contourf( x,y,what_I_plot, zelevels, cmap = palette )269 contourf( x, y, what_I_plot, zelevels, cmap = palette ) 258 270 else: 259 271 if hole: what_I_plot = nolow(what_I_plot) 260 pcolor(x,y,what_I_plot, cmap = palette, \ 261 vmin=zevmin, vmax=zevmax ) 262 if colorb != 'nobar' and var != 'HGT' : 263 #subplot(111) 264 #colorbar() 272 pcolor( x, y, what_I_plot, cmap = palette, vmin=zevmin, vmax=zevmax ) 273 if colorb != 'nobar' and var != 'HGT' : 265 274 colorbar(fraction=0.05,pad=0.03,format=fmtvar(fvar.upper()),\ 266 275 ticks=np.linspace(zevmin,zevmax,min([ndiv+1,20])),\ 267 276 extend='neither',spacing='proportional') 268 277 # both min max neither 269 ### If we plot a 1-D field278 ##### 1D field 270 279 elif len(what_I_plot.shape) is 1: 271 what_I_plot,x,y = define_axis(lon,lat,vert,time,indexlon,indexlat,indexvert,\272 indextime,what_I_plot,len(all_var[index_f].shape),vertmode)273 # x = np.array(x)274 # y = np.array(y)275 print "what_I_plot.shape", what_I_plot.shape276 print "x.shape", x.shape277 280 plot(x,what_I_plot) 278 ### If we plot something that is not a 2-D or 1-D field 279 ### (maybe plot 3-D field one day or movie ??) 281 #### Other cases: (maybe plot 3-D field one day or movie ??) 280 282 else: 281 283 print "WARNING!!! ",len(what_I_plot.shape),"-D PLOT NOT SUPPORTED !!!"
Note: See TracChangeset
for help on using the changeset viewer.