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

16 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-07 02:46 -0700

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 

22 

23from .._butler import Butler 

24from ..core import Timespan 

25from ..registry import CollectionType 

26 

27 

28def certifyCalibrations( 

29 repo, input_collection, output_collection, dataset_type_name, begin_date, end_date, search_all_inputs 

30): 

31 """Certify a set of calibrations with a validity range. 

32 

33 Parameters 

34 ---------- 

35 repo : `str` 

36 URI to the location of the repo or URI to a config file describing the 

37 repo and its location. 

38 inputCollection : `str` 

39 Data collection to pull calibrations from. Usually an existing 

40 `~CollectionType.RUN` or `~CollectionType.CHAINED` collection, and may 

41 _not_ be a `~CollectionType.CALIBRATION` collection or a nonexistent 

42 collection. 

43 outputCollection : `str` 

44 Data collection to store final calibrations. If it already exists, it 

45 must be a `~CollectionType.CALIBRATION` collection. If not, a new 

46 `~CollectionType.CALIBRATION` collection with this name will be 

47 registered. 

48 datasetTypeName : `str` 

49 Name of the dataset type to certify. 

50 begin_date : `str`, optional 

51 ISO-8601 date (TAI) this calibration should start being used. 

52 end_date : `str`, optional 

53 ISO-8601 date (TAI) this calibration should stop being used. 

54 search_all_inputs : `bool`, optional 

55 Search all children of the inputCollection if it is a CHAINED 

56 collection, instead of just the most recent one. 

57 """ 

58 butler = Butler(repo, writeable=True) 

59 registry = butler.registry 

60 timespan = Timespan( 

61 begin=astropy.time.Time(begin_date, scale="tai") if begin_date is not None else None, 

62 end=astropy.time.Time(end_date, scale="tai") if end_date is not None else None, 

63 ) 

64 if not search_all_inputs: 

65 if registry.getCollectionType(input_collection) is CollectionType.CHAINED: 

66 input_collection = next(iter(registry.getCollectionChain(input_collection))) 

67 

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)