Coverage for python/lsst/obs/base/script/defineVisits.py: 16%

27 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-06 04:13 -0700

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

21import logging 

22 

23from lsst.daf.butler import Butler 

24from lsst.obs.base import DefineVisitsConfig, DefineVisitsTask 

25from lsst.pipe.base import Instrument 

26 

27log = logging.getLogger("lsst.obs.base.defineVisits") 

28 

29 

30def defineVisits( 

31 repo, 

32 config_file, 

33 collections, 

34 instrument, 

35 where=None, 

36 update_records=False, 

37 incremental=False, 

38 raw_name="raw", 

39): 

40 """Implement the command line interface `butler define-visits` subcommand, 

41 should only be called by command line tools and unit test code that tests 

42 this function. 

43 

44 Defines visits from exposures in the butler registry 

45 

46 Parameters 

47 ---------- 

48 repo : `str` 

49 URI to the location to create the repo. 

50 config_file : `str` or `None` 

51 Path to a config file that contains overrides to the ingest config. 

52 collections : `list` [`str`] 

53 An expression specifying the collections to be searched (in order) when 

54 reading datasets, and optionally dataset type restrictions on them. 

55 If empty it will be passed as `None` to Butler. 

56 instrument : `str` 

57 The name or fully-qualified class name of an instrument. 

58 where : `str`, optional 

59 Query clause to use when querying for dataIds. Can be used to limit 

60 the relevant exposures. 

61 update_records : `bool`, optional 

62 Control whether recalculated visit definitions will be accepted or 

63 not. 

64 incremental : `bool`, optional 

65 Declare that the visit definitions are being run in a situation 

66 where data from multi-snap visits are being ingested incrementally 

67 and so the visit definition could change as new data arrive. 

68 raw_name : `str`, optional 

69 Name of the raw dataset type name. Defaults to 'raw'. 

70 

71 Notes 

72 ----- 

73 Camera geometry is not currently found in registry but instead a default 

74 camera will be used for the relevant instrument. 

75 """ 

76 if not collections: 

77 collections = None 

78 butler = Butler(repo, collections=collections, writeable=True) 

79 instr = Instrument.from_string(instrument, butler.registry) 

80 config = DefineVisitsConfig() 

81 instr.applyConfigOverrides(DefineVisitsTask._DefaultName, config) 

82 

83 # If this is old schema but is using modern visit grouping algorithm, 

84 # (which is the default for new code) revert to one-to-one (which 

85 # was the old default). 

86 exposure_dimension = butler.dimensions["exposure"] 

87 modern = "one-to-one-and-by-counter" 

88 if "seq_end" not in exposure_dimension.metadata and config.groupExposures.name == modern: 

89 legacy = "one-to-one" 

90 log.warning( 

91 "Request to use %s grouping algorithm but registry schema is too old. Using %s instead.", 

92 modern, 

93 legacy, 

94 ) 

95 config.groupExposures.name = legacy 

96 

97 if collections is None: 

98 # Default to the raw collection for this instrument 

99 collections = instr.makeDefaultRawIngestRunName() 

100 log.info("Defaulting to searching for raw exposures in collection %s", collections) 

101 

102 if not where: 

103 where = None 

104 

105 if config_file is not None: 

106 config.load(config_file) 

107 task = DefineVisitsTask(config=config, butler=butler) 

108 

109 # Assume the dataset type is "raw" -- this is required to allow this 

110 # query to filter out exposures not relevant to the specified collection. 

111 task.run( 

112 butler.registry.queryDataIds( 

113 ["exposure"], 

114 dataId={"instrument": instr.getName()}, 

115 collections=collections, 

116 datasets=raw_name, 

117 where=where, 

118 ).expanded(), 

119 collections=collections, 

120 update_records=update_records, 

121 incremental=incremental, 

122 )