LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
forcedPhotImage.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # LSST Data Management System
4 # Copyright 2008, 2009, 2010, 2014 LSST Corporation.
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 <http://www.lsstcorp.org/LegalNotices/>.
22 #
23 
24 """Base command-line driver task for forced measurement. Must be inherited to specialize for
25 a specific dataset to be used (see ForcedPhotCcdTask, ForcedPhotCoaddTask).
26 """
27 
28 import lsst.pex.config
29 import lsst.daf.base
30 import lsst.pipe.base
31 import lsst.pex.config
32 
33 from .base import *
34 from .references import CoaddSrcReferencesTask
35 from .forcedMeasurement import *
36 
37 __all__ = ("ProcessImageForcedConfig", "ProcessImageForcedTask")
38 
39 class ProcessImageForcedConfig(lsst.pex.config.Config):
40  """Config class for forced measurement driver task."""
41 
42  references = lsst.pex.config.ConfigurableField(
43  target=CoaddSrcReferencesTask,
44  doc="subtask to retrieve reference source catalog"
45  )
46  measurement = lsst.pex.config.ConfigurableField(
47  target=ForcedMeasurementTask,
48  doc="subtask to do forced measurement"
49  )
50  coaddName = lsst.pex.config.Field(
51  doc = "coadd name: typically one of deep or goodSeeing",
52  dtype = str,
53  default = "deep",
54  )
55 
56 ## @addtogroup LSST_task_documentation
57 ## @{
58 ## @page ProcessImageForcedTask
59 ## ProcessImageForcedTask
60 ## @copybrief ProcessImageForcedTask
61 ## @}
62 
63 class ProcessImageForcedTask(lsst.pipe.base.CmdLineTask):
64  """!
65  A base class for command-line forced measurement drivers.
66 
67  This is a an abstract class, which is the common ancestor for ForcedPhotCcdTask
68  and ForcedPhotCoaddTask. It provides the run() method that does most of the
69  work, while delegating a few customization tasks to other methods that are
70  overridden by subclasses.
71  """
72  ConfigClass = ProcessImageForcedConfig
73  _DefaultName = "processImageForcedTask"
74 
75  def __init__(self, butler=None, refSchema=None, **kwds):
76  super(lsst.pipe.base.CmdLineTask, self).__init__(**kwds)
77  self.makeSubtask("references")
78  if not refSchema:
79  refSchema = self.references.getSchema(butler)
80  self.makeSubtask("measurement", refSchema=refSchema)
81 
82  def run(self, dataRef):
83  """!
84  Measure a single exposure using forced detection for a reference catalog.
85 
86  @param[in] dataRef An lsst.daf.persistence.ButlerDataRef. It is passed to
87  the references subtask to load the reference catalog (see the
88  CoaddSrcReferencesTask for more information), and
89  the getExposure() and writeOutputs() methods (implemented by
90  derived classes) to read the measurement image and write the
91  outputs. See derived class documentation for which datasets
92  and data ID keys are used.
93 
94  @return lsst.pipe.base.Struct containing the source catalog resulting from the
95  forced measurement on the exposure.
96  """
97  refWcs = self.references.getWcs(dataRef)
98  exposure = self.getExposure(dataRef)
99  refCat = list(self.fetchReferences(dataRef, exposure))
100  retStruct = self.measurement.run(exposure, refCat, refWcs,
101  idFactory=self.makeIdFactory(dataRef))
102  self.writeOutput(dataRef, retStruct.sources)
103 
104  def makeIdFactory(self, dataRef):
105  """Hook for derived classes to define how to make an IdFactory for forced sources.
106 
107  Note that this is for forced source IDs, not object IDs, which are usually handled by
108  the copyColumns config option.
109  """
110  raise NotImplementedError()
111 
112  def fetchReferences(self, dataRef, exposure):
113  """Hook for derived classes to define how to get references objects.
114 
115  Derived classes should call one of the fetch* methods on the references subtask,
116  but which one they call depends on whether the region to get references for is a
117  easy to describe in patches (as it would be when doing forced measurements on a
118  coadd), or is just an arbitrary box (as it would be for CCD forced measurements).
119  """
120  raise NotImplementedError()
121 
122  def getExposure(self, dataRef):
123  """Read input exposure on which to perform the measurements
124 
125  @param dataRef Data reference from butler.
126  """
127  return dataRef.get(self.dataPrefix + "calexp", immediate=True)
128 
129  def writeOutput(self, dataRef, sources):
130  """Write forced source table
131 
132  @param dataRef Data reference from butler; the forced_src dataset (with self.dataPrefix included)
133  is all that will be modified.
134  @param sources SourceCatalog to save
135  """
136  dataRef.put(sources, self.dataPrefix + "forced_src")
137 
138  def getSchemaCatalogs(self):
139  """Get a dict of Schema catalogs that will be used by this Task.
140  In the case of forced taks, there is only one schema for each type of forced measurement.
141  The dataset type for this measurement is defined in the mapper.
142  """
143  catalog = lsst.afw.table.SourceCatalog(self.forcedMeasurement.mapper.getOutputSchema())
144  catalog.getTable().setMetadata(self.measurement.algMetadata)
145  datasetType = self.dataPrefix + "forced"
146  return {datasetType:catalog}
147 
148  def _getConfigName(self):
149  """Return the name of the config dataset. Forces config comparison from run-to-run
150  """
151  return self.dataPrefix + "forced_config"
152 
153  def _getMetadataName(self):
154  """Return the name of the metadata dataset. Forced metadata to be saved
155  """
156  return self.dataPrefix + "forced_metadata"
157 
def run
Measure a single exposure using forced detection for a reference catalog.
Custom catalog class for record/table subclasses that are guaranteed to have an ID, and should generally be sorted by that ID.
Definition: fwd.h:55
A base class for command-line forced measurement drivers.