Changeset 896 for trunk/UTIL
- Timestamp:
- Mar 10, 2013, 10:44:32 PM (12 years ago)
- Location:
- trunk/UTIL/PYTHON
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/myplot.py
r886 r896 98 98 ## this allows to get much faster and use much less memory esp. with large datasets 99 99 print " Opening variable",var," with", dimension, "dimensions ..." 100 print indextime, indexlon, indexlat, indexvert 100 101 if dimension == 2: 101 102 field = nc.variables[var][indextime,indexlon] … … 1610 1611 idx=idxsub[0]+np.min(idxs) ; idy=idysub[0]+np.min(idys) 1611 1612 return np.int(idx),np.int(idy) 1613 1614 # Author : A.S. 1615 # This is temporary. An object formulation would solve this kind of inelegant approach. 1616 def alltransfer(zeto,zefrom,all_varname,all_time,all_vert,all_lat,all_lon,all_namefile,all_var2,all_colorb,all_var): 1617 all_varname[zeto] = all_varname[zefrom] 1618 all_time[zeto] = all_time[zefrom] 1619 all_vert[zeto] = all_vert[zefrom] 1620 all_lat[zeto] = all_lat[zefrom] 1621 all_lon[zeto] = all_lon[zefrom] 1622 all_namefile[zeto] = all_namefile[zefrom] 1623 all_var2[zeto] = all_var2[zefrom] 1624 all_colorb[zeto] = all_colorb[zefrom] 1625 all_var[zeto] = all_var[zefrom] -
trunk/UTIL/PYTHON/planetoplot.py
r893 r896 118 118 print "********* SPEED MODE. EXPERIMENTAL. ********" 119 119 print "********************************************" 120 ### we ensure namefiles and var are arrays 120 ### we ensure namefiles and var are arrays and we get their size 121 121 if not isinstance(namefiles, np.ndarray): namefiles = [namefiles] 122 122 if not isinstance(var, np.ndarray): var = [var] 123 zelenfile = len(namefiles) ; zelenvar = len(var) 124 ### we check colorbars options (including trycol i.e. the user wants to try a set of colorbars) 125 if trycol: clb = ["Greys","Blues","YlOrRd","jet","spectral","hot","RdBu","RdYlBu","Paired"] ; zetitle = clb ; var = [var[0]]*9 ; zelenvar = len(var) 126 if clb is None: clb = ["def"]*zelenvar 127 elif len(clb) < zelenvar: clb = [clb[0]]*zelenvar ; print "WARNING: less color than vars! setting all to 1st value." 123 128 ### we initialize a few variables 124 129 initime=-1 ; sslon = None ; sslat = None … … 127 132 if slon is not None: sslon = np.zeros([1,2]) 128 133 if slat is not None: sslat = np.zeros([1,2]) 129 if clb is None: clb = ["def"]*len(var)130 elif len(clb) < len(var): clb = [clb[0]]*len(var) ; print "WARNING: less color than vars! setting all to 1st value."131 134 if redope is not None and winds: winds=False ; print "WARNING: no winds with redope. setting winds to False." 132 ### we set option trycol i.e. the user wants to try a set of colorbars133 if trycol: clb = ["Greys","Blues","YlOrRd","jet","spectral","hot","RdBu","RdYlBu","Paired"] ; zetitle = clb ; var = [var[0]]*9134 135 ### we avoid specific cases not yet implemented 135 if mrate is not None and len(var)> 1: myplot.errormess("multivar not allowed in movies. should be fixed soon!")136 if mrate is not None and zelenvar > 1: myplot.errormess("multivar not allowed in movies. should be fixed soon!") 136 137 ### we prepare number of plot fields [zelen] and number of plot instances [numplot] according to user choices 137 138 ### --> we support multifile and multivar plots : files + vars separated by commas are on the same figure 138 139 nlon, nlat, nvert, ntime, mapmode, nslices = myplot.determineplot(slon, slat, svert, stime, redope) 139 zelen = len(namefiles)*len(var)140 zelen = zelenfile*zelenvar 140 141 if (nslices > 1 and monster): myplot.errormess("multislice + monster not supported yet. to be done soon") 141 142 ### we have a special mode obtained by -p noproj in which lat/lon plots are just flat 2D plots … … 143 144 ### we correct number of plot fields for possible operation (substract, etc...) 144 145 if ope is not None: 145 if fileref is not None: zelen = 3* len(var)*len(namefiles)146 if fileref is not None: zelen = 3*zelenvar*zelenfile 146 147 elif "var" in ope: zelen = zelen + 1 147 148 numplot = zelen*nslices 148 print "********** FILES, SLICES, VARS, TOTAL PLOTS: ", len(namefiles), nslices, len(var), numplot149 print "********** FILES, SLICES, VARS, TOTAL PLOTS: ", zelenfile, nslices, zelenvar, numplot 149 150 print "********** MAPMODE: ", mapmode 150 151 ### we define the arrays for plot fields -- which will be placed within multiplot loops … … 160 161 ############################# 161 162 162 for nnn in range( len(namefiles)):163 for vvv in range( len(var)):163 for nnn in range(zelenfile): 164 for vvv in range(zelenvar): 164 165 165 166 ### we load each NETCDF objects in namefiles … … 362 363 ## 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 363 364 if ope is not None: 364 if fileref is not None: index_f = (k//(nlon*nlat*nvert*ntime))%(3* len(namefiles)) ## OK only 1 var, see test in the beginning365 elif "var" in ope: index_f = (k//(nlon*nlat*nvert*ntime))%( len(var)+1) ## OK only 1 file, see test in the beginning365 if fileref is not None: index_f = (k//(nlon*nlat*nvert*ntime))%(3*zelenfile) ## OK only 1 var, see test in the beginning 366 elif "var" in ope: index_f = (k//(nlon*nlat*nvert*ntime))%(zelenvar+1) ## OK only 1 file, see test in the beginning 366 367 elif "cat" in ope: index_f = 0 367 368 elif not (k == 0): 368 #if len(namefiles) > 1 and len(var)== 1 and which == "unidim": pass ## TROUVER UN MOYEN POUR unidim369 if len(namefiles) > 1 and len(var)== 1: pass370 else: yeah = len(namefiles)*len(var); index_f = (k//(nlon*nlat*nvert*ntime))%yeah371 else: yeah = len(namefiles)*len(var); index_f = (k//(nlon*nlat*nvert*ntime))%yeah369 #if zelenfile > 1 and zelenvar == 1 and which == "unidim": pass ## TROUVER UN MOYEN POUR unidim 370 if zelenfile > 1 and zelenvar == 1: pass 371 else: yeah = zelenfile*zelenvar ; index_f = (k//(nlon*nlat*nvert*ntime))%yeah 372 else: yeah = zelenfile*zelenvar ; index_f = (k//(nlon*nlat*nvert*ntime))%yeah 372 373 373 374 ilon = myplot.getsindex(sslon,k%nlon,lon) … … 424 425 if ope is not None and "var" in ope: 425 426 print "********** OPERATION: ",ope 426 if len(namefiles)> 1: myplot.errormess("for this operation... please set only one file !")427 if len(var)> 2: myplot.errormess("not sure this works for more than 2 vars... please check.")427 if zelenfile > 1: myplot.errormess("for this operation... please set only one file !") 428 if zelenvar > 2: myplot.errormess("not sure this works for more than 2 vars... please check.") 428 429 if "div_var" in ope: all_var[k] = all_var[k-2] / all_var[k-1] ; insert = '_div_' 429 430 elif "mul_var" in ope: all_var[k] = all_var[k-2] * all_var[k-1] ; insert = '_mul_' … … 442 443 all_varname[0] = all_varname[k-2] + insert + all_varname[k-1] 443 444 444 445 ##################################446 ### Operation on files (II) without _var447 # we re-iterate on the plots to set operation subplots to make it compatible with multifile (using the same ref file)448 # (k+1)%3==0 is the index of operation plots449 # (k+2)%3==0 is the index of reference plots450 # (k+3)%3==0 is the index of first plots451 opefirstpass=True452 445 if ope is not None and "var" not in ope: 453 446 print "********** OPERATION: ",ope 447 if zelenvar > 1: myplot.errormess("for this operation... please set only one var !") 448 if fileref is None and ope not in ['cat']: myplot.errormess("fileref is missing!") 449 ################################## this is terribly complex for the main program file. got to do something about this 450 ### Operation on files (II) without _var 451 # we re-iterate on the plots to set operation subplots to make it compatible with multifile (using the same ref file) 452 # (k+1)%3==0 is the index of operation plots 453 # (k+2)%3==0 is the index of reference plots 454 # (k+3)%3==0 is the index of first plots 455 opefirstpass=True 454 456 for k in np.arange(zelen): 455 if len(var) > 1: myplot.errormess("for this operation... please set only one var !")456 457 if ope in ["-","+","-%","-_only","+_only","-%_only","-_histo"]: 457 if fileref is None: myplot.errormess("fileref is missing!") 458 else:ncref = Dataset(fileref) 458 ncref = netCDF4.Dataset(fileref) 459 459 460 460 if opefirstpass: ## first plots 461 for ll in np.arange( len(namefiles)):461 for ll in np.arange(zelenfile): 462 462 print "SETTING FIRST PLOT" 463 all_varname[3*ll] = all_varname[ll] ; all_time[3*ll] = all_time[ll] ; all_vert[3*ll] = all_vert[ll] ; all_lat[3*ll] = all_lat[ll] ; all_lon[3*ll] = all_lon[ll] ; all_namefile[3*ll] = all_namefile[ll] ; all_var2[3*ll] = all_var2[ll] ; all_colorb[3*ll] = all_colorb[ll] ; all_var[3*ll] = all_var[ll]463 myplot.alltransfer(3*ll,ll,all_varname,all_time,all_vert,all_lat,all_lon,all_namefile,all_var2,all_colorb,all_var) 464 464 if plot_y[ll] is not None: plot_y[3*ll] = plot_y[ll] ; plot_x[3*ll] = plot_x[ll] 465 465 else: plot_y[3*ll] = None ; plot_x[3*ll] = None … … 468 468 if (k+2)%3==0: ## reference plots 469 469 print "SETTING REFERENCE PLOT" 470 all_varname[k] = all_varname[k-1] ; all_time[k] = all_time[k-1] ; all_vert[k] = all_vert[k-1] ; all_lat[k] = all_lat[k-1] ; all_lon[k] = all_lon[k-1] ; all_namefile[k] = all_namefile[k-1] ; all_var2[k] = all_var2[k-1] ; all_colorb[k] = all_colorb[k-1] 470 myplot.alltransfer(k,k-1,all_varname,all_time,all_vert,all_lat,all_lon,all_namefile,all_var2,all_colorb,all_var) 471 ### all_var is actually overwritten here 471 472 all_var[k], plot_x[k], plot_y[k] = myplot.select_getfield(zvarname=all_varname[k-1],znc=ncref,ztypefile=typefile,mode='getvar',ztsat=tsat,ylon=all_lon[k],ylat=all_lat[k],yalt=all_vert[k],ytime=all_time[k],analysis=analysis) 472 473 if winds: all_windu[k] = myplot.getfield(ncref,uchar) ; all_windv[k] = myplot.getfield(ncref,vchar) … … 499 500 tabtime = all_time[0];tab = all_var[0];k = 1 500 501 if var2: tab2 = all_var2[0] 501 while k != len(namefiles)and len(all_time[k]) != 0:502 while k != zelenfile and len(all_time[k]) != 0: 502 503 if var2: tab2 = np.append(tab2,all_var2[k],axis=0) 503 504 tabtime = np.append(tabtime,all_time[k]) ; tab = np.append(tab,all_var[k],axis=0) ; k += 1 … … 514 515 fig = mpl.pyplot.figure() 515 516 subv,subh = myplot.definesubplot( numplot, fig, ipreferline = (mapmode == 1) ) 516 if ope in ['-','-%','-_histo'] and len(namefiles)==1 : subv,subh = 2,2517 elif ope in ['-','-%'] and len(namefiles)>1 : subv, subh = len(namefiles), 3517 if ope in ['-','-%','-_histo'] and zelenfile ==1 : subv,subh = 2,2 518 elif ope in ['-','-%'] and zelenfile>1 : subv, subh = zelenfile, 3 518 519 519 520 ################################# … … 532 533 ## 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 533 534 if ope is not None: 534 if fileref is not None: index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(3* len(namefiles)) ## OK only 1 var, see test in the beginning535 elif "var" in ope: index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%( len(var)+1) ## OK only 1 file, see test in the beginning535 if fileref is not None: index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(3*zelenfile) ## OK only 1 var, see test in the beginning 536 elif "var" in ope: index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%(zelenvar+1) ## OK only 1 file, see test in the beginning 536 537 elif "cat" in ope: index_f = 0 537 538 elif not firstpass: 538 if len(namefiles) > 1 and len(var)== 1 and which == "unidim": pass539 else: yeah = len(namefiles)*len(var); index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah540 else: yeah = len(namefiles)*len(var); index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah539 if zelenfile > 1 and zelenvar == 1 and which == "unidim": pass 540 else: yeah = zelenfile*zelenvar ; index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah 541 else: yeah = zelenfile*zelenvar ; index_f = ((nplot-1)//(nlon*nlat*nvert*ntime))%yeah 541 542 time = all_time[index_f] ; vert = all_vert[index_f] ; lat = all_lat[index_f] ; lon = all_lon[index_f] 542 543 indexlon = myplot.getsindex(sslon,(nplot-1)%nlon,lon) … … 669 670 which = "unidim" 670 671 if what_I_plot.shape[-1] == 1: print "VALUE VALUE VALUE VALUE ::: ", what_I_plot[0] ; save = 'donothing' 671 ## if which == "unidim" and len(namefiles)> 1: numplot = 1 # this case is similar to several vars from one file672 ## if which == "unidim" and zelenfile > 1: numplot = 1 # this case is similar to several vars from one file 672 673 ##### IMOV LOOP #### IMOV LOOP 673 674 while imov <= iend: … … 780 781 if teststream: 781 782 print 'INFO: Using stream file',streamfile, 'for stream lines' 782 ncstream = Dataset(streamfile)783 ncstream = netCDF4.Dataset(streamfile) 783 784 psi = myplot.getfield(ncstream,'psi') 784 785 psi = psi[0,:,:,0] # time and longitude are dummy dimensions … … 871 872 872 873 elif which == "contour": 873 mpl.pyplot.rcParams['contour.negative_linestyle'] = 'solid' # no dashed line for negative values874 #mpl.pyplot.rcParams['contour.negative_linestyle'] = 'solid' # no dashed line for negative values 874 875 zevminc, zevmaxc = myplot.calculate_bounds(what_I_plot_frame, vmin=min(what_I_plot_frame), vmax=max(what_I_plot_frame)) 875 876 zelevels = np.linspace(zevminc,zevmaxc,ticks/2) #20) … … 880 881 elif var2 == 'wstar': zelevels = np.arange(0,10,1.0) 881 882 elif var2 == 'zmax_th': zelevels = np.arange(0,10,2.0) ; what_I_plot_frame = what_I_plot_frame / 1000. 882 elif var2 in ['u']: zelevels = np.arange(-400.,400., 10.)883 elif var2 in ['u']: zelevels = np.arange(-400.,400.,5.) 883 884 ### 884 885 if mapmode == 0: … … 901 902 if zxmin is not None: mpl.pyplot.xlim(xmin=zxmin) 902 903 if zxmax is not None: mpl.pyplot.xlim(xmax=zxmax) 904 if zxmin is not None and zxmax is not None: 905 ax = mpl.pyplot.gca() 906 ax.get_xaxis().set_ticks(np.linspace(xaxis[0],xaxis[1],ticks/2+1)) 903 907 if zymin is not None: mpl.pyplot.ylim(ymin=zymin) 904 908 if zymax is not None: mpl.pyplot.ylim(ymax=zymax) … … 976 980 nplot += 1 977 981 978 if len(namefiles) > 1 and len(var)== 1 and which == "unidim": index_f=index_f+1982 if zelenfile > 1 and zelenvar == 1 and which == "unidim": index_f=index_f+1 979 983 firstpass=False 980 984
Note: See TracChangeset
for help on using the changeset viewer.