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

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

21 statements  

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 

25 

26from ..utils import getInstrument 

27 

28log = logging.getLogger("lsst.obs.base.defineVisits") 

29 

30 

31def defineVisits(repo, config_file, collections, instrument, where=None, 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. 

35 

36 Defines visits from exposures in the butler registry 

37 

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 where : `str`, optional 

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

52 the relevant exposures. 

53 raw_name : `str`, optional 

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

55 

56 Notes 

57 ----- 

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

59 camera will be used for the relevant instrument. 

60 """ 

61 if not collections: 

62 collections = None 

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

64 instr = getInstrument(instrument, butler.registry) 

65 config = DefineVisitsConfig() 

66 instr.applyConfigOverrides(DefineVisitsTask._DefaultName, config) 

67 

68 if collections is None: 

69 # Default to the raw collection for this instrument 

70 collections = instr.makeDefaultRawIngestRunName() 

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

72 

73 if not where: 

74 where = None 

75 

76 if config_file is not None: 

77 config.load(config_file) 

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

79 

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

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

82 task.run( 

83 butler.registry.queryDataIds( 

84 ["exposure"], 

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

86 collections=collections, 

87 datasets=raw_name, 

88 where=where, 

89 ), 

90 collections=collections, 

91 )