File GeneralPsfFitter.h

namespace lsst

Class for a simple mapping implementing a generic AstrometryTransform.

Remove all non-astronomical counts from the Chunk Exposure’s pixels.

Forward declarations for lsst::utils::Cache

For details on the Cache class, see the Cache.h file.

It uses a template rather than a pointer so that the derived classes can use the specifics of the transform. The class simplePolyMapping overloads a few routines.

A base class for image defects

Numeric constants used by the Integrate.h integrator routines.

Compute Image Statistics

Note

Gauss-Kronrod-Patterson quadrature coefficients for use in quadpack routine qng. These coefficients were calculated with 101 decimal digit arithmetic by L. W. Fullerton, Bell Labs, Nov 1981.

Note

The Statistics class itself can only handle lsst::afw::image::MaskedImage() types. The philosophy has been to handle other types by making them look like lsst::afw::image::MaskedImage() and reusing that code. Users should have no need to instantiate a Statistics object directly, but should use the overloaded makeStatistics() factory functions.

namespace meas
namespace modelfit
class GeneralPsfFitter
#include <GeneralPsfFitter.h>

Class for fitting multishapelet models to PSF images.

This class fits up to four shapelet expansions simultaneously to a PSF image, with the relative radii and number of shapelet coefficients for each expansion separately configurable. These expansions are also named; this allows us to map different fits with some expansions disabled to each other, in order to first fit an approximate model and follow this up with a more complete model, using the approximate model as a starting point.

The configuration also defines a simple Bayesian prior for the fit, defined using simple independent Gaussians for the ellipse parameters of each component. The priors can be disabled by setting their width (xxPriorSigma in the control object) to infinity, and those parameters can be held fixed at their input values by setting the prior width to zero. The priors are always centered at the input value, meaning that it may be more appropriate to think of the priors as a form of regularization, rather than a rigorous prior. In fact, it’s impossible to use a prior here rigorously without a noise model for the PSF image, which is something the LSST Psf class doesn’t provide, and here is just provided as a constant noise sigma to be provided by the user (who generally just has to chose a small number arbitrarily). Decreasing the noise sigma will of course decrease the effect of the priors (and vice versa). In any case, having some sort of regularization is probably a good idea, as this is a very high-dimensional fit.

Subclassed by lsst::meas::modelfit::GeneralPsfFitterAlgorithm

Unnamed Group

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.

Parameters
  • [in] image: The image to fit, typically the result of Psf::computeKernelImage(). The image’s xy0 should be set such that the center of the PSF is at (0,0).

  • [in] moments: Second moments of the PSF, typically result of Psf::computeShape() or running some other adaptive moments code on the PSF image. This will be used to set the initial ellipses of the multishapelet model.

  • [in] noiseSigma: An estimate of the noise in the image. As LSST PSF images are generally assumed to be noise-free, this is really just a fiddle-factor for the user. A default value from the control object is used if this is negative.

  • [in] pState: Pointer to an integer which is used to return the optimizerState from apply.

shapelet::MultiShapeletFunction apply(afw::image::Image<double> const &image, afw::geom::ellipses::Quadrupole const &moments, Scalar noiseSigma = -1, int *pState = nullptr) const

Unnamed Group

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

Parameters
  • [in] image: The image to fit, typically the result of Psf::computeKernelImage(). The image’s xy0 should be set such that the center of the PSF is at (0,0).

  • [in] initial: The result of a previous call to apply(), using an identically-configured GeneralPsfFitter instance. To use a result from a differently-configured GeneralPsfFitter, use adapt().

  • [in] noiseSigma: An estimate of the noise in the image. As LSST PSF images are generally assumed to be noise-free, this is really just a fiddle-factor for the user. A default value from the control object is used if this is negative.

  • [in] pState: Pointer to an integer which is used to return the optimizerState from apply.

shapelet::MultiShapeletFunction apply(afw::image::Image<double> const &image, shapelet::MultiShapeletFunction const &initial, Scalar noiseSigma = -1, int *pState = nullptr) const

