LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.meas.modelfit.display.interactive.Interactive Class Reference

Public Member Functions

def __init__ (self, root, tag=None, config=None, dataId=None, mode="ccd")
 
def fit (self, outRecord)
 
def plotDistribution (self, *records)
 
def displayOptimizer (self, record, **kwds)
 
def displayResiduals (self, record, nonlinear="fit", amplitudes="fit", doApplyWeights=False)
 

Public Attributes

 mode
 
 butler
 
 dataRef
 
 task
 
 inputs
 

Detailed Description

Interactive analysis helper class

This class manages a butler, calexp, modelfits catalog, and an instance
of a Measure*Task, allowing individual objects to be re-fit and plotted.

Definition at line 44 of file interactive.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.meas.modelfit.display.interactive.Interactive.__init__ (   self,
  root,
  tag = None,
  config = None,
  dataId = None,
  mode = "ccd" 
)
Construct an interactive analysis object.

@param[in]  rerun    Output directory, relative to $S13_DATA_DIR/output.
                     measureCcd.py (or measureCoadd.py if mode='coadd') must
                     have been run (possibly with prepOnly=True) previously
                     with this output directory.
@param[in]  tag      Tag associated with the run; see BaseMeasureConfig.tag.
                     If None, config must not be (and config.tag will be used).
@param[in]  config   ConfigClass instance; if None, it will be loaded from disk.
@param[in]  dataId   Butler data ID of the image to analyze.
@param[in]  mode     One of "ccd", "coadd", or "multi", indicating whether
                     to use MeasureCcdTask, MeasureCoaddTask, or MeasureMultiTask.

Definition at line 51 of file interactive.py.

51  def __init__(self, root, tag=None, config=None, dataId=None, mode="ccd"):
52  """Construct an interactive analysis object.
53 
54  @param[in] rerun Output directory, relative to $S13_DATA_DIR/output.
55  measureCcd.py (or measureCoadd.py if mode='coadd') must
56  have been run (possibly with prepOnly=True) previously
57  with this output directory.
58  @param[in] tag Tag associated with the run; see BaseMeasureConfig.tag.
59  If None, config must not be (and config.tag will be used).
60  @param[in] config ConfigClass instance; if None, it will be loaded from disk.
61  @param[in] dataId Butler data ID of the image to analyze.
62  @param[in] mode One of "ccd", "coadd", or "multi", indicating whether
63  to use MeasureCcdTask, MeasureCoaddTask, or MeasureMultiTask.
64  """
65  self.mode = mode.lower()
66  self.butler = lsst.daf.persistence.Butler(root)
67  TaskClass = None
68  configName = None
69  if self.mode == "ccd":
70  if dataId is None:
71  dataId = dict(visit=100, raft="2,2", sensor="1,1")
72  self.dataRef = self.butler.dataRef("calexp", dataId=dataId)
73  configName = "measureCcd_config"
74  TaskClass = MeasureCcdTask
75  elif self.mode == "coadd":
76  if dataId is None:
77  dataId = dict(tract=0, patch="2,2", filter="i")
78  self.dataRef = self.butler.dataRef("deepCoadd_calexp", dataId=dataId)
79  configName = "deep_measureCoadd_config"
80  TaskClass = MeasureCoaddTask
81  elif self.mode.startswith("multi"):
82  if dataId is None:
83  dataId = dict(tract=0, patch="2,2", filter="i")
84  self.dataRef = self.butler.dataRef("deepCoadd_calexp", dataId=dataId)
85  configName = "deep_measureMulti_config"
86  TaskClass = MeasureMultiTask
87  if config is None:
88  config = self.butler.get(configName, tag=tag, immediate=True)
89  config.previous = tag
90  if tag is None:
91  if config is None:
92  raise ValueError("tag and config arguments cannot both be None")
93  tag = config.tag
94  else:
95  config.tag = "intermediate"
96  self.task = TaskClass(config=config, butler=self.butler)
97  self.inputs = self.task.readInputs(self.dataRef)
98 

Member Function Documentation

◆ displayOptimizer()

def lsst.meas.modelfit.display.interactive.Interactive.displayOptimizer (   self,
  record,
**  kwds 
)

Definition at line 139 of file interactive.py.

139  def displayOptimizer(self, record, **kwds):
140  likelihood = self.task.makeLikelihood(self.inputs, record)
141  objective = modelfitLib.OptimizerObjective.makeFromLikelihood(likelihood, self.task.prior)
142  return OptimizerDisplay(record.getSamples(), self.task.model, objective)
143 

◆ displayResiduals()

def lsst.meas.modelfit.display.interactive.Interactive.displayResiduals (   self,
  record,
  nonlinear = "fit",
  amplitudes = "fit",
  doApplyWeights = False 
)
Display the data postage stamp along with the model image and residuals in ds9.

@param[in] record       ModelFitRecord defining the object to display
@param[in] nonlinear    Vector of nonlinear parameters, or a string prefix (see below)
@param[in] amplitudes   Vector of linear parameters, or a string prefix (see below)
@param[in] doApplyWeights  Whether to show the weighted images used directly in the fit
                           or the original unweighted data.

String prefixes are used to extract the parameters from the record.  Usually the following
are available:
  fit ------- use record.get("fit.*"); the best-fit parameters
  initial --- use record.get("initial.*"); the initial parameters

Definition at line 144 of file interactive.py.

144  def displayResiduals(self, record, nonlinear="fit", amplitudes="fit", doApplyWeights=False):
145  """Display the data postage stamp along with the model image and residuals in ds9.
146 
147  @param[in] record ModelFitRecord defining the object to display
148  @param[in] nonlinear Vector of nonlinear parameters, or a string prefix (see below)
149  @param[in] amplitudes Vector of linear parameters, or a string prefix (see below)
150  @param[in] doApplyWeights Whether to show the weighted images used directly in the fit
151  or the original unweighted data.
152 
153  String prefixes are used to extract the parameters from the record. Usually the following
154  are available:
155  fit ------- use record.get("fit.*"); the best-fit parameters
156  initial --- use record.get("initial.*"); the initial parameters
157  """
158  likelihood = self.task.makeLikelihood(self.inputs, record)
159 
160  if isinstance(nonlinear, str):
161  nonlinear = record.get(nonlinear + ".nonlinear")
162  else:
163  assert nonlinear.shape == (likelihood.getNonlinearDim(),)
164 
165  matrix = numpy.zeros((likelihood.getAmplitudeDim(), likelihood.getDataDim()),
166  dtype=modelfitLib.Pixel).transpose()
167  likelihood.computeModelMatrix(matrix, nonlinear, doApplyWeights)
168 
169  if isinstance(amplitudes, str):
170  amplitudes = record.get(amplitudes + ".amplitudes")
171  else:
172  assert amplitudes.shape == (likelihood.getAmplitudeDim(),)
173 
174  bbox = record.getFootprint().getBBox()
175  bbox.grow(2)
176  flatModel = numpy.zeros(likelihood.getDataDim(), dtype=modelfitLib.Pixel)
177  flatModel[:] = numpy.dot(matrix, amplitudes)
178 
179  imgData = lsst.afw.image.MaskedImageF(self.inputs.exposure.getMaskedImage(), bbox,
180  lsst.afw.image.PARENT, True)
181  bitmask = imgData.getMask().addMaskPlane("FIT_REGION")
182  regionMask = lsst.afw.image.MaskU(bbox)
183  lsst.afw.detection.setMaskFromFootprint(regionMask, record.getFootprint(), bitmask)
184  dataMask = imgData.getMask()
185  dataMask |= regionMask
186  if doApplyWeights:
187  imgData.getImage().set(0.0)
188  imgData.getVariance().set(0.0)
189  flatData = likelihood.getData()
190  lsst.afw.detection.expandArray(record.getFootprint(), flatData, imgData.getImage().getArray(),
191  imgData.getXY0())
192  imgModel = lsst.afw.image.MaskedImageF(lsst.afw.image.ImageF(bbox), regionMask)
193  lsst.afw.detection.expandArray(record.getFootprint(), flatModel, imgModel.getImage().getArray(),
194  imgModel.getXY0())
195  imgResiduals = lsst.afw.image.MaskedImageF(imgData, True)
196  imgResiduals -= imgModel
198  mosaic.setMode("x")
199  mosaic.append(imgData, "data")
200  mosaic.append(imgModel, "model")
201  mosaic.append(imgResiduals, "data-model")
202  grid = mosaic.makeMosaic()
daf::base::PropertySet * set
Definition: fits.cc:912
def setMaskTransparency(name, frame=None)
Definition: ds9.py:80
def mtv(data, frame=None, title="", wcs=None, *args, **kwargs)
Definition: ds9.py:92

