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 = getattr(transforms, "attributes", []) components = controlvect.datavect.components comps = components.attributes # Loops backwards on available transformations and update inputs/outputs # According to model inputs itransf = len(transfs_ids) ntransf_before = len(all_transforms.attributes) while itransf > 0: itransf -= 1 ntransf_loc = 0 transform = "{}_before".format(transfs_ids[itransf]) # Initializes mapper if not already done if transform not in mapper: # Replacing the transform by a transform class # if not already initialized transf = getattr(transforms, transfs_ids[itransf]) if transf is None: transf = Transform.from_dict({}, orig_name=transform) setattr(all_transforms, transform, transf) all_transforms.attributes.insert(0, transform) # Updating the general mapper, and creates a local one transf_mapper = transf.ini_mapper( general_mapper=mapper, backup_comps=backup_comps, ) transf.mapper = transf_mapper mapper[transform] = transf_mapper else: transf_mapper = mapper[transform] # Keep in memory transformations on the controlvect side all_transforms.controlpipe = [tr for tr in all_transforms.attributes]