lsst.meas.base  14.0-22-gcfb0d17+3
measurementInvestigationLib.py
Go to the documentation of this file.
1 #
2 # LSST Data Management System
3 #
4 # Copyright 2008-2017 AURA/LSST.
5 #
6 # This product includes software developed by the
7 # LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20 # the GNU General Public License along with this program. If not,
21 # see <https://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 from collections import Iterable
25 
26 from lsst.afw.table import SourceCatalog
27 from lsst.meas.base import NoiseReplacer, NoiseReplacerConfig
28 from lsst.meas.base import SingleFrameMeasurementTask as SFMT # noqa N814
29 
30 
31 def rebuildNoiseReplacer(exposure, measCat):
32  """ Recreate NoiseReplacer used in measurement
33 
34  Given a measurement catalog and the exposure on which the measurements were
35  made, reconstruct the NoiseReplacer object that was used to mask out
36  sources during measurement.
37 
38  Parameters
39  ----------
40  exposure : lsst.awf.exposure.Exposure
41  The exposure on which measurements were made
42 
43  meaCat : lsst.afw.table.SourceCatalog
44  Catalog containing the outputs of measurements on each source
45 
46  Returns
47  -------
48  noiseReplacer : lsst.meas.base.NoiseReplacer
49  Object used to replace and or restore sources in the exposure with
50  deterministic noise
51  """
52 
53  algMetadata = measCat.getMetadata()
54  noiseReplacerConf = NoiseReplacerConfig()
55  noiseReplacerConf.noiseSeedMultiplier = \
56  algMetadata.get(SFMT.NOISE_SEED_MULTIPLIER)
57  noiseReplacerConf.noiseSource = algMetadata.get(SFMT.NOISE_SOURCE)
58  noiseReplacerConf.noiseOffset = algMetadata.get(SFMT.NOISE_OFFSET)
59 
60  footprints = {src.getId(): (src.getParent(), src.getFootprint())
61  for src in measCat}
62 
63  try:
64  exposureId = algMetadata.get(SFMT.NOISE_EXPOSURE_ID)
65  except Exception:
66  exposureId = None
67 
68  noiseReplacer = NoiseReplacer(noiseReplacerConf, exposure, footprints,
69  exposureId=exposureId)
70  return noiseReplacer
71 
72 
73 def makeRerunCatalog(schema, oldCatalog, idList, fields=None):
74  """ Creates a catalog prepopulated with ids
75 
76  This function is used to generate a SourceCatalog containing blank records
77  with Ids specified in the idList parameter
78 
79  This function is primarily used when rerunning measurements on a footprint.
80  Specifying ids in a new measurement catalog which correspond to ids in an
81  old catalog makes comparing results much easier.
82 
83  Parameters
84  ----------
85  schema : lsst.afw.table.Schema
86  Schema used to describe the fields in the resulting SourceCatalog
87 
88  oldCatalog : lsst.afw.table.SourceCatalog
89  Catalog containing previous measurements.
90 
91  idList : iterable
92  Python iterable whose values should be numbers corresponding to
93  measurement ids, ids must exist in the oldCatalog
94 
95  fields : iterable
96  Python iterable whose entries should be strings corresponding to schema
97  keys that exist in both the old catalog and input schema. Fields listed
98  will be copied from the old catalog into the new catalog.
99 
100  Returns
101  -------
102  measCat : lsst.afw.table.SourceCatalog
103  SourceCatalog prepopulated with entries corresponding to the ids
104  specified
105  """
106 
107  if fields is None:
108  fields = []
109  if not isinstance(fields, Iterable):
110  raise RuntimeError("fields list must be an iterable with string"
111  "elements")
112  for entry in fields:
113  if entry not in schema:
114  schema.addField(oldCatalog.schema.find(entry).field)
115 
116  measCat = SourceCatalog(schema)
117  for srcId in idList:
118  oldSrc = oldCatalog.find(srcId)
119  src = measCat.addNew()
120  src.setId(srcId)
121  src.setFootprint(oldSrc.getFootprint())
122  src.setParent(oldSrc.getParent())
123  src.setCoord(oldSrc.getCoord())
124  for entry in fields:
125  src[entry] = oldSrc[entry]
126  return measCat
Class that handles replacing sources with noise during measurement.
def makeRerunCatalog(schema, oldCatalog, idList, fields=None)