◆ fit()

def lsst.meas.modelfit.display.interactive.Interactive.fit (   self,
  outRecord 
)
Re-fit the object indicated by the given record sequential index or source ID,
returning the record.

Definition at line 99 of file interactive.py.

99  def fit(self, outRecord):
100  """Re-fit the object indicated by the given record sequential index or source ID,
101  returning the record.
102  """
103  likelihood = self.task.makeLikelihood(self.inputs, outRecord)
104  self.task.fitter.run(likelihood, outRecord)
105  return outRecord
106 

◆ plotDistribution()

def lsst.meas.modelfit.display.interactive.Interactive.plotDistribution (   self,
records 
)
Plot a representation of the posterior distribution from a ModelFitRecord.

Definition at line 107 of file interactive.py.

107  def plotDistribution(self, *records):
108  """Plot a representation of the posterior distribution from a ModelFitRecord.
109  """
110  import matplotlib
111  recordId = records[0].getId()
112  figure = matplotlib.pyplot.figure(recordId, figsize=(10, 10))
113  data = {}
114  layers = {}
115  for record in records:
116  assert record.getId() == recordId
117  if modelfitLib.MarginalSamplingInterpreter.cast(record.getInterpreter()):
118  data["marginal"] = SamplingDataAdapter(record)
119  layers["marginal.samples"] = HistogramLayer("direct")
120  layers["marginal.proposal"] = SurfaceLayer("direct")
121  elif modelfitLib.DirectSamplingInterpreter.cast(record.getInterpreter()):
122  data["direct"] = SamplingDataAdapter(record)
123  layers["direct.samples"] = HistogramLayer("direct")
124  layers["direct.proposal"] = SurfaceLayer("direct")
125  elif modelfitLib.OptimizerInterpreter.cast(record.getInterpreter()):
126  data["optimizer"] = OptimizerDataAdapter(record)
127  layers["optimizer.track"] = OptimizerTrackLayer("optimizer")
128  layers["optimizer.pdf"] = SurfaceLayer("optimizer",
129  kwds1d=dict(color='g'),
130  kwds2d=dict(cmap=matplotlib.cm.Greens))
131  layers["optimizer.points"] = CrossPointsLayer("optimizer")
132  else:
133  raise ValueError("Unknown or missing interpreter")
134  p = DensityPlot(figure, **data)
135  p.layers.update(layers)
136  p.draw()
137  return p
138 

Member Data Documentation

◆ butler

lsst.meas.modelfit.display.interactive.Interactive.butler

Definition at line 66 of file interactive.py.

◆ dataRef

lsst.meas.modelfit.display.interactive.Interactive.dataRef

Definition at line 72 of file interactive.py.

◆ inputs

lsst.meas.modelfit.display.interactive.Interactive.inputs

Definition at line 97 of file interactive.py.

◆ mode

lsst.meas.modelfit.display.interactive.Interactive.mode

Definition at line 65 of file interactive.py.

◆ task

lsst.meas.modelfit.display.interactive.Interactive.task

Definition at line 96 of file interactive.py.


The documentation for this class was generated from the following file: