LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst.pipe.base.argumentParser.DataIdContainer Class Reference

A container for data IDs and associated data references. More...

Inheritance diagram for lsst.pipe.base.argumentParser.DataIdContainer:

Public Member Functions

def __init__
 Construct a DataIdContainer. More...
 
def setDatasetType
 Set actual dataset type, once it is known. More...
 
def castDataIds
 Validate data IDs and cast them to the correct type (modify idList in place). More...
 
def makeDataRefList
 Compute refList based on idList. More...
 

Public Attributes

 datasetType
 
 level
 
 idList
 
 refList
 

Detailed Description

A container for data IDs and associated data references.

Override 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, you may use this class and specify doMakeDataRefList=False in add_id_argument.)

Definition at line 62 of file argumentParser.py.

Constructor & Destructor Documentation

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

Construct a DataIdContainer.

Definition at line 70 of file argumentParser.py.

70 
71  def __init__(self, level=None):
72  """!Construct a DataIdContainer"""
73  self.datasetType = None # the actual dataset type, as specified on the command line (if dynamic)
74  self.level = level
75  self.idList = []
76  self.refList = []
def __init__
Construct a DataIdContainer.

Member Function Documentation

def lsst.pipe.base.argumentParser.DataIdContainer.castDataIds (   self,
  butler 
)

Validate data IDs and cast them to the correct type (modify idList in place).

Parameters
[in]butlerdata butler (a lsst.daf.persistence.Butler)

Definition at line 81 of file argumentParser.py.

81 
82  def castDataIds(self, butler):
83  """!Validate data IDs and cast them to the correct type (modify idList in place).
84 
85  @param[in] butler data butler (a \ref lsst.daf.persistence.butler.Butler
86  "lsst.daf.persistence.Butler")
87  """
88  if self.datasetType is None:
89  raise RuntimeError("Must call setDatasetType first")
90  try:
91  idKeyTypeDict = butler.getKeys(datasetType=self.datasetType, level=self.level)
92  except KeyError:
93  raise KeyError("Cannot get keys for datasetType %s at level %s" % (self.datasetType, self.level))
94 
95  for dataDict in self.idList:
96  for key, strVal in dataDict.iteritems():
97  try:
98  keyType = idKeyTypeDict[key]
99  except KeyError:
100  validKeys = sorted(idKeyTypeDict.keys())
101  raise KeyError("Unrecognized ID key %r; valid keys are: %s" % (key, validKeys))
102  if keyType != str:
103  try:
104  castVal = keyType(strVal)
105  except Exception:
106  raise TypeError("Cannot cast value %r to %s for ID key %r" % (strVal, keyType, key,))
107  dataDict[key] = castVal
def castDataIds
Validate data IDs and cast them to the correct type (modify idList in place).
def lsst.pipe.base.argumentParser.DataIdContainer.makeDataRefList (   self,
  namespace 
)

Compute refList based on idList.

Not called if add_id_argument called with doMakeDataRef=False

Parameters
[in]namespaceresults of parsing command-line (with 'butler' and 'log' elements)

Definition at line 108 of file argumentParser.py.

109  def makeDataRefList(self, namespace):
110  """!Compute refList based on idList
111 
112  Not called if add_id_argument called with doMakeDataRef=False
113 
114  @param[in] namespace results of parsing command-line (with 'butler' and 'log' elements)
115  """
116  if self.datasetType is None:
117  raise RuntimeError("Must call setDatasetType first")
118  butler = namespace.butler
119  for dataId in self.idList:
120  refList = list(butler.subset(datasetType=self.datasetType, level=self.level, dataId=dataId))
121  # exclude nonexistent data
122  # this is a recursive test, e.g. for the sake of "raw" data
123  refList = [dr for dr in refList if dataExists(butler=butler, datasetType=self.datasetType,
124  dataRef=dr)]
125  if not refList:
126  namespace.log.warn("No data found for dataId=%s" % (dataId,))
127  continue
128  self.refList += refList
129 
def dataExists
Return True if data exists at the current level or any data exists at a deeper level, False otherwise.
def makeDataRefList
Compute refList based on idList.
def lsst.pipe.base.argumentParser.DataIdContainer.setDatasetType (   self,
  datasetType 
)

Set actual dataset type, once it is known.

Definition at line 77 of file argumentParser.py.

77 
78  def setDatasetType(self, datasetType):
79  """!Set actual dataset type, once it is known"""
80  self.datasetType = datasetType
def setDatasetType
Set actual dataset type, once it is known.

Member Data Documentation

lsst.pipe.base.argumentParser.DataIdContainer.datasetType

Definition at line 72 of file argumentParser.py.

lsst.pipe.base.argumentParser.DataIdContainer.idList

Definition at line 74 of file argumentParser.py.

lsst.pipe.base.argumentParser.DataIdContainer.level

Definition at line 73 of file argumentParser.py.

lsst.pipe.base.argumentParser.DataIdContainer.refList

Definition at line 75 of file argumentParser.py.


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