LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst.pipe.base.argumentParser.DataIdContainer Class Reference
Inheritance diagram for lsst.pipe.base.argumentParser.DataIdContainer:
lsst.meas.base.forcedPhotCcd.PerTractCcdDataIdContainer

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 
def __init__(self, minimum, dataRange, Q)

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 = "Cannot get keys for datasetType %s at level %s" % (self.datasetType, 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 string
161  keyType = str
162 
163  log = lsstLog.Log.getDefaultLogger()
164  log.warn("Unexpected ID %s; guessing type is \"%s\"" %
165  (key, 'str' if keyType == str else keyType))
166  idKeyTypeDict[key] = keyType
167 
168  if keyType != str:
169  try:
170  castVal = keyType(strVal)
171  except Exception:
172  raise TypeError("Cannot cast value %r to %s for ID key %r" % (strVal, keyType, key,))
173  dataDict[key] = castVal
174 

◆ 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 175 of file argumentParser.py.

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

◆ 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: