21 from __future__
import annotations
23 __all__ = [
"StandardRepoConverter"]
26 from dataclasses
import dataclass
27 from typing
import TYPE_CHECKING, Dict, Iterator, Optional, Tuple
32 from lsst.daf.butler
import DatasetType, DatasetRef, DataCoordinate, FileDataset
33 from .repoConverter
import RepoConverter
34 from .repoWalker
import RepoWalker
36 SKYMAP_DATASET_TYPES = {
37 coaddName: f
"{coaddName}Coadd_skyMap" for coaddName
in (
"deep",
"goodSeeing",
"dcr")
42 from lsst.daf.butler
import StorageClass, FormatterParameter
43 from .cameraMapper
import CameraMapper
44 from .repoWalker.scanner
import PathElementHandler
45 from ..mapping
import Mapping
as CameraMapperMapping
50 """Struct containing information about a SkyMap found in a Gen2 repository.
54 """Name of the skymap used in Gen3 data IDs.
58 """An instance of the actual skymap class.
62 """The coadd name used as a prefix for the dataset type this skymap was
67 """A `DatasetRef` that can be used to ingest the skymap dataset into a
72 """Name of the file containing the skymap dataset, relative to the
78 """A specialization of `RepoConverter` for non-calibration repositories.
83 Keyword arguments are forwarded to (and required by) `RepoConverter`.
97 return datasetTypeName
in SKYMAP_DATASET_TYPES.values()
101 self.
task.log.info(f
"Looking for skymaps in root {self.root}.")
102 for coaddName, datasetTypeName
in SKYMAP_DATASET_TYPES.items():
103 if not self.
task.isDatasetTypeIncluded(datasetTypeName):
106 exists = self.
butler2.datasetExists(datasetTypeName)
107 except AttributeError:
112 instance = self.
butler2.get(datasetTypeName)
113 name = self.
task.useSkyMap(instance, datasetTypeName)
114 datasetType = DatasetType(datasetTypeName, dimensions=[
"skymap"],
115 storageClass=
"SkyMap", universe=self.
task.universe)
116 dataId = DataCoordinate.standardize(skymap=name, universe=self.
task.universe)
117 struct =
FoundSkyMap(name=name, instance=instance, coaddName=coaddName,
118 ref=DatasetRef(datasetType, dataId),
119 filename=self.
butler2.getUri(datasetTypeName))
121 self.
task.log.info(
"Found skymap %s in %s in %s.", name, datasetTypeName, self.
root)
126 for datasetTypeName, mapping
in self.
mapper.mappings.items():
127 if datasetTypeName
not in self.
mapper.calibrations:
128 yield datasetTypeName, mapping
131 """Return the appropriate SkyMap for the given dataset type.
135 datasetTypeName : `str`
136 Name of the dataset type for which a skymap is sought.
140 skyMap : `BaseSkyMap` or `None`
141 The `BaseSkyMap` instance, or `None` if there was no match.
142 skyMapName : `str` or `None`
143 The Gen3 name for the SkyMap, or `None` if there was no match.
148 for coaddName
in SKYMAP_DATASET_TYPES.keys():
149 if coaddName
in datasetTypeName:
158 (
"Dataset %s looks like it might need a skymap, but no %sCoadd_skyMap "
159 "found in repo %s."),
160 datasetTypeName, coaddName, self.
root
162 if struct
is not None:
163 return struct.instance, struct.name
168 storageClass: StorageClass,
169 formatter: FormatterParameter =
None,
170 targetHandler: Optional[PathElementHandler] =
None,
171 ) -> RepoWalker.Target:
174 return RepoWalker.Target(
175 datasetTypeName=datasetTypeName,
176 storageClass=storageClass,
179 universe=self.
task.registry.dimensions,
180 instrument=self.
task.instrument.getName(),
182 skyMapName=skyMapName,
184 targetHandler=targetHandler,
185 translatorFactory=self.
task.translatorFactory,
191 if self.
task.isDatasetTypeIncluded(struct.ref.datasetType.name):
192 yield FileDataset(path=os.path.join(self.
root, struct.filename), refs=struct.ref)
199 """Gen2 butler associated with this repository.
203 """Gen2 mapper associated with this repository.