def __variables(self, proc_spc): if proc_spc == 'TFLAG': time = self.variables['TIME_%s' % char.decode(self.spcnames)[0][1].strip()] date = self.variables['DATE_%s' % char.decode(self.spcnames[0])[1].strip()] tmpvals = ConvertCAMxTime(date[:, 0, 0, 0], time[:, 0, 0, 0], len(self.dimensions['VAR'])) tmpvar = pncvar(self, 'proc_spc', 'i', ('TSTEP', 'VAR', 'DATE-TIME'), values=tmpvals) self.variables['TFLAG'] = tmpvar return self.variables['TFLAG'] self.variables.clear() spcstrs = char.decode(self.spcnames['SPECIES']).tolist() for k in self.proc_dict: proc = proc_spc[:len(k)] spc = proc_spc[len(k) + 1:] if proc == k and spc.ljust(10) in spcstrs: spcprocs = self.__readalltime(spc) for p, plong in self.proc_dict.items(): var_name = p + '_' + spc # IPR units are consistent with 'IPR' if p == 'UCNV': units = 'm**3/mol' elif p == 'AVOL': units = 'm**3' else: units = get_uamiv_units('IPR', spc) tmpvar = pncvar(self, var_name, 'f', ('TSTEP', 'LAY', 'ROW', 'COL'), values=spcprocs[p], units=units, var_desc=var_name.ljust(16), long_name=var_name.ljust(16)) self.variables[var_name] = tmpvar del spcprocs return self.variables[proc_spc] raise KeyError("Bad!")
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 """ self.runmessage = self.__rffile.read("80s") self.start_date, self.start_time, self.end_date, self.end_time = \ self.__rffile.read("ifif") self.grids = [] for grid in range(self.__rffile.read("i")[-1]): self.grids.append( dict( zip(['orgx', 'orgy', 'ncol', 'nrow', 'xsize', 'ysize'], self.__rffile.read("iiiiii")))) self.spcnames = [] for spc in range(self.__rffile.read("i")[-1]): self.spcnames.append( char.decode(self.__rffile.read("10s")[-1]).strip()) self.nspec = len(self.spcnames) self.padomains = [] for padomain in range(self.__rffile.read("i")[-1]): self.padomains.append( dict( zip([ 'grid', 'istart', 'iend', 'jstart', 'jend', 'blay', 'tlay' ], self.__rffile.read("iiiiiii")))) self.activedomain = self.padomains[0] self.prcnames = [] for i in range(self.__rffile.read('i')[-1]): self.prcnames.append(self.__rffile.read('25s')[-1].strip()) self.data_start_byte = self.__rffile.record_start self.record_fmt = self.id_fmt + str(len(self.prcnames)) + self.data_fmt self.record_size = self.__rffile.record_size self.SDATE, self.STIME, dummy, dummy, dummy, dummy, dummy, dummy = \ self.__rffile.read(self.id_fmt) self.__rffile.previous() self.TSTEP = 100. self.padded_size = self.record_size + 8 domain = self.padomains[0] domi = (domain['iend'] - domain['istart'] + 1) domj = (domain['jend'] - domain['jstart'] + 1) doml = (domain['tlay'] - domain['blay'] + 1) self.records_per_time = self.nspec * domi * domj * doml self.time_data_block = self.padded_size * self.records_per_time self.time_step = 100.
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
def __start(self, ntime, spc): nspec = char.decode( self.spcnames['SPECIES']).tolist().index(spc.ljust(10)) return (self.__data_start_byte + (int(ntime) * self.__block4d + self.__block3d * nspec) * self.__ipr_record_type.itemsize)