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

27 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-27 09:52 +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/>. 

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(repo, config_file, collections, instrument, where=None, raw_name="raw"): 

31 """Implements the command line interface `butler define-visits` subcommand, 

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

33 this function. 

34 

35 Defines visits from exposures in the butler registry 

36 

37 Parameters 

38 ---------- 

39 repo : `str` 

40 URI to the location to create the repo. 

41 config_file : `str` or `None` 

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

43 collections : `list` [`str`] 

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

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

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

47 instrument : `str` 

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

49 where : `str`, optional 

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

51 the relevant exposures. 

52 raw_name : `str`, optional 

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

54 

55 Notes 

56 ----- 

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

58 camera will be used for the relevant instrument. 

59 """ 

60 if not collections: 

61 collections = None 

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

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

64 config = DefineVisitsConfig() 

65 instr.applyConfigOverrides(DefineVisitsTask._DefaultName, config) 

66 

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

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

69 # was the old default). 

70 exposure_dimension = butler.registry.dimensions["exposure"] 

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

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

73 legacy = "one-to-one" 

74 log.warning( 

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

76 modern, 

77 legacy, 

78 ) 

79 config.groupExposures.name = legacy 

80 

81 if collections is None: 

82 # Default to the raw collection for this instrument 

83 collections = instr.makeDefaultRawIngestRunName() 

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

85 

86 if not where: 

87 where = None 

88 

89 if config_file is not None: 

90 config.load(config_file) 

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

92 

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

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

95 task.run( 

96 butler.registry.queryDataIds( 

97 ["exposure"], 

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

99 collections=collections, 

100 datasets=raw_name, 

101 where=where, 

102 ), 

103 collections=collections, 

104 )