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
forcedPhotCcd.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 import argparse
25 
26 import lsst.pex.config
27 import lsst.pipe.base
28 import lsst.afw.image
29 import lsst.afw.table
30 
31 from .forcedPhotImage import ProcessImageForcedTask, ProcessImageForcedConfig
32 
33 try:
34  from lsst.meas.mosaic import applyMosaicResults
35 except ImportError:
36  applyMosaicResults = None
37 
38 __all__ = ("ForcedPhotCcdConfig", "ForcedPhotCcdTask")
39 
40 class ForcedPhotCcdDataIdContainer(lsst.pipe.base.DataIdContainer):
41  """A version of DataIdContainer specialized for forced photometry on CCDs.
42 
43  Required because we need to add "tract" to the raw data ID keys, and that's tricky.
44  This IdContainer assumes that a calexp is being measured using the detection information
45  from the set of coadds which intersect with the calexp. a set of reference catalog
46  from a coadd which overlaps it. It needs the calexp id (e.g. visit, raft, sensor), but it
47  also uses the tract to decide what set of coadds to use. The references from the tract
48  whose patches intersect with the calexp are used.
49  """
50  def makeDataRefList(self, namespace):
51  """Make self.refList from self.idList
52  """
53  for dataId in self.idList:
54  if "tract" not in dataId:
55  raise argparse.ArgumentError(None, "--id must include tract")
56  tract = dataId.pop("tract")
57  # making a DataRef for src fills out any missing keys and allows us to iterate
58  for srcDataRef in namespace.butler.subset("src", dataId=dataId):
59  forcedDataId = srcDataRef.dataId.copy()
60  forcedDataId['tract'] = tract
61  dataRef = namespace.butler.dataRef(
62  datasetType = "forced_src",
63  dataId = forcedDataId,
64  )
65  self.refList.append(dataRef)
66 
67 class ForcedPhotCcdConfig(ProcessImageForcedConfig):
68  doApplyUberCal = lsst.pex.config.Field(
69  dtype = bool,
70  doc = "Apply meas_mosaic ubercal results to input calexps?",
71  default = False
72  )
73 
74 ## @addtogroup LSST_task_documentation
75 ## @{
76 ## @page processForcedCcdTask
77 ## ForcedPhotCcdTask
78 ## @copybrief ForcedPhotCcdTask
79 ## @}
80 
81 class ForcedPhotCcdTask(ProcessImageForcedTask):
82  """!
83  A command-line driver for performing forced measurement on CCD images
84 
85  This task is a subclass of ForcedPhotImageTask which is specifically for doing forced
86  measurement on a single CCD exposure, using as a reference catalog the detections which
87  were made on overlapping coadds.
88 
89  The run method (inherited from ForcedPhotImageTask) takes a lsst.daf.persistence.ButlerDataRef
90  argument that corresponds to a single CCD. This should contain the data ID keys that correspond to
91  the "forced_src" dataset (the output dataset for ForcedPhotCcdTask), which are typically all those
92  used to specify the "calexp" dataset (e.g. visit, raft, sensor for LSST data) as well as a coadd
93  tract. The tract is used to look up the appropriate coadd measurement catalogs to use as references
94  (e.g. deepCoadd_src; see CoaddSrcReferencesTask for more information). While the tract must be given
95  as part of the dataRef, the patches are determined automatically from the bounding box and WCS of the
96  calexp to be measured, and the filter used to fetch references is set via config
97  (BaseReferencesConfig.filter).
98 
99  In addition to the run method, ForcedPhotCcdTask overrides several methods of ForcedPhotImageTask
100  to specialize it for single-CCD processing, including makeIdFactory(), fetchReferences(), and
101  getExposure(). None of these should be called directly by the user, though it may be useful
102  to override them further in subclasses.
103  """
104 
105  ConfigClass = ForcedPhotCcdConfig
106  RunnerClass = lsst.pipe.base.ButlerInitializedTaskRunner
107  _DefaultName = "forcedPhotCcdTask"
108  dataPrefix = ""
109 
110  def makeIdFactory(self, dataRef):
111  """Create an object that generates globally unique source IDs from per-CCD IDs and the CCD ID.
112 
113  @param dataRef Data reference from butler. The "ccdExposureId_bits" and "ccdExposureId"
114  datasets are accessed. The data ID must have the keys that correspond
115  to ccdExposureId, which is generally the same that correspond to "calexp"
116  (e.g. visit, raft, sensor for LSST data).
117  """
118  expBits = dataRef.get("ccdExposureId_bits")
119  expId = long(dataRef.get("ccdExposureId"))
120  return lsst.afw.table.IdFactory.makeSource(expId, 64 - expBits)
121 
122  def fetchReferences(self, dataRef, exposure):
123  """Return an iterable of reference sources which overlap the exposure
124 
125  @param dataRef Data reference from butler corresponding to the image to be measured;
126  should have tract, patch, and filter keys.
127  @param exposure lsst.afw.image.Exposure to be measured (used only to obtain a Wcs and bounding
128  box).
129 
130  All work is delegated to the references subtask; see CoaddSrcReferencesTask for information
131  about the default behavior.
132  """
133  bbox = exposure.getBBox()
134  return self.references.fetchInBox(dataRef, bbox, exposure.getWcs())
135 
136  def getExposure(self, dataRef):
137  """Read input exposure to measure
138 
139  @param dataRef Data reference from butler. Only the 'calexp' dataset is used,
140  unless config.doApplyUberCal is true, in which case the corresponding
141  meas_mosaic outputs are used as well.
142  """
143  exposure = ProcessImageForcedTask.getExposure(self, dataRef)
144  if not self.config.doApplyUberCal:
145  return exposure
146  if applyMosaicResults is None:
147  raise RuntimeError(
148  "Cannot use improved calibrations for %s because meas_mosaic could not be imported."
149  % dataRef.dataId
150  )
151  else:
152  applyMosaicResults(dataRef, calexp=exposure)
153  return exposure
154 
155  @classmethod
157  parser = lsst.pipe.base.ArgumentParser(name=cls._DefaultName)
158  parser.add_id_argument("--id", "forced_src", help="data ID, with raw CCD keys + tract",
159  ContainerClass=ForcedPhotCcdDataIdContainer)
160  return parser
161 
162 
static boost::shared_ptr< IdFactory > makeSource(RecordId expId, int reserved)
Return an IdFactory that includes another, fixed ID in the higher-order bits.
A command-line driver for performing forced measurement on CCD images.