Exemple #1
0
    def __readheader(self):
        """
        __readheader reads the header section of the ipr file
        it initializes each header field (see CAMx Users Manual for a list)
        as properties of the ipr class
        """
        vals = self.rffile.read(self.emiss_hdr_fmt)
        self.name, self.note, ione, self.nspec, self.start_date, self.start_time, self.end_date, self.end_time = vals[
            0:10], vals[10:70], vals[70], vals[71], vals[72], vals[73], vals[
                74], vals[75]
        rdum, rdum, self.iutm, self.xorg, self.yorg, self.delx, self.dely, self.nx, self.ny, self.nz, idum, idum, rdum, rdum, rdum = self.rffile.read(
            self.grid_hdr_fmt)
        if self.nz == 0:
            #Special case of gridded emissions
            #Seems to be same as avrg
            self.nlayers = 1
        else:
            self.nlayers = self.nz
        ione, ione, nx, ny = self.rffile.read(self.cell_hdr_fmt)
        if not (self.nx, self.ny) == (nx, ny):
            raise ValueError(
                "nx, ny defined first as %i, %i and then as %i, %i" %
                (self.nx, self.ny, nx, ny))
        species_temp = self.rffile.read(self.nspec * self.spc_fmt)
        self.spcnames = []
        for i in range(0, self.nspec * 10, 10):
            self.spcnames.append(Int2Asc(species_temp[i:i + 10]))

        ione, self.nstk = self.rffile.read(self.nstk_hdr_fmt)

        stkprms = zeros((self.nstk * len(self.stk_hdr_fmt), ), 'f')
        read_into(self.rffile, stkprms, '')
        self.rffile.next()
        #self.rffile.previous()
        #self.tmplist=self.rffile.read('ffffff'*self.nstk)

        stkprms = stkprms.reshape((self.nstk, len(self.stk_hdr_fmt)))
        for i in range(stkprms.shape[0]):
            if stkprms[i, -1] == array_nan:
                stkprms[i, -1] = float('-nan')
        self.stk_props = stkprms.tolist()
        self.data_start_byte = self.rffile.record_start
        self.start_date, self.start_time, end_date, end_time = self.rffile.read(
            self.time_hdr_fmt)

        self.time_step = timediff((self.start_date, self.start_time),
                                  (end_date, end_time))
        self.end_time += self.time_step
        self.time_step_count = int(
            timediff((self.start_date, self.start_time),
                     (self.end_date, self.end_time),
                     (2400, 24)[int(self.time_step % 2)]) / self.time_step)

        self.stk_time_prop_fmt = "" + ("iiiff" * self.nstk)
        self.padded_stk_time_prop_size = struct.calcsize(
            "ii" + self.stk_time_prop_fmt)

        self.record_fmt = ("i10i") + self.data_fmt * (self.nstk)
        self.record_size = struct.calcsize(self.record_fmt)
        self.padded_size = self.record_size + 8
Exemple #2
0
    def __readheader(self):
        """
        __readheader reads the header section of the ipr file
        it initializes each header field (see CAMx Users Manual for a list)
        as properties of the ipr class
        """
        vals=self.rffile.read(self.emiss_hdr_fmt)
        self.name,self.note,ione,self.nspec,self.start_date,self.start_time,self.end_date,self.end_time=vals[0:10],vals[10:70],vals[70],vals[71],vals[72],vals[73],vals[74],vals[75]
        rdum,rdum,self.iutm,self.xorg,self.yorg,self.delx,self.dely,self.nx,self.ny,self.nz,idum,idum,rdum,rdum,rdum=self.rffile.read(self.grid_hdr_fmt)
        if self.nz==0:
            #Special case of gridded emissions
            #Seems to be same as avrg
            self.nlayers=1
        else:
            self.nlayers=self.nz
        ione,ione,nx,ny=self.rffile.read(self.cell_hdr_fmt)
        if not (self.nx,self.ny)==(nx,ny):
            raise ValueError("nx, ny defined first as %i, %i and then as %i, %i" % (self.nx,self.ny,nx,ny))
        species_temp=self.rffile.read(self.nspec*self.spc_fmt)
        self.spcnames=[]
        for i in range(0,self.nspec*10,10):
            self.spcnames.append(Int2Asc(species_temp[i:i+10]))
        
        ione,self.nstk=self.rffile.read(self.nstk_hdr_fmt)

        stkprms=zeros((self.nstk*len(self.stk_hdr_fmt),),'f')
        read_into(self.rffile,stkprms,'')
        self.rffile.next()
        #self.rffile.previous()
        #self.tmplist=self.rffile.read('ffffff'*self.nstk)
        
        stkprms=stkprms.reshape((self.nstk,len(self.stk_hdr_fmt)))
        for i in range(stkprms.shape[0]):
            if stkprms[i,-1]==array_nan:
                stkprms[i,-1]=float('-nan')
        self.stk_props=stkprms.tolist()
        self.data_start_byte=self.rffile.record_start
        self.start_date,self.start_time,end_date,end_time=self.rffile.read(self.time_hdr_fmt)
        
        self.time_step=timediff((self.start_date,self.start_time),(end_date,end_time))
        self.end_time += self.time_step
        self.time_step_count=int(timediff((self.start_date,self.start_time),(self.end_date,self.end_time),(2400,24)[int(self.time_step % 2)])/self.time_step)
        
        self.stk_time_prop_fmt=""+("iiiff"*self.nstk)
        self.padded_stk_time_prop_size=struct.calcsize("ii"+self.stk_time_prop_fmt)
        
        self.record_fmt=("i10i")+self.data_fmt*(self.nstk)
        self.record_size=struct.calcsize(self.record_fmt)
        self.padded_size=self.record_size+8
Exemple #3
0
    def read_into(self, dest):
        """
        Transfer values from current record to dest
        dest - numeric or numpy array
        """

        return read_into(self.rffile, dest, self.id_fmt, self.data_fmt)
Exemple #4
0
 def read_into(self,dest):
     """
     Transfer values from current record to dest
     dest - numeric or numpy array
     """
     
     return read_into(self.rffile,dest,self.id_fmt,self.data_fmt)
Exemple #5
0
 def read_into(self, dest):
     """
     put values from rffile read into dest
     dest - numpy or numeric array
     """
     return read_into(self.rffile, dest, self.id_fmt, self.data_fmt)
Exemple #6
0
 def read_into(self,dest):
     """
     put values from rffile read into dest
     dest - numpy or numeric array
     """
     return read_into(self.rffile,dest,self.id_fmt,self.data_fmt)