LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
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, PipelineTaskConnections, connectionTypes
32 from lsst.verify import Measurement
33 from lsst.verify.gen2tasks import MetricTask, register
34 from lsst.verify.tasks import MetricComputationError
35 
36 
38  PipelineTaskConnections,
39  dimensions={"Instrument", "Exposure", "Detector"}):
40  sources = connectionTypes.Input(
41  doc="The catalog of science sources.",
42  name="src",
43  storageClass="SourceCatalog",
44  dimensions={"Instrument", "Exposure", "Detector"},
45  )
46 
47 
49  MetricTask.ConfigClass,
50  pipelineConnections=NumberSciSourcesMetricConnections):
51  pass
52 
53 
54 @register("numSciSources")
55 class NumberSciSourcesMetricTask(MetricTask):
56  """Task that computes the number of cataloged science sources.
57  """
58  _DefaultName = "numSciSources"
59  ConfigClass = NumberSciSourcesMetricConfig
60 
61  def run(self, sources):
62  """Count the number of science sources.
63 
64  Parameters
65  ----------
66  sources : `lsst.afw.table.SourceCatalog` or `None`
67  A science source catalog, which may be empty or `None`.
68 
69  Returns
70  -------
71  result : `lsst.pipe.base.Struct`
72  A `~lsst.pipe.base.Struct` containing the following component:
73 
74  ``measurement``
75  the total number of science sources (`lsst.verify.Measurement`
76  or `None`)
77  """
78  if sources is not None:
79  nSciSources = len(sources)
80  meas = Measurement(self.getOutputMetricName(self.config), nSciSources * u.count)
81  else:
82  self.log.info("Nothing to do: no catalogs found.")
83  meas = None
84  return Struct(measurement=meas)
85 
86  @classmethod
87  def getOutputMetricName(cls, config):
88  return "ip_diffim.numSciSources"
89 
90 
92  PipelineTaskConnections,
93  dimensions={"Instrument", "Exposure", "Detector"},
94  defaultTemplates={"coaddName": "deep"}):
95  sciSources = connectionTypes.Input(
96  doc="The catalog of science sources.",
97  name="src",
98  storageClass="SourceCatalog",
99  dimensions={"Instrument", "Exposure", "Detector"},
100  )
101  diaSources = connectionTypes.Input(
102  doc="The catalog of DIASources.",
103  name="{coaddName}Diff_diaSrc",
104  storageClass="SourceCatalog",
105  dimensions={"Instrument", "Exposure", "Detector"},
106  )
107 
108 
109 class FractionDiaSourcesToSciSourcesMetricConfig(
110  MetricTask.ConfigClass,
111  pipelineConnections=FractionDiaSourcesToSciSourcesMetricConnections):
112  pass
113 
114 
115 @register("fracDiaSourcesToSciSources")
116 class FractionDiaSourcesToSciSourcesMetricTask(MetricTask):
117  """Task that computes the ratio of difference image sources to science
118  sources in an image, visit, etc.
119  """
120  _DefaultName = "fracDiaSourcesToSciSources"
121  ConfigClass = FractionDiaSourcesToSciSourcesMetricConfig
122 
123  def run(self, sciSources, diaSources):
124  """Compute the ratio of DIASources to science sources.
125 
126  Parameters
127  ----------
128  sciSources : `lsst.afw.table.SourceCatalog` or `None`
129  A science source catalog, which may be empty or `None`.
130  diaSources : `lsst.afw.table.SourceCatalog` or `None`
131  A DIASource catalog for the same unit of processing
132  as ``sciSources``.
133 
134  Returns
135  -------
136  result : `lsst.pipe.base.Struct`
137  A `~lsst.pipe.base.Struct` containing the following component:
138 
139  ``measurement``
140  the ratio (`lsst.verify.Measurement` or `None`)
141  """
142  if diaSources is not None and sciSources is not None:
143  nSciSources = len(sciSources)
144  nDiaSources = len(diaSources)
145  metricName = self.getOutputMetricName(self.config)
146  if nSciSources <= 0.0:
147  raise MetricComputationError(
148  "No science sources found; ratio of DIASources to science sources ill-defined.")
149  else:
150  meas = Measurement(metricName, nDiaSources / nSciSources * u.dimensionless_unscaled)
151  else:
152  self.log.info("Nothing to do: no catalogs found.")
153  meas = None
154  return Struct(measurement=meas)
155 
156  @classmethod
157  def getOutputMetricName(cls, config):
158  return "ip_diffim.fracDiaSourcesToSciSources"
def run(self, skyInfo, tempExpRefList, imageScalerList, weightList, altMaskList=None, mask=None, supplementaryData=None)