def __variables(self,k): if k in ['TFLAG','ETFLAG','NSTKS']: return self.variables[k] elif k in ['XSTK','YSTK','HSTK','DSTK','TSTK','VSTK']: v=PseudoNetCDFVariable(self,k,'f',('NSTK',),values=self.__stk_props[k].ravel()) v.units={'XSTK':'m','YSTK':'m','HSTK':'m','DSTK':'m','TSTK':'K','VSTK':'m/h'}[k] v.long_name=k.ljust(16) v.var_desc=k.ljust(16) return v elif k in ['IONE', 'ITWO', 'KCELL','FLOW','PLMHT']: data_type={'IONE':'i', 'ITWO':'i', 'KCELL':'i','FLOW':'f','PLMHT':'f'}[k] v=self.createVariable(k,data_type,('TSTEP','NSTK')) v.units={'IONE':'#', 'ITWO':'#', 'KCELL':'#', 'FLOW':'m**3/hr', 'PLMHT':'m'}[k] v.long_name=k.ljust(16) v.var_desc=k.ljust(16) vals = self.__hourly_stk_props[:,:,['IONE','ITWO','KCELL','FLOW','PLMHT'].index(k)] v[:] = vals.view('>' + data_type) return v elif k in self.__spc_names: v=PseudoNetCDFVariable(self,k,'f',('TSTEP','NSTK'),values=self.__emiss_data[:,self.__getspcidx(k),:]) v.units='mole/hr'.ljust(16) v.long_name=k.ljust(16) v.var_desc=k.ljust(16) return v else: raise KeyError("Unknown key %s" % k)
def __DEPTH__(self): val=CAMxHeightToDepth(self.variables['HGHT']) var=PseudoNetCDFVariable(self,'DEPTH','f',('TSTEP','LAY','ROW','COL'),values=val) var.units='m' var.long_name='RATE'.ljust(16) var.var_desc='RATE'.ljust(16) return var
def __FCLOUD__(self): val = self.variables["CLOUD"] >= 5 var = PseudoNetCDFVariable(self, "FCLOUD", "i", ("TSTEP", "LAY", "ROW", "COL"), values=array(val, dtype="i")) var.units = "None" var.long_name = "FCLOUD".ljust(16) var.var_desc = "FCLOUD".ljust(16) return var
def __set_var(self, key, vals_idx): times = len(self.dimensions['TSTEP']) lays = len(self.dimensions['LAY']) rows = len(self.dimensions['ROW']) cols = len(self.dimensions['COL']) v = PseudoNetCDFVariable(self, key, 'f', ('TSTEP', 'LAY', 'ROW', 'COL'), values = self.__memmap[vals_idx].reshape(times, lays, rows, cols)) v.units = {'COD':'None'}.get(key, 'g/m**3') v.long_name = key v.var_desc = key self.variables[key] = v
def __PRECIP_RATE__(self): if "PRECIP" in self.variables.keys(): val = self.variables["PRECIP"] else: val = self.variables["RAIN"] + self.variables["SNOW"] + self.variables["GRAUPEL"] var = PseudoNetCDFVariable(self, "PRECIP_RATE", "f", ("TSTEP", "LAY", "ROW", "COL"), values=(val * 10) ** 1.27) var.units = "mm/h" var.long_name = "PRECIP_RATE".ljust(16) var.var_desc = "PRECIP_RATE".ljust(16) return var
def __FCLOUD__(self): val = self.variables['CLOUD'] >= 5 var = PseudoNetCDFVariable(self, 'FCLOUD', 'i', ('TSTEP', 'LAY', 'ROW', 'COL'), values=array(val, dtype='i')) var.units = 'None' var.long_name = 'FCLOUD'.ljust(16) var.var_desc = 'FCLOUD'.ljust(16) return var
def __PRECIP_RATE__(self): if 'PRECIP' in self.variables.keys(): val = self.variables['PRECIP'] else: val = self.variables['RAIN'] + \ self.variables['SNOW'] + self.variables['GRAUPEL'] var = PseudoNetCDFVariable(self, 'PRECIP_RATE', 'f', ('TSTEP', 'LAY', 'ROW', 'COL'), values=(val * 10)**1.27) var.units = 'mm/h' var.long_name = 'PRECIP_RATE'.ljust(16) var.var_desc = 'PRECIP_RATE'.ljust(16) return var
def __set_var(self, key, vals_idx): times = len(self.dimensions['TSTEP']) lays = len(self.dimensions['LAY']) rows = len(self.dimensions['ROW']) cols = len(self.dimensions['COL']) v = PseudoNetCDFVariable(self, key, 'f', ('TSTEP', 'LAY', 'ROW', 'COL'), values=self.__memmap[vals_idx].reshape( times, lays, rows, cols)) v.units = {'COD': 'None'}.get(key, 'g/m**3') v.long_name = key v.var_desc = key self.variables[key] = v
def childvariables(self, k): for f in self.__files: if k in f.variables.keys(): v = f.variables[k] if k=='TFLAG': v = PseudoNetCDFVariable(self, 'TFLAG', 'i', v.dimensions, values = v[:][:, [0], :].repeat(len(self.dimensions['VAR']), 1)) v.long_name = 'TFLAG'.ljust(16) v.var_desc = 'TFLAG'.ljust(16) v.units = 'DATE-TIME' if k=='LAY' and k in self.dimensions.keys() and len(k.shape) > 1: if v.shape[1]==1: dims = list(v.dimensions) dims[1] = 'SURFLAY' v.dimensions = tuple(dims) return v
def ConvertCAMxTime(date,time,nvars): class temp: pass f = temp() f.dimensions = {'TSTEP': date.shape[0], 'VAR': nvars, 'DATE-TIME': 2} a=array([date,time],dtype='i').swapaxes(0,1) if len(a.shape)==2: a=a[:,newaxis,:] date=a[:,:,0] if (date<70000).any(): date+=2000000 else: date+=1900000 time=a[:,:,1] while not (time==0).all() and time.max()<10000: time*=100 a=PseudoNetCDFVariable(f,'TFLAG','i',('TSTEP','VAR','DATE-TIME'),values=a[:,[0],:].repeat(nvars,1)) a.units='DATE-TIME'.ljust(16) a.long_name='TFLAG'.ljust(16) a.var_desc=a.long_name return a
def __add_variables(self): v=self.createVariable('TFLAG','i',('TSTEP','VAR','DATE-TIME'),keep=True) v[:] = self.__windfile.variables['TFLAG'][self.__timeslice] v.long_name='Time flag' v.units='DATE-TIME' if self.__force_stagger and self.__windfile.LSTAGGER==0: warn('Cell centered values are being averaged as though staggered'+ \ 'Could just be pre v4.3 file that was actually staggered') for k in ['U','V']: if self.__force_stagger or self.__windfile.LSTAGGER!=0: if k=='U': preproc=CenterCAMxU elif k=='V': preproc=CenterCAMxV else: preproc=CenterTime var=self.__windfile.variables[k] v=PseudoNetCDFVariable(self,k,'f',('TSTEP','LAY','ROW','COL'),values=preproc(var)) v.units=var.units v.long_name=k.ljust(16) v.var_desc=(k+' at center').ljust(16) self.variables[k]=PseudoNetCDFVariableConvertUnit(v,self.__outunit)