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

54 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2024-02-15 11:10 +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 click 

23from lsst.daf.butler.cli.opt import ( 

24 config_file_option, 

25 config_option, 

26 locations_argument, 

27 options_file_option, 

28 processes_option, 

29 regex_option, 

30 repo_argument, 

31 run_option, 

32 transfer_option, 

33 where_option, 

34) 

35from lsst.daf.butler.cli.utils import ButlerCommand, split_commas, typeStrAcceptsMultiple 

36from lsst.pipe.base.cli.opt import instrument_argument 

37 

38from ... import script 

39from ..opt import failfast_option 

40 

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

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

43 

44 

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

46@repo_argument( 

47 required=True, 

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

49) 

50@click.option("--gen2root", required=True, help="Root path of the gen 2 repo to be converted.") 

51@click.option("--skymap-name", help="Name of the new gen3 skymap (e.g. 'discrete/ci_hsc').") 

52@click.option("--skymap-config", help="Path to skymap config file defining the new gen3 skymap.") 

53@click.option( 

54 "--calibs", help="Path to the gen 2 calibration repo. It can be absolute or relative to gen2root." 

55) 

56@click.option( 

57 "--reruns", 

58 multiple=True, 

59 callback=split_commas, 

60 metavar=typeStrAcceptsMultiple, 

61 help=( 

62 "List of rerun paths to convert. Output collection names will be " 

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

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

65 "be used." 

66 ), 

67) 

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

69@processes_option() 

70@config_file_option( 

71 help="Path to a `ConvertRepoConfig` override to be included after the Instrument config " 

72 "overrides are applied." 

73) 

74@options_file_option() 

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

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

77 

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

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

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

81 used on more complex suites of repositories. 

82 """ 

83 raise RuntimeError( 

84 "Gen2 conversion to Gen3 is no longer supported. " 

85 "Please use version v23.0 of the pipelines code to do legacy conversions." 

86 ) 

87 

88 

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

90@repo_argument(required=True) 

91@instrument_argument(required=True) 

92@config_file_option( 

93 help="Path to a pex_config override to be included after the Instrument config overrides are applied." 

94) 

95@click.option( 

96 "--collections", 

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

98 multiple=True, 

99 callback=split_commas, 

100 metavar=typeStrAcceptsMultiple, 

101) 

102@where_option() 

103@click.option( 

104 "--update-records/--no-update-records", 

105 default=False, 

106 help="Use this option to force updates to the visit definition record. " 

107 "Should only be used if you know that there has been a change to the " 

108 "exposure records, such as a change to the metadata translator.", 

109) 

110@click.option( 

111 "--incremental/--no-incremental", 

112 default=False, 

113 help="Use this option to force updates to the visit definition record " 

114 "when multi-snap visits are being ingested incrementally and so you " 

115 "might encounter partial visits. Implies --update-records.", 

116) 

117@options_file_option() 

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

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

120 

121 The calibration collection containing the camera geometry can not 

122 be specified. 

123 """ 

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

125 

126 

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

128@repo_argument(required=True) 

129@locations_argument( 

130 help="LOCATIONS specifies files to ingest and/or locations to search for files.", required=True 

131) 

132@regex_option( 

133 default=fits_re, 

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

135 "Searches for fits files by default.", 

136) 

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

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

139@run_option(required=False) 

140@transfer_option() 

141@processes_option() 

142@click.option( 

143 "--ingest-task", 

144 default="lsst.obs.base.RawIngestTask", 

145 help="The fully qualified class name of the ingest task to use.", 

146) 

147@click.option( 

148 "--track-file-attrs/--no-track-file-attrs", 

149 default=True, 

150 help="Indicate to the datastore whether file attributes such as file size" 

151 " or checksum should be tracked or not. Whether this parameter is honored" 

152 " depends on the specific datastore implentation.", 

153) 

154@failfast_option() 

155@options_file_option() 

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

157 """Ingest raw frames into from a directory into the butler registry.""" 

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

159 

160 

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

162@repo_argument(required=True) 

163@instrument_argument(required=True) 

164@click.option( 

165 "--collection", 

166 required=False, 

167 help="Name of the calibration collection that associates datasets with validity ranges.", 

168) 

169@click.option( 

170 "--label", 

171 "labels", 

172 multiple=True, 

173 help=( 

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

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

176 ), 

177) 

178@options_file_option() 

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

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

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