Source code for pycif.plugins.chemistries.iconart.make_chemistry
[docs]
def create_chemicalscheme(self):
"""
Read the mandatory chemistry files, create the optional ones and set the
species attributes
consistently with the data retrieved
"""
# Derive emitted species
self.emis_species = []
for spec in self.acspecies.attributes:
self.emis_species += self.mapping_active2emi[spec]
self.emis_species = sorted(list(set(self.emis_species)))
# Map the emitted species to the active species
self.mapping_emi2active = {emspec: [] for emspec in self.emis_species}
for spec in self.acspecies.attributes:
for emspec in self.mapping_active2emi[spec]:
self.mapping_emi2active[emspec] += [spec]
# Store reference species (for EnSRF)
self.ref_acspecies = list(set([s.split("__sample#")[0]
for s in self.acspecies.attributes]))
self.ref_emis_species = list(set([ems.split("__sample#")[0]
for ems in self.emis_species]))
# Create attribute to store tracer information for the xml file
self.dict_tracers = {}
default_xml_config = {
'transport': 'stdchem',
'unit': 'none',
'c_solve': 'passive',
'init_mode': '0',
}
self.oem_categories = []
self.oem_tracers = []
for spec in self.acspecies.attributes:
spec_ref = spec.split("__sample#")[0]
# Create the config for the background tracer
spec_bg = spec_ref + '_BG'
if spec_bg not in self.dict_tracers:
self.dict_tracers[spec_bg] = {
'id': spec_bg,
**default_xml_config
}
# Create the emission config for the reference tracer
emis_species_ref = self.mapping_active2emi_ref[spec_ref]
if len(emis_species_ref) > 0:
oem_xml_config = {
'oem_type': 'emis',
'oem_tscale': '3',
'oem_cat': sorted(emis_species_ref),
'oem_vp': ['ground_emissions'] * len(emis_species_ref),
'oem_tp': sorted(emis_species_ref)
}
else:
oem_xml_config = {}
# Create the reference tracer
if spec_ref not in self.dict_tracers:
self.dict_tracers[spec_ref] = {
'id': spec_ref,
**default_xml_config,
**oem_xml_config
}
# Store the order of categories in tracers.xml
self.oem_categories += sorted(emis_species_ref)
self.oem_tracers += [spec_ref]
# To monitor emissions, add an active tracer for each emitted tracer
for emi_spec in emis_species_ref:
self.dict_tracers[emi_spec] = {
'id': emi_spec,
**default_xml_config,
**{
'oem_type': 'emis',
'oem_tscale': '3',
'oem_cat': [emi_spec],
'oem_vp': ['ground_emissions'],
'oem_tp': [emi_spec]
}
}
# If ensemble
if "__sample#" in spec:
# Create the config for the optimized background tracer
spec_bg_post = spec_ref + '_BG_POST'
if spec_bg_post not in self.dict_tracers:
self.dict_tracers[spec_bg_post] = {
'id': spec_bg_post,
**default_xml_config
}
# Create the config for the optimized emitted tracers
for emi_spec in emis_species_ref:
emi_spec_post = emi_spec + '_POST'
if emi_spec_post not in self.dict_tracers:
self.dict_tracers[emi_spec_post] = {
'id': emi_spec_post,
**default_xml_config,
**{
'oem_type': 'emis',
'oem_tscale': '3',
'oem_cat': [emi_spec + '_POST'],
'oem_vp': ['ground_emissions'],
'oem_tp': [emi_spec]
}
}
# Create the config for the sample active tracer
self.dict_tracers[spec] = {
'id': spec,
**default_xml_config
}