Public Functions

GeneralPsfFitter(GeneralPsfFitterControl const &ctrl)

Initialize the fitter class with the given control object.

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().

Return

a FunctorKey that can get/set MultiShapeletFunctions that match the configuration of this fitter on a record.

Parameters
  • [inout] schema: Schema to add fields to.

  • [in] prefix: Field name prefix for all fields.

PTR(Model) const

Return the Model object that corresponds to the configuration.

In addition to the shapelet coefficients (stored in the “amplitudes” array), this Model stores all the initial ellipse parameters in the “fixed” array, as these are used to define the center of the prior; the “nonlinear” parameters are the free-to-vary ellipse parameters minus the corresponding initial values.

PTR(Prior) const

Return the Prior object that corresponds to the configuration.

This Prior class only supports evaluate() and evaluateDerivatives(), reflecting the fact that we only intend to use it with a Optimizer, not a Sampler.

shapelet::MultiShapeletFunction lsst::meas::modelfit::GeneralPsfFitter::adapt(shapelet::MultiShapeletFunction const & previousFit, PTR ( Model ) previousModel) const

Adapt a differently-configured previous fit to be used as an starting point for this GeneralPsfFitter.

Return

a new MultiShapelet function that may be passed directly to apply(). When possible, the ellipse and shapelet coefficeints will be copied from previousFit; higher-order coefficients will be set to zero, and any components used in this but unused in the previous fit will have their ellipses set relative to the previous fit’s “primary” component.

Parameters

Private Functions

PTR(Model)
PTR(Prior)

Private Members

GeneralPsfFitterControl _ctrl
class GeneralPsfFitterAlgorithm : public lsst::meas::modelfit::GeneralPsfFitter

Public Types

typedef GeneralPsfFitterControl Control

Public Functions

GeneralPsfFitterAlgorithm(GeneralPsfFitterControl const &ctrl, afw::table::Schema &schema, std::string const &prefix)
shapelet::MultiShapeletFunctionKey getKey()
void measure(afw::table::SourceRecord &measRecord, afw::image::Image<double> const &image, shapelet::MultiShapeletFunction const &initial) const
void measure(afw::table::SourceRecord &measRecord, afw::image::Image<double> const &image, afw::geom::ellipses::Quadrupole const &moments) const
void fail(afw::table::SourceRecord &measRecord, lsst::meas::base::MeasurementError *error = nullptr) const

Public Static Functions

static base::FlagDefinitionList const &getFlagDefinitions()

Public Static Attributes

base::FlagDefinition const FAILURE
base::FlagDefinition const MAX_INNER_ITERATIONS
base::FlagDefinition const MAX_OUTER_ITERATIONS
base::FlagDefinition const EXCEPTION
base::FlagDefinition const CONTAINS_NAN

Private Members

shapelet::MultiShapeletFunctionKey _key
lsst::meas::base::FlagHandler _flagHandler
class GeneralPsfFitterComponentControl
#include <GeneralPsfFitter.h>

Control object used to define one piece of multishapelet fit to a PSF model; see GeneralPsfFitterControl

Public Functions

GeneralPsfFitterComponentControl(int order_ = 0, double radiusFactor_ = 1.0)
lsst::meas::modelfit::GeneralPsfFitterComponentControl::LSST_CONTROL_FIELD(order, int, "shapelet order for this component; negative to disable this component completely")
lsst::meas::modelfit::GeneralPsfFitterComponentControl::LSST_CONTROL_FIELD(positionPriorSigma, double, "sigma (in pixels) in an isotropic 2-d Gaussian prior on the center of this shapelet component, " "relative to the center of the PSF image")
lsst::meas::modelfit::GeneralPsfFitterComponentControl::LSST_CONTROL_FIELD(ellipticityPriorSigma, double, "sigma in an isotropic 2-d Gaussian prior on the conformal-shear ellipticity eta")
lsst::meas::modelfit::GeneralPsfFitterComponentControl::LSST_CONTROL_FIELD(radiusFactor, double, "Sets the fiducial radius of this component relative to the 'primary radius' of the PSF: either " "the second-moments radius of the PSF image in an initial fit, or the radius of the primary " "component in a previous fit. Ignored if the previous fit included this component(as then we " "can just use that radius).")
lsst::meas::modelfit::GeneralPsfFitterComponentControl::LSST_CONTROL_FIELD(radiusPriorSigma, double, "sigma in a Gaussian prior on ln(radius/fiducialRadius)")
class GeneralPsfFitterControl
#include <GeneralPsfFitter.h>

