Example #1
0
 root_grp.XCENT = 10.
 root_grp.YCENT = 52.
 root_grp.XORIG = XORIG
 root_grp.YORIG = YORIG
 root_grp.XCELL = float(grd) * 1000  # Domain in km
 root_grp.YCELL = float(grd) * 1000
 root_grp.IUTM = np.int32(0)  # ?
 root_grp.CPROJ = np.int32(2)  # ?
 root_grp.ITZON = np.int32(0)  # ?
 root_grp.VAR_LIST = '      '.join(specs)
 root_grp.NAME = "EMISSIONS"
 root_grp.history = "Created " + dt.datetime.today().strftime(
     "%d%m%Y")
 root_grp.FILEDESC = "EMISSIONS"
 root_grp.FTYPE = np.int32(1)  # ? [IO-API file type = CUSTOM3]
 root_grp.CDATE = np.int32(dt.datetime.today().strftime(
     "%Y%j"))  # [IO-API file creation date]
 root_grp.CTIME = np.int32(dt.datetime.today().strftime(
     "%k%M%S"))  # [IO-API file creation time]
 root_grp.WDATE = np.int32(dt.datetime.today().strftime(
     "%Y%j"))  # [IO-API file write date]
 root_grp.WTIME = np.int32(dt.datetime.today().strftime(
     "%k%M%S"))  # [IO-API file write time]
 root_grp.GDTYP = np.int32(2)  # ? [IO-API map projection]
 root_grp.NTHIK = np.int32(1)
 root_grp.VGTYP = np.int32(
     6)  # ? [IO-API grid type = H: m above ground]
 root_grp.VGTOP = 10000.  # ? [IO-API grid top for sigma coordinates]
 root_grp.VGLVLS = np.int32(0)  # ? [IO-API levels from 0 to NLAYS]
 root_grp.GDNAM = " "
 root_grp.UPNAM = " "
 root_grp.UPDSC = " "
Example #2
0
    def _create_netcdf(self, out_path, jdate):
        ''' Creates a blank CMAQ-ready NetCDF file, including all the important
            boilerplate and header information. But does not fill in any emissions data.
        '''
        # define some header variables
        current_date = int(time.strftime("%Y%j"))
        current_time = int(time.strftime("%H%M%S"))

        # create and outline NetCDF file
        rootgrp = Dataset(out_path, 'w', format='NETCDF4_CLASSIC')
        _ = rootgrp.createDimension('TSTEP', None)
        _ = rootgrp.createDimension('DATE-TIME', 2)
        _ = rootgrp.createDimension('LAY', 1)
        _ = rootgrp.createDimension('VAR', self.num_species)  # number of variables/species
        _ = rootgrp.createDimension('ROW', self.nrows)        # Domain: number of rows
        _ = rootgrp.createDimension('COL', self.ncols)        # Domain: number of columns

        # define TFLAG Variable
        TFLAG = rootgrp.createVariable('TFLAG', 'i4', ('TSTEP', 'VAR', 'DATE-TIME',), zlib=True)
        TFLAG.units = '<YYYYDDD,HHMMSS>'
        TFLAG.long_name = 'TFLAG'
        TFLAG.var_desc = 'Timestep-valid flags:  (1) YYYYDDD or (2) HHMMSS'

        # define variables and attribute definitions
        varl = ''
        for spec in self.species:
            units = self.units[spec]
            rootgrp.createVariable(spec, 'f4', ('TSTEP', 'LAY', 'ROW', 'COL'), zlib=True)
            rootgrp.variables[spec].long_name = spec
            rootgrp.variables[spec].units = units
            rootgrp.variables[spec].var_desc = 'emissions'
            varl += spec.ljust(16)

        # global attributes
        rootgrp.IOAPI_VERSION = self.header['IOAPI_VERSION']
        rootgrp.EXEC_ID = self.header['EXEC_ID']
        rootgrp.FTYPE = self.header['FTYPE']    # file type ID
        rootgrp.CDATE = current_date            # current date  e.g. 2013137
        rootgrp.CTIME = current_time            # current time  e.g. 50126
        rootgrp.WDATE = current_date            # current date  e.g. 2013137
        rootgrp.WTIME = current_time            # current time  e.g. 50126
        rootgrp.SDATE = jdate                   # scenario date e.g. 2010091
        rootgrp.STIME = self.header['STIME']    # start time    e.g. 80000 (for GMT)
        rootgrp.TSTEP = self.header['TSTEP']    # time step     e.g. 10000 (1 hour)
        rootgrp.NTHIK = self.header['NTHIK']    # Domain: perimeter thickness (boundary files only)
        rootgrp.NCOLS = self.header['NCOLS']    # Domain: number of columns in modeling domain
        rootgrp.NROWS = self.header['NROWS']    # Domain: number of rows in modeling domain
        rootgrp.NLAYS = self.header['NLAYS']    # Domain: number of vertical layers
        rootgrp.NVARS = self.num_species        # number of variables/species
        rootgrp.GDTYP = self.header['GDTYP']    # Domain: grid type ID (lat-lon, UTM, RADM, etc...)
        rootgrp.P_ALP = self.header['P_ALP']    # Projection: alpha
        rootgrp.P_BET = self.header['P_BET']    # Projection: betha
        rootgrp.P_GAM = self.header['P_GAM']    # Projection: gamma
        rootgrp.XCENT = self.header['XCENT']    # Projection: x centroid longitude
        rootgrp.YCENT = self.header['YCENT']    # Projection: y centroid latitude
        rootgrp.XORIG = self.header['XORIG']    # Domain: -684000 for CA_4k, -84000 for SC_4k
        rootgrp.YORIG = self.header['YORIG']    # Domain: -564000 for CA_4k, -552000 for SC_4k
        rootgrp.XCELL = self.header['XCELL']    # Domain: x cell width in meters
        rootgrp.YCELL = self.header['YCELL']    # Domain: y cell width in meters
        rootgrp.VGTYP = self.header['VGTYP']    # Domain: grid type ID (lat-lon, UTM, RADM, etc...)
        rootgrp.VGTOP = self.header['VGTOP']    # Domain: Top Vertical layer at 10km
        rootgrp.VGLVLS = self.header['VGLVLS']  # Domain: Vertical layer locations
        rootgrp.GDNAM = self.header['GDNAM']
        rootgrp.UPNAM = self.header['UPNAM']
        rootgrp.FILEDESC = self.header['FILEDESC']
        rootgrp.HISTORY = self.header['HISTORY']
        rootgrp.setncattr('VAR-LIST', varl)     # use this b/c the library does not like hyphens

        # seconds since epoch
        secs = time.mktime(time.strptime("%s 12" % jdate, "%Y%j %H"))
        gmt_shift = time.strftime("%H", time.gmtime(secs))
        secs -= (int(gmt_shift) - 8) * 3600

        # build TFLAG variable
        tflag = np.ones((25, self.num_species, 2), dtype=np.int32)
        for hr in xrange(25):
            gdh = time.strftime("%Y%j %H0000", time.gmtime(secs + hr * 3600))
            a_date, ghr = map(int, gdh.split())
            tflag[hr,:,0] = tflag[hr,:,0] * a_date
            tflag[hr,:,1] = tflag[hr,:,1] * ghr
        rootgrp.variables['TFLAG'][:] = tflag

        return rootgrp, gmt_shift