22 from lsst.daf.butler
import Butler, DatasetType
28 out_collection='skymaps', skymap_id='discrete'):
29 """Implements the command line interface `butler make-discrete-skymap` subcommand,
30 should only be called by command line tools and unit test code that tests
33 Constructs a skymap from calibrated exposure in the butler repository
38 URI to the location to read the repo.
39 config_file : `str` or `None`
40 Path to a config file that contains overrides to the skymap config.
41 collections : `list` [`str`]
42 An expression specifying the collections to be searched (in order) when
43 reading datasets, and optionally dataset type restrictions on them.
44 At least one collection must be specified. This is the collection
45 with the calibrated exposures.
47 The name or fully-qualified class name of an instrument.
48 out_collection : `str`, optional
49 The name of the collection to save the skymap to. Default is 'skymaps'.
50 skymap_id : `str`, optional
51 The identifier of the skymap to save. Default is 'discrete'.
53 butler = Butler(repo, collections=collections, writeable=
True, run=out_collection)
54 instr = getInstrument(instrument, butler.registry)
56 instr.applyConfigOverrides(MakeDiscreteSkyMapTask._DefaultName, config)
58 if config_file
is not None:
59 config.load(config_file)
60 skymap_name = config.coaddName +
"Coadd_skyMap"
63 if out_collection
in collections:
64 raise ValueError(f
"Cannot overwrite dataset. If appending, specify an output "
65 f
"collection not in the input collections.")
66 dataId = {
'skymap': skymap_id}
68 oldSkyMap = butler.get(skymap_name, collections=collections, dataId=dataId)
69 except LookupError
as e:
70 msg = (f
"Could not find seed skymap for {skymap_name} with dataId {dataId} "
71 f
"in collections {collections} but doAppend is {config.doAppend}. Aborting...")
72 raise LookupError(msg, *e.args[1:])
74 datasets = butler.registry.queryDatasets(
'calexp', collections=collections)
75 wcs_md_tuple_list = [(butler.getDirect(
'calexp.metadata', ref), butler.getDirect(
'calexp.wcs', ref))
78 result = task.run(wcs_md_tuple_list, oldSkyMap)
79 skymap_dataset_type = DatasetType(skymap_name, dimensions=[
"skymap", ],
80 universe=butler.registry.dimensions,
81 storageClass=
"SkyMap")
82 butler.registry.registerDatasetType(skymap_dataset_type)
85 result.skyMap.register(skymap_id, butler.registry)
86 butler.put(result.skyMap, skymap_name, dataId={
'skymap': skymap_id})