Beispiel #1
0
 def __init__(self,rf,proc_dict=None,units='umol/m**3', oldnames = False, **props):
     """
     Initialization included reading the header and learning
     about the format.
     
     see __readheader and __gettimestep() for more info
     
     Keywords (i.e., props) for projection: P_ALP, P_BET, P_GAM, XCENT, YCENT, XORIG, YORIG, XCELL, YCELL
     """
     if proc_dict!=None:
         self.proc_dict=proc_dict
     else:
         self.proc_dict=None
     self.__rffile=open(rf, 'rb')
     self.__rffile.seek(0,2)
     if self.__rffile.tell()<2147483648:
         warn("For greater speed on files <2GB use ipr_memmap")
     self.__rffile.seek(0,0)
     self.units=units
     self.__readheader()
     self.__setDomain__()
     self.__gettimestep()
     tdim = self.createDimension('TSTEP',self.NSTEPS)
     tdim.setunlimited(True)
     self.createDimension('DATE-TIME',2)
     self.createDimension('VAR',self.NSPCS*self.NPROCESS)
     varkeys=["_".join([j[1],j[0]]) for j in [i for i in cartesian([i.strip() for i in self.spcnames['SPECIES'].tolist()],self.proc_dict.keys())]]+['TFLAG']
     self.variables=PseudoNetCDFVariables(self.__variables,varkeys)
     for k, v in props.items():
         setattr(self, k, v)
     add_cf_from_ioapi(self)
Beispiel #2
0
 def __init__(self,
              rf,
              proc_dict=None,
              units='umol/m**3',
              oldnames=False,
              **props):
     """
     Initialization included reading the header and learning
     about the format.
     
     see __readheader and __gettimestep() for more info
     
     Keywords (i.e., props) for projection: P_ALP, P_BET, P_GAM, XCENT, YCENT, XORIG, YORIG, XCELL, YCELL
     """
     if proc_dict != None:
         self.proc_dict = proc_dict
     else:
         self.proc_dict = None
     self.__rffile = open(rf, 'rb')
     self.__rffile.seek(0, 2)
     if self.__rffile.tell() < 2147483648:
         warn("For greater speed on files <2GB use ipr_memmap")
     self.__rffile.seek(0, 0)
     self.units = units
     self.__readheader()
     self.__setDomain__()
     self.__gettimestep()
     tdim = self.createDimension('TSTEP', self.NSTEPS)
     tdim.setunlimited(True)
     self.createDimension('DATE-TIME', 2)
     self.createDimension('VAR', self.NSPCS * self.NPROCESS)
     varkeys = [
         "_".join([j[1], j[0]]) for j in [
             i for i in cartesian([
                 i.strip()
                 for i in char.decode(self.spcnames['SPECIES']).tolist()
             ], self.proc_dict.keys())
         ]
     ] + ['TFLAG']
     self.variables = PseudoNetCDFVariables(self.__variables, varkeys)
     for k, v in props.items():
         setattr(self, k, v)
     try:
         add_cf_from_ioapi(self)
     except:
         pass
