Changeset 1968 in lmdz_wrf
- Timestamp:
- Jul 24, 2018, 6:45:52 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/drawing.py
r1948 r1968 9151 9151 * NOTE: limits of the graph will be computed from the continuous variable 9152 9152 values=[vnamefs]:[dvarxn],[dvaryn]:[dimxyfmt]:[colorbarvals]:[sminv],[smaxv]: 9153 [discvals]:[figt]:[kindfig]:[reverse]:[mapv]:[ close]9153 [discvals]:[figt]:[kindfig]:[reverse]:[mapv]:[plotrange]:[close] 9154 9154 [vnamefs]: Name in the figure of the variable to be shaded 9155 9155 [dvarxn],[dvaryn]: name of the dimensions for the final x-axis and y-axis at … … 9207 9207 * 'h', high 9208 9208 * 'f', full 9209 [plotrange]: range of the plot 9210 'strict': map covers only the minimum and maximum lon,lats from the 9211 locations of the discrtete points 9212 'sponge,'[dlon],[dlat]: map covers an extended [dlon],[dlat] from the 9213 minimum and maximum lon,lats from the locations of the discrtete points 9214 'fullcontinuous': map covers all the shadding area 9209 9215 [close]: Whether figure should be finished or not 9210 9216 """ … … 9217 9223 9218 9224 expectargs = '[vnamefs]:[dvarxn],[dvaryn]:[dimxyfmt]:[colorbarvals]:[sminv],' + \ 9219 '[smaxv]:[discvals]:[figt]:[kindfig]:[reverse]:[mapv]:[ close]'9225 '[smaxv]:[discvals]:[figt]:[kindfig]:[reverse]:[mapv]:[plotrange]:[close]' 9220 9226 9221 9227 drw.check_arguments(fname,values,expectargs,':') … … 9231 9237 revals = values.split(':')[8] 9232 9238 mapvalue = values.split(':')[9] 9233 close = gen.Str_Bool(values.split(':')[10]) 9239 plotrange = values.split(':')[10] 9240 close = gen.Str_Bool(values.split(':')[11]) 9234 9241 9235 9242 ncs = ncfiles.split('@') … … 9266 9273 if not onc.variables.has_key(varn): 9267 9274 print errormsg 9268 print ' ' + fname + ": '" + hfn + "' file '" + ncfile +\9275 print ' ' + fname + ": '" + hfn + "' file '" + ncfilen + \ 9269 9276 "' does not have variable '" + varn + "' !!" 9270 9277 varns = sorted(onc.variables.keys()) … … 9276 9283 vals, dims = drw.slice_variable(ovar, dimvals.replace(',','|')) 9277 9284 9278 # Values have to be 2D (might not be true for disc?)9279 if len(vals.shape) != 2:9285 # Values have to be 2D 9286 if hfn == 'cont' and len(vals.shape) != 2: 9280 9287 print errormsg 9281 9288 print ' ' + fname + ": values have to be 2D !!" … … 9294 9301 if not onc.variables.has_key(vdimxn): 9295 9302 print errormsg 9296 print ' ' + fname + ": '" + hfn + "' file '" + ncfile +\9303 print ' ' + fname + ": '" + hfn + "' file '" + ncfilen + \ 9297 9304 "' does not have x-dimension variable '" + vdimxn + "' !!" 9298 9305 varns = sorted(onc.variables.keys()) … … 9301 9308 if not onc.variables.has_key(vdimyn): 9302 9309 print errormsg 9303 print ' ' + fname + ": '" + hfn + "' file '" + ncfile +\9310 print ' ' + fname + ": '" + hfn + "' file '" + ncfilen + \ 9304 9311 "' does not have y-dimension variable '" + vdimyn + "' !!" 9305 9312 varns = sorted(onc.variables.keys()) … … 9392 9399 absyn = dyn 9393 9400 absyx = dyx 9401 contxynx = [dxn, dxx, dyn, dyx] 9394 9402 9395 9403 else: … … 9403 9411 madiscvarv = vals 9404 9412 9405 # Getting 2D dimensions 9406 [d2Dx, d2Dy] = np.meshgrid(odimxv0, odimyv0) 9407 9408 # Checking for flipping axis? 9409 if d2Dx.shape[0] == vals.shape[1] and d2Dx.shape[1] == vals.shape[0]: 9410 print ' rotating values !' 9411 #madiscvarv = madiscvarv.transpose() 9412 d2Dx = d2Dx.transpose() 9413 d2Dy = d2Dy.transpose() 9414 9415 # vals have to be 2D otherwise... ? 9416 dx = madiscvarv.shape[1] 9417 dy = madiscvarv.shape[0] 9418 for j in range(dy): 9419 for i in range(dx): 9420 if not madiscvarv.mask[j,i]: 9421 discvarv.append(madiscvarv[j,i]) 9422 discx.append(d2Dx[j,i]) 9423 discy.append(d2Dy[j,i]) 9413 if len(vals.shape) == 1: 9414 if type(madiscvarv.mask) == type(np.True_): 9415 discvarv = list(madiscvarv[:]) 9416 discx = list(odimxv0[:]) 9417 discy = list(odimyv0[:]) 9418 else: 9419 for i in range(vals.shape[0]): 9420 if not madiscvarv.mask[i]: 9421 discvarv.append(madiscvarv[i]) 9422 discx.append(odimxv0[i]) 9423 discy.append(odimyv0[i]) 9424 9425 elif len(vals.shape) == 2: 9426 # Getting 2D dimensions 9427 [d2Dx, d2Dy] = np.meshgrid(odimxv0, odimyv0) 9428 9429 # Checking for flipping axis? 9430 if d2Dx.shape[0] == vals.shape[1] and d2Dx.shape[1] == vals.shape[0]: 9431 print ' rotating values !' 9432 #madiscvarv = madiscvarv.transpose() 9433 d2Dx = d2Dx.transpose() 9434 d2Dy = d2Dy.transpose() 9435 9436 # vals have to be 2D otherwise... ? 9437 dx = madiscvarv.shape[1] 9438 dy = madiscvarv.shape[0] 9439 for j in range(dy): 9440 for i in range(dx): 9441 if not madiscvarv.mask[j,i]: 9442 discvarv.append(madiscvarv[j,i]) 9443 discx.append(d2Dx[j,i]) 9444 discy.append(d2Dy[j,i]) 9445 else: 9446 # Values have to be 1D or 2D 9447 print errormsg 9448 print ' ' + fname + ": disc. values have to be 1D or 2D !!" 9449 print ' provided shape:', vals.shape, 'for slice:', dimvals 9450 quit(-1) 9424 9451 9425 9452 Ndiscvals = len(discvarv) … … 9438 9465 onc.close() 9439 9466 9440 graphnx = [absxn, absxx, absyn, absyx] 9441 print 'limits of the graphic:', graphnx 9467 if plotrange[0:6] == 'strict': 9468 graphnx = [absxn, absxx, absyn, absyx] 9469 elif plotrange[0:6] == 'sponge': 9470 dlon = np.float(plotrange.split(',')[1]) 9471 dlat = np.float(plotrange.split(',')[2]) 9472 graphnx = [absxn-dlon, absxx+dlon, absyn-dlat, absyx+dlat] 9473 elif plotrange[0:14] == 'fullcontinuous': 9474 graphnx = contxynx 9475 9476 print " '" + plotrange + "' limits of the graphic:", graphnx 9442 9477 9443 9478 shading_nx = [] -
trunk/tools/drawing_tools.py
r1948 r1968 11837 11837 pixkind = 'data' 11838 11838 11839 print 'reva:', reva11840 11839 if reva is not None: 11841 11840 varsv, dimxv, dimyv, dimxt, dimyt, dimxl, dimyl, dimxT, dimyT, limx, limy = \ … … 11864 11863 dy = lat0.shape[0] 11865 11864 11866 nlon = np.min(lon0) 11867 xlon = np.max(lon0) 11868 nlat = np.min(lat0) 11869 xlat = np.max(lat0) 11865 #nlon = np.min(lon0) 11866 #xlon = np.max(lon0) 11867 #nlat = np.min(lat0) 11868 #xlat = np.max(lat0) 11869 nlon = gmaxmin[0] 11870 xlon = gmaxmin[1] 11871 nlat = gmaxmin[2] 11872 xlat = gmaxmin[3] 11870 11873 11871 11874 lon2 = lon0[dy/2,dx/2] … … 11888 11891 11889 11892 x,y = m(lon0,lat0) 11890 11891 11893 else: 11892 11894 # No following data values … … 11898 11900 fvarsv = varsv.flatten() 11899 11901 fobsv = obsv[:,2].flatten() 11900 allvals = np.array(list(fvarsv) + list(fobsv)) 11902 11903 # Getting extremes only from the plotted area 11904 stmapvals, ijmapvals = ncvar.stats_lonlat_box(varsv, lon0, lat0, nlon, xlon, nlat, xlat) 11905 allvals = np.array(stmapvals[0:2] + list(fobsv)) 11906 #print ' Figure minmax:', stmapvals[0:2], 'absolute:', np.min(varsv), np.max(varsv) 11901 11907 11902 11908 vsend = graphic_range(vs, allvals) … … 11929 11935 11930 11936 for iobs in range(Nobs): 11931 xobs = (obsv[iobs,0]-xmin)/(xmax-xmin) 11932 yobs = (obsv[iobs,1]-ymin)/(ymax-ymin) 11937 if mapv is None: 11938 xobs = (obsv[iobs,0]-xmin)/(xmax-xmin) 11939 yobs = (obsv[iobs,1]-ymin)/(ymax-ymin) 11940 else: 11941 xobs = obsv[iobs,0] 11942 yobs = obsv[iobs,1] 11933 11943 clv = my_cmap(norm(obsv[iobs,2])) 11934 11944 plt.plot(xobs, yobs, discinf[0], color=clv, markersize=discinf[1], zorder=100) … … 12037 12047 plt.title(gen.latex_text(figtitle)) 12038 12048 12039 figname = '2Dshad_obs-sim_comparison .png'12049 figname = '2Dshad_obs-sim_comparison' 12040 12050 output_kind(kfig, figname, close) 12041 12051
Note: See TracChangeset
for help on using the changeset viewer.