Source code for pycif.plugins.models.iconart.perturb_model
import copy
from logging import warn
[docs]
def perturb_model(self, nsamples, transf_mapper):
self.chemistry.nsamples = nsamples
self.chemistry.mapping_active2emi = {}
self.chemistry.mapping_active2emi_ref = {}
# Perturb active species in the chemical scheme
list_acspecies = copy.deepcopy(self.chemistry.acspecies.attributes)
for spec in list_acspecies:
spec_plg = getattr(self.chemistry.acspecies, spec)
list_emis_species = sorted(copy.deepcopy(spec_plg.emis_species))
self.chemistry.mapping_active2emi_ref[spec] = list_emis_species
for i in range(nsamples):
spec_sample = "{}__sample#{:03d}".format(spec, i)
self.chemistry.acspecies.attributes.append(spec_sample)
setattr(self.chemistry.acspecies, spec_sample, spec_plg)
emspecs_sample = ["{}__sample#{:03d}".format(emspec, i)
for emspec in list_emis_species]
self.chemistry.mapping_active2emi[spec_sample] = emspecs_sample
# Remove the old active species
delattr(self.chemistry.acspecies, spec)
self.chemistry.acspecies.attributes.remove(spec)
# Dump updated chemical scheme
self.chemistry.create_chemicalscheme()