LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
metrics.py
Go to the documentation of this file.
1 # This file is part of ip_diffim.
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 
23 __all__ = [
24  "NumberSciSourcesMetricTask", "NumberSciSourcesMetricConfig",
25  "FractionDiaSourcesToSciSourcesMetricTask", "FractionDiaSourcesToSciSourcesMetricConfig",
26 ]
27 
28 
29 import astropy.units as u
30 
31 from lsst.pipe.base import Struct, connectionTypes
32 from lsst.verify import Measurement
33 from lsst.verify.gen2tasks import register
34 from lsst.verify.tasks import MetricTask, MetricConfig, MetricConnections, \
35  MetricComputationError
36 
37 
39  MetricConnections,
40  defaultTemplates={"package": "ip_diffim",
41  "metric": "numSciSources"},
42  dimensions={"Instrument", "Exposure", "Detector"},
43 ):
44  sources = connectionTypes.Input(
45  doc="The catalog of science sources.",
46  name="src",
47  storageClass="SourceCatalog",
48  dimensions={"Instrument", "Exposure", "Detector"},
49  )
50 
51 
52 class NumberSciSourcesMetricConfig(
53  MetricConfig,
54  pipelineConnections=NumberSciSourcesMetricConnections):
55  pass
56 
57 
58 @register("numSciSources")
59 class NumberSciSourcesMetricTask(MetricTask):
60  """Task that computes the number of cataloged science sources.
61  """
62  _DefaultName = "numSciSources"
63  ConfigClass = NumberSciSourcesMetricConfig
64 
65  def run(self, sources):
66  """Count the number of science sources.
67 
68  Parameters
69  ----------
70  sources : `lsst.afw.table.SourceCatalog` or `None`
71  A science source catalog, which may be empty or `None`.
72 
73  Returns
74  -------
75  result : `lsst.pipe.base.Struct`
76  A `~lsst.pipe.base.Struct` containing the following component:
77 
78  ``measurement``
79  the total number of science sources (`lsst.verify.Measurement`
80  or `None`)
81  """
82  if sources is not None:
83  nSciSources = len(sources)
84  meas = Measurement(self.config.metricName, nSciSources * u.count)
85  else:
86  self.log.info("Nothing to do: no catalogs found.")
87  meas = None
88  return Struct(measurement=meas)
89 
90 
91 class FractionDiaSourcesToSciSourcesMetricConnections(
92  MetricTask.ConfigClass.ConnectionsClass,
93  dimensions={"Instrument", "Exposure", "Detector"},
94  defaultTemplates={"coaddName": "deep",
95  "package": "ip_diffim",
96  "metric": "fracDiaSourcesToSciSources"}):
97  sciSources = connectionTypes.Input(
98  doc="The catalog of science sources.",
99  name="src",
100  storageClass="SourceCatalog",
101  dimensions={"Instrument", "Exposure", "Detector"},
102  )
103  diaSources = connectionTypes.Input(
104  doc="The catalog of DIASources.",
105  name="{coaddName}Diff_diaSrc",
106  storageClass="SourceCatalog",
107  dimensions={"Instrument", "Exposure", "Detector"},
108  )
109 
110 
111 class FractionDiaSourcesToSciSourcesMetricConfig(
112  MetricTask.ConfigClass,
113  pipelineConnections=FractionDiaSourcesToSciSourcesMetricConnections):
114  pass
115 
116 
117 @register("fracDiaSourcesToSciSources")
118 class FractionDiaSourcesToSciSourcesMetricTask(MetricTask):
119  """Task that computes the ratio of difference image sources to science
120  sources in an image, visit, etc.
121  """
122  _DefaultName = "fracDiaSourcesToSciSources"
123  ConfigClass = FractionDiaSourcesToSciSourcesMetricConfig
124 
125  def run(self, sciSources, diaSources):
126  """Compute the ratio of DIASources to science sources.
127 
128  Parameters
129  ----------
130  sciSources : `lsst.afw.table.SourceCatalog` or `None`
131  A science source catalog, which may be empty or `None`.
132  diaSources : `lsst.afw.table.SourceCatalog` or `None`
133  A DIASource catalog for the same unit of processing
134  as ``sciSources``.
135 
136  Returns
137  -------
138  result : `lsst.pipe.base.Struct`
139  A `~lsst.pipe.base.Struct` containing the following component:
140 
141  ``measurement``
142  the ratio (`lsst.verify.Measurement` or `None`)
143  """
144  if diaSources is not None and sciSources is not None:
145  nSciSources = len(sciSources)
146  nDiaSources = len(diaSources)
147  metricName = self.config.metricName
148  if nSciSources <= 0.0:
149  raise MetricComputationError(
150  "No science sources found; ratio of DIASources to science sources ill-defined.")
151  else:
152  meas = Measurement(metricName, nDiaSources / nSciSources * u.dimensionless_unscaled)
153  else:
154  self.log.info("Nothing to do: no catalogs found.")
155  meas = None
156  return Struct(measurement=meas)
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)