LSST Applications  22.0.1,22.0.1+01bcf6a671,22.0.1+046ee49490,22.0.1+05c7de27da,22.0.1+0c6914dbf6,22.0.1+1220d50b50,22.0.1+12fd109e95,22.0.1+1a1dd69893,22.0.1+1c910dc348,22.0.1+1ef34551f5,22.0.1+30170c3d08,22.0.1+39153823fd,22.0.1+611137eacc,22.0.1+771eb1e3e8,22.0.1+94e66cc9ed,22.0.1+9a075d06e2,22.0.1+a5ff6e246e,22.0.1+a7db719c1a,22.0.1+ba0d97e778,22.0.1+bfe1ee9056,22.0.1+c4e1e0358a,22.0.1+cc34b8281e,22.0.1+d640e2c0fa,22.0.1+d72a2e677a,22.0.1+d9a6b571bd,22.0.1+e485e9761b,22.0.1+ebe8d3385e
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.pipe.base.pipelineIR.PipelineIR Class Reference

Public Member Functions

def __init__ (self, loaded_yaml)
 
PipelineIR subset_from_labels (self, Set[str] labelSpecifier)
 
def from_string (cls, str pipeline_string)
 
PipelineIR from_file (cls, str filename)
 
PipelineIR from_uri (cls, Union[str, ButlerURI] uri)
 
def to_file (self, str filename)
 
def write_to_uri (self, Union[ButlerURI, str] uri)
 
Dict[str, Any] to_primitives (self)
 
str __str__ (self)
 
str __repr__ (self)
 
def __eq__ (self, object other)
 

Public Attributes

 description
 
 instrument
 
 contracts
 
 parameters
 
 labeled_subsets
 
 imports
 
 tasks
 

Detailed Description

Intermediate representation of a pipeline definition

Parameters
----------
loaded_yaml : `dict`
    A dictionary which matches the structure that would be produced by a
    yaml reader which parses a pipeline definition document

Raises
------
ValueError :
    - If a pipeline is declared without a description
    - If no tasks are declared in a pipeline, and no pipelines are to be
      inherited
    - If more than one instrument is specified
    - If more than one inherited pipeline share a label

Definition at line 459 of file pipelineIR.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.base.pipelineIR.PipelineIR.__init__ (   self,
  loaded_yaml 
)

Definition at line 477 of file pipelineIR.py.

477  def __init__(self, loaded_yaml):
478  # Check required fields are present
479  if "description" not in loaded_yaml:
480  raise ValueError("A pipeline must be declared with a description")
481  if "tasks" not in loaded_yaml and len({"imports", "inherits"} - loaded_yaml.keys()) == 2:
482  raise ValueError("A pipeline must be declared with one or more tasks")
483 
484  # These steps below must happen in this call order
485 
486  # Process pipeline description
487  self.description = loaded_yaml.pop("description")
488 
489  # Process tasks
490  self._read_tasks(loaded_yaml)
491 
492  # Process instrument keys
493  inst = loaded_yaml.pop("instrument", None)
494  if isinstance(inst, list):
495  raise ValueError("Only one top level instrument can be defined in a pipeline")
496  self.instrument = inst
497 
498  # Process any contracts
499  self._read_contracts(loaded_yaml)
500 
501  # Process any defined parameters
502  self._read_parameters(loaded_yaml)
503 
504  # Process any named label subsets
505  self._read_labeled_subsets(loaded_yaml)
506 
507  # Process any inherited pipelines
508  self._read_imports(loaded_yaml)
509 
510  # verify named subsets, must be done after inheriting
511  self._verify_labeled_subsets()
512 

Member Function Documentation

◆ __eq__()

def lsst.pipe.base.pipelineIR.PipelineIR.__eq__ (   self,
object  other 
)

Definition at line 895 of file pipelineIR.py.

895  return str(self)
896 
897  def __eq__(self, other: object):
898  if not isinstance(other, PipelineIR):
899  return False
900  elif all(getattr(self, attr) == getattr(other, attr) for attr in
901  ("contracts", "tasks", "instrument")):
902  return True
903  else:
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.

◆ __repr__()

str lsst.pipe.base.pipelineIR.PipelineIR.__repr__ (   self)
Instance formatting as how it would look in yaml representation

Definition at line 890 of file pipelineIR.py.

890  return yaml.dump(self.to_primitives(), sort_keys=False)
891 
892  def __repr__(self) -> str:
893  """Instance formatting as how it would look in yaml representation
894  """

◆ __str__()

str lsst.pipe.base.pipelineIR.PipelineIR.__str__ (   self)
Instance formatting as how it would look in yaml representation

Definition at line 885 of file pipelineIR.py.

885  return accumulate
886 
887  def __str__(self) -> str:
888  """Instance formatting as how it would look in yaml representation
889  """

◆ from_file()

PipelineIR lsst.pipe.base.pipelineIR.PipelineIR.from_file (   cls,
str  filename 
)
Create a `PipelineIR` object from the document specified by the
input path.

Parameters
----------
filename : `str`
    Location of document to use in creating a `PipelineIR` object.

