21 from __future__
import annotations
23 __all__ = [
"StandardRepoConverter"]
25 from dataclasses
import dataclass
26 from typing
import TYPE_CHECKING, Dict, Iterator, List, Mapping, Optional, Tuple
31 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")
41 from lsst.daf.butler
import StorageClass, FormatterParameter
42 from .cameraMapper
import CameraMapper
43 from .repoWalker.scanner
import PathElementHandler
44 from ..mapping
import Mapping
as CameraMapperMapping
49 """Struct containing information about a SkyMap found in a Gen2 repository.
53 """Name of the skymap used in Gen3 data IDs.
57 """An instance of the actual skymap class.
61 """The coadd name used as a prefix for the dataset type this skymap was
66 """A `DatasetRef` that can be used to ingest the skymap dataset into a
71 """Name of the file containing the skymap dataset, relative to the
77 """A specialization of `RepoConverter` for non-calibration repositories.
82 Keyword arguments are forwarded to (and required by) `RepoConverter`.
97 return datasetTypeName
in SKYMAP_DATASET_TYPES.values()
101 self.
tasktask.log.info(f
"Looking for skymaps in root {self.root}.")
102 for coaddName, datasetTypeName
in SKYMAP_DATASET_TYPES.items():
103 if not self.
tasktask.isDatasetTypeIncluded(datasetTypeName):
106 exists = self.
butler2butler2.datasetExists(datasetTypeName)
107 except AttributeError:
112 instance = self.
butler2butler2.get(datasetTypeName)
113 name = self.
tasktask.useSkyMap(instance, datasetTypeName)
114 datasetType = DatasetType(datasetTypeName, dimensions=[
"skymap"],
115 storageClass=
"SkyMap", universe=self.
tasktask.universe)
116 dataId = DataCoordinate.standardize(skymap=name, universe=self.
tasktask.universe)
117 struct =
FoundSkyMap(name=name, instance=instance, coaddName=coaddName,
118 ref=DatasetRef(datasetType, dataId),
119 filename=self.
butler2butler2.getUri(datasetTypeName))
121 self.
tasktask.log.info(
"Found skymap %s in %s in %s.", name, datasetTypeName, self.
rootroot)
126 for datasetTypeName, mapping
in self.
mappermapper.mappings.items():
127 if datasetTypeName
not in self.
mappermapper.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:
157 self.
tasktask.log.debug(
158 (
"Dataset %s looks like it might need a skymap, but no %sCoadd_skyMap "
159 "found in repo %s."),
160 datasetTypeName, coaddName, self.
rootroot
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.
tasktask.registry.dimensions,
180 instrument=self.
tasktask.instrument.getName(),
182 skyMapName=skyMapName,
184 targetHandler=targetHandler,
185 translatorFactory=self.
tasktask.translatorFactory,
192 def getRun(self, datasetTypeName: str, calibDate: Optional[str] =
None) -> str:
194 run = self.
tasktask.config.runsForced.get(datasetTypeName)
196 if self.
_run_run
is not None:
199 run = self.
tasktask.config.runs.get(datasetTypeName)
201 raise ValueError(f
"No default run for repo at {self.root}, and no "
202 f
"override for dataset {datasetTypeName}.")
203 if run
not in self.
_chain_chain:
208 """Return run names that can be used to construct a chained collection
209 that refers to the converted repository (`list` [ `str` ]).
213 def _finish(self, datasets: Mapping[DatasetType, Mapping[Optional[str], List[FileDataset]]]):
215 super()._finish(datasets)
217 self.
_chain_chain.
append(BaseSkyMap.SKYMAP_RUN_COLLECTION_NAME)
223 """Gen2 butler associated with this repository.
227 """Gen2 mapper associated with this repository.
Tuple[Optional[BaseSkyMap], Optional[str]] findMatchingSkyMap(self, str datasetTypeName)
Iterator[Tuple[str, CameraMapperMapping]] iterMappings(self)
bool isDatasetTypeSpecial(self, str datasetTypeName)
def __init__(self, **kwds)
Iterator[FileDataset] iterDatasets(self)
List[str] getCollectionChain(self)
str getRun(self, str datasetTypeName, Optional[str] calibDate=None)
RepoWalker.Target makeRepoWalkerTarget(self, str datasetTypeName, str template, Dict[str, type] keys, StorageClass storageClass, FormatterParameter formatter=None, Optional[PathElementHandler] targetHandler=None)
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
def temporaryLogLevel(name, level)