def scale_factors(self): """ Scale factors and masks. Returns ------- A read-only list (:class:`pygchem.utils.data_structures.RecordList`) of all scale factors and masks attached to the emission setup. If a scale factor is attached to several base emission fields, it appears only once in the list. """ sf = [] for bef in self.base_emission_fields: sf.extend(bef.scale_factors) # can't using the 'set' python type to get a list of unique elements # ('set' doesn't preserve the order) sf_keys = [f.name for f in sf] sf_duplicates = [] sf_unique = [] for i, k in enumerate(sf_keys): if sf_keys.count(k) > 1: if k in sf_duplicates: continue sf_duplicates.append(k) sf_unique.append(sf[i]) return RecordList(sf_unique, ref_classes=[EmissionScale, EmissionMask], read_only=True, key_attr='name')
def __init__(self, diaginfo_file='', tracerinfo_file=''): self.categories = RecordList([], key_attr='name', ref_classes=CTMCategory) self.diagnostics = RecordList([], key_attr='number', ref_classes=CTMDiagnostic) if diaginfo_file is not None: if not diaginfo_file: diaginfo_file = os.path.join(config.PACKAGE_DATA_PATH, "diaginfo.dat") self.load_diaginfo(diaginfo_file) if tracerinfo_file is not None: if not tracerinfo_file: tracerinfo_file = os.path.join(config.PACKAGE_DATA_PATH, "tracerinfo.dat") self.load_tracerinfo(tracerinfo_file)
def base_emission_fields(self): """ Base emission fields. Returns ------- A read-only list (:class:`pygchem.utils.data_structures.RecordList`) of all base emission fields attached to the emission setup. """ bef = [] for ext in self.extensions: bef.extend(ext.base_emission_fields + ext.extension_data) return RecordList(bef, ref_classes=EmissionBase, read_only=True, key_attr='name')
def __init__(self, extensions=(), description=''): self._extensions = RecordList(extensions, ref_classes=EmissionExt, key_attr='name') self.description = str(description) self.name = str(self.description)
"If None, an ID will be further set automatically.")), required_fields=['name'] ) #----------------------------------------------------------------------------- # Re-define a few properties (for more complex objects or type combinations) #----------------------------------------------------------------------------- # TODO: (var_name, ndim, units) connection between record-type and datafield EmissionBase.scale_factors = property( lambda self: self._scale_factors, lambda self, value: setattr( self, '_scale_factors', RecordList(value, ref_classes=(EmissionScale, EmissionMask), key_attr='name') ), doc=EmissionBase.scale_factors.__doc__ ) EmissionExt.base_emission_fields = property( lambda self: self._base_emission_fields, lambda self, value: setattr( self, '_base_emission_fields', RecordList(value, ref_classes=EmissionBase, key_attr='name'), ), doc=EmissionBase.scale_factors.__doc__ ) EmissionExt.extension_data = property( lambda self: self._extension_data,
class CTMDiagnosticInfo(object): """ Define all the diagnostics (and its metadata) that one can archive with GEOS-Chem. An instance of this class is commonly related to a couple of diaginfo.dat and tracerinfo.dat files. The class provides methods to read/write information from/to these files. Parameters ---------- diaginfo_file : string or None path to the 'diaginfo.dat' file. If None, no file read (no category added) If empty string, the instance is created using a default diaginfo.dat file - located in the data folder of the module installation path) tracerinfo_file : string or None path to the 'tracerinfo.dat' file (or None or empty string). """ def __init__(self, diaginfo_file='', tracerinfo_file=''): self.categories = RecordList([], key_attr='name', ref_classes=CTMCategory) self.diagnostics = RecordList([], key_attr='number', ref_classes=CTMDiagnostic) if diaginfo_file is not None: if not diaginfo_file: diaginfo_file = os.path.join(config.PACKAGE_DATA_PATH, "diaginfo.dat") self.load_diaginfo(diaginfo_file) if tracerinfo_file is not None: if not tracerinfo_file: tracerinfo_file = os.path.join(config.PACKAGE_DATA_PATH, "tracerinfo.dat") self.load_tracerinfo(tracerinfo_file) def load_diaginfo(self, filename, clear=True): """ load diagnostic categories metadata from the 'diaginfo.dat' file given by `filename`. If `clear` is True, all existing categories are removed. """ data = diaginfo.read_diaginfo(filename) if clear: del self.categories[:] self.categories.extend(CTMCategory(**d) for d in data) def load_tracerinfo(self, filename, clear=True): """ Read diagnostics from the 'tracerinfo.dat'-file with given `filename`. If `clear` is True, all existing diagnostics are removed. """ data = diaginfo.read_tracerinfo(filename) if clear: del self.diagnostics[:] for d in data: if d['carbon_weight'] != 1: d['hydrocarbon'] = True d['molecular_weight'] = config.C_MOLECULAR_WEIGHT else: d['hydrocarbon'] = False d['chemical'] = bool(d['molecular_weight']) self.diagnostics.extend(CTMDiagnostic(**d) for d in data) def save_diaginfo(self, filename): """ TODO: """ raise NotYetImplementedError() def save_tracerinfo(self, filename): """ TODO: """ raise NotYetImplementedError()