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.butlerQuantumContext.ButlerQuantumContext Class Reference

Public Member Functions

def __init__ (self, Butler butler, Quantum quantum)
 
object get (self, typing.Union[InputQuantizedConnection, typing.List[DatasetRef], DatasetRef] dataset)
 
def put (self, typing.Union[Struct, typing.List[typing.Any], object] values, typing.Union[OutputQuantizedConnection, typing.List[DatasetRef], DatasetRef] dataset)
 

Public Attributes

 quantum
 
 registry
 
 allInputs
 
 allOutputs
 

Detailed Description

A Butler-like class specialized for a single quantum

A ButlerQuantumContext class wraps a standard butler interface and
specializes it to the context of a given quantum. What this means
in practice is that the only gets and puts that this class allows
are DatasetRefs that are contained in the quantum.

In the future this class will also be used to record provenance on
what was actually get and put. This is in contrast to what the
preflight expects to be get and put by looking at the graph before
execution.

Parameters
----------
butler : `lsst.daf.butler.Butler`
    Butler object from/to which datasets will be get/put
quantum : `lsst.daf.butler.core.Quantum`
    Quantum object that describes the datasets which will be get/put by a
    single execution of this node in the pipeline graph.  All input
    dataset references must be resolved (i.e. satisfy
    ``DatasetRef.id is not None``) prior to constructing the
    `ButlerQuantumContext`.

Notes
-----
Most quanta in any non-trivial graph will not start with resolved dataset
references, because they represent processing steps that can only run
after some other quanta have produced their inputs.  At present, it is the
responsibility of ``lsst.ctrl.mpexec.SingleQuantumExecutor`` to resolve all
datasets prior to constructing `ButlerQuantumContext` and calling
`runQuantum`, and the fact that this precondition is satisfied by code in
a downstream package is considered a problem with the
``pipe_base/ctrl_mpexec`` separation of concerns that will be addressed in
the future.

Definition at line 35 of file butlerQuantumContext.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext.__init__ (   self,
Butler  butler,
Quantum  quantum 
)

Definition at line 71 of file butlerQuantumContext.py.

71  def __init__(self, butler: Butler, quantum: Quantum):
72  self.quantum = quantum
73  self.registry = butler.registry
74  self.allInputs = set()
75  self.allOutputs = set()
76  for refs in quantum.inputs.values():
77  for ref in refs:
78  self.allInputs.add((ref.datasetType, ref.dataId))
79  for refs in quantum.outputs.values():
80  for ref in refs:
81  self.allOutputs.add((ref.datasetType, ref.dataId))
82 
83  # Create closures over butler to discourage anyone from directly
84  # using a butler reference
85  def _get(self, ref):
86  # Butler methods below will check for unresolved DatasetRefs and
87  # raise appropriately, so no need for us to do that here.
88  if isinstance(ref, DeferredDatasetRef):
89  self._checkMembership(ref.datasetRef, self.allInputs)
90  return butler.getDirectDeferred(ref.datasetRef)
91 
92  else:
93  self._checkMembership(ref, self.allInputs)
94  return butler.getDirect(ref)
95 
96  def _put(self, value, ref):
97  self._checkMembership(ref, self.allOutputs)
98  butler.put(value, ref)
99 
100  self._get = types.MethodType(_get, self)
101  self._put = types.MethodType(_put, self)
102 
daf::base::PropertySet * set
Definition: fits.cc:912

Member Function Documentation

◆ get()

object lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext.get (   self,
typing.Union[InputQuantizedConnection, typing.List[DatasetRef], DatasetRef]  dataset 
)
Fetches data from the butler

Parameters
----------
dataset
    This argument may either be an `InputQuantizedConnection` which
    describes all the inputs of a quantum, a list of
    `~lsst.daf.butler.DatasetRef`, or a single
    `~lsst.daf.butler.DatasetRef`. The function will get and return
    the corresponding datasets from the butler.

Returns
-------
return : `object`
    This function returns arbitrary objects fetched from the bulter.
    The structure these objects are returned in depends on the type of
    the input argument. If the input dataset argument is a
    `InputQuantizedConnection`, then the return type will be a
    dictionary with keys corresponding to the attributes of the
    `InputQuantizedConnection` (which in turn are the attribute
    identifiers of the connections). If the input argument is of type
    `list` of `~lsst.daf.butler.DatasetRef` then the return type will
    be a list of objects.  If the input argument is a single
    `~lsst.daf.butler.DatasetRef` then a single object will be
    returned.

Raises
------
ValueError
    Raised if a `DatasetRef` is passed to get that is not defined in
    the quantum object

Definition at line 103 of file butlerQuantumContext.py.

