コード例 #1
0
        datergx = re.compile(wrfdate)  # compile regular expression, also used to infer month (later)
        begindate = datergx.search(filelist[0]).group()
        enddate = datergx.search(filelist[-1]).group()
        # load first file to copy some meta data
        wrfout = Dataset(folder + filelist[0], "r", format="NETCDF4")

        # create monthly mean output file
        mean = Dataset(folder + meanfile % ndom, "w", format="NETCDF4")
        add_coord(
            mean, "time", values=None, dtype="i4", atts=dict(units="month since " + begindate)
        )  # unlimited time dimension
        copy_dims(mean, wrfout, dimlist=dimlist, namemap=dimmap, copy_coords=False)  # don't have coordinate variables
        # global attributes
        copy_ncatts(mean, wrfout, prefix="WRF_")  # copy all attributes and save with prefix WRF
        mean.description = "WRF monthly means"
        mean.begin_date = begindate
        mean.end_date = enddate
        mean.experiment = exp
        mean.creator = "Andre R. Erler"

        # create climatology output file
        clim = Dataset(folder + climfile % ndom, "w", format="NETCDF4")
        add_coord(clim, "time", values=mons, dtype="i4", atts=dict(units="month of the year"))  # month of the year
        copy_dims(clim, wrfout, dimlist=dimlist, namemap=dimmap, copy_coords=False)  # don't have coordinate variables
        # variable with proper names of the months
        clim.createDimension("tstrlen", size=9)
        coord = clim.createVariable("month", "S1", ("time", "tstrlen"))
        for m in xrange(nmons):
            for n in xrange(9):
                coord[m, n] = months[m][n]
        # global attributes
コード例 #2
0
   break # skip and go to next domain
 filelist.sort() # sort alphabetically, so that files are in sequence (temporally)
 datergx = re.compile(wrfdate) # compile regular expression, also used to infer month (later)
 begindate = datergx.search(filelist[0]).group()
 enddate = datergx.search(filelist[-1]).group()
 # load first file to copy some meta data
 wrfout = Dataset(folder+filelist[0], 'r', format='NETCDF4')
 
 # create monthly mean output file
 mean = Dataset(folder+meanfile%ndom, 'w', format='NETCDF4')
 add_coord(mean, 'time', values=None, dtype='i4', atts=dict(units='month since '+begindate)) # unlimited time dimension
 copy_dims(mean, wrfout, dimlist=dimlist, namemap=dimmap, copy_coords=False) # don't have coordinate variables
 # global attributes
 copy_ncatts(mean, wrfout, prefix='WRF_') # copy all attributes and save with prefix WRF
 mean.description = 'WRF monthly means'
 mean.begin_date = begindate; mean.end_date = enddate
 mean.experiment = exp
 mean.creator = 'Andre R. Erler'
 
 # create climatology output file
 clim = Dataset(folder+climfile%ndom, 'w', format='NETCDF4')
 add_coord(clim, 'time', values=mons, dtype='i4', atts=dict(units='month of the year')) # month of the year
 copy_dims(clim, wrfout, dimlist=dimlist, namemap=dimmap, copy_coords=False) # don't have coordinate variables
 # variable with proper names of the months
 clim.createDimension('tstrlen', size=9) 
 coord = clim.createVariable('month','S1',('time','tstrlen'))
 for m in xrange(nmons): 
   for n in xrange(9): coord[m,n] = months[m][n]
 # global attributes
 copy_ncatts(clim, wrfout, prefix='WRF_') # copy all attributes and save with prefix WRF
 clim.description = 'climatology of WRF monthly means'
コード例 #3
0
ファイル: avgCESM.py プロジェクト: andrewsoong/WRF-Tools
  # load first file to copy some meta data
  cesmout = Dataset(srcdir+filelist[0], 'r', format='NETCDF4')
  # create climatology output file  
  clim = Dataset(dstdir+climfile, 'w', format='NETCDF4')
  add_coord(clim, 'time', values=mons, dtype='i4', atts=dict(units='month of the year')) # month of the year
  copy_dims(clim, cesmout, dimlist=dimlist, namemap=dimmap, copy_coords=True, dtype='f4') # don't have coordinate variables
  # variable with proper names of the months
  clim.createDimension('tstrlen', size=9) 
  coord = clim.createVariable('month','S1',('time','tstrlen'))
  for m in xrange(nmons): 
    for n in xrange(9): coord[m,n] = months[m][n]
  # global attributes
  copy_ncatts(clim, cesmout, prefix='CESM_') # copy all attributes and save with prefix WRF
  clim.description = 'climatology of CESM monthly means'
  clim.begin_date = begindate; clim.end_date = enddate
  clim.experiment = cesmname
  clim.creator = 'Andre R. Erler'
  # copy constant variables (no time dimension)
  copy_vars(clim, cesmout, varlist=statlist, namemap=varmap, dimmap=dimmap, remove_dims=['time'], copy_data=True)
  
  # check variable list
  for var in varlist:
    if not cesmout.variables.has_key(varmap.get(var,var)):
      print('\nWARNING: variable %s not found in source file!\n'%(var,))
      del var # remove variable if not present in soruce file
  # copy variables to new datasets
  copy_vars(clim, cesmout, varlist=varlist, namemap=varmap, dimmap=dimmap, copy_data=False)
  # length of time, x, and y dimensions
  nvar = len(varlist)
  nlon = len(cesmout.dimensions['lon'])
