LSSTApplications  20.0.0
LSSTDataManagementBasePackage
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/geom.h"
35 #include "lsst/afw/geom.h"
36 #include "lsst/afw/table/Source.h"
40 
41 namespace lsst { namespace meas { namespace modelfit {
42 
47 public:
48 
49  GeneralPsfFitterComponentControl(int order_=0, double radiusFactor_=1.0) :
51  radiusFactor(radiusFactor_), radiusPriorSigma(0.5)
52  {}
53 
55  order, int,
56  "shapelet order for this component; negative to disable this component completely"
57  );
59  positionPriorSigma, double,
60  "sigma (in pixels) in an isotropic 2-d Gaussian prior on the center of this shapelet component, "
61  "relative to the center of the PSF image"
62  );
64  ellipticityPriorSigma, double,
65  "sigma in an isotropic 2-d Gaussian prior on the conformal-shear ellipticity eta"
66  );
68  radiusFactor, double,
69  "Sets the fiducial radius of this component relative to the 'primary radius' of the PSF: either "
70  "the second-moments radius of the PSF image (in an initial fit), or the radius of the primary "
71  "component in a previous fit. Ignored if the previous fit included this component (as then we "
72  "can just use that radius)."
73  );
75  radiusPriorSigma, double,
76  "sigma in a Gaussian prior on ln(radius/fiducialRadius)"
77  );
78 
79 };
80 
90 public:
91 
93  inner(-1, 0.5), primary(0, 1.0), wings(0, 2.0), outer(-1, 4.0), defaultNoiseSigma(0.001)
94  {}
95 
98  "Innermost shapelet expansion, used to fit PSFs with very sharp cores"
99  );
100 
103  "Primary shapelet expansion, typically used to fit the bulk of the PSF "
104  );
105 
108  "Wing shapelet expansion (between primary and outer), typically used to fit the wings of the PSF"
109  );
110 
113  "Outermost shapelet expansion, used to fit PSFs with very broad wings"
114  );
115 
118  "Configuration of the optimizer used to do the fitting"
119  );
120 
122  defaultNoiseSigma, double, "Default value for the noiseSigma parameter in GeneralPsfFitter.apply()"
123  );
124 
125 };
126 
149 public:
152 
163  std::string const & prefix
164  ) const;
165 
174  PTR(Model) getModel() const { return _model; }
175 
182  PTR(Prior) getPrior() const { return _prior; }
183 
197  shapelet::MultiShapeletFunction const & previousFit,
198  PTR(Model) previousModel
199  ) const;
200 
202 
218  Scalar noiseSigma=-1,
219  int * pState = nullptr
220  ) const;
224  Scalar noiseSigma=-1,
225  int * pState = nullptr
226  ) const {
227  return apply(afw::image::Image<float>(image, true), moments, noiseSigma, pState);
228  }
230 
232 
247  shapelet::MultiShapeletFunction const & initial,
248  Scalar noiseSigma=-1,
249  int * pState = nullptr
250  ) const;
253  shapelet::MultiShapeletFunction const & initial,
254  Scalar noiseSigma=-1,
255  int * pState = nullptr
256  ) const {
257  return apply(afw::image::Image<float>(image, true), initial, noiseSigma);
258  }
260 
261 private:
263  PTR(Model) _model;
264  PTR(Prior) _prior;
265 };
266 
268 public:
269 
270  // Structures and routines to manage flaghandler
277 
279 
282  std::string const & prefix
283  );
284 
286  return _key;
287  }
288 
289  void measure(
290  afw::table::SourceRecord & measRecord,
292  shapelet::MultiShapeletFunction const & initial
293  ) const;
294 
295  void measure(
296  afw::table::SourceRecord & measRecord,
299  ) const;
300 
301  void fail(
302  afw::table::SourceRecord & measRecord,
304  ) const;
305 
306 private:
308  lsst::meas::base::FlagHandler _flagHandler;
309 };
310 
316 public:
317 
319  ndarray::Array<Pixel const,2,1> const & image,
320  geom::Point2I const & xy0,
321  PTR(Model) model,
322  Scalar sigma,
323  ndarray::Array<Scalar const,1,1> const & fixed
324  );
325 
327  ndarray::Array<Pixel,2,-1> const & modelMatrix,
328  ndarray::Array<Scalar const,1,1> const & nonlinear,
329  bool doApplyWeights=true
330  ) const override;
331 
333 
334 private:
335  class Impl;
336  std::unique_ptr<Impl> _impl;
337 };
338 
339 }}} // namespace lsst::meas::modelfit
340 
341 #endif // !LSST_MEAS_MODELFIT_GeneralPsfFitter_h_INCLUDED
schema
table::Schema schema
Definition: Amplifier.cc:115
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::Control
GeneralPsfFitterControl Control
Definition: GeneralPsfFitter.h:278
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
moments
VectorQ moments
Definition: simpleShape.cc:151
FunctorKeys.h
Prior.h
lsst::meas::modelfit::MultiShapeletPsfLikelihood::computeModelMatrix
void computeModelMatrix(ndarray::Array< Pixel, 2,-1 > const &modelMatrix, ndarray::Array< Scalar const, 1, 1 > const &nonlinear, bool doApplyWeights=true) const override
Evaluate the model for the given vector of nonlinear parameters.
lsst::meas::modelfit
Definition: TruncatedGaussian.dox:3
std::string
STL class.
lsst::meas::modelfit::GeneralPsfFitterControl::wings
GeneralPsfFitterComponentControl wings
"Wing shapelet expansion (between primary and outer), typically used to fit the wings of the PSF" ;
Definition: GeneralPsfFitter.h:109
lsst::log.log.logContinued.error
def error(fmt, *args)
Definition: logContinued.py:210
lsst::afw::table::SourceRecord
Record class that contains measurements made on a single exposure.
Definition: Source.h:80
lsst::meas::modelfit::Prior
Base class for Bayesian priors.
Definition: Prior.h:36
lsst::meas::modelfit::GeneralPsfFitterComponentControl
Control object used to define one piece of multishapelet fit to a PSF model; see GeneralPsfFitterCont...
Definition: GeneralPsfFitter.h:46
lsst::meas::modelfit::GeneralPsfFitterComponentControl::ellipticityPriorSigma
double ellipticityPriorSigma
"sigma in an isotropic 2-d Gaussian prior on the conformal-shear ellipticity eta" ;
Definition: GeneralPsfFitter.h:66
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::measure
void measure(afw::table::SourceRecord &measRecord, afw::image::Image< double > const &image, shapelet::MultiShapeletFunction const &initial) const
Likelihood.h
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::measure
void measure(afw::table::SourceRecord &measRecord, afw::image::Image< double > const &image, afw::geom::ellipses::Quadrupole const &moments) const
lsst::meas::modelfit::Scalar
double Scalar
Typedefs to be used for probability and parameter values.
Definition: common.h:44
sigma
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:50
lsst::meas::base::MeasurementError
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::getFlagDefinitions
static base::FlagDefinitionList const & getFlagDefinitions()
exceptions.h
lsst::meas::modelfit::GeneralPsfFitterControl::GeneralPsfFitterControl
GeneralPsfFitterControl()
Definition: GeneralPsfFitter.h:92
lsst::meas::modelfit::Model
Abstract base class and concrete factories that define multi-shapelet galaxy models.
Definition: Model.h:56
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::meas::modelfit::GeneralPsfFitterComponentControl::order
int order
"shapelet order for this component; negative to disable this component completely" ;
Definition: GeneralPsfFitter.h:57
geom.h
geom.h
lsst::meas::modelfit::GeneralPsfFitter::apply
shapelet::MultiShapeletFunction apply(afw::image::Image< Pixel > 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.
lsst::meas::modelfit::Likelihood
Base class for optimizer/sampler likelihood functions that compute likelihood at a point.
Definition: Likelihood.h:70
lsst::meas::modelfit::GeneralPsfFitterControl
Control object used to configure a multishapelet fit to a PSF model; see GeneralPsfFitter.
Definition: GeneralPsfFitter.h:89
lsst::meas::modelfit::GeneralPsfFitter
Class for fitting multishapelet models to PSF images.
Definition: GeneralPsfFitter.h:148
lsst::meas::base::FlagDefinitionList
vector-type utility class to build a collection of FlagDefinitions
Definition: FlagHandler.h:60
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::fail
void fail(afw::table::SourceRecord &measRecord, lsst::meas::base::MeasurementError *error=nullptr) const
lsst::meas::modelfit::GeneralPsfFitterComponentControl::positionPriorSigma
double positionPriorSigma
"sigma (in pixels) in an isotropic 2-d Gaussian prior on the center of this shapelet component,...
Definition: GeneralPsfFitter.h:62
lsst::meas::modelfit::OptimizerControl
Configuration object for Optimizer.
Definition: optimizer.h:187
lsst::meas::modelfit::GeneralPsfFitterComponentControl::radiusPriorSigma
double radiusPriorSigma
"sigma in a Gaussian prior on ln(radius/fiducialRadius)" ;
Definition: GeneralPsfFitter.h:77
lsst::meas::modelfit::GeneralPsfFitter::apply
shapelet::MultiShapeletFunction apply(afw::image::Image< double > const &image, shapelet::MultiShapeletFunction const &initial, Scalar noiseSigma=-1, int *pState=nullptr) const
Definition: GeneralPsfFitter.h:251
lsst::meas::base::FlagHandler
Utility class for handling flag fields that indicate the failure modes of an algorithm.
Definition: FlagHandler.h:148
lsst::meas::modelfit::GeneralPsfFitter::apply
shapelet::MultiShapeletFunction apply(afw::image::Image< double > const &image, afw::geom::ellipses::Quadrupole const &moments, Scalar noiseSigma=-1, int *pState=nullptr) const
Definition: GeneralPsfFitter.h:221
lsst::meas::modelfit::GeneralPsfFitterControl::outer
GeneralPsfFitterComponentControl outer
"Outermost shapelet expansion, used to fit PSFs with very broad wings" ;
Definition: GeneralPsfFitter.h:114
lsst::meas::modelfit::MultiShapeletPsfLikelihood::MultiShapeletPsfLikelihood
MultiShapeletPsfLikelihood(ndarray::Array< Pixel const, 2, 1 > const &image, geom::Point2I const &xy0, boost::shared_ptr< Model > model, Scalar sigma, ndarray::Array< Scalar const, 1, 1 > const &fixed)
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::GeneralPsfFitterAlgorithm
GeneralPsfFitterAlgorithm(GeneralPsfFitterControl const &ctrl, afw::table::Schema &schema, std::string const &prefix)
Model.h
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::EXCEPTION
static base::FlagDefinition const EXCEPTION
Definition: GeneralPsfFitter.h:275
LSST_CONTROL_FIELD
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
A preprocessor macro used to define fields in C++ "control object" structs.
Definition: config.h:43
lsst::meas::modelfit::MultiShapeletPsfLikelihood::~MultiShapeletPsfLikelihood
virtual ~MultiShapeletPsfLikelihood()
lsst::meas::modelfit.psf.psfContinued
Definition: psfContinued.py:1
lsst::meas::modelfit::MultiShapeletPsfLikelihood
Likelihood object used to fit multishapelet models to PSF model images; mostly for internal use by Ge...
Definition: GeneralPsfFitter.h:315
lsst::meas::modelfit::GeneralPsfFitterComponentControl::radiusFactor
double radiusFactor
"Sets the fiducial radius of this component relative to the 'primary radius' of the PSF: either " "th...
Definition: GeneralPsfFitter.h:73
Source.h
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::MAX_INNER_ITERATIONS
static base::FlagDefinition const MAX_INNER_ITERATIONS
Definition: GeneralPsfFitter.h:273
lsst::meas::modelfit::GeneralPsfFitter::getModel
boost::shared_ptr< Model > getModel() const
Return the Model object that corresponds to the configuration.
Definition: GeneralPsfFitter.h:174
lsst::afw::geom::ellipses::Quadrupole
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
lsst::meas::modelfit::GeneralPsfFitter::apply
shapelet::MultiShapeletFunction apply(afw::image::Image< Pixel > const &image, afw::geom::ellipses::Quadrupole const &moments, Scalar noiseSigma=-1, int *pState=nullptr) const
Perform an initial fit to a PSF image.
lsst::meas::base::FlagDefinition
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
Definition: FlagHandler.h:40
lsst::meas
Definition: CoaddBoundedField.h:33
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::CONTAINS_NAN
static base::FlagDefinition const CONTAINS_NAN
Definition: GeneralPsfFitter.h:276
FlagHandler.h
lsst::meas::modelfit::GeneralPsfFitter::GeneralPsfFitter
GeneralPsfFitter(GeneralPsfFitterControl const &ctrl)
Initialize the fitter class with the given control object.
lsst::meas::modelfit::GeneralPsfFitter::addFields
shapelet::MultiShapeletFunctionKey addFields(afw::table::Schema &schema, std::string const &prefix) const
Add fields to a Schema that can be used to store the MultiShapeletFunction returned by apply().
PTR
#define PTR(...)
Definition: base.h:41
lsst::geom::Point< int, 2 >
lsst::meas::modelfit::GeneralPsfFitterControl::primary
GeneralPsfFitterComponentControl primary
"Primary shapelet expansion, typically used to fit the bulk of the PSF " ;
Definition: GeneralPsfFitter.h:104
lsst::meas::modelfit::GeneralPsfFitterControl::inner
GeneralPsfFitterComponentControl inner
"Innermost shapelet expansion, used to fit PSFs with very sharp cores" ;
Definition: GeneralPsfFitter.h:99
optimizer.h
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::getKey
shapelet::MultiShapeletFunctionKey getKey()
Definition: GeneralPsfFitter.h:285
config.h
LSST_NESTED_CONTROL_FIELD
#define LSST_NESTED_CONTROL_FIELD(NAME, MODULE, TYPE, DOC)
A preprocessor macro used to define fields in C++ "control object" structs, for nested control object...
Definition: config.h:69
lsst::meas::modelfit::GeneralPsfFitterAlgorithm
Definition: GeneralPsfFitter.h:267
lsst::shapelet::MultiShapeletFunction
A multi-scale shapelet function.
Definition: MultiShapeletFunction.h:38
lsst::meas::modelfit::GeneralPsfFitterControl::optimizer
OptimizerControl optimizer
"Configuration of the optimizer used to do the fitting" ;
Definition: GeneralPsfFitter.h:119
lsst::afw::image::Image< Pixel >
lsst::meas::modelfit.psf
Definition: __init__.py:1
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::FAILURE
static base::FlagDefinition const FAILURE
Definition: GeneralPsfFitter.h:272
lsst::meas::modelfit::GeneralPsfFitter::adapt
shapelet::MultiShapeletFunction adapt(shapelet::MultiShapeletFunction const &previousFit, boost::shared_ptr< Model > previousModel) const
Adapt a differently-configured previous fit to be used as an starting point for this GeneralPsfFitter...
std::unique_ptr< Impl >
lsst::shapelet::MultiShapeletFunctionKey
Class that maps MultiShapeletFunction objects to fields in afw::table objects.
Definition: FunctorKeys.h:161
lsst::meas::modelfit::GeneralPsfFitter::getPrior
boost::shared_ptr< Prior > getPrior() const
Return the Prior object that corresponds to the configuration.
Definition: GeneralPsfFitter.h:182
lsst::meas::modelfit::GeneralPsfFitterComponentControl::GeneralPsfFitterComponentControl
GeneralPsfFitterComponentControl(int order_=0, double radiusFactor_=1.0)
Definition: GeneralPsfFitter.h:49
lsst::meas::modelfit.optimizer
Definition: __init__.py:1
lsst::meas::modelfit::GeneralPsfFitterControl::defaultNoiseSigma
double defaultNoiseSigma
"Default value for the noiseSigma parameter in GeneralPsfFitter.apply()" ;
Definition: GeneralPsfFitter.h:123
prefix
std::string prefix
Definition: SchemaMapper.cc:79
lsst::meas::modelfit::GeneralPsfFitterAlgorithm::MAX_OUTER_ITERATIONS
static base::FlagDefinition const MAX_OUTER_ITERATIONS
Definition: GeneralPsfFitter.h:274