Hide keyboard shortcuts

Hot-keys 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

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

# 

# LSST Data Management System 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# See COPYRIGHT file at the top of the source tree. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <https://www.lsstcorp.org/LegalNotices/>. 

# 

from __future__ import absolute_import, division, print_function 

 

__all__ = ['output_quantities'] 

 

from .job import Job 

from .measurement import Measurement 

from .naming import Name 

 

 

def output_quantities(package_name, quantities, suffix=None, 

include_metrics=False, metrics_package='verify_metrics'): 

"""Output measurements, as `astropy.units.Quantity` objects, from a 

pipeline task execution to a `lsst.verify`-formatted JSON file. 

 

Parameters 

---------- 

package_name : `str` 

Name of the package producing measurements. This name is used two ways: 

 

1. Make fully-qualified metric names from keys in the ``quantities`` 

dictionary. For example, if a ``quantities`` dict has a key-value 

pair ``{'PA1': 5 * u.mmag}`` and ``package_name='validate_drp'``, 

the fully-qualified metric name is ``'validate_drp.PA1'``. 

2. As a filename prefix for the output JSON file. 

 

quantities : `dict` of `astropy.units.Quantity` values 

Dictionary of measurements as plain `astropy.units.Quantity` 

instances. Each key is the name of a metric. If metric names are 

not fully-specified (in ``package.metric`` format), the package 

name can be provided with the ``package_name`` argument. 

 

suffix : `str`, optional 

Additional suffix to add to the output JSON filename:: 

 

{package_name}_{suffix}.verify.json 

 

The suffix may be used to distinguish measurement output files from 

different tasks in the same package. 

 

include_metrics : `bool`, optional 

Metric and specification definitions are included in the JSON output 

if set to `True`. The metric and specification definitions are 

loaded from a metric package indicated by the ``metrics_package`` 

argument. Normally tasks do not need to include metric definitions if 

a post-processing step is used. Default: `False`. 

 

metrics_package : `str`, optional 

Name of the metrics package to obtain metrics from if 

``include_metrics`` is `True`. Default is ``'verify_metrics'``. 

 

Returns 

------- 

filename : `str` 

Filename where the JSON file was written. 

 

See also 

-------- 

lsst.verify.Job.write 

 

Notes 

----- 

This function is designed for lightweight `lsst.verify` framework usage. 

Rather than maintaining `Job` and `Measurement` objects, 

a task can simply record metric measurements as `astropy.units.Quantity` 

objects. With `output_quantities`, the task can output these measurements 

in a standardized `lsst.verify` JSON format. Post-processing tools 

can load this data for local analysis, or submit it to the 

https://squash.lsst.codes dashboard service. 

 

Tasks that need to include `Blob`\ s, `Measurement.extras` or query 

`Metric` objects should create a `Job` instance and use 

`Job.write` instead. 

""" 

96 ↛ 97line 96 didn't jump to line 97, because the condition on line 96 was never true if include_metrics: 

job = Job.load_metrics_package(metrics_package, subset=package_name) 

else: 

job = Job() 

 

for name, quantity in quantities.items(): 

metric_name = Name(package=package_name, metric=name) 

measurement = Measurement(metric_name, quantity=quantity) 

job.measurements.insert(measurement) 

 

106 ↛ 107line 106 didn't jump to line 107, because the condition on line 106 was never true if suffix is not None: 

filename = '{package}_{suffix}.verify.json'.format( 

package=package_name, suffix=suffix) 

else: 

filename = '{package}.verify.json'.format(package=package_name) 

 

job.write(filename) 

 

return filename