Coverage for python / lsst / obs / base / script / writeCuratedCalibrations.py: 31%

12 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-28 08:47 +0000

1# This file is part of obs_base. 

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/>. 

21 

22import logging 

23 

24from lsst.daf.butler import Butler 

25from lsst.obs.base import Instrument 

26 

27log = logging.getLogger(__name__) 

28 

29 

30def writeCuratedCalibrations( 

31 repo: str, instrument: str, collection: str | None, labels: list[str], prefix: str | None = None 

32) -> None: 

33 """Add an instrument's curated calibrations to the data repository. 

34 

35 Parameters 

36 ---------- 

37 repo : `str` 

38 URI to the location to create the repo. 

39 instrument : `str` 

40 The name or the fully qualified class name of an instrument. 

41 collection : `str` or `None` 

42 The path to the collection that associates datasets with validity 

43 ranges. 

44 Can be `None` in which case the collection name will be determined 

45 automatically. 

46 labels : `collections.abc.Sequence` [ `str` ] 

47 Extra strings to include in the names of collections that datasets are 

48 inserted directly into, and if ``collection`` is `None`, the automatic 

49 calibration collection name as well. 

50 prefix : `str`, optional 

51 Prefix for the collection name to use instead of the instrument name. 

52 Ignored if ``collection`` is passed. 

53 

54 Raises 

55 ------ 

56 RuntimeError 

57 Raised if the instrument can not be imported, instantiated, or obtained 

58 from the registry. 

59 TypeError 

60 Raised if the instrument is not a subclass of 

61 `lsst.obs.base.Instrument`. 

62 """ 

63 with Butler.from_config(repo, writeable=True) as butler: 

64 instr = Instrument.from_string(instrument, butler.registry, collection_prefix=prefix) 

65 if collection is None and not labels: 

66 labels = instr.get_curated_calibration_labels() 

67 if not labels: 

68 raise ValueError("At least one label or --collection must be provided.") 

69 instr.writeCuratedCalibrations(butler, collection=collection, labels=labels)