Coverage for python/lsst/daf/butler/script/certifyCalibrations.py : 15%

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 daf_butler.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://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/>.
21import astropy.time
23from .. import Butler, CollectionType, Timespan
26def certifyCalibrations(repo, input_collection, output_collection, dataset_type_name,
27 begin_date, end_date, search_all_inputs):
28 """Certify a set of calibrations with a validity range.
30 Parameters
31 ----------
32 repo : `str`
33 URI to the location of the repo or URI to a config file describing the
34 repo and its location.
35 inputCollection : `str`
36 Data collection to pull calibrations from. Usually an existing
37 `~CollectionType.RUN` or `~CollectionType.CHAINED` collection, and may
38 _not_ be a `~CollectionType.CALIBRATION` collection or a nonexistent
39 collection.
40 outputCollection : `str`
41 Data collection to store final calibrations. If it already exists, it
42 must be a `~CollectionType.CALIBRATION` collection. If not, a new
43 `~CollectionType.CALIBRATION` collection with this name will be
44 registered.
45 datasetTypeName : `str`
46 Name of the dataset type to certify.
47 begin_date : `str`, optional
48 ISO-8601 date (TAI) this calibration should start being used.
49 end_date : `str`, optional
50 ISO-8601 date (TAI) this calibration should stop being used.
51 search_all_inputs : `bool`, optional
52 Search all children of the inputCollection if it is a CHAINED
53 collection, instead of just the most recent one.
54 """
55 butler = Butler(repo, writeable=True)
56 registry = butler.registry
57 timespan = Timespan(
58 begin=astropy.time.Time(begin_date, scale='tai') if begin_date is not None else None,
59 end=astropy.time.Time(end_date, scale='tai') if end_date is not None else None,
60 )
61 if not search_all_inputs:
62 try:
63 input_collection = next(iter(registry.getCollectionChain(input_collection)))
64 except TypeError:
65 # Not a CHAINED collection; do nothing.
66 pass
68 refs = set(registry.queryDatasets(dataset_type_name, collections=[input_collection]))
69 if not refs:
70 raise RuntimeError(f"No inputs found for dataset {dataset_type_name} in {input_collection}.")
71 registry.registerCollection(output_collection, type=CollectionType.CALIBRATION)
72 registry.certify(output_collection, refs, timespan)