Coverage for python/lsst/daf/butler/script/certifyCalibrations.py: 30%
16 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-08-05 01:25 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-08-05 01:25 +0000
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/>.
21from __future__ import annotations
23import astropy.time
25from .._butler import Butler
26from ..core import Timespan
27from ..registry import CollectionType
30def certifyCalibrations(
31 repo: str,
32 input_collection: str,
33 output_collection: str,
34 dataset_type_name: str,
35 begin_date: str | None,
36 end_date: str | None,
37 search_all_inputs: bool,
38) -> None:
39 """Certify a set of calibrations with a validity range.
41 Parameters
42 ----------
43 repo : `str`
44 URI to the location of the repo or URI to a config file describing the
45 repo and its location.
46 inputCollection : `str`
47 Data collection to pull calibrations from. Usually an existing
48 `~CollectionType.RUN` or `~CollectionType.CHAINED` collection, and may
49 _not_ be a `~CollectionType.CALIBRATION` collection or a nonexistent
50 collection.
51 outputCollection : `str`
52 Data collection to store final calibrations. If it already exists, it
53 must be a `~CollectionType.CALIBRATION` collection. If not, a new
54 `~CollectionType.CALIBRATION` collection with this name will be
55 registered.
56 datasetTypeName : `str`
57 Name of the dataset type to certify.
58 begin_date : `str`, optional
59 ISO-8601 date (TAI) this calibration should start being used.
60 end_date : `str`, optional
61 ISO-8601 date (TAI) this calibration should stop being used.
62 search_all_inputs : `bool`, optional
63 Search all children of the inputCollection if it is a CHAINED
64 collection, instead of just the most recent one.
65 """
66 butler = Butler(repo, writeable=True, without_datastore=True)
67 registry = butler.registry
68 timespan = Timespan(
69 begin=astropy.time.Time(begin_date, scale="tai") if begin_date is not None else None,
70 end=astropy.time.Time(end_date, scale="tai") if end_date is not None else None,
71 )
72 if not search_all_inputs and registry.getCollectionType(input_collection) is CollectionType.CHAINED:
73 input_collection = next(iter(registry.getCollectionChain(input_collection)))
75 refs = set(registry.queryDatasets(dataset_type_name, collections=[input_collection]))
76 if not refs:
77 raise RuntimeError(f"No inputs found for dataset {dataset_type_name} in {input_collection}.")
78 registry.registerCollection(output_collection, type=CollectionType.CALIBRATION)
79 registry.certify(output_collection, refs, timespan)