LSSTApplications  18.0.0+106,18.0.0+50,19.0.0,19.0.0+1,19.0.0+10,19.0.0+11,19.0.0+13,19.0.0+17,19.0.0+2,19.0.0-1-g20d9b18+6,19.0.0-1-g425ff20,19.0.0-1-g5549ca4,19.0.0-1-g580fafe+6,19.0.0-1-g6fe20d0+1,19.0.0-1-g7011481+9,19.0.0-1-g8c57eb9+6,19.0.0-1-gb5175dc+11,19.0.0-1-gdc0e4a7+9,19.0.0-1-ge272bc4+6,19.0.0-1-ge3aa853,19.0.0-10-g448f008b,19.0.0-12-g6990b2c,19.0.0-2-g0d9f9cd+11,19.0.0-2-g3d9e4fb2+11,19.0.0-2-g5037de4,19.0.0-2-gb96a1c4+3,19.0.0-2-gd955cfd+15,19.0.0-3-g2d13df8,19.0.0-3-g6f3c7dc,19.0.0-4-g725f80e+11,19.0.0-4-ga671dab3b+1,19.0.0-4-gad373c5+3,19.0.0-5-ga2acb9c+2,19.0.0-5-gfe96e6c+2,w.2020.01
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | List of all members
lsst::afw::math::ChebyshevBoundedField Class Reference

A BoundedField based on 2-d Chebyshev polynomials of the first kind. More...

#include <ChebyshevBoundedField.h>

Inheritance diagram for lsst::afw::math::ChebyshevBoundedField:
lsst::afw::table::io::PersistableFacade< ChebyshevBoundedField > lsst::afw::math::BoundedField lsst::afw::table::io::PersistableFacade< BoundedField > lsst::afw::table::io::Persistable

Public Types

typedef ChebyshevBoundedFieldControl Control
 

Public Member Functions

 ChebyshevBoundedField (lsst::geom::Box2I const &bbox, ndarray::Array< double const, 2, 2 > const &coefficients)
 Initialize the field from its bounding box an coefficients. More...
 
 ChebyshevBoundedField (ChebyshevBoundedField const &)
 
 ChebyshevBoundedField (ChebyshevBoundedField &&)
 
ChebyshevBoundedFieldoperator= (ChebyshevBoundedField const &)=delete
 
ChebyshevBoundedFieldoperator= (ChebyshevBoundedField &&)=delete
 
 ~ChebyshevBoundedField () override
 
ndarray::Array< double const, 2, 2 > getCoefficients () const
 Return the coefficient matrix. More...
 
std::shared_ptr< ChebyshevBoundedFieldtruncate (Control const &ctrl) const
 Return a new ChebyshevBoudedField with maximum orders set by the given control object. More...
 
std::shared_ptr< ChebyshevBoundedFieldrelocate (lsst::geom::Box2I const &bbox) const
 Return a new ChebyshevBoundedField with domain set to the given bounding box. More...
 
double evaluate (lsst::geom::Point2D const &position) const override
 Evaluate the field at the given point. More...
 
double integrate () const override
 Compute the integral of this function over its bounding-box. More...
 
double mean () const override
 Compute the mean of this function over its bounding-box. More...
 
bool isPersistable () const noexcept override
 ChebyshevBoundedField is always persistable. More...
 
std::shared_ptr< BoundedFieldoperator* (double const scale) const override
 Return a scaled BoundedField. More...
 
bool operator== (BoundedField const &rhs) const override
 BoundedFields (of the same sublcass) are equal if their bounding boxes and parameters are equal. More...
 
double evaluate (double x, double y) const
 Evaluate the field at the given point. More...
 
virtual ndarray::Array< double, 1, 1 > evaluate (ndarray::Array< double const, 1 > const &x, ndarray::Array< double const, 1 > const &y) const
 Evaluate the field at multiple arbitrary points. More...
 
lsst::geom::Box2I getBBox () const
 Return the bounding box that defines the region where the field is valid. More...
 
