23 """Class for checking sourceTable_visit dataIds
26 import lsst.pipe.base
as pipeBase
27 import lsst.log
as lsstLog
31 """A version of lsst.pipe.base.DataIdContainer that ensures that tract
32 is additionally set with sourceTable_visit catalogs.
37 """Validate data IDs and cast them to the correct type
38 (modify self.idList in place).
40 This code casts the values in the data IDs dicts in `self.idList`
41 to the type required by the butler. Data IDs are read from the
42 command line as `str`, but the butler requires some values to be
43 other types. For example "visit" values should be `int` (which
44 is defined by the templates).
46 This is taken from lsst.pipe.base.ArgumentParser.castDataIds(),
47 adding in a check that the tract is an int, which must be done
48 explicitly because it is not in the template.
52 butler : `lsst.daf.persistence.Butler`
55 datasetType =
'sourceTable_visit'
57 idKeyTypeDict = butler.getKeys(datasetType=datasetType, level=self.level)
59 msg = f
"Cannot get keys for datasetType {datasetType} at level {self.level}"
60 raise KeyError(msg)
from e
62 idKeyTypeDict = idKeyTypeDict.copy()
63 idKeyTypeDict[
'tract'] = int
67 for dataDict
in self.idList:
68 for key, strVal
in dataDict.items():
70 keyType = idKeyTypeDict[key]
76 log = lsstLog.Log.getDefaultLogger()
77 log.warn(
"Unexpected ID %s; guessing type is \"%s\"",
78 key,
'str' if keyType == str
else keyType)
79 idKeyTypeDict[key] = keyType
83 castVal = keyType(strVal)
85 raise TypeError(f
"Cannot cast value {strVal!r} to {keyType} for ID key {key}")
86 dataDict[key] = castVal
89 if self.datasetType
is None:
90 raise RuntimeError(
"Must call setDatasetType first")
93 for dataId
in self.idList:
94 if "tract" not in dataId:
95 raise RuntimeError(
"Must set tract for dataId")
96 tracts.add(dataId[
'tract'])
98 self.refList.append(namespace.butler.dataRef(datasetType=self.datasetType,
102 raise RuntimeError(
"Can only run a single tract")
def castDataIds(self, butler)
def makeDataRefList(self, namespace)