Control object used to configure a multishapelet fit to a PSF model; see GeneralPsfFitter.

The default configuration corresponds to fitting an elliptical double-Gaussian, in which each component can have different radii, positions, and ellipticities. While the fitter can support much more complex models, at present, fitting these is prohibitively slow, and is not recommended in production environments (use DoubleShapeletPsfApprox instead).

Public Functions

GeneralPsfFitterControl()
lsst::meas::modelfit::GeneralPsfFitterControl::LSST_NESTED_CONTROL_FIELD(inner, lsst.meas.modelfit.psf. psfContinued, GeneralPsfFitterComponentControl, "Innermost shapelet expansion, used to fit PSFs with very sharp cores")
lsst::meas::modelfit::GeneralPsfFitterControl::LSST_NESTED_CONTROL_FIELD(primary, lsst.meas.modelfit.psf. psfContinued, GeneralPsfFitterComponentControl, "Primary shapelet expansion, typically used to fit the bulk of the PSF ")
lsst::meas::modelfit::GeneralPsfFitterControl::LSST_NESTED_CONTROL_FIELD(wings, lsst.meas.modelfit.psf. psfContinued, GeneralPsfFitterComponentControl, "Wing shapelet expansion between primary and outer, typically used to fit the wings of the PSF")
lsst::meas::modelfit::GeneralPsfFitterControl::LSST_NESTED_CONTROL_FIELD(outer, lsst.meas.modelfit.psf. psfContinued, GeneralPsfFitterComponentControl, "Outermost shapelet expansion, used to fit PSFs with very broad wings")
lsst::meas::modelfit::GeneralPsfFitterControl::LSST_NESTED_CONTROL_FIELD(optimizer, lsst.meas.modelfit. optimizer, OptimizerControl, "Configuration of the optimizer used to do the fitting")
lsst::meas::modelfit::GeneralPsfFitterControl::LSST_CONTROL_FIELD(defaultNoiseSigma, double, "Default value for the noiseSigma parameter in GeneralPsfFitter.apply ()")
class MultiShapeletPsfLikelihood : public lsst::meas::modelfit::Likelihood
#include <GeneralPsfFitter.h>

Likelihood object used to fit multishapelet models to PSF model images; mostly for internal use by GeneralPsfFitter.

Public Functions

lsst::meas::modelfit::MultiShapeletPsfLikelihood::MultiShapeletPsfLikelihood(ndarray::Array< Pixel const, 2, 1 > const & image, geom::Point2I const & xy0, PTR ( Model ) model, Scalar sigma, ndarray::Array< Scalar const, 1, 1 > const & fixed)
void computeModelMatrix(ndarray::Array<Pixel, 2, -1> const &modelMatrix, ndarray::Array<Scalar const, 1, 1> const &nonlinear, bool doApplyWeights = true) const

Evaluate the model for the given vector of nonlinear parameters.

Parameters
  • [out] modelMatrix: The dataDim x amplitudeDim matrix \(B\) that expresses the model projected in such a way that it can be compared to the data when multiplied by an amplitude vector \(\alpha\). It should be weighted if the data vector is. The caller is responsible for guaranteeing that the shape of the matrix correct, but implementations should not assume anything about the initial values of the matrix elements.

  • [in] nonlinear: Vector of nonlinear parameters at which to evaluate the model.

  • [in] doApplyWeights: If False, do not apply the weights to the modelMatrix.

virtual ~MultiShapeletPsfLikelihood()

Private Members

std::unique_ptr<Impl> _impl