Coverage for python/lsst/obs/base/cli/cmd/commands.py: 91%

55 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-02-05 18:01 -0800

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 click 

23 

24from lsst.daf.butler.cli.opt import (repo_argument, 

25 config_option, 

26 config_file_option, 

27 locations_argument, 

28 options_file_option, 

29 processes_option, 

30 regex_option, 

31 run_option, 

32 transfer_option 

33 ) 

34from lsst.daf.butler.cli.utils import ( 

35 ButlerCommand, 

36 split_commas, 

37 typeStrAcceptsMultiple 

38) 

39from ..opt import instrument_argument 

40from ... import script 

41 

42 

43# regular expression that can be used to find supported fits file extensions. 

44fits_re = r"\.fit[s]?\b" 

45 

46 

47@click.command(short_help="Convert a gen2 repo to gen3.", cls=ButlerCommand) 

48@repo_argument(required=True, 

49 help="REPO is the URI or path to the gen3 repository. Will be created if it does not already " 

50 "exist") 

51@click.option("--gen2root", required=True, 

52 help="Root path of the gen 2 repo to be converted.") 

53@click.option("--skymap-name", 

54 help="Name of the new gen3 skymap (e.g. 'discrete/ci_hsc').") 

55@click.option("--skymap-config", 

56 help="Path to skymap config file defining the new gen3 skymap.") 

57@click.option("--calibs", 

58 help="Path to the gen 2 calibration repo. It can be absolute or relative to gen2root.") 

59@click.option("--reruns", multiple=True, callback=split_commas, metavar=typeStrAcceptsMultiple, 

60 help=("List of rerun paths to convert. Output collection names will be " 

61 "guessed, which can fail if the Gen2 repository paths do not follow a " 

62 "recognized convention. In this case, the command-line interface cannot " 

63 "be used.")) 

64@transfer_option(help="Mode to use to transfer files into the new repository.") 

65@processes_option() 

66@config_file_option(help="Path to a `ConvertRepoConfig` override to be included after the Instrument config " 

67 "overrides are applied.") 

68@options_file_option() 

69def convert(*args, **kwargs): 

70 """Convert one or more Butler gen 2 repositories into a gen 3 repository. 

71 

72 This is a highly simplified interface that should only be used to convert 

73 suites of gen 2 repositories that contain at most one calibration repo and 

74 has no chained reruns. Custom scripts that call ConvertRepoTask should be 

75 used on more complex suites of repositories. 

76 """ 

77 script.convert(*args, **kwargs) 

78 

79 

80@click.command(short_help="Define visits from exposures.", cls=ButlerCommand) 

81@repo_argument(required=True) 

82@instrument_argument(required=True) 

83@config_file_option(help="Path to a pex_config override to be included after the Instrument config overrides " 

84 "are applied.") 

85@click.option("--collections", 

86 help="The collections to be searched (in order) when reading datasets.", 

87 multiple=True, 

88 callback=split_commas, 

89 metavar=typeStrAcceptsMultiple) 

90@processes_option() 

91@options_file_option() 

92def define_visits(*args, **kwargs): 

93 """Define visits from exposures in the butler registry. 

94 

95 The calibration collection containing the camera geometry can not 

96 be specified. 

97 """ 

98 script.defineVisits(*args, **kwargs) 

99 

100 

101@click.command(short_help="Ingest raw frames.", cls=ButlerCommand) 

102@repo_argument(required=True) 

103@locations_argument(help="LOCATIONS specifies files to ingest and/or locations to search for files.", 

104 required=True) 

105@regex_option(default=fits_re, 

106 help="Regex string used to find files in directories listed in LOCATIONS. " 

107 "Searches for fits files by default.") 

108@config_option(metavar="TEXT=TEXT", multiple=True) 

109@config_file_option(type=click.Path(exists=True, writable=False, file_okay=True, dir_okay=False)) 

110@run_option(required=False) 

111@transfer_option() 

112@processes_option() 

113@click.option("--ingest-task", default="lsst.obs.base.RawIngestTask", help="The fully qualified class name " 

114 "of the ingest task to use.") 

115@options_file_option() 

116def ingest_raws(*args, **kwargs): 

117 """Ingest raw frames into from a directory into the butler registry""" 

118 script.ingestRaws(*args, **kwargs) 

119 

120 

121@click.command(short_help="Add an instrument to the repository", cls=ButlerCommand) 

122@repo_argument(required=True) 

123@instrument_argument(required=True, nargs=-1, help="The fully-qualified name of an Instrument subclass.") 

124@click.option("--update", is_flag=True) 

125def register_instrument(*args, **kwargs): 

126 """Add an instrument to the data repository. 

127 """ 

128 script.registerInstrument(*args, **kwargs) 

129 

130 

131@click.command(short_help="Add an instrument's curated calibrations.", cls=ButlerCommand) 

132@repo_argument(required=True) 

133@instrument_argument(required=True) 

134@click.option("--collection", required=False, 

135 help="Name of the calibration collection that associates datasets with validity ranges.") 

136@click.option("--label", "labels", multiple=True, 

137 help=("Extra strings to include (with automatic delimiters) in all RUN collection names, " 

138 "as well as the calibration collection name if it is not provided via --collection.")) 

139@options_file_option() 

140def write_curated_calibrations(*args, **kwargs): 

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

142 """ 

143 script.writeCuratedCalibrations(*args, **kwargs)