Returns
-------
pipelineIR : `PipelineIR`
    The loaded pipeline

Note
----
This method is deprecated, please use from_uri

Definition at line 798 of file pipelineIR.py.

798  version="v21.0,", category=FutureWarning) # type: ignore
799  def from_file(cls, filename: str) -> PipelineIR:
800  """Create a `PipelineIR` object from the document specified by the
801  input path.
802 
803  Parameters
804  ----------
805  filename : `str`
806  Location of document to use in creating a `PipelineIR` object.
807 
808  Returns
809  -------
810  pipelineIR : `PipelineIR`
811  The loaded pipeline
812 
813  Note
814  ----
815  This method is deprecated, please use from_uri
816  """
817  return cls.from_uri(filename)

◆ from_string()

def lsst.pipe.base.pipelineIR.PipelineIR.from_string (   cls,
str  pipeline_string 
)
Create a `PipelineIR` object from a string formatted like a pipeline
document

Parameters
----------
pipeline_string : `str`
    A string that is formatted according like a pipeline document

Definition at line 784 of file pipelineIR.py.

784  def from_string(cls, pipeline_string: str):
785  """Create a `PipelineIR` object from a string formatted like a pipeline
786  document
787 
788  Parameters
789  ----------
790  pipeline_string : `str`
791  A string that is formatted according like a pipeline document
792  """
793  loaded_yaml = yaml.load(pipeline_string, Loader=PipelineYamlLoader)
794  return cls(loaded_yaml)
795 

◆ from_uri()

PipelineIR lsst.pipe.base.pipelineIR.PipelineIR.from_uri (   cls,
Union[str, ButlerURI]  uri 
)
Create a `PipelineIR` object from the document specified by the
input uri.

Parameters
----------
uri: `str` or `ButlerURI`
    Location of document to use in creating a `PipelineIR` object.

Returns
-------
pipelineIR : `PipelineIR`
    The loaded pipeline

Definition at line 819 of file pipelineIR.py.

819  @classmethod
820  def from_uri(cls, uri: Union[str, ButlerURI]) -> PipelineIR:
821  """Create a `PipelineIR` object from the document specified by the
822  input uri.
823 
824  Parameters
825  ----------
826  uri: `str` or `ButlerURI`
827  Location of document to use in creating a `PipelineIR` object.
828 
829  Returns
830  -------
831  pipelineIR : `PipelineIR`
832  The loaded pipeline
833  """
834  loaded_uri = ButlerURI(uri)
835  # With ButlerURI we have the choice of always using a local file or
836  # reading in the bytes directly. Reading in bytes can be more
837  # efficient for reasonably-sized files when the resource is remote.
838  # For now use the local file variant. For a local file as_local() does
839  # nothing.
840  with loaded_uri.as_local() as local:
841  # explicitly read here, there was some issue with yaml trying
842  # to read the ButlerURI itself (I think because it only
843  # pretends to be conformant to the io api)
844  loaded_yaml = yaml.load(local.read(), Loader=PipelineYamlLoader)
845  return cls(loaded_yaml)

◆ subset_from_labels()

PipelineIR lsst.pipe.base.pipelineIR.PipelineIR.subset_from_labels (   self,
Set[str]  labelSpecifier 
)
Subset a pipelineIR to contain only labels specified in
labelSpecifier.

Parameters
----------
labelSpecifier : `set` of `str`
    Set containing labels that describes how to subset a pipeline.

Returns
-------
pipeline : `PipelineIR`
    A new pipelineIR object that is a subset of the old pipelineIR

Raises
------
ValueError
    Raised if there is an issue with specified labels

Notes
-----
This method attempts to prune any contracts that contain labels which
are not in the declared subset of labels. This pruning is done using a
string based matching due to the nature of contracts and may prune more
than it should. Any labeled subsets defined that no longer have all
members of the subset present in the pipeline will be removed from the
resulting pipeline.

Definition at line 718 of file pipelineIR.py.

