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

import itertools
import copy

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


[docs] def init_mainpipe(self, all_transforms, backup_comps, mapper): """Initialize the core of the transform pipeline. Reads ``self.transform_pipe`` (transforms defined directly on the observation operator in the YAML) and inserts each of its transforms before the first element already present in ``self.mainpipe``. If no ``transform_pipe`` is defined and ``self.ignore_model`` is ``False``, a default ``run_model`` transform is added automatically. .. warning:: If ``transform_pipe`` is specified in the observation operator, **only** the explicitly listed transforms are used — the CTM model is **not** added automatically. To run the model on top of custom transforms, include ``run_model`` explicitly in the list. For most applications it is preferable to define extra transforms in the ``controlvect`` or ``obsvect`` ``transform_pipe`` instead. Args: self (ObsOperator): the obs-operator plugin instance. On return, ``self.mainpipe`` is updated with the IDs of the newly inserted transforms. all_transforms: the :class:`~pycif.utils.classes.transforms.Transform` object holding all transforms; modified in-place. 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 no pipe is specified, assume that the model should be run if not hasattr(self, "transform_pipe"): if not self.ignore_model: yml_dict = { "run_model": { "plugin": { "name": "run_model", "version": "std", "type": "transform", } } } else: yml_dict = {} self.transform_pipe = Transform.from_dict(yml_dict) main_transforms = self.transform_pipe transfs_ids = copy.deepcopy(getattr(main_transforms, "attributes", [])) # Loops backwards on available transformations and update inputs/out # According to model outputs ref_index = 0 if self.mainpipe != []: ref_index = all_transforms.attributes.index(self.mainpipe[0]) for transform in transfs_ids[::-1]: # Initializes mapper if not already done if transform in mapper: continue # Replacing the transform by a transform class # if not already initialized transf = getattr(main_transforms, transform) 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)
# # Keep in memory the transformations in the main pipe # all_transforms.mainpipe = \ # [tr for tr in all_transforms.attributes # if tr not in all_transforms.obsvectpipe]