Beispiel #3
0
    def __init__(self, rf, multi=False, **props):
        """
        Initialization included reading the header and learning
        about the format.
        
        see __readheader and __gettimestep() for more info

        Keywords (i.e., props) for projection: P_ALP, P_BET, P_GAM, XCENT, YCENT, XORIG, YORIG, XCELL, YCELL
        """
        self.__rffile = OpenRecordFile(rf)
        self.__readheader()
        self.__ipr_record_type = {
            24:
            dtype(
                dict(names=[
                    'SPAD', 'DATE', 'TIME', 'SPC', 'PAGRID', 'NEST', 'I', 'J',
                    'K', 'INIT', 'CHEM', 'EMIS', 'PTEMIS', 'PIG', 'WADV',
                    'EADV', 'SADV', 'NADV', 'BADV', 'TADV', 'DIL', 'WDIF',
                    'EDIF', 'SDIF', 'NDIF', 'BDIF', 'TDIF', 'DDEP', 'WDEP',
                    'AERCHEM', 'FCONC', 'UCNV', 'AVOL', 'EPAD'
                ],
                     formats=[
                         '>i', '>i', '>f', '>S10', '>i', '>i', '>i', '>i',
                         '>i', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                         '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                         '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>i'
                     ])),
            26:
            dtype(
                dict(names=[
                    'SPAD', 'DATE', 'TIME', 'SPC', 'PAGRID', 'NEST', 'I', 'J',
                    'K', 'INIT', 'CHEM', 'EMIS', 'PTEMIS', 'PIG', 'WADV',
                    'EADV', 'SADV', 'NADV', 'BADV', 'TADV', 'DIL', 'WDIF',
                    'EDIF', 'SDIF', 'NDIF', 'BDIF', 'TDIF', 'DDEP', 'WDEP',
                    'INORGACHEM', 'ORGACHEM', 'AQACHEM', 'FCONC', 'UCNV',
                    'AVOL', 'EPAD'
                ],
                     formats=[
                         '>i', '>i', '>f', '>S10', '>i', '>i', '>i', '>i',
                         '>i', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                         '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                         '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                         '>i'
                     ]))
        }[len(self.prcnames)]

        prcs = [
            'SPAD', 'DATE', 'TIME', 'PAGRID', 'NEST', 'I', 'J', 'K', 'INIT',
            'CHEM', 'EMIS', 'PTEMIS', 'PIG', 'WADV', 'EADV', 'SADV', 'NADV',
            'BADV', 'TADV', 'DIL', 'WDIF', 'EDIF', 'SDIF', 'NDIF', 'BDIF',
            'TDIF', 'DDEP', 'WDEP'
        ] + {
            24: ['AERCHEM'],
            26: ['INORGACHEM', 'ORGACHEM', 'AQACHEM']
        }[len(self.prcnames)] + ['FCONC', 'UCNV', 'AVOL', 'EPAD']
        varkeys = ['_'.join(i) for i in cartesian(prcs, self.spcnames)]
        varkeys += [
            'SPAD', 'DATE', 'TIME', 'PAGRID', 'NEST', 'I', 'J', 'K', 'TFLAG'
        ]
        self.groups = {}
        NSTEPS = len([i_ for i_ in self.timerange()])
        NVARS = len(varkeys)
        self.createDimension('VAR', NVARS)
        self.createDimension('DATE-TIME', 2)
        self.createDimension('TSTEP', NSTEPS)
        padatatype = []
        pavarkeys = []
        for di, domain in enumerate(self.padomains):
            dk = 'PA%02d' % di
            prefix = dk + '_'
            grp = self.groups[dk] = PseudoNetCDFFile()
            pavarkeys.extend([prefix + k for k in varkeys])
            grp.createDimension('VAR', NVARS)
            grp.createDimension('DATE-TIME', 2)
            grp.createDimension('TSTEP', NSTEPS)
            grp.createDimension('COL', domain['iend'] - domain['istart'] + 1)
            grp.createDimension('ROW', domain['jend'] - domain['jstart'] + 1)
            grp.createDimension('LAY', domain['tlay'] - domain['blay'] + 1)
            padatatype.append(
                (dk, self.__ipr_record_type, (len(grp.dimensions['ROW']),
                                              len(grp.dimensions['COL']),
                                              len(grp.dimensions['LAY']))))
            if len(self.padomains) == 1:
                self.createDimension('COL',
                                     domain['iend'] - domain['istart'] + 1)
                self.createDimension('ROW',
                                     domain['jend'] - domain['jstart'] + 1)
                self.createDimension('LAY',
                                     domain['tlay'] - domain['blay'] + 1)
            exec(
                """def varget(k):
                return self._ipr__variables('%s', k)""" % dk, dict(self=self),
                locals())
            if len(self.padomains) == 1:
                self.variables = PseudoNetCDFVariables(varget, varkeys)
            else:
                grp.variables = PseudoNetCDFVariables(varget, varkeys)

        self.__memmaps = memmap(self.__rffile.infile.name, dtype(padatatype),
                                'r', self.data_start_byte).reshape(
                                    NSTEPS, len(self.spcnames))
        for k, v in props.items():
            setattr(self, k, v)
        try:
            add_cf_from_ioapi(self)
        except:
            pass
