Coverage for python/lsst/cp/pipe/cpCertify.py : 31%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of cp_pipe.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
22import lsst.pex.config as pexConfig
23import lsst.pipe.base as pipeBase
24from lsst.daf.butler import CollectionType
27class CertifyCalibration(pipeBase.Task):
28 """Create a way to bless existing calibration products.
30 The inputs are assumed to have been constructed via cp_pipe, and
31 already exist in the butler.
33 Parameters
34 ----------
35 registry : `lsst.daf.butler.Registry`
36 Registry pointing at the butler repository to operate on.
37 inputCollection : `str`
38 Data collection to pull calibrations from. Usually an existing
39 `~CollectionType.RUN` or `~CollectionType.CHAINED` collection, and may
40 _not_ be a `~CollectionType.CALIBRATION` collection or a nonexistent
41 collection.
42 outputCollection : `str`
43 Data collection to store final calibrations. If it already exists, it
44 must be a `~CollectionType.CALIBRATION` collection. If not, a new
45 `~CollectionType.CALIBRATION` collection with this name will be
46 registered.
47 lastRunOnly : `bool`, optional
48 If `True` (default) and ``inputCollection`` is a
49 `~CollectionType.CHAINED` collection, only search its first child
50 collection (which usually corresponds to the last processing run),
51 instead of all child collections in the chain. This behavior ensures
52 that datasets in a collection used as input to that processing run
53 are never included in the certification.
54 **kwargs :
55 Additional arguments forwarded to `lsst.pipe.base.Task.__init__`.
56 """
57 _DefaultName = 'CertifyCalibration'
58 ConfigClass = pexConfig.Config
60 def __init__(self, *, registry, inputCollection, outputCollection, lastRunOnly=True, **kwargs):
61 super().__init__(**kwargs)
62 self.registry = registry
63 if lastRunOnly:
64 try:
65 inputCollection, _ = next(iter(self.registry.getCollectionChain(inputCollection)))
66 except TypeError:
67 # Not a CHAINED collection; do nothing.
68 pass
69 self.inputCollection = inputCollection
70 self.outputCollection = outputCollection
72 def run(self, datasetTypeName, timespan):
73 """Certify all of the datasets of the given type in the input
74 collection.
76 Parameters
77 ----------
78 datasetTypeName : `str`
79 Name of the dataset type to certify.
80 timespan : `lsst.daf.butler.Timespan`
81 Timespan for the validity range.
82 """
83 refs = set(self.registry.queryDatasets(datasetTypeName, collections=[self.inputCollection]))
84 if not refs:
85 raise RuntimeError(f"No inputs found for dataset {datasetTypeName} in {self.inputCollection}.")
86 self.registry.registerCollection(self.outputCollection, type=CollectionType.CALIBRATION)
87 self.registry.certify(self.outputCollection, refs, timespan)