Changeset 1868 in lmdz_wrf for trunk/tools
- Timestamp:
- Mar 26, 2018, 10:59:24 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var_tools.py
r1867 r1868 22867 22867 #quit() 22868 22868 22869 def getvar_listonc(varn, listoc):22869 def getvar_listonc(varn, fns, listoc): 22870 22870 """ Function to get a variable object from a list of netCDF file object 22871 22871 varn= name of the variable to be found 22872 fns= list with the name of the files 22872 22873 listoc= list of NetCDF file objects 22873 22874 """ … … 22875 22876 22876 22877 allfs = {} 22877 fns = []22878 22878 for ioc in range(len(listoc)): 22879 22879 oc = listoc[ioc] 22880 allfs[oc.filepath] = [oc.dimensions, oc.variables.keys()] 22881 fns.append(oc.filepath) 22880 # Seems that ObjNetcdf.filepath() requires netcdf >= 4.1.2.... 22881 # Thus avoiding to use the functionality 22882 #allfs[oc.filepath()] = ... 22883 allfs[fns[ioc]] = [oc.dimensions, oc.variables.keys()] 22882 22884 22883 22885 # Looping for all files … … 22885 22887 for ioc in range(len(listoc)): 22886 22888 oc = listoc[ioc] 22887 oncvars = allfs[ioc] 22889 # Seems that ObjNetcdf.filepath() requires netcdf >= 4.1.2.... 22890 # Thus avoiding to use the functionality 22891 oncvars = allfs[fns[ioc]] 22888 22892 oncvars.sort() 22889 22893 if oc.variables.has_key(varn): … … 22894 22898 if not found: 22895 22899 print errormsg 22896 print ' ' + fname + "': any netcdf file '" + allfs.keys() + "' contain " + \22900 print ' ' + fname + "': any netcdf file '" + ','.join(fns) + "' contain " + \ 22897 22901 "variable '" + varn + "' !!" 22898 22902 print ' available ones _______' … … 22902 22906 listoc[ioc].close() 22903 22907 ioc = ioc + 1 22904 22908 quit(-1) 22905 22909 22906 22910 return ov 22907 22911 22908 def projection2D_information(PROJn, AXinf, projinf, dx, dy, oncs):22912 def projection2D_information(PROJn, AXinf, projinf, dx, dy, Fns, oncs): 22909 22913 """ Function to get the basic information of the 2D-projection: new dimensions, variables, ... 22910 22914 Reproducing: class Projection from wrfncxnj.py 22911 22915 PROJn= name of the projection 22912 AXinf: dictionary with the informatino of the axes 'X', 'Y', 'Z', 'T' 22913 projinf: dictionary with all the information of the projection 22916 AXinf= dictionary with the informatino of the axes 'X', 'Y', 'Z', 'T' 22917 projinf= dictionary with all the information of the projection 22918 Fns= list with the name of the files 22914 22919 oncs= list of netCDF objects from which retrieve the information 22915 22920 Returns: … … 22921 22926 fname = 'projection2D_information' 22922 22927 22923 availproj = ['Lambert_Conformal', 'Rotated_Pole', 'Mercator'] 22928 availproj = ['Lambert_Conformal', 'Rotated_Pole/Rotate_Latituded_Longitude', \ 22929 'Mercator'] 22924 22930 22925 22931 # Explanation of certain attributes in projection file … … 22997 23003 AXinf['Y'] = axv 22998 23004 22999 elif PROJn == "Rotated_Pole" :23005 elif PROJn == "Rotated_Pole" or PROJn == 'Rotated_Latitude_Longitude': 23000 23006 proj_attr = ["grid_mapping_name", "grid_north_pole_latitude", \ 23001 23007 "grid_north_pole_longitude", 'fileXvals', 'fileYvals'] … … 23022 23028 'degrees'] 23023 23029 23024 ovar = getvar_listonc(projinf['fileXvals'][0], oncs)23030 ovar = getvar_listonc(projinf['fileXvals'][0], Fns, oncs) 23025 23031 oXvar = ovar[0] 23026 23032 if len(oXvar.shape) == 3: … … 23043 23049 newdim['rlat'] = dy 23044 23050 newvar['rlat'] = ['grid_latitude', 'latitude in rotated pole grid', 'degrees'] 23045 ovar = getvar_listonc(projinf['fileYvals'][0], oncs)23051 ovar = getvar_listonc(projinf['fileYvals'][0], Fns, oncs) 23046 23052 oYvar = ovar[0] 23047 23053 if len(oYvar.shape) == 3: … … 23116 23122 else: 23117 23123 print errormsg 23118 print ' ' + fname + ": projection '" + + "' not ready !!"23124 print ' ' + fname + ": projection '" + PROJn + "' not ready !!" 23119 23125 print ' available ones:', availproj 23120 23126 quit(-1) … … 23436 23442 23437 23443 # Joining all netCDF files 23438 allonc = exonc + [onc] 23444 allonc = [onc] + exonc 23445 afNs = [ncfile] + extrafiles 23439 23446 allfileNs = {} 23440 23447 for ionc in range(len(allonc)): 23441 23448 onc = allonc[ionc] 23442 allfileNs[ onc.filepath] = [onc.dimensions.keys(), onc.variables.keys()]23449 allfileNs[afNs[ionc]] = [onc.dimensions.keys(), onc.variables.keys()] 23443 23450 23444 23451 # Creation of new file name … … 23476 23483 # Axis values from file 23477 23484 if vardimn != 'WRFtime': 23478 oaxisv = getvar_listonc(vardimn, a llloncs)23485 oaxisv = getvar_listonc(vardimn, afNs, allonc) 23479 23486 else: 23480 23487 print infmsg 23481 23488 print ' ' + fname + ": creation of variable 'time' from WRF 'Times' !!" 23482 odimvar = getvar_listonc('Times', a llloncs)23489 odimvar = getvar_listonc('Times', afNs, allonc) 23483 23490 timewrfv = odimvar[:] 23484 23491 refT = gen.datetimeStr_conversion(gattr['basetime'], 'Y-m-dTH:M:SZ', \ … … 23599 23606 newDim, newVar, newVARv, nonCFproj = projection2D_information(gattr['grid'], \ 23600 23607 CFdimvals, pattr, filedimvals['X'].shape[1], filedimvals['X'].shape[0], \ 23601 a lloncs)23608 afNs, allonc) 23602 23609 23603 23610 if len(newDim.keys()) > 0:
Note: See TracChangeset
for help on using the changeset viewer.