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. Reads ``controlvect.transform_pipe`` and inserts each of its transforms **before** the first element of ``self.mainpipe`` in *all_transforms*, preserving the user-defined order. Also loops over all components/tracers of the ``datavect`` and, for those that specify the ``unit_conversion`` argument, automatically inserts a :doc:`unit_conversion </documentation/plugins/transforms/basic/unit_conversion>` transform. Args: self (ObsOperator): the obs-operator plugin instance; uses ``self.mainpipe`` to determine the insertion point. all_transforms: the :class:`~pycif.utils.classes.transforms.Transform` object holding all transforms; modified in-place. controlvect (ControlVect): control-vector object; its ``transform_pipe`` is read to determine which transforms to insert. backup_comps (dict): backed-up component definitions forwarded to :func:`~.utils.add_default.add_default`. mapper (dict): the pipeline mapper dictionary; updated in-place. """ # 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 = f"{transf_id}_before" # 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)