33 __all__ = [
"PerTractCcdDataIdContainer"]
37 """A version of lsst.pipe.base.DataIdContainer that combines raw data IDs (defined as whatever we use 38 for 'src') with a tract. 42 """Validate data IDs and cast them to the correct type (modify idList in place). 50 idKeyTypeDict = butler.getKeys(datasetType=
"src", level=self.level)
52 raise KeyError(
"Cannot get keys for datasetType %s at level %s: %s" % (
"src", self.level, e))
54 idKeyTypeDict = idKeyTypeDict.copy()
55 idKeyTypeDict[
"tract"] = int
57 for dataDict
in self.idList:
58 for key, strVal
in dataDict.items():
60 keyType = idKeyTypeDict[key]
62 validKeys = sorted(idKeyTypeDict.keys())
63 raise KeyError(
"Unrecognized ID key %r; valid keys are: %s" % (key, validKeys))
66 castVal = keyType(strVal)
68 raise TypeError(
"Cannot cast value %r to %s for ID key %r" % (strVal, keyType, key,))
69 dataDict[key] = castVal
71 def _addDataRef(self, namespace, dataId, tract):
72 """Construct a dataRef based on dataId, but with an added tract key""" 73 forcedDataId = dataId.copy()
74 forcedDataId[
'tract'] = tract
75 dataRef = namespace.butler.dataRef(datasetType=self.datasetType, dataId=forcedDataId)
76 self.refList.
append(dataRef)
79 """Make self.refList from self.idList 81 if self.datasetType
is None:
82 raise RuntimeError(
"Must call setDatasetType first")
87 for dataId
in self.idList:
88 if "tract" not in dataId:
90 log.infof(
"Reading WCS to determine tracts for components of dataId={}", dict(dataId))
94 for ref
in namespace.butler.subset(
"calexp", dataId=dataId):
95 if not ref.datasetExists(
"calexp"):
96 log.warnf(
"calexp with dataId: {} not found.", dict(dataId))
100 if "visit" in ref.dataId.keys():
101 visit = ref.dataId[
"visit"]
104 visit = namespace.butler.queryMetadata(
"calexp", (
"visit"), ref.dataId)[0]
105 if visit
not in visitRefs:
106 visitRefs[visit] =
list()
107 visitRefs[visit].
append(ref)
109 wcs = ref.get(
"calexp_wcs", immediate=
True)
113 tract = skymap.findTract(wcs.pixelToSky(box.getCenter()))
114 if lsst.meas.base.imageOverlapsTract(tract, wcs, box):
115 if visit
not in visitTract:
116 visitTract[visit] =
set()
117 visitTract[visit].add(tract.getId())
119 tract = dataId.pop(
"tract")
121 for ref
in namespace.butler.subset(
"src", dataId=dataId):
122 if ref.datasetExists():
128 for visit, tractSet
in sorted(visitTract.items()):
129 for ref
in visitRefs[visit]:
130 for tract
in sorted(tractSet):
133 tractCounter = collections.Counter()
134 for tractSet
in visitTract.values():
135 tractCounter.update(tractSet)
136 log.infof(
"Number of visits per tract: {}", dict(tractCounter))
def _addDataRef(self, namespace, dataId, tract)
A floating-point coordinate rectangle geometry.
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
def castDataIds(self, butler)
def getSkymap(self, namespace)
def makeDataRefList(self, namespace)
static Log getLogger(Log const &logger)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...