105  DatasetRef]) -> object:
106  """Fetches data from the butler
107 
108  Parameters
109  ----------
110  dataset
111  This argument may either be an `InputQuantizedConnection` which
112  describes all the inputs of a quantum, a list of
113  `~lsst.daf.butler.DatasetRef`, or a single
114  `~lsst.daf.butler.DatasetRef`. The function will get and return
115  the corresponding datasets from the butler.
116 
117  Returns
118  -------
119  return : `object`
120  This function returns arbitrary objects fetched from the bulter.
121  The structure these objects are returned in depends on the type of
122  the input argument. If the input dataset argument is a
123  `InputQuantizedConnection`, then the return type will be a
124  dictionary with keys corresponding to the attributes of the
125  `InputQuantizedConnection` (which in turn are the attribute
126  identifiers of the connections). If the input argument is of type
127  `list` of `~lsst.daf.butler.DatasetRef` then the return type will
128  be a list of objects. If the input argument is a single
129  `~lsst.daf.butler.DatasetRef` then a single object will be
130  returned.
131 
132  Raises
133  ------
134  ValueError
135  Raised if a `DatasetRef` is passed to get that is not defined in
136  the quantum object
137  """
138  if isinstance(dataset, InputQuantizedConnection):
139  retVal = {}
140  for name, ref in dataset:
141  if isinstance(ref, list):
142  val = [self._get(r) for r in ref]
143  else:
144  val = self._get(ref)
145  retVal[name] = val
146  return retVal
147  elif isinstance(dataset, list):
148  return [self._get(x) for x in dataset]
149  elif isinstance(dataset, DatasetRef) or isinstance(dataset, DeferredDatasetRef):
150  return self._get(dataset)
151  else:
152  raise TypeError("Dataset argument is not a type that can be used to get")
153 

◆ put()

def lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext.put (   self,
typing.Union[Struct, typing.List[typing.Any], object]  values,
typing.Union[OutputQuantizedConnection, typing.List[DatasetRef], DatasetRef]  dataset 
)
Puts data into the butler

Parameters
----------
values : `Struct` or `list` of `object` or `object`
    The data that should be put with the butler. If the type of the
    dataset is `OutputQuantizedConnection` then this argument should be
    a `Struct` with corresponding attribute names. Each attribute
    should then correspond to either a list of object or a single
    object depending of the type of the corresponding attribute on
    dataset. I.e. if ``dataset.calexp`` is
    ``[datasetRef1, datasetRef2]`` then ``values.calexp`` should be
    ``[calexp1, calexp2]``. Like wise if there is a single ref, then
    only a single object need be passed. The same restriction applies
    if dataset is directly a `list` of `DatasetRef` or a single
    `DatasetRef`.
dataset
    This argument may either be an `InputQuantizedConnection` which
    describes all the inputs of a quantum, a list of
    `lsst.daf.butler.DatasetRef`, or a single
    `lsst.daf.butler.DatasetRef`. The function will get and return
    the corresponding datasets from the butler.

Raises
------
ValueError
    Raised if a `DatasetRef` is passed to put that is not defined in
    the quantum object, or the type of values does not match what is
    expected from the type of dataset.

Definition at line 154 of file butlerQuantumContext.py.

155  dataset: typing.Union[OutputQuantizedConnection, typing.List[DatasetRef], DatasetRef]):
156  """Puts data into the butler
157 
158  Parameters
159  ----------
160  values : `Struct` or `list` of `object` or `object`
161  The data that should be put with the butler. If the type of the
162  dataset is `OutputQuantizedConnection` then this argument should be
163  a `Struct` with corresponding attribute names. Each attribute
164  should then correspond to either a list of object or a single
165  object depending of the type of the corresponding attribute on
166  dataset. I.e. if ``dataset.calexp`` is
167  ``[datasetRef1, datasetRef2]`` then ``values.calexp`` should be
168  ``[calexp1, calexp2]``. Like wise if there is a single ref, then
169  only a single object need be passed. The same restriction applies
170  if dataset is directly a `list` of `DatasetRef` or a single
171  `DatasetRef`.
172  dataset
173  This argument may either be an `InputQuantizedConnection` which
174  describes all the inputs of a quantum, a list of
175  `lsst.daf.butler.DatasetRef`, or a single
176  `lsst.daf.butler.DatasetRef`. The function will get and return
177  the corresponding datasets from the butler.
178 
179  Raises
180  ------
181  ValueError
182  Raised if a `DatasetRef` is passed to put that is not defined in
183  the quantum object, or the type of values does not match what is
184  expected from the type of dataset.
185  """
186  if isinstance(dataset, OutputQuantizedConnection):
187  if not isinstance(values, Struct):
188  raise ValueError("dataset is a OutputQuantizedConnection, a Struct with corresponding"
189  " attributes must be passed as the values to put")
190  for name, refs in dataset:
191  valuesAttribute = getattr(values, name)
192  if isinstance(refs, list):
193  if len(refs) != len(valuesAttribute):
194  raise ValueError(f"There must be a object to put for every Dataset ref in {name}")
195  for i, ref in enumerate(refs):
196  self._put(valuesAttribute[i], ref)
197  else:
198  self._put(valuesAttribute, refs)
199  elif isinstance(dataset, list):
200  if len(dataset) != len(values):
201  raise ValueError("There must be a common number of references and values to put")
202  for i, ref in enumerate(dataset):
203  self._put(values[i], ref)
204  elif isinstance(dataset, DatasetRef):
205  self._put(values, dataset)
206  else:
207  raise TypeError("Dataset argument is not a type that can be used to put")
208 

Member Data Documentation

◆ allInputs

lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext.allInputs

Definition at line 74 of file butlerQuantumContext.py.

◆ allOutputs

lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext.allOutputs

Definition at line 75 of file butlerQuantumContext.py.

◆ quantum

lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext.quantum

Definition at line 72 of file butlerQuantumContext.py.

◆ registry

lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext.registry

Definition at line 73 of file butlerQuantumContext.py.


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