Beispiel #4
0
    def __init__(self,rf,multi=False, **props):
        """
        Initialization included reading the header and learning
        about the format.
        
        see __readheader and __gettimestep() for more info

        Keywords (i.e., props) for projection: P_ALP, P_BET, P_GAM, XCENT, YCENT, XORIG, YORIG, XCELL, YCELL
        """
        self.__rffile=OpenRecordFile(rf)
        self.__readheader()
        self.__ipr_record_type={
            24: dtype(
                        dict(
                            names=['SPAD', 'DATE', 'TIME', 'SPC', 'PAGRID', 'NEST', 'I', 'J', 'K', 
                                    'INIT', 'CHEM', 'EMIS', 'PTEMIS', 'PIG', 'WADV', 'EADV', 'SADV', 
                                    'NADV', 'BADV', 'TADV', 'DIL', 'WDIF', 'EDIF', 'SDIF', 'NDIF', 
                                    'BDIF', 'TDIF', 'DDEP', 'WDEP', 'AERCHEM', 'FCONC', 'UCNV', 'AVOL', 
                                    'EPAD'], 
                            formats=['>i', '>i', '>f', '>S10', '>i', '>i', '>i', '>i', '>i', 
                                    '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                                    '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                                    '>f', '>f', '>f', '>f', '>f', '>f', '>i'])),
            26: dtype(
                        dict(
                            names=['SPAD', 'DATE', 'TIME', 'SPC', 'PAGRID', 'NEST', 'I', 'J', 'K', 
                                    'INIT', 'CHEM', 'EMIS', 'PTEMIS', 'PIG', 'WADV', 'EADV', 'SADV', 
                                    'NADV', 'BADV', 'TADV', 'DIL', 'WDIF', 'EDIF', 'SDIF', 'NDIF', 
                                    'BDIF', 'TDIF', 'DDEP', 'WDEP', 'INORGACHEM', 'ORGACHEM', 'AQACHEM', 'FCONC', 'UCNV', 'AVOL', 
                                    'EPAD'], 
                            formats=['>i', '>i', '>f', '>S10', '>i', '>i', '>i', '>i', '>i', 
                                    '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                                    '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f',
                                    '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>f', '>i']))
                                }[len(self.prcnames)]

        prcs=['SPAD', 'DATE', 'TIME', 'PAGRID', 'NEST', 'I', 'J', 'K', 
                'INIT', 'CHEM', 'EMIS', 'PTEMIS', 'PIG', 'WADV', 'EADV', 'SADV', 
                'NADV', 'BADV', 'TADV', 'DIL', 'WDIF', 'EDIF', 'SDIF', 'NDIF', 
                'BDIF', 'TDIF', 'DDEP', 'WDEP']+{24: ['AERCHEM'], 26: ['INORGACHEM', 'ORGACHEM', 'AQACHEM']}[len(self.prcnames)]+['FCONC', 'UCNV', 'AVOL', 
                'EPAD']
        varkeys=['_'.join(i) for i in cartesian(prcs,self.spcnames)]
        varkeys+=['SPAD','DATE','TIME','PAGRID','NEST','I','J','K','TFLAG']
        self.groups = {}
        NSTEPS = len([i_ for i_ in self.timerange()])
        NVARS = len(varkeys)
        self.createDimension('VAR', NVARS)
        self.createDimension('DATE-TIME', 2)
        self.createDimension('TSTEP', NSTEPS)
        padatatype = []
        pavarkeys = []
        for di, domain in enumerate(self.padomains):
            dk = 'PA%02d' % di
            prefix = dk + '_'
            grp = self.groups[dk] = PseudoNetCDFFile()
            pavarkeys.extend([prefix + k for k in varkeys])
            grp.createDimension('VAR', NVARS)
            grp.createDimension('DATE-TIME', 2)
            grp.createDimension('TSTEP', NSTEPS)
            grp.createDimension('COL', domain['iend'] - domain['istart'] + 1)
            grp.createDimension('ROW', domain['jend'] - domain['jstart'] + 1)
            grp.createDimension('LAY', domain['tlay'] - domain['blay'] + 1)
            padatatype.append((dk, self.__ipr_record_type, (len(grp.dimensions['ROW']), len(grp.dimensions['COL']), len(grp.dimensions['LAY']))))
            if len(self.padomains) == 1:
                self.createDimension('COL', domain['iend']-domain['istart']+1)
                self.createDimension('ROW', domain['jend']-domain['jstart']+1)
                self.createDimension('LAY', domain['tlay']-domain['blay']+1)
            exec("""def varget(k):
                return self._ipr__variables('%s', k)""" % dk, dict(self = self), locals())
            if len(self.padomains) == 1:
                self.variables = PseudoNetCDFVariables(varget,varkeys)
            else:
                grp.variables = PseudoNetCDFVariables(varget,varkeys)
        
        self.__memmaps=memmap(self.__rffile.infile.name,dtype(padatatype),'r',self.data_start_byte).reshape(NSTEPS, len(self.spcnames))
        for k, v in props.items():
            setattr(self, k, v)
        try:
            add_cf_from_ioapi(self)
        except:
            pass