Example #1
0
                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
        clim.creator = "Andre R. Erler"

        # check variable list
        for var in varlist:
            if not wrfout.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(mean, wrfout, varlist=varlist, namemap=varmap, dimmap=dimmap, copy_data=False)
        copy_vars(clim, wrfout, varlist=varlist, namemap=varmap, dimmap=dimmap, copy_data=False)
        # length of time, x, and y dimensions
        nvar = len(varlist)
        nx = len(wrfout.dimensions[dimmap["x"]])
        ny = len(wrfout.dimensions[dimmap["y"]])
        nfiles = len(filelist)  # number of files
        # close sample input file
        wrfout.close()

        ## compute monthly means and climatology
        # allocate arrays
        print("\n Computing monthly means from %s to %s (incl);" % (begindate, enddate))
        print("%3i fields of shape (%i,%i):\n" % (nvar, nx, ny))
        for var in varlist:
            print("   %s (%s)" % (var, varmap.get(var, var)))
Example #2
0
 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'])
 nlat = len(cesmout.dimensions['lat'])
 nfiles = len(filelist) # number of files
 # close sample input file
 cesmout.close()
Example #3
0
        clim.description = 'climatology of WRF monthly means'
        clim.begin_date = begindate
        clim.end_date = enddate
        clim.experiment = exp
        clim.creator = 'Andre R. Erler'

        # check variable list
        for var in varlist:
            if not wrfout.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(mean,
                  wrfout,
                  varlist=varlist,
                  namemap=varmap,
                  dimmap=dimmap,
                  copy_data=False)
        copy_vars(clim,
                  wrfout,
                  varlist=varlist,
                  namemap=varmap,
                  dimmap=dimmap,
                  copy_data=False)
        # length of time, x, and y dimensions
        nvar = len(varlist)
        nx = len(wrfout.dimensions[dimmap['x']])
        ny = len(wrfout.dimensions[dimmap['y']])
        nfiles = len(filelist)  # number of files
        # close sample input file
        wrfout.close()
Example #4
0
    # 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]
    for (key, value) in hidynset.iteritems():
        copy_vars(higrp, value, [key], namemap=hidynvar, copy_data=False)
        higrp.variables[key][:, :, :] = hidynclim[key]

    ## dataset feedback and diagnostics
    # dataset and groups
#  print outgrp
#  print outgrp.file_format
#  print fngrp
Example #5
0
    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,
Example #6
0
        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]
    for (key, value) in hidynset.iteritems():
        copy_vars(higrp, value, [key], namemap=hidynvar, copy_data=False)
        higrp.variables[key][:, :, :] = hidynclim[key]

    ## dataset feedback and diagnostics
    # dataset and groups
    #  print outgrp
    #  print outgrp.file_format
    #  print fngrp
    #  print higrp
    # dimensions