Changeset 579 for trunk/UTIL/PYTHON/planetoplot.py
- Timestamp:
- Mar 14, 2012, 1:22:19 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UTIL/PYTHON/planetoplot.py
r578 r579 10 10 ### A. Spiga -- LMD -- 12/2011 -- Added HTML animated page capability + general tests of consistency [winds, etc...] + consistent generic movie loop 11 11 ### J. Leconte -- LMD -- 02/2012 -- Added area weighted averaging. Compatibility with terrestrial gcm. 12 ### A. Spiga -- LMD -- 03/2012 -- Cleaning and improved comments 12 13 def planetoplot (namefiles,\ 13 14 level=0,\ … … 86 87 #from singlet import singlet 87 88 88 ################################ 89 ### Preliminary stuff 90 ################################ 89 ######################### 90 ### PRELIMINARY STUFF ### 91 ######################### 92 ### we say hello 91 93 print "********************************************" 92 94 print "********** WELCOME TO PLANETOPLOT **********" 93 95 print "********************************************" 96 ### we ensure namefiles and var are arrays 94 97 if not isinstance(namefiles, np.ndarray): namefiles = [namefiles] 95 98 if not isinstance(var, np.ndarray): var = [var] 96 initime=-1 97 98 ################################ 99 ### Which plot needs to be done? 100 ################################ 101 sslon = None ; sslat = None 99 ### we initialize a few variables 100 initime=-1 ; sslon = None ; sslat = None 101 k = 0 ; firstfile = True ; count = 0 102 ### we avoid specific cases not yet implemented 103 if mrate is not None and len(var) > 1: errormess("multivar not allowed in movies. should be fixed soon!") 104 ### we prepare number of plot fields [zelen] and plot instances [numplot] according to user choices 105 ### --> we support multifile and multivar plots : files + vars separated by commas are on the same figure 102 106 nlon, nlat, nvert, ntime, mapmode, nslices = determineplot(slon, slat, svert, stime) 103 if mrate is not None and len(var) > 1: errormess("multivar not allowed in movies. should be fixed soon!")104 107 zelen = len(namefiles)*len(var) 105 108 numplot = zelen*nslices 106 109 print "********** FILES, SLICES, VARS, TOTAL PLOTS: ", len(namefiles), nslices, len(var), numplot 110 print "********** MAPMODE: ", mapmode 111 ### we correct number of plot fields for possible operation (substract, etc...) 107 112 if ope is not None: 108 113 if fileref is not None: zelen = zelen + 2 109 114 elif "var" in ope: zelen = zelen + 1 110 all_var = [[]]*zelen ; all_var2 = [[]]*zelen ; all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen ; all_windu = [[]]*zelen ; all_windv = [[]]*zelen 115 ### we define the arrays for plot fields -- which will be placed within multiplot loops 116 all_var = [[]]*zelen ; all_var2 = [[]]*zelen 117 all_title = [[]]*zelen ; all_varname = [[]]*zelen ; all_namefile = [[]]*zelen ; all_time = [[]]*zelen 118 all_windu = [[]]*zelen ; all_windv = [[]]*zelen 111 119 112 ################################################################################################# 113 ### Loop over the files + vars initially separated by commas to be plotted on the same figure ### 114 ################################################################################################# 115 k = 0 ; firstfile = True ; count = 0 120 ############################# 121 ### LOOP OVER PLOT FIELDS ### 122 ############################# 116 123 for nnn in range(len(namefiles)): 117 124 for vvv in range(len(var)): 118 125 119 ###################### 120 ### Load NETCDF object 126 ### we load each NETCDF objects in namefiles 121 127 namefile = namefiles[nnn] 122 128 nc = Dataset(namefile) 129 ### we explore the variables in the file 123 130 varinfile = nc.variables.keys() 124 131 if seevar: print varinfile ; exit() 125 126 ################################## 127 ### Initial checks and definitions 128 ### ... TYPEFILE 132 ### we define the type of file we have (gcm, meso, etc...) 129 133 typefile = whatkindfile(nc) 134 if firstfile: typefile0 = typefile 135 elif typefile != typefile0: errormess("Not the same kind of files !", [typefile0, typefile]) 136 ### we care for input file being 1D simulations 130 137 if typefile in ['gcm'] and len(nc.variables["longitude"][:]) is 1 and len(nc.variables["latitude"][:]) is 1: mapmode=0 ; winds=False 131 138 elif typefile in ['earthgcm'] and len(nc.variables["lon"][:]) is 1 and len(nc.variables["lat"][:]) is 1: mapmode=0 ; winds=False 139 ### we create default vert and time prescriptions if not here in case mapping mode is on (lat/lon maps) 132 140 if redope is None and mapmode == 1: 133 141 if svert is None: svert = readslices(str(level)) ; nvert=1 … … 135 143 stime = readslices(str(0)) ; ntime=1 ## this is a default choice 136 144 print "WELL... nothing about time axis. I took default: first time reference stored in file." 137 138 if firstfile: print "********** MAPMODE: ", mapmode 139 if firstfile: typefile0 = typefile 140 elif typefile != typefile0: errormess("Not the same kind of files !", [typefile0, typefile]) 141 ### ... VAR 145 ### we get the names of variables to be read. in case only one available, we choose this one. 142 146 varname=var[vvv] 143 147 if ((varname not in nc.variables) and not ((typefile in ['meso']) and (varname in ['UV','uv','uvmet']))): 144 148 if len(varinfile) == 1: varname = varinfile[0] 145 149 else: varname = False 146 ### ... WINDS150 ### we get the names of wind variables to be read (if any) 147 151 if winds: 148 152 [uchar,vchar,metwind] = getwinddef(nc) 149 153 if uchar == 'not found': winds = False 154 ### we tell the user that either no var or no wind is not acceptable 150 155 if not varname and not winds: errormess("please set at least winds or var",printvar=nc.variables) 151 ### ... COORDINATES, could be moved below156 ### we get the coordinates lat/lon to be used 152 157 [lon2d,lat2d] = getcoorddef(nc) 153 ### ... PROJECTION158 ### we get an adapted map projection if none is provided by the user 154 159 if proj == None: proj = getproj(nc) 155 160 ### we define plot boundaries given projection or user choices 156 161 if firstfile: 157 ##########################158 ### Define plot boundaries159 ### todo: possible areas in latinterv in argument (ex: "Far_South_Pole")160 162 if proj in ["npstere","spstere"]: [wlon,wlat] = polarinterv(lon2d,lat2d) 161 163 elif proj in ["lcc","laea"]: [wlon,wlat] = wrfinterv(lon2d,lat2d) … … 493 495 if not tile: zeline='-' 494 496 else: zeline=',' 495 if indexvert is not None or indextime is None: plot(x,what_I_plot_frame,zeline,label=lbl) ## regular plot 496 else: plot(what_I_plot_frame,x,zeline,label=lbl) ## vertical profile 497 this_is_a_regular_plot = (indexvert is not None) or (indextime is None) or (indexlat is None) or (indexlon is None) 498 if this_is_a_regular_plot: plot(x,what_I_plot_frame,zeline,label=lbl) ## vertical profile 499 else: plot(what_I_plot_frame,x,zeline,label=lbl) ## regular plot 497 500 if nplot > 1: legend(loc='best') 498 501 if indextime is None and axtime is not None and xlab is None: xlabel(axtime.upper()) ## define the right label
Note: See TracChangeset
for help on using the changeset viewer.