Exemplo n.º 1
0
    def __init__(self, rf, chemparam=None):
        """
        Initialization included reading the header and learning
        about the format.

        see __readheader and __gettimestep() for more info
        """

        self.rffile = OpenRecordFile(rf)
        if chemparam is None:
            self._aerosol_names = None
        else:
            self._aerosol_names = get_chemparam_names(chemparam)

        self.padded_time_hdr_size = struct.calcsize(self.time_hdr_fmt + "ii")
        self.__readheader()
        self.__gettimestep()
        self.dimensions = {}
        self.createDimension('LAY', self.nlayers)
        self.createDimension('COL', self.nx)
        self.createDimension('ROW', self.ny)
        self.createDimension('TSTEP', self.time_step_count)
        self.createDimension('DATE-TIME', 2)

        self.variables = PseudoNetCDFVariables(
            self.__var_get, [sn.strip() for sn in self.spcnames])
Exemplo n.º 2
0
    def __init__(self,
                 rf,
                 mode='r',
                 P_ALP=None,
                 P_BET=None,
                 P_GAM=None,
                 XCENT=None,
                 YCENT=None,
                 GDTYP=None,
                 endian='big',
                 chemparam=None):
        """
        Parameters
        ----------
        rf : string or RecordFile
            usually a path to a CAMx formatted file, can be a FortranFileUtil
            RecordFile object.
        mode : string
            file open mode read ('r'), write ('w'), append ('a', 'r+')
        P_ALP : float
            see IOAPI GRIDDESC documentation
        P_BET : float
            see IOAPI GRIDDESC documentation
        P_GAM : float
            see IOAPI GRIDDESC documentation
        XCENT : float
            see IOAPI GRIDDESC documentation
        YCENT : float
            see IOAPI GRIDDESC documentation
        GDTYP : float
            see IOAPI GRIDDESC documentation
        endian : string
            'big' or 'little' usually only if mistaken compile
        chemparam : None or string
            used to identify gases and aerosols

        Returns
        -------
        outf : uamiv
            PseudoNetCDFFile populated from file
        """
        if chemparam is None:
            self._aerosol_names = None
        else:
            self._aerosol_names = get_chemparam_names(chemparam)['aerosol']

        self.__endianprefix = dict(big='>', little='<')[endian]
        self._make_header_fmt()
        self.__rffile = rf
        self.__mode = mode

        self.createDimension('DATE-TIME', 2)

        self.__readheader()

        # Add IOAPI metavariables
        self.NLAYS = len(self.dimensions['LAY'])
        self.NROWS = len(self.dimensions['ROW'])
        self.NCOLS = len(self.dimensions['COL'])
        self.NVARS = len(self.dimensions['VAR'])
        self.NSTEPS = len(self.dimensions['TSTEP'])
        varlist = "".join([i.ljust(16) for i in self.__var_names__])
        setattr(self, 'VAR-LIST', varlist)
        self.NAME = self.__emiss_hdr['name'][0, :,
                                             0].copy().view('S10')[0].decode()
        self.NOTE = self.__emiss_hdr['note'][0, :,
                                             0].copy().view('S60')[0].decode()
        self.ITZON = self.__emiss_hdr['itzon'][0]
        self.FTYPE = 1
        self.VGTYP = 2
        self.VGTOP = 10000.
        self.VGLVLS = linspace(0, 1, self.NLAYS + 1)[::-1]
        self.GDNAM = "CAMx            "
        self.UPNAM = "CAMx            "
        self.FILEDESC = "CAMx            "
        # Create variables
        self.variables = PseudoNetCDFVariables(
            self.__variables, ['TFLAG', 'ETFLAG'] + self.__var_names__)
        tflag = ConvertCAMxTime(self.__memmap__['DATE']['BDATE'],
                                self.__memmap__['DATE']['BTIME'], self.NVARS)
        etflag = ConvertCAMxTime(self.__memmap__['DATE']['EDATE'],
                                 self.__memmap__['DATE']['ETIME'], self.NVARS)
        tflagv = self.createVariable('TFLAG',
                                     'i', ('TSTEP', 'VAR', 'DATE-TIME'),
                                     values=tflag,
                                     units='DATE-TIME',
                                     long_name='TFLAG'.ljust(16),
                                     var_desc='TFLAG'.ljust(80))
        etflagv = self.createVariable('ETFLAG',
                                      'i', ('TSTEP', 'VAR', 'DATE-TIME'),
                                      values=etflag,
                                      units='DATE-TIME',
                                      long_name='ETFLAG'.ljust(16),
                                      var_desc='Ending TFLAG'.ljust(80))

        self.SDATE, self.STIME = self.variables['TFLAG'][0, 0, :]
        self.TSTEP = etflagv[0, 0, 1] - tflagv[0, 0, 1]
        if P_ALP is not None:
            self.P_ALP = P_ALP
        if P_BET is not None:
            self.P_BET = P_BET
        if P_GAM is not None:
            self.P_GAM = P_GAM
        if XCENT is not None:
            self.XCENT = XCENT
        if YCENT is not None:
            self.YCENT = YCENT
        if GDTYP is not None:
            self.GDTYP = GDTYP
