Coverage for python/lsst/obs/base/script/defineVisits.py: 24%
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
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
23from lsst.daf.butler import Butler
24from lsst.obs.base import DefineVisitsConfig, DefineVisitsTask
26from ..utils import getInstrument
28log = logging.getLogger("lsst.obs.base.defineVisits")
31def defineVisits(repo, config_file, collections, instrument, raw_name="raw"):
32 """Implements the command line interface `butler define-visits` subcommand,
33 should only be called by command line tools and unit test code that tests
34 this function.
36 Defines visits from exposures in the butler registry
38 Parameters
39 ----------
40 repo : `str`
41 URI to the location to create the repo.
42 config_file : `str` or `None`
43 Path to a config file that contains overrides to the ingest config.
44 collections : `list` [`str`]
45 An expression specifying the collections to be searched (in order) when
46 reading datasets, and optionally dataset type restrictions on them.
47 If empty it will be passed as `None` to Butler.
48 instrument : `str`
49 The name or fully-qualified class name of an instrument.
50 raw_name : `str`, optional
51 Name of the raw dataset type name. Defaults to 'raw'.
53 Notes
54 -----
55 Camera geometry is not currently found in registry but instead a default
56 camera will be used for the relevant instrument.
57 """
58 if not collections:
59 collections = None
60 butler = Butler(repo, collections=collections, writeable=True)
61 instr = getInstrument(instrument, butler.registry)
62 config = DefineVisitsConfig()
63 instr.applyConfigOverrides(DefineVisitsTask._DefaultName, config)
65 if collections is None:
66 # Default to the raw collection for this instrument
67 collections = instr.makeDefaultRawIngestRunName()
68 log.info("Defaulting to searching for raw exposures in collection %s", collections)
70 if config_file is not None:
71 config.load(config_file)
72 task = DefineVisitsTask(config=config, butler=butler)
74 # Assume the dataset type is "raw" -- this is required to allow this
75 # query to filter out exposures not relevant to the specified collection.
76 task.run(
77 butler.registry.queryDataIds(
78 ["exposure"], dataId={"instrument": instr.getName()}, collections=collections, datasets=raw_name
79 ),
80 collections=collections,
81 )