LSSTApplications  19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+10,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+5,19.0.0-20-g5a5a17ab+8,19.0.0-21-g2644856+10,19.0.0-22-gc5dc5b1+5,19.0.0-23-gdc29a50+2,19.0.0-24-g923e380+10,19.0.0-25-g6c8df7140,19.0.0-27-g567f04d+6,19.0.0-3-g2b32d65+5,19.0.0-3-g8227491+9,19.0.0-3-g9c54d0d+9,19.0.0-3-gca68e65+5,19.0.0-3-gcfc5f51+5,19.0.0-3-ge110943+8,19.0.0-3-ge74d124,19.0.0-3-gfe04aa6+10,19.0.0-4-g06f5963+5,19.0.0-4-g3d16501+10,19.0.0-4-g4a9c019+5,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8278b9b+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+10,19.0.0-4-ge404a01+9,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gfb03ce7+10,19.0.0-6-gbaebbfb+9,19.0.0-60-gafafd468+10,19.0.0-64-gf672fef+7,19.0.0-7-g039c0b5+8,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+10,19.0.0-8-g3a3ce09+5,19.0.0-9-g463f923+9,w.2020.21
LSSTDataManagementBasePackage
convertGen2RepoToGen3.py
Go to the documentation of this file.
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 
22 """Convert a gen2 butler repo to gen 3. See
23 `lsst.obs.base.ConvertRepoConfig` for most of the config options.
24 """
25 
26 import argparse
27 import logging
28 
29 import lsst.daf.butler
30 import lsst.log
31 import lsst.utils
32 
33 from ..gen2to3 import ConvertRepoTask, ConvertRepoSkyMapConfig, Rerun
34 
35 
37  parser = argparse.ArgumentParser(description=__doc__,
38  formatter_class=argparse.RawDescriptionHelpFormatter)
39  parser.add_argument("instrumentClass", metavar="lsst.obs.CAMERA.INSTRUMENT",
40  help=("The full import path to the gen3 Instrument class for this camera"
41  " (e.g. lsst.obs.decam.DarkEnergyCamera)."))
42  parser.add_argument("--gen2root", required=True,
43  help="Root path of the gen 2 repo to be converted.")
44  parser.add_argument("--gen3root", required=True,
45  help="Root path of the gen 3 repo to be produced.")
46  parser.add_argument("--skymapName", default=None,
47  help="Name of the new gen3 skymap (e.g. 'discrete/ci_hsc').")
48  parser.add_argument("--skymapConfig", default=None,
49  help="Path to skymap config file defining the new gen3 skymap.")
50  parser.add_argument("--calibs", default=None,
51  help="Path to the gen 2 calibration repo; absolute, or relative to gen2root.")
52  parser.add_argument("--reruns", default=[], nargs="*",
53  help="List of gen 2 reruns to convert.")
54  parser.add_argument("--transferMode", default="auto",
55  choices=["auto", "link", "symlink", "hardlink", "copy", "move", "relsymlink"],
56  help="Mode to use to transfer files into the new repository.")
57  parser.add_argument("-v", "--verbose", action="store_const", dest="verbose",
58  default=lsst.log.Log.INFO, const=lsst.log.Log.DEBUG,
59  help="Set the log level to DEBUG.")
60  parser.add_argument("-c", "--config", default=None,
61  help=("Path to a `ConvertRepoConfig` override to be included after "
62  "the Instrument config overrides are applied."))
63 
64  return parser
65 
66 
67 def parse_args(parser):
68  args = parser.parse_args()
69 
70  skymapList = [args.skymapName, args.skymapConfig]
71  if not all(x is None for x in skymapList) and not all(x is not None for x in skymapList):
72  parser.error("Must specify both --skymapName and --skymapConfig, or neither.")
73 
74  return args
75 
76 
77 def convert(gen2root, gen3root, instrumentClass,
78  skymapName=None, skymapConfig=None,
79  calibs=None, reruns=[], config=None, transferMode="auto"):
80  """Convert the gen 2 Butler repo living at gen2root into a gen 3 repo
81  living at gen3root.
82 
83  Parameters
84  ----------
85  gen2root : `str`
86  Root path to the gen2 repo to be converted.
87  gen3root : `str`
88  Root path to the gen3 output repo.
89  instrumentClass : `str`
90  Full python path to the `lsst.obs.base.Instrument` class of the repo
91  being converted.
92  skymapName : `str`, optional
93  Name of the skymap to be converted in the repo.
94  skymapConfig : `str`, optional
95  Path to the `lsst.skymap.BaseSkyMapConfig` of the gen2 skymap to be
96  converted.
97  calibs : `str`, optional
98  Path to the gen2 calibration repository to be converted.
99  If a relative path, it is assumed to be relative to ``gen2root``.
100  reruns : `list` [`str`], optional
101  List of reruns to convert. They will be placed in the
102  ``shared/INSTRUMENT/RERUN`` collection.
103  config : `str`, optional
104  Path to `lsst.obs.base.ConvertRepoConfig` configuration to load
105  after all default/instrument configurations.
106  transferMode : `str`, optional
107  Mode to use when transferring data into the gen3 repository.
108  """
109  # instantiate the correct instrument
110  instrument = lsst.utils.doImport(instrumentClass)()
111 
112  convertRepoConfig = ConvertRepoTask.ConfigClass()
113  instrument.applyConfigOverrides(ConvertRepoTask._DefaultName, convertRepoConfig)
114  convertRepoConfig.instrument = instrumentClass
115  convertRepoConfig.raws.transfer = transferMode
116  if skymapName is not None:
117  convertRepoConfig.skyMaps[skymapName] = ConvertRepoSkyMapConfig()
118  convertRepoConfig.skyMaps[skymapName].load(skymapConfig)
119  convertRepoConfig.rootSkyMapName = skymapName
120  if config is not None:
121  convertRepoConfig.load(config)
122 
123  rerunsArg = [Rerun(rerun, runName=f"shared/{instrument.getName()}/{rerun}",
124  chainName=f"shared/{instrument.getName()}", parents=[]) for rerun in reruns]
125 
126  # Allow a gen3 butler to be reused
127  try:
128  butlerConfig = lsst.daf.butler.Butler.makeRepo(gen3root)
129  except FileExistsError:
130  # Use the existing butler configuration
131  butlerConfig = gen3root
132  butler = lsst.daf.butler.Butler(butlerConfig, run=f"raw/{instrument.getName()}")
133  convertRepoTask = ConvertRepoTask(config=convertRepoConfig, butler3=butler)
134  convertRepoTask.run(
135  root=gen2root,
136  reruns=rerunsArg,
137  calibs=None if calibs is None else {calibs: f"calib/{instrument.getName()}"}
138  )
139 
140 
141 def main():
142  """To be run by the commandline script in `bin/`.
143  """
144  parser = build_argparser()
145  args = parser.parse_args()
146 
147  log = lsst.log.Log.getLogger("convertRepo")
148  log.setLevel(args.verbose)
149  # Forward python logging to lsst logger
150  logger = logging.getLogger("convertRepo")
151  logger.setLevel(lsst.log.LevelTranslator.lsstLog2logging(log.getLevel()))
152  logger.addHandler(lsst.log.LogHandler())
153 
154  convert(args.gen2root, args.gen3root, args.instrumentClass,
155  skymapName=args.skymapName, skymapConfig=args.skymapConfig,
156  calibs=args.calibs, reruns=args.reruns, config=args.config, transferMode=args.transferMode)
lsst.obs.base.gen2to3.convertRepo.ConvertRepoSkyMapConfig
Definition: convertRepo.py:102
lsst::log::Log::getLogger
static Log getLogger(Log const &logger)
Definition: Log.h:760
lsst.obs.base.script.convertGen2RepoToGen3.build_argparser
def build_argparser()
Definition: convertGen2RepoToGen3.py:36
lsst::geom::all
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.
Definition: CoordinateExpr.h:81
lsst::log
Definition: Log.h:706
lsst::utils
Definition: Backtrace.h:29
lsst.obs.base.script.convertGen2RepoToGen3.convert
def convert(gen2root, gen3root, instrumentClass, skymapName=None, skymapConfig=None, calibs=None, reruns=[], config=None, transferMode="auto")
Definition: convertGen2RepoToGen3.py:77
lsst.obs.base.script.convertGen2RepoToGen3.parse_args
def parse_args(parser)
Definition: convertGen2RepoToGen3.py:67
lsst.obs.base.gen2to3.convertRepo.Rerun
Definition: convertRepo.py:73
lsst.obs.base.script.convertGen2RepoToGen3.main
def main()
Definition: convertGen2RepoToGen3.py:141
lsst.obs.base.gen2to3.convertRepo.ConvertRepoTask
Definition: convertRepo.py:287
lsst::utils.doImport
Definition: doImport.py:1
lsst::log.log.logContinued.LogHandler
Definition: logContinued.py:316