Changeset 1855 in lmdz_wrf
- Timestamp:
- Mar 25, 2018, 6:56:17 PM (7 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/nc_var.py
r1847 r1855 18 18 ## e.g. # nc_var.py -o WRF_to_newCF -f wrfout_d01_1995-01-01_00\:00\:00 -S 'XLONG:XLAT:Times:19491201000000:minutes' -v QVAPOR,T2,Q2 19 19 ## e.g. # nc_var.py -o reconstruct_matrix_from_vector -f cruncep_halfdeg_1958.nc -S 'nav_lon:nav_lat:-90.:-7.:-67.:15.:latlon:0.5:0.5:0.05' -v all 20 ## e.g. # nc_var.py -o CFmorzization -S 'X|west_east|XLONG,Y|south_north|XLAT,T|Time|WRFtime,Z|bottom_top|ZNU:GlobalAttr1995.inf:proj1995.inf' -f ~/PY/wrfout_d01_1995-01-01_00\:00\:00 -v QFX20 ## e.g. # nc_var.py -o nc_var.py -o CFmorzization -S 'X|west_east|XLONG,Y|south_north|XLAT,T|Time|WRFtime,Z|bottom_top|ZNU:GlobalAttr1995.inf:proj1995.inf' -f ~/PY/wrfout_d01_1995-01-01_00\:00\:00 -v QFX@instantaneous@None 21 21 22 22 ## e.g. ccrc468-17 # ./nc_var.py -v time -f 123/CCRC_NARCliM_Sydney_All_1990-1999_pr10max.nc -o out -S 1:-1 -
trunk/tools/nc_var_tools.py
r1853 r1855 22618 22618 quit(-1) 22619 22619 22620 Nbnds = int( dFCt/ dtbnds)22620 Nbnds = int((dFCt + dtbnds)/ dtbnds) 22621 22621 if Nbnds < 2: 22622 22622 print errormsg … … 22660 22660 #otime = onc.variables['Times'] 22661 22661 #wtimev = otime[:] 22662 #tbnds, tc, tu = compute_WRFtime_bnds(wtimev, ' i,1', kindWRFt='begperiod', \22662 #tbnds, tc, tu = compute_WRFtime_bnds(wtimev, 'd,1', kindWRFt='begperiod', \ 22663 22663 # refdate='19491201000000', tunitsval='minutes') 22664 22664 … … 22727 22727 proj_units [value] (units of the resoltion of the projection) 22728 22728 ncfile= netCDF file to use 22729 variable= ',' list of variables to CF transform ('all' for all variables). A separated file will be created 22730 for each variable 22729 variable= ',' list of [varfn]@[method]@[Tbnds] to CF transform. A separated file will be 22730 created for each variable 22731 use [varfn]@instantaneous@None for instantaneous values 22731 22732 NOTE: CF values will be taken from 'variables_values.dat' 22733 [varfn]: name of the variable inside the file 22734 [method]: cell_method of the variable ('!' for spaces) uing, standard CF description: 22735 http://cfconventions.org/cf-conventions/cf-conventions.html#_data_representative_of_cells 22736 [var_time_bnds]: variable with the time_bnds values ('WRFtime_bnds'|[tunit]|[quantity], to be computed 22737 directly from WRF) 22738 'WRFtime_bnds'|[tunit]|[quantity] period to compute the bounds as: 22739 [tunit]: unit of time: 'c' century, 'y' year, 'm' month, 'w' week, 'd' day, 22740 'h' hour, 'i' minute, 's' second 22741 [quantity] = amount (integer) of [tunit] to cover a period of time_bnds 22732 22742 """ 22733 22743 import datetime as dt … … 23049 23059 print ' ', axn 23050 23060 print ' ', CFdimvals[axn] 23051 print ' Values for variables-axes ________'23061 print 'Dimensions for variables-axes ________' 23052 23062 for axn in axes: 23053 23063 print ' ', axn, ':', CFaxisvardimvals[axn] … … 23055 23065 # Processing variables in file 23056 23066 ## 23057 for vn in Varns: 23067 for vtmn in Varns: 23068 vn = vtmn.split('@')[0] 23069 vm = vtmn.split('@')[1].replace('!', ' ') 23070 vtb = vtmn.split('@')[2] 23071 23058 23072 # getting CF information 23059 23073 varinf = gen.variables_values(vn) … … 23163 23177 onewnc.sync() 23164 23178 23179 # time_bnds 23180 if vm != 'instantaneous': 23181 print infmsg 23182 print ' ' + fname + ": Adding 'time_bnds' variable ..." 23183 set_attribute(newvar, 'cell_methods', vm) 23184 ovtime = onewnc.variables['time'] 23185 set_attribute(ovtime, 'bounds', 'time_bnds') 23186 if vtb[0:12] == 'WRFtime_bnds': 23187 vtbvals = vtb.split('|') 23188 if len(vtbvals) != 3: 23189 print errormsg 23190 print ' ' + fname + ": to compute 'time_bnds' from WRF " + \ 23191 "'Times', one needs to provide the period of the " + \ 23192 "bounds as: 'WRFtime_bnds'|[tunit]|[quantity]" 23193 print " values passed: '" + vtb 23194 onc.close() 23195 quit(-1) 23196 period = vtbvals[1] + ',' + vtbvals[2] 23197 print infmsg 23198 print ' ' + fname + ": creation of variable 'time_bnds' " + \ 23199 "from WRF 'Times' using period '" + period + "' !!" 23200 odimvar = onc.variables['Times'] 23201 timewrfv = odimvar[:] 23202 refT = gen.datetimeStr_conversion(gattr['basetime'], \ 23203 'Y-m-dTH:M:SZ', 'YmdHMS') 23204 tbvals, tvals, urefvals = compute_WRFtime_bnds(timewrfv, period, \ 23205 kindWRFt='begperiod', refdate=refT, tunitsval='minutes') 23206 else: 23207 if not onc.variables.has_key(vardimn): 23208 print errormsg 23209 print ' '+fname+"': netcdf file '"+ncfile + "' does not " + \ 23210 "contain variable '" + vardimn+ "' with time_bnds values !!" 23211 print ' available ones:', oncvars 23212 onc.close() 23213 quit(-1) 23214 tbvals = onc.variables[vardimn] 23215 # Re-setting time values to the center of the bounds 23216 ovtime[:] = tvals[:] 23217 onewnc.sync() 23218 23219 # creation of time_bnds variable 23220 if not gen.searchInlist(onewnc.dimensions, 'nv'): 23221 onewnc.createDimension('nv', 2) 23222 newvar = onewnc.createVariable('time_bnds', 'f8', ('time', 'nv')) 23223 newvar[:] = tbvals[:] 23224 23165 23225 # Adding projection variable 23166 23226 print infmsg
Note: See TracChangeset
for help on using the changeset viewer.