template<typename T >
void fillImage (image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
 Assign the field to an image, overwriting values already present. More...
 
template<typename T >
void addToImage (image::Image< T > &image, double scaleBy=1.0, bool overlapOnly=false, int xStep=1, int yStep=1) const
 Add the field or a constant multiple of it to an image in-place. More...
 
template<typename T >
void multiplyImage (image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
 Multiply an image by the field in-place. More...
 
template<typename T >
void divideImage (image::Image< T > &image, bool overlapOnly=false, int xStep=1, int yStep=1) const
 Divide an image by the field in-place. More...
 
std::shared_ptr< BoundedFieldoperator/ (double scale) const
 
bool operator!= (BoundedField const &rhs) const
 BoundedFields (of the same sublcass) are equal if their bounding boxes and parameters are equal. More...
 
void writeFits (std::string const &fileName, std::string const &mode="w") const
 Write the object to a regular FITS file. More...
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 Write the object to a FITS image in memory. More...
 
void writeFits (fits::Fits &fitsfile) const
 Write the object to an already-open FITS object. More...
 

Static Public Member Functions

static std::shared_ptr< ChebyshevBoundedFieldfit (lsst::geom::Box2I const &bbox, ndarray::Array< double const, 1 > const &x, ndarray::Array< double const, 1 > const &y, ndarray::Array< double const, 1 > const &z, Control const &ctrl)
 Fit a Chebyshev approximation to non-gridded data with equal weights. More...
 
static std::shared_ptr< ChebyshevBoundedFieldfit (lsst::geom::Box2I const &bbox, ndarray::Array< double const, 1 > const &x, ndarray::Array< double const, 1 > const &y, ndarray::Array< double const, 1 > const &z, ndarray::Array< double const, 1 > const &w, Control const &ctrl)
 Fit a Chebyshev approximation to non-gridded data with unequal weights. More...
 
template<typename T >
static std::shared_ptr< ChebyshevBoundedFieldfit (image::Image< T > const &image, Control const &ctrl)
 Fit a Chebyshev approximation to gridded data with equal weights. More...
 
static std::shared_ptr< ChebyshevBoundedFieldreadFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static std::shared_ptr< ChebyshevBoundedFieldreadFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU)
 Read an object from a regular FITS file. More...
 
static std::shared_ptr< ChebyshevBoundedFieldreadFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
 Read an object from a FITS file in memory. More...
 
static std::shared_ptr< ChebyshevBoundedFielddynamicCast (std::shared_ptr< Persistable > const &ptr)
 Dynamically cast a shared_ptr. More...
 
static std::shared_ptr< BoundedFieldreadFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static std::shared_ptr< BoundedFieldreadFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU)
 Read an object from a regular FITS file. More...
 
static std::shared_ptr< BoundedFieldreadFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
 Read an object from a FITS file in memory. More...
 
static std::shared_ptr< BoundedFielddynamicCast (std::shared_ptr< Persistable > const &ptr)
 Dynamically cast a shared_ptr. More...
 

Protected Types

typedef io::OutputArchiveHandle OutputArchiveHandle
 

Protected Member Functions

std::string getPersistenceName () const override
 Return the unique name used to persist this object and look up its factory. More...
 
std::string getPythonModule () const override
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered. More...
 
void write (OutputArchiveHandle &handle) const override
 Write the object to one or more catalogs. More...
 

Detailed Description

A BoundedField based on 2-d Chebyshev polynomials of the first kind.

The 2-d Chebyshev polynomial used here is defined as:

\[ f(x,y) = \sum_i \sum_j a_{i,j} T_i(x) T_j(y) \]

where \(T_n(x)\) is the n-th order Chebyshev polynomial of \(x\) and \(a_{i,j}\) is the corresponding coefficient of the (i,j) polynomial term.

ChebyshevBoundedField supports fitting to gridded and non-gridded data, as well coefficient matrices with different x- and y-order.

There is currently quite a bit of duplication of functionality between ChebyshevBoundedField, ApproximateChebyshev, and Chebyshev1Function2; the intent is that ChebyshevBoundedField will ultimately replace ApproximateChebyshev and should be preferred over Chebyshev1Function2 when the parametrization interface that is part of the Function2 class is not needed.

Definition at line 76 of file ChebyshevBoundedField.h.

Member Typedef Documentation

◆ Control

Definition at line 79 of file ChebyshevBoundedField.h.

◆ OutputArchiveHandle

typedef io::OutputArchiveHandle lsst::afw::table::io::Persistable::OutputArchiveHandle
protectedinherited

Definition at line 108 of file Persistable.h.

Constructor & Destructor Documentation

◆ ChebyshevBoundedField() [1/3]

lsst::afw::math::ChebyshevBoundedField::ChebyshevBoundedField ( lsst::geom::Box2I const &  bbox,
ndarray::Array< double const, 2, 2 > const &  coefficients 
)

Initialize the field from its bounding box an coefficients.

This constructor is mostly intended for testing purposes and persistence, but it also provides a way to initialize the object from Chebyshev coefficients derived from some external source.

Note that because the bounding box provided is always an integer bounding box, and LSST convention puts the center of each pixel at an integer, the actual floating-point domain of the Chebyshev functions is lsst::geom::Box2D(bbox), that is, the box that contains the entirety of all the pixels included in the integer bounding box.

The coefficients are ordered [y,x], so the shape is (orderY+1, orderX+1), and the arguments to the Chebyshev functions are transformed such that the region lsst::geom::Box2D(bbox) is mapped to [-1, 1]x[-1, 1].

Example:

bbox = lsst::geom::Box2I(lsst::geom::Point2I(10, 20), lsst::geom::Point2I(30, 40));
ndarray::Array<double, 2, 2> coeffs = ndarray::allocate(ndarray::makeVector(2, 2));
coeffs[0][0] = 1;
coeffs[1][0] = 2;
coeffs[0][1] = 3;
coeffs[1][1] = 4;
ndarray::Array<double, 2, 2> coeffs = ndarray::external(data);
poly = ChebyshevBoundedField(bbox, coeffs);

will result in the following polynomial:

\[ f(x,y) = 1 T_0(x) T_0(y) + 2 T_0(x) T_1(y) + 3 T_1(x) T_0(y) + 4 T_1(x) T_1(y) \]

Definition at line 60 of file ChebyshevBoundedField.cc.

62  : BoundedField(bbox),
63  _toChebyshevRange(makeChebyshevRangeTransform(lsst::geom::Box2D(bbox))),
64  _coefficients(coefficients) {}
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
table::Box2IKey bbox
BoundedField(BoundedField const &)=default
ndarray::Array< double const, 2, 2 > coefficients

◆ ChebyshevBoundedField() [2/3]

lsst::afw::math::ChebyshevBoundedField::ChebyshevBoundedField ( ChebyshevBoundedField const &  )
default

◆ ChebyshevBoundedField() [3/3]

lsst::afw::math::ChebyshevBoundedField::ChebyshevBoundedField ( ChebyshevBoundedField &&  )
default

◆ ~ChebyshevBoundedField()

lsst::afw::math::ChebyshevBoundedField::~ChebyshevBoundedField ( )
overridedefault

Member Function Documentation

◆ addToImage()

template<typename T >
template void lsst::afw::math::BoundedField::addToImage ( image::Image< T > &  image,
double  scaleBy = 1.0,
bool  overlapOnly = false,
int  xStep = 1,
int  yStep = 1 
) const
inherited

Add the field or a constant multiple of it to an image in-place.

Parameters
[out]imageImage to add to.
[in]scaleByMultiply the field by this before adding it to the image.
[in]overlapOnlyIf true, only modify the region in the intersection of image.getBBox(image::PARENT) and this->getBBox().
[in]xStepDistance between grid points in X to evaluate; values between grid points will be linearly interpolated.
[in]yStepDistance between grid points in Y to evaluate; values between grid points will be linearly interpolated.
Exceptions
pex::exceptions::RuntimeErrorif the bounding boxes do not overlap and overlapOnly=false.

Definition at line 264 of file BoundedField.cc.

265  {
266  applyToImage(*this, img, ScaledAdd(scaleBy), overlapOnly, xStep, yStep);
267 }
double scaleBy
Definition: BoundedField.cc:76

◆ divideImage()

template<typename T >
template void lsst::afw::math::BoundedField::divideImage ( image::Image< T > &  image,
bool  overlapOnly = false,
int  xStep = 1,
int  yStep = 1 
) const
inherited

Divide an image by the field in-place.

Parameters
[out]imageImage to fill.
[in]overlapOnlyIf true, only modify the region in the intersection of image.getBBox(image::PARENT) and this->getBBox().
[in]xStepDistance between grid points in X to evaluate; values between grid points will be linearly interpolated.
[in]yStepDistance between grid points in Y to evaluate; values between grid points will be linearly interpolated.
Exceptions
pex::exceptions::RuntimeErrorif the bounding boxes do not overlap and overlapOnly=false.

Definition at line 275 of file BoundedField.cc.

275  {
276  applyToImage(*this, img, Divide(), overlapOnly, xStep, yStep);
277 }

◆ dynamicCast() [1/2]

Dynamically cast a shared_ptr.

Dynamically cast a shared pointer and raise on failure.

You must provide an explicit template instantiation in the .cc file for each class that inherits from PersistableFacade. Designed to work around RTTI issues on macOS with hidden symbols;

Exceptions
lsst::pex::exceptions::LogicErrorif the cast fails

param[in] ptr The pointer to be cast.

Returns
The cast pointer.
Exceptions
lsst::pex::exceptions::TypeErrorIf the dynamic cast fails.

Definition at line 18 of file Persistable.cc.

18  {
20  if (!result) {
21  throw LSST_EXCEPT(pex::exceptions::TypeError, "Dynamic pointer cast failed");
22  }
23  return result;
24 }
uint64_t * ptr
Definition: RangeSet.cc:88
T dynamic_pointer_cast(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
py::object result
Definition: _schema.cc:429

◆ dynamicCast() [2/2]

Dynamically cast a shared_ptr.

Dynamically cast a shared pointer and raise on failure.

You must provide an explicit template instantiation in the .cc file for each class that inherits from PersistableFacade. Designed to work around RTTI issues on macOS with hidden symbols;

Exceptions
lsst::pex::exceptions::LogicErrorif the cast fails

param[in] ptr The pointer to be cast.

Returns
The cast pointer.
Exceptions
lsst::pex::exceptions::TypeErrorIf the dynamic cast fails.

Definition at line 18 of file Persistable.cc.

18  {
20  if (!result) {
21  throw LSST_EXCEPT(pex::exceptions::TypeError, "Dynamic pointer cast failed");
22  }
23  return result;
24 }
uint64_t * ptr
Definition: RangeSet.cc:88
T dynamic_pointer_cast(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
py::object result
Definition: _schema.cc:429

◆ evaluate() [1/3]

double lsst::afw::math::BoundedField::evaluate ( double  x,
double  y 
) const
inlineinherited

Evaluate the field at the given point.

This delegates to the evaluate() method that takes lsst::geom::Point2D.

There is no bounds-checking on the given position; this is the responsibility of the user, who can almost always do it more efficiently.

Definition at line 75 of file BoundedField.h.

75 { return evaluate(lsst::geom::Point2D(x, y)); }
int y
Definition: SpanSet.cc:49
double x
virtual double evaluate(lsst::geom::Point2D const &position) const =0
Evaluate the field at the given point.

◆ evaluate() [2/3]

ndarray::Array< double, 1, 1 > lsst::afw::math::BoundedField::evaluate ( ndarray::Array< double const, 1 > const &  x,
ndarray::Array< double const, 1 > const &  y 
) const
virtualinherited

Evaluate the field at multiple arbitrary points.

Parameters
[in]xarray of x coordinates, same shape as y
[in]yarray of y coordinates, same shape as x
Returns
an array of output values, same shape as x and y

There is no bounds-checking on the given positions; this is the responsibility of the user, who can almost always do it more efficiently.

Reimplemented in lsst::afw::math::PixelAreaBoundedField, lsst::afw::math::TransformBoundedField, and lsst::afw::math::ProductBoundedField.

Definition at line 40 of file BoundedField.cc.

41  {
42  ndarray::Array<double, 1, 1> out = ndarray::allocate(x.getSize<0>());
43  for (int i = 0, n = x.getSize<0>(); i < n; ++i) {
44  out[i] = evaluate(x[i], y[i]);
45  }
46  return out;
47 }
int y
Definition: SpanSet.cc:49
double x
virtual double evaluate(lsst::geom::Point2D const &position) const =0
Evaluate the field at the given point.

◆ evaluate() [3/3]

double lsst::afw::math::ChebyshevBoundedField::evaluate ( lsst::geom::Point2D const &  position) const
overridevirtual

Evaluate the field at the given point.

This is the only abstract method to be implemented by subclasses.

Subclasses should not provide bounds checking on the given position; this is the responsibility of the user, who can almost always do it more efficiently.

Implements lsst::afw::math::BoundedField.

Definition at line 282 of file ChebyshevBoundedField.cc.

282  {
283  lsst::geom::Point2D p = _toChebyshevRange(position);
284  return evaluateFunction1d(RecursionArrayImitator(_coefficients, p.getX()), p.getY(),
285  _coefficients.getSize<0>());
286 }

◆ fillImage()

template<typename T >
template void lsst::afw::math::BoundedField::fillImage ( image::Image< T > &  image,
bool  overlapOnly = false,
int  xStep = 1,
int  yStep = 1 
) const
inherited

Assign the field to an image, overwriting values already present.

Parameters
[out]imageImage to fill.
[in]overlapOnlyIf true, only modify the region in the intersection of image.getBBox(image::PARENT) and this->getBBox().
[in]xStepDistance between grid points in X to evaluate; values between grid points will be linearly interpolated.
[in]yStepDistance between grid points in Y to evaluate; values between grid points will be linearly interpolated.
Exceptions
pex::exceptions::RuntimeErrorif the bounding boxes do not overlap and overlapOnly=false.

Definition at line 259 of file BoundedField.cc.

259  {
260  applyToImage(*this, img, Assign(), overlapOnly, xStep, yStep);
261 }

◆ fit() [1/3]

std::shared_ptr< ChebyshevBoundedField > lsst::afw::math::ChebyshevBoundedField::fit ( lsst::geom::Box2I const &  bbox,
ndarray::Array< double const, 1 > const &  x,
ndarray::Array< double const, 1 > const &  y,
ndarray::Array< double const, 1 > const &  z,
Control const &  ctrl 
)
static

Fit a Chebyshev approximation to non-gridded data with equal weights.

Parameters
[in]bboxInteger bounding box of the resulting approximation. All given points must lie within lsst::geom::Box2D(bbox).
[in]xArray of x coordinate values.
[in]yArray of y coordinate values.
[in]zArray of field values to be fit at each (x,y) point.
[in]ctrlSpecifies the orders and triangularity of the coefficient matrix.

Definition at line 149 of file ChebyshevBoundedField.cc.

153  {
154  // Initialize the result object, so we can make use of the AffineTransform it builds
156  // This packer object knows how to map the 2-d Chebyshev functions onto a 1-d array,
157  // using only those that the control says should have nonzero coefficients.
158  Packer const packer(ctrl);
159  // Create a "design matrix" for the linear least squares problem (A in min||Ax-b||)
160  ndarray::Array<double, 2, 2> matrix = makeMatrix(x, y, result->_toChebyshevRange, packer, ctrl);
161  // Solve the linear least squares problem.
163  // Unpack the solution into a 2-d matrix, with zeros for values we didn't fit.
164  result->_coefficients = packer.unpack(lstsq.getSolution());
165  return result;
166 }
ChebyshevBoundedField(lsst::geom::Box2I const &bbox, ndarray::Array< double const, 2, 2 > const &coefficients)
Initialize the field from its bounding box an coefficients.
table::Box2IKey bbox
int y
Definition: SpanSet.cc:49
static LeastSquares fromDesignMatrix(ndarray::Array< T1, 2, C1 > const &design, ndarray::Array< T2, 1, C2 > const &data, Factorization factorization=NORMAL_EIGENSYSTEM)
Initialize from the design matrix and data vector given as ndarrays.
Definition: LeastSquares.h:100
double z
Definition: Match.cc:44
Use the normal equations with a symmetric Eigensystem decomposition.
Definition: LeastSquares.h:72
double x
py::object result
Definition: _schema.cc:429

◆ fit() [2/3]

std::shared_ptr< ChebyshevBoundedField > lsst::afw::math::ChebyshevBoundedField::fit ( lsst::geom::Box2I const &  bbox,
ndarray::Array< double const, 1 > const &  x,
ndarray::Array< double const, 1 > const &  y,
ndarray::Array< double const, 1 > const &  z,
ndarray::Array< double const, 1 > const &  w,
Control const &  ctrl 
)
static

Fit a Chebyshev approximation to non-gridded data with unequal weights.

Parameters
[in]bboxInteger bounding box of the resulting approximation. All given points must lie within lsst::geom::Box2D(bbox).
[in]xArray of x coordinate values.
[in]yArray of y coordinate values.
[in]zArray of field values to be fit at each (x,y) point.
[in]wArray of weights for each point in the fit. For points with Gaussian noise, w = 1/sigma.
[in]ctrlSpecifies the orders and triangularity of the coefficient matrix.

Definition at line 168 of file ChebyshevBoundedField.cc.

173  {
174  // Initialize the result object, so we can make use of the AffineTransform it builds
176  // This packer object knows how to map the 2-d Chebyshev functions onto a 1-d array,
177  // using only those that the control says should have nonzero coefficients.
178  Packer const packer(ctrl);
179  // Create a "design matrix" for the linear least squares problem ('A' in min||Ax-b||)
180  ndarray::Array<double, 2, 2> matrix = makeMatrix(x, y, result->_toChebyshevRange, packer, ctrl);
181  // We want to do weighted least squares, so we multiply both the data vector 'b' and the
182  // matrix 'A' by the weights.
183  ndarray::asEigenArray(matrix).colwise() *= ndarray::asEigenArray(w);
184  ndarray::Array<double, 1, 1> wz = ndarray::copy(z);
185  ndarray::asEigenArray(wz) *= ndarray::asEigenArray(w);
186  // Solve the linear least squares problem.
187  LeastSquares lstsq = LeastSquares::fromDesignMatrix(matrix, wz, LeastSquares::NORMAL_EIGENSYSTEM);
188  // Unpack the solution into a 2-d matrix, with zeros for values we didn't fit.
189  result->_coefficients = packer.unpack(lstsq.getSolution());
190  return result;
191 }
ChebyshevBoundedField(lsst::geom::Box2I const &bbox, ndarray::Array< double const, 2, 2 > const &coefficients)
Initialize the field from its bounding box an coefficients.
table::Box2IKey bbox
int y
Definition: SpanSet.cc:49
static LeastSquares fromDesignMatrix(ndarray::Array< T1, 2, C1 > const &design, ndarray::Array< T2, 1, C2 > const &data, Factorization factorization=NORMAL_EIGENSYSTEM)
Initialize from the design matrix and data vector given as ndarrays.
Definition: LeastSquares.h:100
double z
Definition: Match.cc:44
Use the normal equations with a symmetric Eigensystem decomposition.
Definition: LeastSquares.h:72
double x
double w
Definition: CoaddPsf.cc:69
py::object result
Definition: _schema.cc:429

◆ fit() [3/3]

template<typename T >
std::shared_ptr< ChebyshevBoundedField > lsst::afw::math::ChebyshevBoundedField::fit ( image::Image< T > const &  image,
Control const &  ctrl 
)
static

Fit a Chebyshev approximation to gridded data with equal weights.

Parameters
[in]imageThe Image containing the data to fit. image.getBBox(PARENT) is used as the bounding box of the BoundedField.
[in]ctrlSpecifies the orders and triangularity of the coefficient matrix.

Instantiated for float and double.

Note
if the image to be fit is a binned version of the actual image the field should correspond to, call relocate() with the unbinned image's bounding box after fitting.

Definition at line 194 of file ChebyshevBoundedField.cc.

195  {
196  // Initialize the result object, so we can make use of the AffineTransform it builds
197  lsst::geom::Box2I bbox = img.getBBox(image::PARENT);
199  // This packer object knows how to map the 2-d Chebyshev functions onto a 1-d array,
200  // using only those that the control says should have nonzero coefficients.
201  Packer const packer(ctrl);
202  ndarray::Array<double, 2, 2> matrix = makeMatrix(bbox, result->_toChebyshevRange, packer, ctrl);
203  // Flatten the data image into a 1-d vector.
204  ndarray::Array<double, 2, 2> imgCopy = ndarray::allocate(img.getArray().getShape());
205  imgCopy.deep() = img.getArray();
206  ndarray::Array<double const, 1, 1> z = ndarray::flatten<1>(imgCopy);
207  // Solve the linear least squares problem.
208  LeastSquares lstsq = LeastSquares::fromDesignMatrix(matrix, z, LeastSquares::NORMAL_EIGENSYSTEM);
209  // Unpack the solution into a 2-d matrix, with zeros for values we didn't fit.
210  result->_coefficients = packer.unpack(lstsq.getSolution());
211  return result;
212 }
ChebyshevBoundedField(lsst::geom::Box2I const &bbox, ndarray::Array< double const, 2, 2 > const &coefficients)
Initialize the field from its bounding box an coefficients.
table::Box2IKey bbox
static LeastSquares fromDesignMatrix(ndarray::Array< T1, 2, C1 > const &design, ndarray::Array< T2, 1, C2 > const &data, Factorization factorization=NORMAL_EIGENSYSTEM)
Initialize from the design matrix and data vector given as ndarrays.
Definition: LeastSquares.h:100
double z
Definition: Match.cc:44
Use the normal equations with a symmetric Eigensystem decomposition.
Definition: LeastSquares.h:72
An integer coordinate rectangle.
Definition: Box.h:55
py::object result
Definition: _schema.cc:429

◆ getBBox()

lsst::geom::Box2I lsst::afw::math::BoundedField::getBBox ( ) const
inlineinherited

Return the bounding box that defines the region where the field is valid.

Because this is an integer bounding box, its minimum and maximum positions are the centers of the pixels where the field is valid, but the field can be assumed to be valid to the edges of those pixels, which is the boundary you'd get by converting the returned lsst::geom::Box2I into a lsst::geom::Box2D.

Definition at line 112 of file BoundedField.h.

112 { return _bbox; }

◆ getCoefficients()

ndarray::Array<double const, 2, 2> lsst::afw::math::ChebyshevBoundedField::getCoefficients ( ) const
inline

Return the coefficient matrix.

The coefficients are ordered [y,x], so the shape is (orderY+1, orderX+1).

Definition at line 180 of file ChebyshevBoundedField.h.

180 { return _coefficients; }

◆ getPersistenceName()

std::string lsst::afw::math::ChebyshevBoundedField::getPersistenceName ( ) const
overrideprotectedvirtual

Return the unique name used to persist this object and look up its factory.

Must be less than ArchiveIndexSchema::MAX_NAME_LENGTH characters.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 358 of file ChebyshevBoundedField.cc.

358  {
359  return getChebyshevBoundedFieldPersistenceName();
360 }

◆ getPythonModule()

std::string lsst::afw::math::ChebyshevBoundedField::getPythonModule ( ) const
overrideprotectedvirtual

Return the fully-qualified Python module that should be imported to guarantee that its factory is registered.

Must be less than ArchiveIndexSchema::MAX_MODULE_LENGTH characters.

Will be ignored if empty.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 362 of file ChebyshevBoundedField.cc.

362 { return "lsst.afw.math"; }

◆ integrate()

double lsst::afw::math::ChebyshevBoundedField::integrate ( ) const
overridevirtual

Compute the integral of this function over its bounding-box.

Returns
The value of the integral.

Reimplemented from lsst::afw::math::BoundedField.

Definition at line 297 of file ChebyshevBoundedField.cc.

297  {
298  double result = 0;
299  double determinant = getBBox().getArea() / 4.0;
300  for (ndarray::Size j = 0; j < _coefficients.getSize<0>(); j++) {
301  for (ndarray::Size i = 0; i < _coefficients.getSize<1>(); i++) {
302  result += _coefficients[j][i] * integrateTn(i) * integrateTn(j);
303  }
304  }
305  return result * determinant;
306 }
int getArea() const
Definition: Box.h:189
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
Definition: BoundedField.h:112
py::object result
Definition: _schema.cc:429

◆ isPersistable()

bool lsst::afw::math::ChebyshevBoundedField::isPersistable ( ) const
inlineoverridevirtualnoexcept

ChebyshevBoundedField is always persistable.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 205 of file ChebyshevBoundedField.h.

205 { return true; }

◆ mean()

double lsst::afw::math::ChebyshevBoundedField::mean ( ) const
overridevirtual

Compute the mean of this function over its bounding-box.

Returns
The value of the mean.

Reimplemented from lsst::afw::math::BoundedField.

Definition at line 308 of file ChebyshevBoundedField.cc.

308 { return integrate() / getBBox().getArea(); }
int getArea() const
Definition: Box.h:189
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
Definition: BoundedField.h:112
double integrate() const override
Compute the integral of this function over its bounding-box.

◆ multiplyImage()

template<typename T >
template void lsst::afw::math::BoundedField::multiplyImage ( image::Image< T > &  image,
bool  overlapOnly = false,
int  xStep = 1,
int  yStep = 1 
) const
inherited

Multiply an image by the field in-place.

Parameters
[out]imageImage to fill.
[in]overlapOnlyIf true, only modify the region in the intersection of image.getBBox(image::PARENT) and this->getBBox().
[in]xStepDistance between grid points in X to evaluate; values between grid points will be linearly interpolated.
[in]yStepDistance between grid points in Y to evaluate; values between grid points will be linearly interpolated.
Exceptions
pex::exceptions::RuntimeErrorif the bounding boxes do not overlap and overlapOnly=false.

Definition at line 270 of file BoundedField.cc.

270  {
271  applyToImage(*this, img, Multiply(), overlapOnly, xStep, yStep);
272 }

◆ operator!=()

bool lsst::afw::math::BoundedField::operator!= ( BoundedField const &  rhs) const
inlineinherited

BoundedFields (of the same sublcass) are equal if their bounding boxes and parameters are equal.

Definition at line 195 of file BoundedField.h.

195 { return !(*this == rhs); };

◆ operator*()

std::shared_ptr< BoundedField > lsst::afw::math::ChebyshevBoundedField::operator* ( double const  scale) const
overridevirtual

Return a scaled BoundedField.

Parameters
[in]scaleScaling factor

Implements lsst::afw::math::BoundedField.

Definition at line 376 of file ChebyshevBoundedField.cc.

376  {
377  return std::make_shared<ChebyshevBoundedField>(getBBox(), ndarray::copy(getCoefficients() * scale));
378 }
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:109
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
Definition: BoundedField.h:112
ndarray::Array< double const, 2, 2 > getCoefficients() const
Return the coefficient matrix.

◆ operator/()

std::shared_ptr<BoundedField> lsst::afw::math::BoundedField::operator/ ( double  scale) const
inlineinherited

Definition at line 190 of file BoundedField.h.

190 { return (*this) * (1.0 / scale); }
def scale(algorithm, min, max=None, frame=None)
Definition: ds9.py:109

◆ operator=() [1/2]

ChebyshevBoundedField& lsst::afw::math::ChebyshevBoundedField::operator= ( ChebyshevBoundedField const &  )
delete

◆ operator=() [2/2]

ChebyshevBoundedField& lsst::afw::math::ChebyshevBoundedField::operator= ( ChebyshevBoundedField &&  )
delete

◆ operator==()

bool lsst::afw::math::ChebyshevBoundedField::operator== ( BoundedField const &  rhs) const
overridevirtual

BoundedFields (of the same sublcass) are equal if their bounding boxes and parameters are equal.

Implements lsst::afw::math::BoundedField.

Definition at line 380 of file ChebyshevBoundedField.cc.

380  {
381  auto rhsCasted = dynamic_cast<ChebyshevBoundedField const*>(&rhs);
382  if (!rhsCasted) return false;
383 
384  return (getBBox() == rhsCasted->getBBox()) &&
385  (_coefficients.getShape() == rhsCasted->_coefficients.getShape()) &&
386  all(equal(_coefficients, rhsCasted->_coefficients));
387 }
ChebyshevBoundedField(lsst::geom::Box2I const &bbox, ndarray::Array< double const, 2, 2 > const &coefficients)
Initialize the field from its bounding box an coefficients.
bool all(CoordinateExpr< N > const &expr) noexcept
Return true if all elements are true.
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
Definition: BoundedField.h:112
T equal(T... args)

◆ readFits() [1/6]

Read an object from an already open FITS object.

Parameters
[in]fitsfileFITS object to read from, already positioned at the desired HDU.

Definition at line 183 of file Persistable.h.

183  {
184  return dynamicCast(Persistable::_readFits(fitsfile));
185  }
static std::shared_ptr< ChebyshevBoundedField > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18

◆ readFits() [2/6]

static std::shared_ptr<BoundedField > lsst::afw::table::io::PersistableFacade< BoundedField >::readFits ( fits::Fits fitsfile)
inlinestaticinherited

Read an object from an already open FITS object.

Parameters
[in]fitsfileFITS object to read from, already positioned at the desired HDU.

Definition at line 183 of file Persistable.h.

183  {
184  return dynamicCast(Persistable::_readFits(fitsfile));
185  }
static std::shared_ptr< BoundedField > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18

◆ readFits() [3/6]

static std::shared_ptr<BoundedField > lsst::afw::table::io::PersistableFacade< BoundedField >::readFits ( std::string const &  fileName,
int  hdu = fits::DEFAULT_HDU 
)
inlinestaticinherited

Read an object from a regular FITS file.

Parameters
[in]fileNameName of the file to read.
[in]hduHDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty.

Definition at line 194 of file Persistable.h.

194  {
195  return dynamicCast(Persistable::_readFits(fileName, hdu));
196  }
static std::shared_ptr< BoundedField > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18

◆ readFits() [4/6]

static std::shared_ptr<ChebyshevBoundedField > lsst::afw::table::io::PersistableFacade< ChebyshevBoundedField >::readFits ( std::string const &  fileName,
int  hdu = fits::DEFAULT_HDU 
)
inlinestaticinherited

Read an object from a regular FITS file.

Parameters
[in]fileNameName of the file to read.
[in]hduHDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty.

Definition at line 194 of file Persistable.h.

194  {
195  return dynamicCast(Persistable::_readFits(fileName, hdu));
196  }
static std::shared_ptr< ChebyshevBoundedField > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18

◆ readFits() [5/6]

static std::shared_ptr<BoundedField > lsst::afw::table::io::PersistableFacade< BoundedField >::readFits ( fits::MemFileManager manager,
int  hdu = fits::DEFAULT_HDU 
)
inlinestaticinherited

Read an object from a FITS file in memory.

Parameters
[in]managerManager for the memory to read from.
[in]hduHDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty.

Definition at line 205 of file Persistable.h.

205  {
206  return dynamicCast(Persistable::_readFits(manager, hdu));
207  }
static std::shared_ptr< BoundedField > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18

◆ readFits() [6/6]

static std::shared_ptr<ChebyshevBoundedField > lsst::afw::table::io::PersistableFacade< ChebyshevBoundedField >::readFits ( fits::MemFileManager manager,
int  hdu = fits::DEFAULT_HDU 
)
inlinestaticinherited

Read an object from a FITS file in memory.

Parameters
[in]managerManager for the memory to read from.
[in]hduHDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty.

Definition at line 205 of file Persistable.h.

205  {
206  return dynamicCast(Persistable::_readFits(manager, hdu));
207  }
static std::shared_ptr< ChebyshevBoundedField > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18

◆ relocate()

std::shared_ptr< ChebyshevBoundedField > lsst::afw::math::ChebyshevBoundedField::relocate ( lsst::geom::Box2I const &  bbox) const

Return a new ChebyshevBoundedField with domain set to the given bounding box.

Because this leaves the coefficients unchanged, it is equivalent to transforming the function by the affine transform that maps the old box to the new one.

Definition at line 240 of file ChebyshevBoundedField.cc.

240  {
241  return std::make_shared<ChebyshevBoundedField>(bbox, _coefficients);
242 }
table::Box2IKey bbox

◆ truncate()

std::shared_ptr< ChebyshevBoundedField > lsst::afw::math::ChebyshevBoundedField::truncate ( Control const &  ctrl) const

Return a new ChebyshevBoudedField with maximum orders set by the given control object.

Definition at line 216 of file ChebyshevBoundedField.cc.

216  {
217  if (static_cast<std::size_t>(ctrl.orderX) >= _coefficients.getSize<1>()) {
218  throw LSST_EXCEPT(pex::exceptions::LengthError,
219  (boost::format("New x order (%d) exceeds old x order (%d)") % ctrl.orderX %
220  (_coefficients.getSize<1>() - 1))
221  .str());
222  }
223  if (static_cast<std::size_t>(ctrl.orderY) >= _coefficients.getSize<0>()) {
224  throw LSST_EXCEPT(pex::exceptions::LengthError,
225  (boost::format("New y order (%d) exceeds old y order (%d)") % ctrl.orderY %
226  (_coefficients.getSize<0>() - 1))
227  .str());
228  }
229  ndarray::Array<double, 2, 2> coefficients = ndarray::allocate(ctrl.orderY + 1, ctrl.orderX + 1);
230  coefficients.deep() = _coefficients[ndarray::view(0, ctrl.orderY + 1)(0, ctrl.orderX + 1)];
231  if (ctrl.triangular) {
232  Packer packer(ctrl);
233  ndarray::Array<double, 1, 1> packed = ndarray::allocate(packer.size);
234  packer.pack(packed, coefficients);
235  packer.unpack(coefficients, packed);
236  }
237  return std::make_shared<ChebyshevBoundedField>(getBBox(), coefficients);
238 }
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
Definition: BoundedField.h:112
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
ndarray::Array< double const, 2, 2 > coefficients

◆ write()

void lsst::afw::math::ChebyshevBoundedField::write ( OutputArchiveHandle handle) const
overrideprotectedvirtual

Write the object to one or more catalogs.

The handle object passed to this function provides an interface for adding new catalogs and adding nested objects to the same archive (while checking for duplicates). See OutputArchiveHandle for more information.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 364 of file ChebyshevBoundedField.cc.

364  {
365  PersistenceHelper const keys(_coefficients.getSize<1>(), _coefficients.getSize<0>());
366  table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
367  std::shared_ptr<table::BaseRecord> record = catalog.addNew();
368  record->set(keys.orderX, _coefficients.getSize<1>() - 1);
369  record->set(keys.bbox, getBBox());
370  (*record)[keys.coefficients].deep() = ndarray::flatten<1>(_coefficients);
371  handle.saveCatalog(catalog);
372 }
CatalogT< BaseRecord > BaseCatalog
Definition: fwd.h:71
lsst::geom::Box2I getBBox() const
Return the bounding box that defines the region where the field is valid.
Definition: BoundedField.h:112

◆ writeFits() [1/3]

void lsst::afw::table::io::Persistable::writeFits ( std::string const &  fileName,
std::string const &  mode = "w" 
) const
inherited

Write the object to a regular FITS file.

Parameters
[in]fileNameName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

Definition at line 24 of file Persistable.cc.

24  {
25  fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
26  writeFits(fitsfile);
27 }
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.
Definition: Persistable.cc:24

◆ writeFits() [2/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::MemFileManager manager,
std::string const &  mode = "w" 
) const
inherited

Write the object to a FITS image in memory.

Parameters
[in]managerName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

Definition at line 29 of file Persistable.cc.

29  {
30  fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
31  writeFits(fitsfile);
32 }
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.
Definition: Persistable.cc:24

◆ writeFits() [3/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::Fits fitsfile) const
inherited

Write the object to an already-open FITS object.

Parameters
[in]fitsfileOpen FITS object to write to.

Definition at line 18 of file Persistable.cc.

18  {
19  OutputArchive archive;
20  archive.put(this);
21  archive.writeFits(fitsfile);
22 }

The documentation for this class was generated from the following files: