21 import lsst.pex.config 
as pexConfig
 
   23 from lsst.daf.butler 
import DatasetType
 
   26 from sqlalchemy.exc 
import IntegrityError
 
   30     """Config for MakeGen3SkyMapTask 
   32     datasetTypeName = pexConfig.Field(
 
   33         doc=
"Name assigned to created skymap in butler registry",
 
   35         default=
"deepCoadd_skyMap",
 
   37     name = pexConfig.Field(
 
   38         doc=
"Name assigned to created skymap in butler registry",
 
   43     skyMap = skyMapRegistry.makeField(
 
   50             raise ValueError(
"The name field must be set to the name of the specific " 
   51                              "skymap to use when writing to the butler")
 
   55     ConfigClass = MakeGen3SkyMapConfig
 
   56     _DefaultName = 
"makeGen3SkyMap" 
   58     """This is a task to construct and optionally save a SkyMap into a gen3 
   63     config : `MakeGen3SkyMapConfig` or None 
   64         Instance of a configuration class specifying task options, a default 
   65         config is created if value is None 
   69         super().
__init__(config=config, **kwargs)
 
   71     def run(self, butler):
 
   72         """Construct and optionally save a SkyMap into a gen3 repository 
   75         butler : `lsst.daf.butler.Butler` 
   76             Butler repository to which the new skymap will be written 
   78         skyMap = self.config.skyMap.apply()
 
   79         skyMap.logSkyMapInfo(self.log)
 
   80         skyMapHash = skyMap.getSha1()
 
   81         self.log.
info(f
"Registering dataset type {self.config.datasetTypeName}.")
 
   82         butler.registry.registerDatasetType(DatasetType(name=self.config.datasetTypeName,
 
   83                                                         dimensions=[
"skymap"],
 
   84                                                         storageClass=
"SkyMap",
 
   85                                                         universe=butler.registry.dimensions))
 
   86         self.log.
info(f
"Inserting SkyMap {self.config.name} with hash={skyMapHash}")
 
   87         with butler.registry.transaction():
 
   89                 skyMap.register(self.config.name, butler.registry)
 
   90             except IntegrityError 
as err:
 
   91                 raise RuntimeError(
"A skymap with the same name or hash already exists.") 
from err
 
   92             butler.put(skyMap, self.config.datasetTypeName, {
"skymap": self.config.name})
 
   93         return pipeBase.Struct(