Exemplo n.º 3
0
    def __init__(self,
                 rf,
                 mode='r',
                 P_ALP=None,
                 P_BET=None,
                 P_GAM=None,
                 XCENT=None,
                 YCENT=None,
                 GDTYP=None,
                 endian='big',
                 chemparam=None):
        """
        Initialization included reading the header and learning
        about the format.
        
        see __readheader and __gettimestep() for more info
        """
        if chemparam is None:
            self._aerosol_names = None
        else:
            self._aerosol_names = get_chemparam_names(chemparam)['aerosol']

        ep = self.__endianprefix = dict(big='>', little='<')[endian]
        self._make_header_fmt()
        self.__rffile = rf
        self.__mode = mode

        self.createDimension('DATE-TIME', 2)

        self.__readheader()

        # Add IOAPI metavariables
        nlays = self.NLAYS = len(self.dimensions['LAY'])
        nrows = self.NROWS = len(self.dimensions['ROW'])
        ncols = self.NCOLS = len(self.dimensions['COL'])
        nvars = self.NVARS = len(self.dimensions['VAR'])
        nsteps = self.NSTEPS = len(self.dimensions['TSTEP'])
        setattr(self, 'VAR-LIST',
                "".join([i.ljust(16) for i in self.__var_names__]))
        self.NAME = self.__emiss_hdr['name'][0, :,
                                             0].copy().view('S10')[0].decode()
        self.NOTE = self.__emiss_hdr['note'][0, :,
                                             0].copy().view('S60')[0].decode()
        self.ITZON = self.__emiss_hdr['itzon'][0]
        self.FTYPE = 1
        self.VGTYP = 2
        self.VGTOP = 10000.
        self.VGLVLS = linspace(0, 1, self.NLAYS + 1)[::-1]
        self.GDNAM = "CAMx            "
        self.UPNAM = "CAMx            "
        self.FILEDESC = "CAMx            "
        # Create variables
        self.variables = PseudoNetCDFVariables(
            self.__variables, ['TFLAG', 'ETFLAG'] + self.__var_names__)
        tflag = ConvertCAMxTime(self.__memmap__['DATE']['BDATE'],
                                self.__memmap__['DATE']['BTIME'], self.NVARS)
        etflag = ConvertCAMxTime(self.__memmap__['DATE']['EDATE'],
                                 self.__memmap__['DATE']['ETIME'], self.NVARS)
        tflagv = self.createVariable('TFLAG',
                                     'i', ('TSTEP', 'VAR', 'DATE-TIME'),
                                     values=tflag,
                                     units='DATE-TIME',
                                     long_name='TFLAG'.ljust(16),
                                     var_desc='TFLAG'.ljust(80))
        etflagv = self.createVariable('ETFLAG',
                                      'i', ('TSTEP', 'VAR', 'DATE-TIME'),
                                      values=etflag,
                                      units='DATE-TIME',
                                      long_name='ETFLAG'.ljust(16),
                                      var_desc='Ending TFLAG'.ljust(80))

        self.SDATE, self.STIME = self.variables['TFLAG'][0, 0, :]
        self.TSTEP = self.variables['ETFLAG'][
            0, 0, 1] - self.variables['TFLAG'][0, 0, 1]
        if not P_ALP is None:
            self.P_ALP = P_ALP
        if not P_BET is None:
            self.P_BET = P_BET
        if not P_GAM is None:
            self.P_GAM = P_GAM
        if not XCENT is None:
            self.XCENT = XCENT
        if not YCENT is None:
            self.YCENT = YCENT
        if not GDTYP is None:
            self.GDTYP = GDTYP
        try:
            add_cf_from_ioapi(self)
        except Exception as e:
            warn(repr(e))
            pass