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.argumentParser.DataIdContainer Class Reference

Public Member Functions

def __init__ (self, level=None)
 
def setDatasetType (self, datasetType)
 
def castDataIds (self, butler)
 
def makeDataRefList (self, namespace)
 

Public Attributes

 datasetType
 
 level
 
 idList
 
 refList
 

Detailed Description

Container for data IDs and associated data references.

Parameters
----------
level : `str`
    The lowest hierarchy level to descend to for this dataset type,
    for example `"amp"` for `"raw"` or `"ccd"` for `"calexp"`.
    Use `""` to use the mapper's default for the dataset type.
    This class does not support `None`, but if it did, `None`
    would mean the level should not be restricted.

Notes
-----
Override this class for data IDs that require special handling to be
converted to ``data references``, and specify the override class
as ``ContainerClass`` for ``add_id_argument``.

If you don't want the argument parser to compute data references,
specify ``doMakeDataRefList=False`` in ``add_id_argument``.

Definition at line 75 of file argumentParser.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.base.argumentParser.DataIdContainer.__init__ (   self,
  level = None 
)

Definition at line 97 of file argumentParser.py.

97  def __init__(self, level=None):
98  self.datasetType = None
99  """Dataset type of the data references (`str`).
100  """
101  self.level = level
102  """See parameter ``level`` (`str`).
103  """
104  self.idList = []
105  """List of data IDs specified on the command line for the
106  appropriate data ID argument (`list` of `dict`).
107  """
108  self.refList = []
109  """List of data references for the data IDs in ``idList``
110  (`list` of `lsst.daf.persistence.ButlerDataRef`).
111  Elements will be omitted if the corresponding data is not found.
112  The list will be empty when returned by ``parse_args`` if
113  ``doMakeDataRefList=False`` was specified in ``add_id_argument``.
114  """
115 

Member Function Documentation

◆ castDataIds()

def lsst.pipe.base.argumentParser.DataIdContainer.castDataIds (   self,
  butler 
)
Validate data IDs and cast them to the correct type
(modify idList in place).

This code casts the values in the data IDs dicts in `dataIdList`
to the type required by the butler. Data IDs are read from the
command line as `str`, but the butler requires some values to be
other types. For example "visit" values should be `int`.

Parameters
----------
butler : `lsst.daf.persistence.Butler`
    Data butler.

Definition at line 133 of file argumentParser.py.

133  def castDataIds(self, butler):
134  """Validate data IDs and cast them to the correct type
135  (modify idList in place).
136 
137  This code casts the values in the data IDs dicts in `dataIdList`
138  to the type required by the butler. Data IDs are read from the
139  command line as `str`, but the butler requires some values to be
140  other types. For example "visit" values should be `int`.
141 
142  Parameters
143  ----------
144  butler : `lsst.daf.persistence.Butler`
145  Data butler.
146  """
147  if self.datasetType is None:
148  raise RuntimeError("Must call setDatasetType first")
149  try:
150  idKeyTypeDict = butler.getKeys(datasetType=self.datasetType, level=self.level)
151  except KeyError as e:
152  msg = f"Cannot get keys for datasetType {self.datasetType} at level {self.level}"
153  raise KeyError(msg) from e
154 
155  for dataDict in self.idList:
156  for key, strVal in dataDict.items():
157  try:
158  keyType = idKeyTypeDict[key]
159  except KeyError:
160  # OK, assume that it's a valid key and guess that it's a
161  # string
162  keyType = str
163 
164  log = lsstLog.Log.getDefaultLogger()
165  log.warn("Unexpected ID %s; guessing type is \"%s\"",
166  key, 'str' if keyType == str else keyType)
167  idKeyTypeDict[key] = keyType
168 
169  if keyType != str:
170  try:
171  castVal = keyType(strVal)
172  except Exception:
173  raise TypeError(f"Cannot cast value {strVal!r} to {keyType} for ID key {key}")
174  dataDict[key] = castVal
175 

◆ makeDataRefList()

def lsst.pipe.base.argumentParser.DataIdContainer.makeDataRefList (   self,
  namespace 
)
Compute refList based on idList.

Parameters
----------
namespace : `argparse.Namespace`
    Results of parsing command-line. The ``butler`` and ``log``
    elements must be set.

Notes
-----
Not called if ``add_id_argument`` was called with
``doMakeDataRefList=False``.

Definition at line 176 of file argumentParser.py.

176  def makeDataRefList(self, namespace):
177  """Compute refList based on idList.
178 
179  Parameters
180  ----------
181  namespace : `argparse.Namespace`
182  Results of parsing command-line. The ``butler`` and ``log``
183  elements must be set.
184 
185  Notes
186  -----
187  Not called if ``add_id_argument`` was called with
188  ``doMakeDataRefList=False``.
189  """
190  if self.datasetType is None:
191  raise RuntimeError("Must call setDatasetType first")
192  butler = namespace.butler
193  for dataId in self.idList:
194  refList = dafPersist.searchDataRefs(butler, datasetType=self.datasetType,
195  level=self.level, dataId=dataId)
196  if not refList:
197  namespace.log.warn("No data found for dataId=%s", dataId)
198  continue
199  self.refList += refList
200 
201 

◆ setDatasetType()

def lsst.pipe.base.argumentParser.DataIdContainer.setDatasetType (   self,
  datasetType 
)
Set actual dataset type, once it is known.

Parameters
----------
datasetType : `str`
    Dataset type.

Notes
-----
The reason ``datasetType`` is not a constructor argument is that
some subclasses do not know the dataset type until the command
is parsed. Thus, to reduce special cases in the code,
``datasetType`` is always set after the command is parsed.

Definition at line 116 of file argumentParser.py.

116  def setDatasetType(self, datasetType):
117  """Set actual dataset type, once it is known.
118 
119  Parameters
120  ----------
121  datasetType : `str`
122  Dataset type.
123 
124  Notes
125  -----
126  The reason ``datasetType`` is not a constructor argument is that
127  some subclasses do not know the dataset type until the command
128  is parsed. Thus, to reduce special cases in the code,
129  ``datasetType`` is always set after the command is parsed.
130  """
131  self.datasetType = datasetType
132 

Member Data Documentation

◆ datasetType

lsst.pipe.base.argumentParser.DataIdContainer.datasetType

Definition at line 98 of file argumentParser.py.

◆ idList

lsst.pipe.base.argumentParser.DataIdContainer.idList

Definition at line 104 of file argumentParser.py.

◆ level

lsst.pipe.base.argumentParser.DataIdContainer.level

Definition at line 101 of file argumentParser.py.

◆ refList

lsst.pipe.base.argumentParser.DataIdContainer.refList

Definition at line 108 of file argumentParser.py.


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