LSSTApplications  18.1.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/afw/table/Source.h"
38 
39 namespace lsst { namespace meas { namespace modelfit {
40 
45 public:
46 
47  GeneralPsfFitterComponentControl(int order_=0, double radiusFactor_=1.0) :
49  radiusFactor(radiusFactor_), radiusPriorSigma(0.5)
50  {}
51 
53  order, int,
54  "shapelet order for this component; negative to disable this component completely"
55  );
57  positionPriorSigma, double,
58  "sigma (in pixels) in an isotropic 2-d Gaussian prior on the center of this shapelet component, "
59  "relative to the center of the PSF image"
60  );
62  ellipticityPriorSigma, double,
63  "sigma in an isotropic 2-d Gaussian prior on the conformal-shear ellipticity eta"
64  );
66  radiusFactor, double,
67  "Sets the fiducial radius of this component relative to the 'primary radius' of the PSF: either "
68  "the second-moments radius of the PSF image (in an initial fit), or the radius of the primary "
69  "component in a previous fit. Ignored if the previous fit included this component (as then we "
70  "can just use that radius)."
71  );
73  radiusPriorSigma, double,
74  "sigma in a Gaussian prior on ln(radius/fiducialRadius)"
75  );
76 
77 };
78 
88 public:
89 
91  inner(-1, 0.5), primary(0, 1.0), wings(0, 2.0), outer(-1, 4.0), defaultNoiseSigma(0.001)
92  {}
93 
96  "Innermost shapelet expansion, used to fit PSFs with very sharp cores"
97  );
98 
101  "Primary shapelet expansion, typically used to fit the bulk of the PSF "
102  );
103 
106  "Wing shapelet expansion (between primary and outer), typically used to fit the wings of the PSF"
107  );
108 
111  "Outermost shapelet expansion, used to fit PSFs with very broad wings"
112  );
113 
116  "Configuration of the optimizer used to do the fitting"
117  );
118 
120  defaultNoiseSigma, double, "Default value for the noiseSigma parameter in GeneralPsfFitter.apply()"
121  );
122 
123 };
124 
147 public:
149  explicit GeneralPsfFitter(GeneralPsfFitterControl const & ctrl);
150 
161  std::string const & prefix
162  ) const;
163 
172  PTR(Model) getModel() const { return _model; }
173 
180  PTR(Prior) getPrior() const { return _prior; }
181 
195  shapelet::MultiShapeletFunction const & previousFit,
196  PTR(Model) previousModel
197  ) const;
198 
200 
216  Scalar noiseSigma=-1,
217  int * pState = nullptr
218  ) const;
220  afw::image::Image<double> const & image,
221  afw::geom::ellipses::Quadrupole const & moments,
222  Scalar noiseSigma=-1,
223  int * pState = nullptr
224  ) const {
225  return apply(afw::image::Image<float>(image, true), moments, noiseSigma, pState);
226  }
228 
230 
244  afw::image::Image<Pixel> const & image,
245  shapelet::MultiShapeletFunction const & initial,
246  Scalar noiseSigma=-1,
247  int * pState = nullptr
248  ) const;
250  afw::image::Image<double> const & image,
251  shapelet::MultiShapeletFunction const & initial,
252  Scalar noiseSigma=-1,
253  int * pState = nullptr
254  ) const {
255  return apply(afw::image::Image<float>(image, true), initial, noiseSigma);
256  }
258 
259 private:
261  PTR(Model) _model;
262  PTR(Prior) _prior;
263 };
264 
266 public:
267 
268  // Structures and routines to manage flaghandler
269  static base::FlagDefinitionList const & getFlagDefinitions();
275 
277 
280  std::string const & prefix
281  );
282 
284  return _key;
285  }
286 
287  void measure(
288  afw::table::SourceRecord & measRecord,
290  shapelet::MultiShapeletFunction const & initial
291  ) const;
292 
293  void measure(
294  afw::table::SourceRecord & measRecord,
295  afw::image::Image<double> const & image,
297  ) const;
298 
299  void fail(
300  afw::table::SourceRecord & measRecord,
302  ) const;
303 
304 private:
306  lsst::meas::base::FlagHandler _flagHandler;
307 };
308 
314 public:
315 
317  ndarray::Array<Pixel const,2,1> const & image,
318  afw::geom::Point2I const & xy0,
319  PTR(Model) model,
320  Scalar sigma,
321  ndarray::Array<Scalar const,1,1> const & fixed
322  );
323 
324  void computeModelMatrix(
325  ndarray::Array<Pixel,2,-1> const & modelMatrix,
326  ndarray::Array<Scalar const,1,1> const & nonlinear,
327  bool doApplyWeights=true
328  ) const override;
329 
330  virtual ~MultiShapeletPsfLikelihood();
331 
332 private:
333  class Impl;
334  std::unique_ptr<Impl> _impl;
335 };
336 
337 }}} // namespace lsst::meas::modelfit
338 
339 #endif // !LSST_MEAS_MODELFIT_GeneralPsfFitter_h_INCLUDED
Likelihood object used to fit multishapelet models to PSF model images; mostly for internal use by Ge...
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Defines the fields and offsets for a table.
Definition: Schema.h:50
#define PTR(...)
Definition: base.h:41
Class that maps MultiShapeletFunction objects to fields in afw::table objects.
Definition: FunctorKeys.h:161
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
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...
Definition: FlagHandler.h:40
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.
std::string prefix
Definition: SchemaMapper.cc:79
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Definition: exceptions.h:48
#define LSST_CONTROL_FIELD(NAME, TYPE, DOC)
A preprocessor macro used to define fields in C++ "control object" structs.
Definition: config.h:36
STL class.
Abstract base class and concrete factories that define multi-shapelet galaxy models.
Definition: Model.h:56
Utility class for handling flag fields that indicate the failure modes of an algorithm.
Definition: FlagHandler.h:148
A base class for image defects.
static base::FlagDefinition const FAILURE
A multi-scale shapelet function.
table::Schema schema
Definition: Camera.cc:161
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)
A preprocessor macro used to define fields in C++ "control object" structs, for nested control object...
Definition: config.h:62
afw::table::Key< double > sigma
Definition: GaussianPsf.cc:50
Control object used to define one piece of multishapelet fit to a PSF model; see GeneralPsfFitterCont...
VectorQ moments
Definition: simpleShape.cc:151
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...
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.
def measure(mi, x, y, size, statistic, stats)
Definition: fringe.py:357
double ellipticityPriorSigma
"sigma in an isotropic 2-d Gaussian prior on the conformal-shear ellipticity eta" ; ...
Record class that contains measurements made on a single exposure.
Definition: Source.h:82
Control object used to configure a multishapelet fit to a PSF model; see GeneralPsfFitter.
static base::FlagDefinition const CONTAINS_NAN
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
vector-type utility class to build a collection of FlagDefinitions
Definition: FlagHandler.h:60
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