Source code for pycif.plugins.obsoperators.standard.transforms.init_control_transformations

import itertools
import copy
from .utils import add_default
from .....utils.classes.transforms import Transform


[docs] def init_control_transformations( self, all_transforms, controlvect, backup_comps, mapper): """Initialize transforms on the control vector side. Also loops on all components/tracers of the ``datavect`` and for those for which the argument ``unit_conversion`` is specified, applies the :doc:`unit_conversion </documentation/plugins/transforms/basic/unit_conversion>` transform. """ # Initializes the overall transform pipe if not hasattr(controlvect, "transform_pipe"): controlvect.transform_pipe = Transform.from_dict({}) transforms = controlvect.transform_pipe transfs_ids = copy.deepcopy(getattr(transforms, "attributes", [])) components = controlvect.datavect.components comps = components.attributes # Loops backwards on available transformations and update inputs/outputs # According to model inputs ref_index = 0 if self.mainpipe != []: ref_index = all_transforms.attributes.index(self.mainpipe[0]) for transf_id in transfs_ids[::-1]: transform = "{}_before".format(transf_id) # Initializes mapper if not already done if transform in mapper: continue # Replacing the transform by a transform class # if not already initialized transf = getattr(transforms, transf_id) if transf is None: transf = Transform.from_dict({}, orig_name=transform) yml_dict = transf.to_dict(transf, full_output=True) _, new_id = add_default.add_default( self, all_transforms, yml_dict, position="index", index=ref_index, mapper=mapper, init=True, backup_comps=backup_comps, transform_id=transform ) ref_index = all_transforms.attributes.index(new_id) self.mainpipe.insert(0, new_id)