Changeset 392 for trunk/UTIL/PYTHON/myplot.py
- Timestamp:
- Nov 17, 2011, 2:17:48 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/myplot.py
r391 r392 43 43 elif 'HGT_M' in nc.variables: typefile = 'geo' 44 44 #else: errormess("whatkindfile: typefile not supported.") 45 else: typefile = 'gcm' # for lslin-ed files from gcm45 else: typefile = 'gcm' # for lslin-ed files from gcm 46 46 return typefile 47 47 … … 50 50 ## this allows to get much faster (than simply referring to nc.variables[var]) 51 51 dimension = len(nc.variables[var].dimensions) 52 print " Opening variable with", dimension, "dimensions ..."52 #print " Opening variable with", dimension, "dimensions ..." 53 53 if dimension == 2: field = nc.variables[var][:,:] 54 54 elif dimension == 3: field = nc.variables[var][:,:,:] … … 65 65 shape = np.array(input).shape 66 66 #print 'd1,d2,d3,d4: ',d1,d2,d3,d4 67 print ' dim,shape: ',dimension,shape67 print 'IN REDUCEFIELD dim,shape: ',dimension,shape 68 68 output = input 69 69 error = False … … 98 98 elif max(d1) >= shape[3]: error = True 99 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 = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt[d3]); output = mean(output[d2,:],axis=0); output = mean(output[d1],axis=0) 100 output = mean(input[d4,:,:,:],axis=0) 101 output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt,indice=d3) 102 output = mean(output[d2,:],axis=0) 103 output = mean(output[d1],axis=0) 101 104 elif d4 is not None and d3 is not None and d2 is not None: 102 output = mean(input[d4,:,:,:],axis=0); output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt[d3]); output = mean(output[d2,:],axis=0) 105 output = mean(input[d4,:,:,:],axis=0) 106 output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt,indice=d3) 107 output = mean(output[d2,:],axis=0) 103 108 elif d4 is not None and d3 is not None and d1 is not None: 104 output = mean(input[d4,:,:,:],axis=0); output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt[d3]); output = mean(output[:,d1],axis=1) 109 output = mean(input[d4,:,:,:],axis=0) 110 output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt,indice=d3) 111 output = mean(output[:,d1],axis=1) 105 112 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) 113 output = mean(input[d4,:,:,:],axis=0) 114 output = mean(output[:,d2,:],axis=1) 115 output = mean(output[:,d1],axis=1) 107 116 elif d3 is not None and d2 is not None and d1 is not None: 108 output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt[d3]); output = mean(output[:,d2,:],axis=1); output = mean(output[:,d1],axis=1) 109 elif d4 is not None and d3 is not None: output = mean(input[d4,:,:,:],axis=0); output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt[d3]) 110 elif d4 is not None and d2 is not None: output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,d2,:],axis=1) 111 elif d4 is not None and d1 is not None: output = mean(input[d4,:,:,:],axis=0); output = mean(output[:,:,d1],axis=2) 112 elif d3 is not None and d2 is not None: output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt[d3]); output = mean(output[:,d2,:],axis=1) 113 elif d3 is not None and d1 is not None: output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt[d3]); output = mean(output[:,:,d1],axis=0) 114 elif d2 is not None and d1 is not None: output = mean(input[:,:,d2,:],axis=2); output = mean(output[:,:,d1],axis=2) 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 = reduce_zaxis(input[:,d3,:,:],ax=0,yint=yint,vert=alt[d3]) 118 elif d4 is not None: output = mean(input[d4,:,:,:],axis=0) 117 output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt,indice=d3) 118 output = mean(output[:,d2,:],axis=1) 119 output = mean(output[:,d1],axis=1) 120 elif d4 is not None and d3 is not None: 121 output = mean(input[d4,:,:,:],axis=0) 122 output = reduce_zaxis(output[d3,:,:],ax=0,yint=yint,vert=alt,indice=d3) 123 elif d4 is not None and d2 is not None: 124 output = mean(input[d4,:,:,:],axis=0) 125 output = mean(output[:,d2,:],axis=1) 126 elif d4 is not None and d1 is not None: 127 output = mean(input[d4,:,:,:],axis=0) 128 output = mean(output[:,:,d1],axis=2) 129 elif d3 is not None and d2 is not None: 130 output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt,indice=d3) 131 output = mean(output[:,d2,:],axis=1) 132 elif d3 is not None and d1 is not None: 133 output = reduce_zaxis(input[:,d3,:,:],ax=1,yint=yint,vert=alt,indice=d3) 134 output = mean(output[:,:,d1],axis=0) 135 elif d2 is not None and d1 is not None: 136 output = mean(input[:,:,d2,:],axis=2) 137 output = mean(output[:,:,d1],axis=2) 138 elif d1 is not None: output = mean(input[:,:,:,d1],axis=3) 139 elif d2 is not None: output = mean(input[:,:,d2,:],axis=2) 140 elif d3 is not None: output = reduce_zaxis(input[:,d3,:,:],ax=0,yint=yint,vert=alt,indice=d3) 141 elif d4 is not None: output = mean(input[d4,:,:,:],axis=0) 119 142 dimension = np.array(output).ndim 120 143 shape = np.array(output).shape 121 print ' dim,shape: ',dimension,shape144 print 'OUT REDUCEFIELD dim,shape: ',dimension,shape 122 145 return output, error 123 146 124 ## Author: AC 125 126 def reduce_zaxis (input,ax=None,yint=False,vert=None): 147 ## Author: AC + AS 148 def reduce_zaxis (input,ax=None,yint=False,vert=None,indice=None): 127 149 from mymath import max,mean 128 150 from scipy import integrate 129 if yint :151 if yint and vert is not None and indice is not None: 130 152 if type(input).__name__=='MaskedArray': 131 153 input.set_fill_value([np.NaN]) 132 output = integrate.trapz(input.filled(),x=vert ,axis=ax)154 output = integrate.trapz(input.filled(),x=vert[indice],axis=ax) 133 155 else: 134 output = integrate.trapz(input.filled(),x=vert ,axis=ax)156 output = integrate.trapz(input.filled(),x=vert[indice],axis=ax) 135 157 else: 136 158 output = mean(input,axis=ax) … … 257 279 if cen_lat > 10.: 258 280 proj="npstere" 259 print "NP stereographic polar domain"281 #print "NP stereographic polar domain" 260 282 else: 261 283 proj="spstere" 262 print "SP stereographic polar domain"284 #print "SP stereographic polar domain" 263 285 elif map_proj == 1: 264 print "lambert projection domain"286 #print "lambert projection domain" 265 287 proj="lcc" 266 288 elif map_proj == 3: 267 print "mercator projection"289 #print "mercator projection" 268 290 proj="merc" 269 291 else: … … 460 482 elif wlat[1] >= 0.: blat = wlat[0] 461 483 elif wlat[0] <= 0.: blat = wlat[1] 462 print "blat ", blat484 #print "blat ", blat 463 485 h = 50. ## en km 464 486 radius = 3397200. … … 484 506 # step = np.min([5.,step]) 485 507 # steplon = step 486 print step487 508 m.drawmeridians(np.r_[-180.:180.:steplon], labels=[0,0,0,1], color='grey', fontsize=fontsizemer) 488 509 m.drawparallels(np.r_[-90.:90.:step], labels=[1,0,0,0], color='grey', fontsize=fontsizemer) … … 534 555 ### 535 556 if zevmin < 0. and min(fieldcalc) > 0.: zevmin = 0. 536 print " field ", min(fieldcalc), max(fieldcalc)537 print " bounds", zevmin, zevmax557 print "BOUNDS field ", min(fieldcalc), max(fieldcalc) 558 print "BOUNDS adopted ", zevmin, zevmax 538 559 return zevmin, zevmax 539 560 … … 545 566 if zevmin < 0: what_I_plot[ what_I_plot < zevmin*(1. - 1.e-7) ] = zevmin*(1. - 1.e-7) 546 567 else: what_I_plot[ what_I_plot < zevmin*(1. + 1.e-7) ] = zevmin*(1. + 1.e-7) 547 print " new min", min(what_I_plot)568 print "NEW MIN ", min(what_I_plot) 548 569 what_I_plot[ what_I_plot > 9e+35 ] = -9e+35 549 570 what_I_plot[ what_I_plot > zevmax ] = zevmax 550 print "new max ", max(what_I_plot) 551 571 print "NEW MAX ", max(what_I_plot) 552 572 return what_I_plot 553 573 … … 556 576 from mymath import max,min 557 577 lim = 0.15*0.5*(abs(max(what_I_plot))+abs(min(what_I_plot))) 558 print " on vire en dessous de", lim578 print "NO PLOT BELOW VALUE ", lim 559 579 what_I_plot [ abs(what_I_plot) < lim ] = 1.e40 560 580 return what_I_plot … … 566 586 [wlon,wlat] = [ [wlon[0]+zoom*dlon/100.,wlon[1]-zoom*dlon/100.],\ 567 587 [wlat[0]+zoom*dlat/100.,wlat[1]-zoom*dlat/100.] ] 568 print " zoom%",zoom,wlon,wlat588 print "ZOOM %",zoom,wlon,wlat 569 589 return wlon,wlat 570 590 … … 642 662 #W --> spectral ou jet 643 663 #spectral BrBG RdBu_r 644 print "predefined colorbars"664 #print "predefined colorbars" 645 665 if whichone not in whichcolorb: 646 666 whichone = "def" … … 813 833 if axis[imin] == -180 and axis[imax] == 180: 814 834 zeindex = zeindex[0:len(zeindex)-1] 815 print " whole longitude averaging asked, so last point is not taken into account."835 print "INFO: whole longitude averaging asked, so last point is not taken into account." 816 836 return zeindex 817 837 … … 828 848 shape = what_I_plot.shape 829 849 if indextime is None: 830 print " axisis time"850 print "AXIS is time" 831 851 x = time 832 852 count = count+1 833 853 if indexlon is None: 834 print " axisis lon"854 print "AXIS is lon" 835 855 if count == 0: x = lon 836 856 else: y = lon 837 857 count = count+1 838 858 if indexlat is None: 839 print " axisis lat"859 print "AXIS is lat" 840 860 if count == 0: x = lat 841 861 else: y = lat 842 862 count = count+1 843 863 if indexvert is None and dim0 is 4: 844 print " axisis vert"864 print "AXIS is vert" 845 865 if vertmode == 0: # vertical axis is as is (GCM grid) 846 866 if count == 0: x=range(len(vert)) … … 853 873 x = array(x) 854 874 y = array(y) 855 print " what_I_plot.shape", what_I_plot.shape856 print " x.shape, y.shape", x.shape, y.shape875 print "CHECK: what_I_plot.shape", what_I_plot.shape 876 print "CHECK: x.shape, y.shape", x.shape, y.shape 857 877 if len(shape) == 1: 858 878 print shape[0] … … 864 884 if shape[1] == len(y) and shape[0] == len(x) and shape[0] != shape[1]: 865 885 what_I_plot = swapaxes(what_I_plot,0,1) 866 print " swapaxes", what_I_plot.shape, shape886 print "INFO: swapaxes", what_I_plot.shape, shape 867 887 #x0 = x 868 888 #x = y … … 896 916 if slon is None and slat is None: 897 917 mapmode = 1 # in this case we plot a map, with the given projection 898 #elif proj is not None:899 # print "WARNING: you specified a", proj,\900 # "projection but asked for slices", slon,"in longitude and",slat,"in latitude"901 print "mapmode: ", mapmode902 918 903 919 return nlon, nlat, nvert, ntime, mapmode, nslices
Note: See TracChangeset
for help on using the changeset viewer.