Coverage for python/lsst/verify/gen2tasks/metadataTask.py: 61%

16 statements  

« prev     ^ index     » next       coverage.py v6.4.1, created at 2022-07-11 06:50 +0000

1# This file is part of verify. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://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 <https://www.gnu.org/licenses/>. 

21 

22__all__ = ["SquashMetadataTask"] 

23 

24from lsst.pex.config import Config 

25from lsst.pipe.base import Task, Struct 

26 

27 

28class SquashMetadataTask(Task): 

29 """A Task for adding SQuaSH-required metadata to a Job. 

30 

31 This task is intended as a subtask of `MetricsControllerTask`. 

32 """ 

33 

34 _DefaultName = "squashMetadata" 

35 ConfigClass = Config 

36 

37 @staticmethod 

38 def _getInstrument(dataref): 

39 """Extract the instrument name associated with a Butler dataset. 

40 

41 Parameters 

42 ---------- 

43 dataref : `lsst.daf.persistence.ButlerDataRef` 

44 A data reference to any dataset of interest. 

45 

46 Returns 

47 ------- 

48 instrument : `str` 

49 The canonical name of the instrument, in all uppercase form. 

50 """ 

51 camera = dataref.get('camera') 

52 instrument = camera.getName() 

53 return instrument.upper() 

54 

55 def run(self, job, *, dataref, **kwargs): 

56 """Add metadata to a Job object. 

57 

58 Parameters 

59 ---------- 

60 job : `lsst.verify.Job` 

61 The job to be instrumented with metadata. The input object will be 

62 modified by this call. 

63 dataref : `lsst.daf.persistence.ButlerDataRef` 

64 The data reference associated with the job. 

65 kwargs 

66 Additional keyword arguments. These exist to support duck-typing 

67 with tasks that require different inputs, and are unused. 

68 

69 Returns 

70 ------- 

71 struct : `lsst.pipe.base.Struct` 

72 A `~lsst.pipe.base.Struct` containing the following component: 

73 

74 ``job`` 

75 a reference to the input `~lsst.verify.Job`. 

76 

77 Notes 

78 ----- 

79 The current implementation adds the following metadata: 

80 

81 ``"instrument"`` 

82 The canonical name of the instrument, in all 

83 uppercase form (`str`). 

84 ``[data ID key]`` 

85 One metadata key for each key in ``dataref``'s data ID 

86 (e.g., ``"visit"``), with the corresponding value. 

87 """ 

88 job.meta['instrument'] = SquashMetadataTask._getInstrument(dataref) 

89 job.meta['butler_generation'] = 'Gen2' 

90 job.meta.update(dataref.dataId) 

91 

92 return Struct(job=job)