Changeset 1855 in lmdz_wrf


Ignore:
Timestamp:
Mar 25, 2018, 6:56:17 PM (7 years ago)
Author:
lfita
Message:

Working version with `time_bnds' of 'CFmorziation'

Location:
trunk/tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/nc_var.py

    r1847 r1855  
    1818## 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
    1919## 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 QFX
     20## 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
    2121
    2222## 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  
    2261822618        quit(-1)
    2261922619
    22620     Nbnds = int(dFCt / dtbnds)
     22620    Nbnds = int((dFCt + dtbnds)/ dtbnds)
    2262122621    if Nbnds < 2:
    2262222622        print errormsg
     
    2266022660#otime = onc.variables['Times']
    2266122661#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',            \
    2266322663#  refdate='19491201000000', tunitsval='minutes')
    2266422664
     
    2272722727               proj_units [value] (units of the resoltion of the projection)
    2272822728        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
    2273122732          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
    2273222742    """
    2273322743    import datetime as dt
     
    2304923059        print '  ', axn
    2305023060        print '  ', CFdimvals[axn]
    23051     print 'Values for variables-axes ________'
     23061    print 'Dimensions for variables-axes ________'
    2305223062    for axn in axes:
    2305323063        print '  ', axn, ':', CFaxisvardimvals[axn]
     
    2305523065    # Processing variables in file
    2305623066    ##
    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
    2305823072        # getting CF information
    2305923073        varinf = gen.variables_values(vn)
     
    2316323177            onewnc.sync()
    2316423178
     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
    2316523225        # Adding projection variable
    2316623226        print infmsg
Note: See TracChangeset for help on using the changeset viewer.