718  def subset_from_labels(self, labelSpecifier: Set[str]) -> PipelineIR:
719  """Subset a pipelineIR to contain only labels specified in
720  labelSpecifier.
721 
722  Parameters
723  ----------
724  labelSpecifier : `set` of `str`
725  Set containing labels that describes how to subset a pipeline.
726 
727  Returns
728  -------
729  pipeline : `PipelineIR`
730  A new pipelineIR object that is a subset of the old pipelineIR
731 
732  Raises
733  ------
734  ValueError
735  Raised if there is an issue with specified labels
736 
737  Notes
738  -----
739  This method attempts to prune any contracts that contain labels which
740  are not in the declared subset of labels. This pruning is done using a
741  string based matching due to the nature of contracts and may prune more
742  than it should. Any labeled subsets defined that no longer have all
743  members of the subset present in the pipeline will be removed from the
744  resulting pipeline.
745  """
746 
747  pipeline = copy.deepcopy(self)
748 
749  # update the label specifier to expand any named subsets
750  toRemove = set()
751  toAdd = set()
752  for label in labelSpecifier:
753  if label in pipeline.labeled_subsets:
754  toRemove.add(label)
755  toAdd.update(pipeline.labeled_subsets[label].subset)
756  labelSpecifier.difference_update(toRemove)
757  labelSpecifier.update(toAdd)
758  # verify all the labels are in the pipeline
759  if not labelSpecifier.issubset(pipeline.tasks.keys()
760  | pipeline.labeled_subsets):
761  difference = labelSpecifier.difference(pipeline.tasks.keys())
762  raise ValueError("Not all supplied labels (specified or named subsets) are in the pipeline "
763  f"definition, extra labels: {difference}")
764  # copy needed so as to not modify while iterating
765  pipeline_labels = set(pipeline.tasks.keys())
766  # Remove the labels from the pipelineIR, and any contracts that contain
767  # those labels (see docstring on _remove_contracts for why this may
768  # cause issues)
769  for label in pipeline_labels:
770  if label not in labelSpecifier:
771  pipeline.tasks.pop(label)
772  pipeline._remove_contracts(label)
773 
774  # create a copy of the object to iterate over
775  labeled_subsets = copy.copy(pipeline.labeled_subsets)
776  # remove any labeled subsets that no longer have a complete set
777  for label, labeled_subset in labeled_subsets.items():
778  if labeled_subset.subset - pipeline.tasks.keys():
779  pipeline.labeled_subsets.pop(label)
780 
781  return pipeline
782 
daf::base::PropertySet * set
Definition: fits.cc:912

◆ to_file()

def lsst.pipe.base.pipelineIR.PipelineIR.to_file (   self,
str  filename 
)
Serialize this `PipelineIR` object into a yaml formatted string and
write the output to a file at the specified path.

Parameters
----------
filename : `str`
    Location of document to write a `PipelineIR` object.

Definition at line 847 of file pipelineIR.py.

847  @deprecated(reason="This has been replaced with `write_to_uri`. will be removed after v23", version="v21.0,", category=FutureWarning) # type: ignore
848  def to_file(self, filename: str):
849  """Serialize this `PipelineIR` object into a yaml formatted string and
850  write the output to a file at the specified path.
851 
852  Parameters
853  ----------
854  filename : `str`
855  Location of document to write a `PipelineIR` object.
856  """
857 

◆ to_primitives()

Dict[str, Any] lsst.pipe.base.pipelineIR.PipelineIR.to_primitives (   self)
Convert to a representation used in yaml serialization

Definition at line 870 of file pipelineIR.py.

870  butlerUri.write(yaml.dump(self.to_primitives(), sort_keys=False).encode())
871 
872  def to_primitives(self) -> Dict[str, Any]:
873  """Convert to a representation used in yaml serialization
874  """
875  accumulate = {"description": self.description}
876  if self.instrument is not None:
877  accumulate['instrument'] = self.instrument
878  if self.parameters:
879  accumulate['parameters'] = self.parameters.to_primitives()
880  accumulate['tasks'] = {m: t.to_primitives() for m, t in self.tasks.items()}
881  if len(self.contracts) > 0:
882  accumulate['contracts'] = [c.to_primitives() for c in self.contracts]
883  if self.labeled_subsets:
884  accumulate['subsets'] = {k: v.to_primitives() for k, v in self.labeled_subsets.items()}
std::vector< SchemaItem< Flag > > * items

◆ write_to_uri()

def lsst.pipe.base.pipelineIR.PipelineIR.write_to_uri (   self,
Union[ButlerURI, str]  uri 
)
Serialize this `PipelineIR` object into a yaml formatted string and
write the output to a file at the specified uri.

Parameters
----------
uri: `str` or `ButlerURI`
    Location of document to write a `PipelineIR` object.

Definition at line 858 of file pipelineIR.py.

858  self.write_to_uri(filename)
859 
860  def write_to_uri(self, uri: Union[ButlerURI, str]):
861  """Serialize this `PipelineIR` object into a yaml formatted string and
862  write the output to a file at the specified uri.
863 
864  Parameters
865  ----------
866  uri: `str` or `ButlerURI`
867  Location of document to write a `PipelineIR` object.
868  """
869  butlerUri = ButlerURI(uri)

Member Data Documentation

◆ contracts

lsst.pipe.base.pipelineIR.PipelineIR.contracts

Definition at line 525 of file pipelineIR.py.

◆ description

lsst.pipe.base.pipelineIR.PipelineIR.description

Definition at line 487 of file pipelineIR.py.

◆ imports

lsst.pipe.base.pipelineIR.PipelineIR.imports

Definition at line 607 of file pipelineIR.py.

◆ instrument

lsst.pipe.base.pipelineIR.PipelineIR.instrument

Definition at line 496 of file pipelineIR.py.

◆ labeled_subsets

lsst.pipe.base.pipelineIR.PipelineIR.labeled_subsets

Definition at line 556 of file pipelineIR.py.

◆ parameters

lsst.pipe.base.pipelineIR.PipelineIR.parameters

Definition at line 544 of file pipelineIR.py.

◆ tasks

lsst.pipe.base.pipelineIR.PipelineIR.tasks

Definition at line 660 of file pipelineIR.py.


The documentation for this class was generated from the following file: