File Background.h

Defines

LSST_makeBackground_getImage_types
LSST_makeBackground_getApproximate_types
LSST_makeBackground_getImage(m, v, T)
LSST_makeBackground_getApproximate(m, v, T)
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 afw
namespace math

Enums

enum UndersampleStyle

Values:

THROW_EXCEPTION
REDUCE_INTERP_ORDER
INCREASE_NXNYSAMPLE

Functions

UndersampleStyle stringToUndersampleStyle(std::string const &style)

Conversion function to switch a string to an UndersampleStyle

template<typename ImageT>
std::shared_ptr<Background> makeBackground(ImageT const &img, BackgroundControl const &bgCtrl)

A convenience function that uses function overloading to make the correct type of Background

cf. std::make_pair()

class Background
#include <Background.h>

A virtual base class to evaluate image background levels

Subclassed by lsst::afw::math::BackgroundMI

Public Types

typedef float InternalPixelT

type used for any internal images, and returned by getApproximate

Public Functions

Background(Background const&)
Background(Background&&)
Background &operator=(Background const&)
Background &operator=(Background&&)
virtual Background &operator+=(float const delta) = 0

Add a constant level to a background.

virtual Background &operator-=(float const delta) = 0

Subtract a constant level from a background.

template<typename PixelT>
std::shared_ptr<lsst::afw::image::Image<PixelT>> getImage(Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle = THROW_EXCEPTION) const

Method to interpolate and return the background for entire image

Return

A boost shared-pointer to an image containing the estimated background

Parameters
  • interpStyle: Style of the interpolation

  • undersampleStyle: Behaviour if there are too few points

template<typename PixelT>
std::shared_ptr<lsst::afw::image::Image<PixelT>> getImage(std::string const &interpStyle, std::string const &undersampleStyle = "THROW_EXCEPTION") const

Method to interpolate and return the background for entire image

Return

A boost shared-pointer to an image containing the estimated background

Parameters
  • interpStyle: Style of the interpolation

  • undersampleStyle: Behaviour if there are too few points

template<typename PixelT>
std::shared_ptr<lsst::afw::image::Image<PixelT>> getImage(lsst::geom::Box2I const &bbox, Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle = THROW_EXCEPTION) const

Parameters
  • bbox: Bounding box for sub-image

  • interpStyle: Style of the interpolation

  • undersampleStyle: Behaviour if there are too few points

template<typename PixelT>
std::shared_ptr<lsst::afw::image::Image<PixelT>> getImage(lsst::geom::Box2I const &bbox, std::string const &interpStyle, std::string const &undersampleStyle = "THROW_EXCEPTION") const

Parameters
  • bbox: Bounding box for sub-image

  • interpStyle: Style of the interpolation

  • undersampleStyle: Behaviour if there are too few points

template<typename PixelT>
std::shared_ptr<lsst::afw::image::Image<PixelT>> getImage() const

Method to interpolate and return the background for entire image

Interpolate::Style getAsUsedInterpStyle() const

Return the Interpolate::Style that we actually used in the last call to getImage()

N.b. Interpolate can fallback to a lower order if there aren’t enough samples

UndersampleStyle getAsUsedUndersampleStyle() const

Return the UndersampleStyle that we actually used in the last call to getImage()

std::shared_ptr<math::Approximate<InternalPixelT>> getApproximate(ApproximateControl const &actrl, UndersampleStyle const undersampleStyle = THROW_EXCEPTION) const

Method to return an approximation to the background

Parameters
  • actrl: Approximation style

  • undersampleStyle: Behaviour if there are too few points

lsst::geom::Box2I getImageBBox() const

Return the input image’s (PARENT) bounding box

std::shared_ptr<BackgroundControl> getBackgroundControl()
std::shared_ptr<BackgroundControl const> getBackgroundControl() const

Protected Functions

template<typename ImageT>
Background(ImageT const &img, BackgroundControl const &bgCtrl)

Constructor for Background

Estimate the statistical properties of the Image in a grid of cells; we’ll later call getImage() to interpolate those values, creating an image the same size as the original

Note

The old and deprecated API specified the interpolation style as part of the BackgroundControl object passed to this ctor. This is still supported, but the work isn’t done until the getImage() method is called

Parameters
  • img: ImageT (or MaskedImage) whose properties we want

  • bgCtrl: Control how the Background is estimated

Background(lsst::geom::Box2I const imageBBox, int const nx, int const ny)

Create a Background without any values in it

Note

This ctor is mostly used to create a Background given its sample values, and that (in turn) is mostly used to implement persistence.

Parameters
  • imageBBox: Bounding box for image to be created by getImage()

  • nx: Number of samples in x-direction

  • ny: Number of samples in y-direction

virtual ~Background()

dtor

lsst::afw::math::Background::BOOST_PP_SEQ_FOR_EACH(LSST_makeBackground_getImage, ( Background::InternalPixelT ))

Protected Attributes

lsst::geom::Box2I _imgBBox

size and origin of input image

std::shared_ptr<BackgroundControl> _bctrl

control info set by user.

Interpolate::Style _asUsedInterpStyle

the style we actually used

UndersampleStyle _asUsedUndersampleStyle

the undersampleStyle we actually used

std::vector<double> _xcen

x center pix coords of sub images

std::vector<double> _ycen

y center …

std::vector<int> _xorig

x origin pix coords of sub images

std::vector<int> _yorig

y origin …

std::vector<int> _xsize

x size of sub images

std::vector<int> _ysize

y size …

Private Functions

void _setCenOrigSize(int const width, int const height, int const nxSample, int const nySample)

Compute the centers, origins, and sizes of the patches used to compute image statistics when estimating the Background

class BackgroundControl
#include <Background.h>

Pass parameters to a Background object

Public Functions

BackgroundControl(int const nxSample, int const nySample, StatisticsControl const sctrl = StatisticsControl(), Property const prop = MEANCLIP, ApproximateControl const actrl = ApproximateControl(ApproximateControl::UNKNOWN, ))

Parameters
  • nxSample: Num. grid samples in x

  • nySample: Num. grid samples in y

  • sctrl: Configuration for Stats to be computed

  • prop: statistical property to use for grid points

  • actrl: configuration for approx to be computed

BackgroundControl(int const nxSample, int const nySample, StatisticsControl const &sctrl, std::string const &prop, ApproximateControl const actrl = ApproximateControl(ApproximateControl::UNKNOWN, ))

Overload constructor to handle string for statistical operator

Parameters
  • nxSample: num. grid samples in x

  • nySample: num. grid samples in y

  • sctrl: configuration for stats to be computed

  • prop: statistical property to use for grid points

  • actrl: configuration for approx to be computed

BackgroundControl(Interpolate::Style const style, int const nxSample = 10, int const nySample = 10, UndersampleStyle const undersampleStyle = THROW_EXCEPTION, StatisticsControl const sctrl = StatisticsControl(), Property const prop = MEANCLIP, ApproximateControl const actrl = ApproximateControl(ApproximateControl::UNKNOWN, ))

Parameters
  • style: Style of the interpolation

  • nxSample: Num. grid samples in x

  • nySample: Num. grid samples in y

  • undersampleStyle: Behaviour if there are too few points

  • sctrl: Configuration for Stats to be computed

  • prop: statistical property to use for grid points

  • actrl: configuration for approx to be computed

BackgroundControl(std::string const &style, int const nxSample = 10, int const nySample = 10, std::string const &undersampleStyle = "THROW_EXCEPTION", StatisticsControl const sctrl = StatisticsControl(), std::string const &prop = "MEANCLIP", ApproximateControl const actrl = ApproximateControl(ApproximateControl::UNKNOWN, ))

Overload constructor to handle strings for both interp and undersample styles.

Parameters
  • style: Style of the interpolation

  • nxSample: num. grid samples in x

  • nySample: num. grid samples in y

  • undersampleStyle: behaviour if there are too few points

  • sctrl: configuration for stats to be computed

  • prop: statistical property to use for grid points

  • actrl: configuration for approx to be computed

BackgroundControl(BackgroundControl const&)
BackgroundControl(BackgroundControl&&)
BackgroundControl &operator=(BackgroundControl const&)
BackgroundControl &operator=(BackgroundControl&&)
virtual ~BackgroundControl()
void setNxSample(int nxSample)
void setNySample(int nySample)
void setInterpStyle(Interpolate::Style const style)
void setInterpStyle(std::string const &style)
void setUndersampleStyle(UndersampleStyle const undersampleStyle)
void setUndersampleStyle(std::string const &undersampleStyle)
int getNxSample() const
int getNySample() const
Interpolate::Style getInterpStyle() const
UndersampleStyle getUndersampleStyle() const
std::shared_ptr<StatisticsControl> getStatisticsControl()
std::shared_ptr<StatisticsControl const> getStatisticsControl() const
Property getStatisticsProperty() const
void setStatisticsProperty(Property prop)
void setStatisticsProperty(std::string prop)
void setApproximateControl(std::shared_ptr<ApproximateControl> actrl)
std::shared_ptr<ApproximateControl> getApproximateControl()
std::shared_ptr<ApproximateControl const> getApproximateControl() const

Private Members

Interpolate::Style _style
int _nxSample
int _nySample
UndersampleStyle _undersampleStyle
std::shared_ptr<StatisticsControl> _sctrl
Property _prop
std::shared_ptr<ApproximateControl> _actrl
class BackgroundMI : public lsst::afw::math::Background
#include <Background.h>

A class to evaluate image background levels

Break an image up into nx*ny sub-images and use a statistical to estimate the background levels in each square. Then use a user-specified or algorithm to estimate background at a given pixel coordinate.

Methods are available to return the background at a point (inefficiently), or an entire background image. BackgroundControl contains a public StatisticsControl member to allow user control of how the backgrounds are computed.

math::BackgroundControl bctrl(7, 7);  // number of sub-image squares in {x,y}-dimensions
bctrl.sctrl.setNumSigmaClip(5.0);     // use 5-sigma clipping for the sub-image means
std::shared_ptr<math::Background> backobj = math::makeBackground(img, bctrl);
// get a whole background image
Image<PixelT> back = backobj->getImage<PixelT>(math::Interpolate::NATURAL_SPLINE);

// get the background at a pixel at i_x,i_y
double someValue = backobj.getPixel(math::Interpolate::LINEAR, i_x, i_y);

Public Functions

template<typename ImageT>
BackgroundMI(ImageT const &img, BackgroundControl const &bgCtrl)

Constructor for BackgroundMI

Estimate the statistical properties of the Image in a grid of cells; we’ll later call getImage() to interpolate those values, creating an image the same size as the original

There is a ticket (#2825) to allow getImage to specify a default value to use when interpolation fails

Note

If there are heavily masked or Nan regions in the image we may not be able to estimate all the cells in the “statsImage”. Interpolation will still work, but if you want to prevent the code wildly extrapolating, it may be better to set the values directly; e.g.

defaultValue = 10
statsImage = afwMath.cast_BackgroundMI(bkgd).getStatsImage()
sim = statsImage.getImage().getArray()
sim[np.isnan(sim)] = defaultValue # replace NaN by defaultValue
bkgdImage = bkgd.getImageF(afwMath.Interpolate.NATURAL_SPLINE, afwMath.REDUCE_INTERP_ORDER)

Parameters
  • img: ImageT (or MaskedImage) whose properties we want

  • bgCtrl: Control how the BackgroundMI is estimated

BackgroundMI(lsst::geom::Box2I const imageDimensions, image::MaskedImage<InternalPixelT> const &statsImage)

Recreate a BackgroundMI from the statsImage and the original Image’s BBox

Parameters
  • imageDimensions: unbinned Image’s BBox

  • statsImage: Internal stats image

BackgroundMI(BackgroundMI const&)
BackgroundMI(BackgroundMI&&)
BackgroundMI &operator=(BackgroundMI const&)
BackgroundMI &operator=(BackgroundMI&&)
~BackgroundMI()
BackgroundMI &operator+=(float const delta)

Add a scalar to the Background (equivalent to adding a constant to the original image)

Parameters
  • delta: Value to add

BackgroundMI &operator-=(float const delta)

Subtract a scalar from the Background (equivalent to subtracting a constant from the original image)

Parameters
  • delta: Value to subtract

double getPixel(Interpolate::Style const style, int const x, int const y) const

Method to retrieve the background level at a pixel coord.

Return

an estimated background at x,y (double)

Parameters
  • style: How to interpolate

  • x: x-pixel coordinate (column)

  • y: y-pixel coordinate (row)

double getPixel(int const x, int const y) const

Return the background value at a point

Warning

This is very inefficient only use it for debugging, if then.

lsst::afw::image::MaskedImage<InternalPixelT> getStatsImage() const

Return the image of statistical quantities extracted from the image

Private Functions

void _setGridColumns(Interpolate::Style const interpStyle, UndersampleStyle const undersampleStyle, int const iX, std::vector<int> const &ypix) const
lsst::afw::math::BackgroundMI::BOOST_PP_SEQ_FOR_EACH(LSST_makeBackground_getImage, override, ( Background::InternalPixelT ))
lsst::afw::math::BackgroundMI::BOOST_PP_SEQ_FOR_EACH(LSST_makeBackground_getApproximate, override, ( Background::InternalPixelT ))
template<typename PixelT>
std::shared_ptr<image::Image<PixelT>> doGetImage(lsst::geom::Box2I const &bbox, Interpolate::Style const interpStyle_, UndersampleStyle const undersampleStyle) const

Worker routine for getImage

template<typename PixelT>
std::shared_ptr<Approximate<PixelT>> doGetApproximate(ApproximateControl const &actrl, UndersampleStyle const undersampleStyle) const

Private Members

lsst::afw::image::MaskedImage<InternalPixelT> _statsImage
std::vector<std::vector<double>> _gridColumns