コード例 #1
0
ファイル: avgGPCC.py プロジェクト: andrewsoong/WRF-Tools
 # create groups for different resolution
 outdata = Dataset(GPCCroot+test+outfile, 'w', format='NETCDF4') # outgrp.createGroup('fineres')
 # new time dimensions
 months = ['January  ', 'February ', 'March    ', 'April    ', 'May      ', 'June     ', #
           'July     ', 'August   ', 'September', 'October  ', 'November ', 'December ']
 # create time dimensions and coordinate variables
 add_coord(outdata,'time',np.arange(1,ntime+1),dtype='i4')
 outdata.createDimension('tstrlen', 9) # name of month string
 outdata.createVariable('ndays','i4',('time',))[:] = days_per_month
 # names of months (as char array)
 coord = outdata.createVariable('month','S1',('time','tstrlen'))
 for m in xrange(ntime): 
   for n in xrange(9): coord[m,n] = months[m][n]
 # global attributes
 outdata.description = 'Climatology of GPCC monthly precipitation, averaged from %04i to %04i'%(debyr,finyr)
 outdata.creator = 'Andre R. Erler' 
 copy_ncatts(outdata,indata['rain'],prefix='GPCC_')
 # create old lat/lon dimensions and coordinate variables
 copy_dims(outdata, indata['rain'], dimlist=dimlist.keys(), namemap=dimlist, copy_coords=True)
 # create climatology variables  
 dims = ('time','lat','lon'); fill_value = -9999
 # precipitation
 atts = dict(long_name='Precipitation', units='mm/day')
 add_var(outdata, 'rain', dims, values=climdata['rain'].filled(fill_value), atts=atts, fill_value=fill_value)
 # station density
 atts = dict(long_name='Station Density', units='#')
 add_var(outdata, 'stns', dims, values=climdata['stns'].filled(fill_value), atts=atts, fill_value=fill_value)  
 # land mask
 atts = dict(long_name='Land Mask', units='')
 tmp = ma.masked_array(ma.ones((datashape[1],datashape[2])), mask=dataMask)
 add_var(outdata, 'landmask', ('lat','lon'), values=tmp.filled(0))
コード例 #2
0
        # 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"
        clim.begin_date = begindate
コード例 #3
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
 copy_ncatts(clim, wrfout, prefix='WRF_') # copy all attributes and save with prefix WRF
 clim.description = 'climatology of WRF monthly means'
 clim.begin_date = begindate; clim.end_date = enddate
 clim.experiment = exp
コード例 #4
0
ファイル: avgWRF.py プロジェクト: zhenkunl/WRF-Tools
                  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)
コード例 #5
0
ファイル: avgCFSR.py プロジェクト: zhenkunl/WRF-Tools
        grp.createVariable('ndays', 'i4', ('time', ))[:] = days
        # names of months (as char array)
        coord = grp.createVariable('month', 'S1', ('time', 'tstrlen'))
        for m in xrange(ntime):
            for n in xrange(9):
                coord[m, n] = months[m][n]
    # global attributes
    if finmon:        description = \
'Climatology of CFSR monthly means, averaged from January 1979 to %s %04i'%(months[finmon],1979+finyr-1)
    else:
        description = 'Climatology of CFSR monthly means, averaged from 1979 to %04i' % (
            1979 + finyr - 1)
    creator = 'Andre R. Erler'
    # fine grid
    fngrp.description = description
    fngrp.creator = creator
    copy_ncatts(fngrp, fndynset['rain'], prefix='CFSR_')
    #  for att in fndynset['prt'].ncattrs(): fngrp.setncattr('SRC_'+att,fndynset['prt'].getncattr(att))
    higrp.description = description
    higrp.creator = creator
    copy_ncatts(fngrp, hidynset['pmsl'], prefix='CFSR_')
    # create old lat/lon dimensions and coordinate variables
    copy_dims(fngrp,
              fndynset['rain'],
              dimlist=fndim.keys(),
              namemap=fndim,
              copy_coords=True)
    copy_dims(higrp,
              hidynset['pmsl'],
              dimlist=hidim.keys(),
              namemap=hidim,
コード例 #6
0
ファイル: avgCRU.py プロジェクト: zhenkunl/WRF-Tools
 # create groups for different resolution
 outdata = Dataset(CRUroot+test+outfile, 'w', format='NETCDF4') # outgrp.createGroup('fineres')
 # new time dimensions
 months = ['January  ', 'February ', 'March    ', 'April    ', 'May      ', 'June     ', #
           'July     ', 'August   ', 'September', 'October  ', 'November ', 'December ']
 # create time dimensions and coordinate variables
 add_coord(outdata,'time',np.arange(1,ntime+1),dtype='i4')
 outdata.createDimension('tstrlen', 9) # name of month string
 outdata.createVariable('ndays','i4',('time',))[:] = days_per_month
 # names of months (as char array)
 coord = outdata.createVariable('month','S1',('time','tstrlen'))
 for m in xrange(ntime): 
   for n in xrange(9): coord[m,n] = months[m][n]
 # global attributes
 outdata.description = 'Climatology of CRU monthly climate data, averaged from %04i to %04i'%(debyr,finyr)
 outdata.creator = 'Andre R. Erler' 
 copy_ncatts(outdata,indata['rain'],prefix='CRU_')
 # create old lat/lon dimensions and coordinate variables
 copy_dims(outdata, indata['rain'], dimlist=dimlist.keys(), namemap=dimlist, copy_coords=True)
 # create climatology variables  
 dims = ('time','lat','lon'); fill_value = -9999
 # precipitation
 atts = dict(long_name='Precipitation', units='mm/day')
 add_var(outdata, 'rain', dims, values=climdata['rain'].filled(fill_value), atts=atts, fill_value=fill_value)
 # 2m mean Temperature
 atts = dict(long_name='Temperature at 2m', units='K')
 add_var(outdata, 'T2', dims, values=climdata['T2'].filled(fill_value), atts=atts, fill_value=fill_value)  
 # 2m maximum Temperature
 atts = dict(long_name='Maximum 2m Temperature', units='K')
 add_var(outdata, 'Tmax', dims, values=climdata['Tmax'].filled(fill_value), atts=atts, fill_value=fill_value)  
 # 2m minimum Temperature
コード例 #7
0
ファイル: avgCFSR.py プロジェクト: xiefengy/WRF-Tools
     coord = grp.createVariable("month", "S1", ("time", "tstrlen"))
     for m in xrange(ntime):
         for n in xrange(9):
             coord[m, n] = months[m][n]
 # global attributes
 if finmon:
     description = "Climatology of CFSR monthly means, averaged from January 1979 to %s %04i" % (
         months[finmon],
         1979 + finyr - 1,
     )
 else:
     description = "Climatology of CFSR monthly means, averaged from 1979 to %04i" % (1979 + finyr - 1)
 creator = "Andre R. Erler"
 # fine grid
 fngrp.description = description
 fngrp.creator = creator
 copy_ncatts(fngrp, fndynset["rain"], prefix="CFSR_")
 #  for att in fndynset['prt'].ncattrs(): fngrp.setncattr('SRC_'+att,fndynset['prt'].getncattr(att))
 higrp.description = description
 higrp.creator = creator
 copy_ncatts(fngrp, hidynset["pmsl"], prefix="CFSR_")
 # create old lat/lon dimensions and coordinate variables
 copy_dims(fngrp, fndynset["rain"], dimlist=fndim.keys(), namemap=fndim, copy_coords=True)
 copy_dims(higrp, hidynset["pmsl"], dimlist=hidim.keys(), namemap=hidim, copy_coords=True)
 # copy static variables into new dataset
 for (key, value) in fnstatset.iteritems():
     copy_vars(fngrp, value, [key], namemap=fnstatvar, remove_dims=["time"], incl_=False)  # '_' causes problems
 # create dynamic/time-dependent variables
 for (key, value) in fndynset.iteritems():
     copy_vars(fngrp, value, [key], namemap=fndynvar, copy_data=False)
     fngrp.variables[key][:, :, :] = fndynclim[key]