Changeset 1864 in lmdz_wrf
- Timestamp:
- Mar 26, 2018, 7:31:53 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/CFvariables.dat
r1863 r1864 1 1 # File with the values of actions to be done for specific CF variables 2 # [cfvarname] [action] [ newdimension] [newvardim] [newvarvaluesdim]2 # [cfvarname] [action] [values] 3 3 # [action] ________ 4 # new_z_dim: add a z dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim] 4 # new_z_dim: add a height dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim] 5 # # [cfvarname] new_z_dim [newdimension] [newvardim] [newvarvaluesdim] 6 # new_p_dim: add a pressure dimension named [newdimension] with an associated variable-dimension [newvardim] with value [newvarvaluesdim] 7 # # [cfvarname] new_p_dim [newdimension] [newvardim] [newvarvaluesdim] 5 8 # 9 # [newvarvaluesdim] _______ 10 # [number]: direct value to use 11 # Fromfile,[varn]: value to be taken from variable [varn] present in file 6 12 huss new_z_dim height height 2. 7 13 tas new_z_dim height height 2. 8 14 uas new_z_dim height height 10. 9 15 vas new_z_dim height height 10. 16 hus new_z_dim pressure pressure 'FROMfile,press' 17 ta new_z_dim pressure pressure 'FROMfile,press' 18 ua new_z_dim pressure pressure 'FROMfile,press' 19 va new_z_dim pressure pressure 'FROMfile,press' 20 wa new_z_dim pressure pressure 'FROMfile,press' 21 zg new_z_dim pressure pressure 'FROMfile,press' 10 22 -
trunk/tools/nc_var_tools.py
r1863 r1864 22866 22866 #quit() 22867 22867 22868 def projection2D_information(PROJn, AXinf, projinf, dx, dy, onc ):22868 def projection2D_information(PROJn, AXinf, projinf, dx, dy, oncs): 22869 22869 """ Function to get the basic information of the 2D-projection: new dimensions, variables, ... 22870 22870 Reproducing: class Projection from wrfncxnj.py … … 22872 22872 AXinf: dictionary with the informatino of the axes 'X', 'Y', 'Z', 'T' 22873 22873 projinf: dictionary with all the information of the projection 22874 onc = netCDF objectfrom which retrieve the information22874 oncs= netCDF objects from which retrieve the information 22875 22875 Returns: 22876 22876 newdim: dictionary new dimensions to be added {dimn1: dimlength1, ..., dimnN: dimlengthN} … … 22981 22981 newvar['rlon'] = ['grid_longitude', 'longitude in rotated pole grid', \ 22982 22982 'degrees'] 22983 if not gen.searchInlist(onc.variables.keys(),projinf['fileXrefvals'][0]): 22983 found = Flase 22984 fileNs = '' 22985 for ionc in range(len(oncs)): 22986 onc = oncs[ionc] 22987 fileNs = fileNs + onc.filepath + ', ' 22988 if gen.searchInlist(onc.variables.keys(),projinf['fileXrefvals'][0]): 22989 oXvar = onc.variables[projinf['fileXvals'][0]] 22990 break 22991 if not found: 22984 22992 print errormsg 22985 print ' ' + fname + ": file does not have variable with X ref values '"+\22986 projinf['fileXrefvals'][0] + "' !!"22993 print ' ' + fname + ": files: " + fileNs + " do not have variable " + \ 22994 "with X ref values '" + projinf['fileXrefvals'][0] + "' !!" 22987 22995 print ' available ones:', onc.variables.keys() 22988 22996 quit(-1) 22989 oXvar = onc.variables[projinf['fileXvals'][0]]22990 22997 if len(oXvar.shape) == 3: 22991 22998 newvarv['rlon'] = oXvar[0,0,:] … … 23091 23098 return newdim, newvar, newvarv, nonCFattr 23092 23099 23093 def CFvars(cfvarn, vardims, varvalues, outnc):23100 def CFvars(cfvarn, innc, vardims, varvalues, outnc): 23094 23101 """ Function to adapt a given variable and file following CF-standards 23095 23102 NOTE: reading information from 'CFvariables.dat' 23096 23103 cfvarn= provided CF name of the variabale 23104 innc= netCDF object with input 23097 23105 vardims= dimensions of the variable 23098 23106 varvalues= values of the variable … … 23125 23133 action = CFactions[0] 23126 23134 23127 # Adding z-dimension23128 if action == 'new_ z_dim':23135 # Adding p-dimension 23136 if action == 'new_p_dim': 23129 23137 newdim = CFactions[1] 23130 23138 newvdim = CFactions[2] 23131 newvvar = np.float(CFactions[3]) 23139 if CFactions[3].find('FROMfile') == -1: 23140 newvvar = np.float(CFactions[3]) 23141 else: 23142 vn = CFactinos[3].split[0] 23143 if not innc.variables.has_key(vn): 23144 print errormsg 23145 print ' ' + fname + ": input file does not have variable '" + vn\ 23146 + "' !!" 23147 print ' available ones:', innc.variables.keys() 23148 quit(-1) 23149 ovar = innc.variables[vn] 23150 # Assuming all the same value! 23151 var1D = ovar.flatten() 23152 newvvar = var1D[0] 23153 outnc.createDimension(newdim, 1) 23154 dimvals = gen.CFcorValues(newdim) 23155 if not gen.searchInlist(outnc.dimensions, newdim): 23156 newdim = outnc.createDimension(newdim, 1) 23157 if not outnc.variables.has_key(newvdim): 23158 newvar = outnc.createVariable(newvdim, 'f8', (newdim)) 23159 basicvardef(newvar, dimvals['stdn'], dimvals['longname'], \ 23160 dimvals['units']) 23161 newvar[:] = newvvar 23162 for ivn in dimvals.keys(): 23163 if ivn != 'dimn' and ivn != 'stdn' and ivn != 'longname' and \ 23164 ivn != 'units' and ivn != 'maxrank' and ivn != 'length': 23165 set_attribute(newvar,ivn,dimvals[ivn]) 23166 newvdn = [] 23167 newvshape = [] 23168 idim = 0 23169 for vdn in vardims: 23170 if vdn == 'time': 23171 newvdn.append(vdn) 23172 newvshape.append(varvalues.shape[idim]) 23173 newvdn.append(newdim) 23174 newvshape.append(1) 23175 else: 23176 newvdn.append(vdn) 23177 newvshape.append(varvalues.shape[idim]) 23178 idim = idim + 1 23179 newvarvalues = np.zeros(tuple(newvshape), dtype=np.float) 23180 newvarvalues[:,0,:,:] = varvalues 23181 23182 # Adding z-dimension 23183 elif action == 'new_z_dim': 23184 newdim = CFactions[1] 23185 newvdim = CFactions[2] 23186 if CFactions[3].find('FROMfile') == -1: 23187 newvvar = np.float(CFactions[3]) 23188 else: 23189 vn = CFactinos[3].split[0] 23190 if not innc.variables.has_key(vn): 23191 print errormsg 23192 print ' ' + fname + ": input file does not have variable '" + vn\ 23193 + "' !!" 23194 print ' available ones:', innc.variables.keys() 23195 quit(-1) 23196 ovar = innc.variables[vn] 23197 # Assuming all the same value! 23198 var1D = ovar.flatten() 23199 newvvar = var1D[0] 23132 23200 outnc.createDimension(newdim, 1) 23133 23201 dimvals = gen.CFcorValues(newdim) … … 23175 23243 (http://cmip-pcmdi.llnl.gov/cmip5/output_req.html#metadata) 23176 23244 23177 values=[dimvarns]:[globattrfile]:[projectfile] 23245 values=[dimvarns]:[globattrfile]:[projectfile]:[extrafiles] 23178 23246 [dimvarns]: ',' separated list for identification of axes, dimensions and 23179 23247 variable-dimensions as '[AXIS]|[dimn]|[vardimn]' … … 23220 23288 y_resoltuion [value] (resolution along y-axis) 23221 23289 proj_units [value] (units of the resoltion of the projection) 23290 [extrafiles]: ',' list of netCDF files to be used if any additional variable is needed (use 'None' for any) 23222 23291 ncfile= netCDF file to use 23223 23292 variable= ',' list of [varfn]@[method]@[Tbnds] to CF transform. A separated file will be 23224 23293 created for each variable 23225 23294 use [varfn]@instantaneous@None for instantaneous values 23226 NOTE: CF values will be taken from 'variables_values.dat' 23295 NOTE: CF values will be taken from 'variables_values.dat' and 'CFvariables.dat' for fine tunning 23227 23296 [varfn]: name of the variable inside the file 23228 23297 [method]: cell_method of the variable ('!' for spaces) uing, standard CF description: … … 23247 23316 quit() 23248 23317 23249 expectargs = '[dimvarns]:[globattrfilen]:[projectfile] '23318 expectargs = '[dimvarns]:[globattrfilen]:[projectfile]:[extrafiles]' 23250 23319 gen.check_arguments(fname, values, expectargs, ':') 23251 23320 … … 23253 23322 globalattrfilen = values.split(':')[1] 23254 23323 projfilen = values.split(':')[2] 23324 extrafiles = values.split(':')[3].split(',') 23325 23326 exonc = [] 23327 if extrafiles[0] != 'None': 23328 for fln in extrafiles: 23329 if not os.path.isfile(fln): 23330 print errormsg 23331 print ' '+fname+"': netCDF extra file '" +fln+ "' does not exist !!" 23332 quit(-1) 23333 else: 23334 exonc.append(NetCDFFile(fln,'r')) 23255 23335 23256 23336 # CF Mandatory global attributes … … 23496 23576 if len(filedimvals['X'].shape) == 2 or len(filedimvals['Y'].shape) == 2: 23497 23577 newDim, newVar, newVARv, nonCFproj = projection2D_information(gattr['grid'], \ 23498 CFdimvals, pattr, filedimvals['X'].shape[1], filedimvals['X'].shape[0], onc) 23578 CFdimvals, pattr, filedimvals['X'].shape[1], filedimvals['X'].shape[0], \ 23579 exonc + [onc]) 23499 23580 23500 23581 if len(newDim.keys()) > 0: … … 23645 23726 elif cdn == 'time': print ' ' 23646 23727 else: coorv.append(cdn) 23647 newVdims, newVvalues = CFvars(cfvarn, CFvardims, ovar[:], onewnc)23728 newVdims, newVvalues = CFvars(cfvarn, onc, CFvardims, ovar[:], onewnc) 23648 23729 if newVdims is None: 23649 23730 newvar=onewnc.createVariable(cfvarn, 'f4', tuple(CFvardims), \
Note: See TracChangeset
for help on using the changeset viewer.