コード例 #4
0
ファイル: avgWRF.py プロジェクト: zhenkunl/WRF-Tools
                  'time',
                  values=None,
                  dtype='i4',
                  atts=dict(units='month since ' +
                            begindate))  # unlimited time dimension
        copy_dims(mean,
                  wrfout,
                  dimlist=dimlist,
                  namemap=dimmap,
                  copy_coords=False)  # don't have coordinate variables
        # global attributes
        copy_ncatts(
            mean, wrfout,
            prefix='WRF_')  # copy all attributes and save with prefix WRF
        mean.description = 'WRF monthly means'
        mean.begin_date = begindate
        mean.end_date = enddate
        mean.experiment = exp
        mean.creator = 'Andre R. Erler'

        # create climatology output file
        clim = Dataset(folder + climfile % ndom, 'w', format='NETCDF4')
        add_coord(clim,
                  'time',
                  values=mons,
                  dtype='i4',
                  atts=dict(units='month of the year'))  # month of the year
        copy_dims(clim,
                  wrfout,
                  dimlist=dimlist,
                  namemap=dimmap,
コード例 #5
0
   break # skip and go to next domain
 filelist.sort() # sort alphabetically, so that files are in sequence (temporally)
 datergx = re.compile(wrfdate) # compile regular expression, also used to infer month (later)
 begindate = datergx.search(filelist[0]).group()
 enddate = datergx.search(filelist[-1]).group()
 # load first file to copy some meta data
 wrfout = Dataset(folder+filelist[0], 'r', format='NETCDF4')
 
 # create monthly mean output file
 mean = Dataset(folder+meanfile%ndom, 'w', format='NETCDF4')
 add_coord(mean, 'time', values=None, dtype='i4', atts=dict(units='month since '+begindate)) # unlimited time dimension
 copy_dims(mean, wrfout, dimlist=dimlist, namemap=dimmap, copy_coords=False) # don't have coordinate variables
 # global attributes
 copy_ncatts(mean, wrfout, prefix='WRF_') # copy all attributes and save with prefix WRF
 mean.description = 'WRF monthly means'
 mean.begin_date = begindate; mean.end_date = enddate
 mean.experiment = exp
 mean.creator = 'Andre R. Erler'
 
 # create climatology output file
 clim = Dataset(folder+climfile%ndom, 'w', format='NETCDF4')
 add_coord(clim, 'time', values=mons, dtype='i4', atts=dict(units='month of the year')) # month of the year
 copy_dims(clim, wrfout, dimlist=dimlist, namemap=dimmap, copy_coords=False) # don't have coordinate variables
 # variable with proper names of the months
 clim.createDimension('tstrlen', size=9) 
 coord = clim.createVariable('month','S1',('time','tstrlen'))
 for m in xrange(nmons): 
   for n in xrange(9): coord[m,n] = months[m][n]
 # global attributes
 copy_ncatts(clim, wrfout, prefix='WRF_') # copy all attributes and save with prefix WRF
 clim.description = 'climatology of WRF monthly means'
コード例 #6
0
ファイル: avgCESM.py プロジェクト: zhenkunl/WRF-Tools
              cesmout,
              dimlist=dimlist,
              namemap=dimmap,
              copy_coords=True,
              dtype='f4')  # don't have coordinate variables
    # variable with proper names of the months
    clim.createDimension('tstrlen', size=9)
    coord = clim.createVariable('month', 'S1', ('time', 'tstrlen'))
    for m in xrange(nmons):
        for n in xrange(9):
            coord[m, n] = months[m][n]
    # global attributes
    copy_ncatts(clim, cesmout,
                prefix='CESM_')  # copy all attributes and save with prefix WRF
    clim.description = 'climatology of CESM monthly means'
    clim.begin_date = begindate
    clim.end_date = enddate
    clim.experiment = cesmname
    clim.creator = 'Andre R. Erler'
    # copy constant variables (no time dimension)
    copy_vars(clim,
              cesmout,
              varlist=statlist,
              namemap=varmap,
              dimmap=dimmap,
              remove_dims=['time'],
              copy_data=True)

    # check variable list
    for var in varlist:
        if not cesmout.variables.has_key(varmap.get(var, var)):