lsst.meas.modelfit  18.0.0-1-ga759dd9
GeneralPsfFitter.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 /*
3  * LSST Data Management System
4  * Copyright 2008-2013 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 #ifndef LSST_MEAS_MODELFIT_GeneralPsfFitter_h_INCLUDED
25 #define LSST_MEAS_MODELFIT_GeneralPsfFitter_h_INCLUDED
26 
27 #include <memory>
28 
29 #include "lsst/pex/config.h"
34 #include "lsst/afw/geom.h"
35 #include "lsst/afw/table/Source.h"
39 
40 namespace lsst { namespace meas { namespace modelfit {
41 
46 public:
47 
48  GeneralPsfFitterComponentControl(int order_=0, double radiusFactor_=1.0) :
50  radiusFactor(radiusFactor_), radiusPriorSigma(0.5)
51  {}
52 
54  order, int,
55  "shapelet order for this component; negative to disable this component completely"
56  );
58  positionPriorSigma, double,
59  "sigma (in pixels) in an isotropic 2-d Gaussian prior on the center of this shapelet component, "
60  "relative to the center of the PSF image"
61  );
63  ellipticityPriorSigma, double,
64  "sigma in an isotropic 2-d Gaussian prior on the conformal-shear ellipticity eta"
65  );
67  radiusFactor, double,
68  "Sets the fiducial radius of this component relative to the 'primary radius' of the PSF: either "
69  "the second-moments radius of the PSF image (in an initial fit), or the radius of the primary "
70  "component in a previous fit. Ignored if the previous fit included this component (as then we "
71  "can just use that radius)."
72  );
74  radiusPriorSigma, double,
75  "sigma in a Gaussian prior on ln(radius/fiducialRadius)"
76  );
77 
78 };
79 
89 public:
90 
92  inner(-1, 0.5), primary(0, 1.0), wings(0, 2.0), outer(-1, 4.0), defaultNoiseSigma(0.001)
93  {}
94 
97  "Innermost shapelet expansion, used to fit PSFs with very sharp cores"
98  );
99 
102  "Primary shapelet expansion, typically used to fit the bulk of the PSF "
103  );
104 
107  "Wing shapelet expansion (between primary and outer), typically used to fit the wings of the PSF"
108  );
109 
112  "Outermost shapelet expansion, used to fit PSFs with very broad wings"
113  );
114 
117  "Configuration of the optimizer used to do the fitting"
118  );
119 
121  defaultNoiseSigma, double, "Default value for the noiseSigma parameter in GeneralPsfFitter.apply()"
122  );
123 
124 };
125 
148 public:
150  explicit GeneralPsfFitter(GeneralPsfFitterControl const & ctrl);
151 
162  std::string const & prefix
163  ) const;
164 
173  PTR(Model) getModel() const { return _model; }
174 
181  PTR(Prior) getPrior() const { return _prior; }
182 
196  shapelet::MultiShapeletFunction const & previousFit,
197  PTR(Model) previousModel
198  ) const;
199 
201 
216  afw::geom::ellipses::Quadrupole const & moments,
217  Scalar noiseSigma=-1,
218  int * pState = nullptr
219  ) const;
221  afw::image::Image<double> const & image,
222  afw::geom::ellipses::Quadrupole const & moments,
223  Scalar noiseSigma=-1,
224  int * pState = nullptr
225  ) const {
226  return apply(afw::image::Image<float>(image, true), moments, noiseSigma, pState);
227  }
229 
231 
245  afw::image::Image<Pixel> const & image,
246  shapelet::MultiShapeletFunction const & initial,
247  Scalar noiseSigma=-1,
248  int * pState = nullptr
249  ) const;
251  afw::image::Image<double> const & image,
252  shapelet::MultiShapeletFunction const & initial,
253  Scalar noiseSigma=-1,
254  int * pState = nullptr
255  ) const {
256  return apply(afw::image::Image<float>(image, true), initial, noiseSigma);
257  }
259 
260 private:
262  PTR(Model) _model;
263  PTR(Prior) _prior;
264 };
265 
267 public:
268 
269  // Structures and routines to manage flaghandler
270  static base::FlagDefinitionList const & getFlagDefinitions();
276 
278 
280  afw::table::Schema & schema,
281  std::string const & prefix
282  );
283 
285  return _key;
286  }
287 
288  void measure(
289  afw::table::SourceRecord & measRecord,
291  shapelet::MultiShapeletFunction const & initial
292  ) const;
293 
294  void measure(
295  afw::table::SourceRecord & measRecord,
296  afw::image::Image<double> const & image,
297  afw::geom::ellipses::Quadrupole const & moments
298  ) const;
299 
300  void fail(
301  afw::table::SourceRecord & measRecord,
302  lsst::meas::base::MeasurementError * error=nullptr
303  ) const;
304 
305 private:
307  lsst::meas::base::FlagHandler _flagHandler;
308 };
309 
315 public:
316 
318  ndarray::Array<Pixel const,2,1> const & image,
319  afw::geom::Point2I const & xy0,
320  PTR(Model) model,
321  Scalar sigma,
322  ndarray::Array<Scalar const,1,1> const & fixed
323  );
324 
325  void computeModelMatrix(
326  ndarray::Array<Pixel,2,-1> const & modelMatrix,
327  ndarray::Array<Scalar const,1,1> const & nonlinear,
328  bool doApplyWeights=true
329  ) const override;
330 
331  virtual ~MultiShapeletPsfLikelihood();
332 
333 private:
334  class Impl;
335  std::unique_ptr<Impl> _impl;
336 };
337 
338 }}} // namespace lsst::meas::modelfit
339 
340 #endif // !LSST_MEAS_MODELFIT_GeneralPsfFitter_h_INCLUDED
Likelihood object used to fit multishapelet models to PSF model images; mostly for internal use by Ge...
afw::table::Key< afw::table::Array< ImagePixelT > > image
GeneralPsfFitterComponentControl(int order_=0, double radiusFactor_=1.0)
double radiusPriorSigma
"sigma in a Gaussian prior on ln(radius/fiducialRadius)" ;
static base::FlagDefinition const MAX_OUTER_ITERATIONS
table::Schema schema
double Scalar
Typedefs to be used for probability and parameter values.
Definition: common.h:44
boost::shared_ptr< Model > getModel() const
Return the Model object that corresponds to the configuration.
#define PTR(...)
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
afw::table::Key< double > sigma
STL class.
Abstract base class and concrete factories that define multi-shapelet galaxy models.
Definition: Model.h:56
static base::FlagDefinition const FAILURE
double positionPriorSigma
"sigma (in pixels) in an isotropic 2-d Gaussian prior on the center of this shapelet component...
#define LSST_NESTED_CONTROL_FIELD(NAME, MODULE, TYPE, DOC)
Control object used to define one piece of multishapelet fit to a PSF model; see GeneralPsfFitterCont...
shapelet::MultiShapeletFunctionKey getKey()
Configuration object for Optimizer.
Definition: optimizer.h:187
static base::FlagDefinition const MAX_INNER_ITERATIONS
Base class for Bayesian priors.
Definition: Prior.h:36
Base class for optimizer/sampler likelihood functions that compute likelihood at a point...
Definition: Likelihood.h:69
Class for fitting multishapelet models to PSF images.
double radiusFactor
"Sets the fiducial radius of this component relative to the &#39;primary radius&#39; of the PSF: either " "th...
std::string prefix
shapelet::MultiShapeletFunction apply(afw::image::Image< double > const &image, afw::geom::ellipses::Quadrupole const &moments, Scalar noiseSigma=-1, int *pState=nullptr) const
Perform an initial fit to a PSF image.
double ellipticityPriorSigma
"sigma in an isotropic 2-d Gaussian prior on the conformal-shear ellipticity eta" ; ...
Control object used to configure a multishapelet fit to a PSF model; see GeneralPsfFitter.
static base::FlagDefinition const CONTAINS_NAN
int order
"shapelet order for this component; negative to disable this component completely" ; ...
shapelet::MultiShapeletFunction apply(afw::image::Image< double > const &image, shapelet::MultiShapeletFunction const &initial, Scalar noiseSigma=-1, int *pState=nullptr) const
Perform a fit to a PSF image, using a previous fit as a starting point.
boost::shared_ptr< Prior > getPrior() const
Return the Prior object that corresponds to the configuration.
static base::FlagDefinition const EXCEPTION