Source code for pycif.plugins.obsoperators.standard.transforms.connect_pipes
import copy
import itertools
from logging import debug
from .utils import add_default
[docs]
def connect_pipes(self, all_transforms,
backup_comps, mapper):
"""Connect transforms based on their inputs and outputs"""
# Update precursors and successors with all possible transformation
# using the corresponding input/output
# For each transformation, looking for all trid in its own inputs that
# are found in outputs from another transform before it
for itransf, transform in enumerate(all_transforms.attributes):
transf = getattr(all_transforms, transform)
transf_mapper = mapper[transform]
transf_mapper["precursors"] = transf_mapper.get("precursors", {})
precursors = transf_mapper["precursors"]
for inpt in transf_mapper["inputs"]:
if inpt not in precursors:
precursors[inpt] = []
for tr in all_transforms.attributes[:itransf]:
if inpt in mapper[tr]["outputs"] \
and tr not in precursors[inpt]:
precursors[inpt].append(tr)
transf_mapper["successors"] = transf_mapper.get("successors", {})
successors = transf_mapper["successors"]
for outpt in transf_mapper["outputs"]:
if outpt not in successors:
successors[outpt] = []
for tr in all_transforms.attributes[itransf + 1:]:
if outpt in mapper[tr]["inputs"] \
and tr not in successors[outpt]:
successors[outpt].append(tr)
# Clean successors and precursors by removing direct pipes
# This means that some successive transforms may have the same
# inputs/outputs and only carry on computations on them only, i.e.,
# not changing the shape of the datastore.
for itransf, transform in enumerate(all_transforms.attributes):
transf = getattr(all_transforms, transform)
transf_mapper = mapper[transform]
successors = transf_mapper["successors"]
for trid in successors:
redundancy = set(itertools.chain(
*[mapper[tr_ref]["successors"].get(trid, [])
for tr_ref in successors[trid]]))
for trtmp in redundancy:
if trtmp != transform:
successors[trid].remove(trtmp)
precursors = transf_mapper["precursors"]
for trid in precursors:
redundancy = set(itertools.chain(
*[mapper[tr_ref]["precursors"].get(trid, [])
for tr_ref in precursors[trid]]))
for trtmp in redundancy:
if trtmp != transform:
precursors[trid].remove(trtmp)