25#ifndef LSST_AFW_MATH_KERNEL_H
26#define LSST_AFW_MATH_KERNEL_H
35#include "boost/format.hpp"
140 explicit Kernel(
int width,
int height,
unsigned int nKernelParams,
207 double y = 0.0)
const;
215 _width = dims.getX();
216 _height = dims.getY();
218 inline void setWidth(
int width) { _width = width; }
325 spatialParams.
push_back((*spFuncIter)->getParameters());
327 return spatialParams;
346 if (nParams != params.
size()) {
348 (
boost::format(
"Number of parameters is wrong, saw %d expected %d") % nParams %
352 for (
unsigned int ii = 0; ii < nParams; ++ii) {
409 struct PersistenceHelper;
456 unsigned int _nKernelParams;
608 double y = 0.0)
const;
837 void _setKernelList(
KernelList const &kernelList);
844 bool _isDeltaFunctionBasis;
931 double x = 0.0,
double y = 0.0)
const;
934 unsigned int const ncol = _kernelColFunctionPtr->
getNParameters();
992 bool doNormalize)
const;
1010 assert(dim[0] ==
static_cast<int>(_kernelX.
size()));
1011 for (
int i = 0; i != dim.getX(); ++i) {
1012 _kernelX[i] = i - ctr.getX();
1015 assert(dim[1] ==
static_cast<int>(_kernelY.
size()));
1016 for (
int i = 0; i != dim.getY(); ++i) {
1017 _kernelY[i] = i - ctr.getY();
table::Key< int > kernelFunction
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
A class to represent a 2-dimensional array of pixels.
A kernel described by a function.
std::vector< double > getKernelParameters() const override
Return the current kernel parameters.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
AnalyticKernel(AnalyticKernel &&)=delete
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
AnalyticKernel(const AnalyticKernel &)=delete
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
KernelFunctionPtr _kernelFunctionPtr
AnalyticKernel & operator=(AnalyticKernel &&)=delete
AnalyticKernel & operator=(const AnalyticKernel &)=delete
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
AnalyticKernel()
Construct an empty spatially invariant AnalyticKernel of size 0x0.
~AnalyticKernel() override=default
A kernel that has only one non-zero pixel (of value 1)
DeltaFunctionKernel(int width, int height, lsst::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
DeltaFunctionKernel & operator=(DeltaFunctionKernel &&)=delete
~DeltaFunctionKernel() override=default
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
lsst::geom::Point2I getPixel() const
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
DeltaFunctionKernel(DeltaFunctionKernel &&)=delete
DeltaFunctionKernel & operator=(const DeltaFunctionKernel &)=delete
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
DeltaFunctionKernel(const DeltaFunctionKernel &)=delete
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
A kernel created from an Image.
FixedKernel(FixedKernel &&)=delete
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
FixedKernel()
Construct an empty FixedKernel of size 0x0.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
~FixedKernel() override=default
FixedKernel & operator=(FixedKernel &&)=delete
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
virtual Pixel getSum() const
FixedKernel & operator=(const FixedKernel &)=delete
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
FixedKernel(const FixedKernel &)=delete
A Function taking one argument.
A Function taking two arguments.
virtual double getParameter(unsigned int ind) const
Get one function parameter without range checking.
unsigned int getNParameters() const noexcept
Return the number of function parameters.
Kernels are used for convolution with MaskedImages and (eventually) Images.
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
virtual void _setKernelXY()
std::vector< SpatialFunctionPtr > _spatialFunctionList
Kernel(const Kernel &)=delete
virtual void computeCache(int const)
Compute a cache of Kernel values, if desired.
int getHeight() const
Return the Kernel's height.
lsst::geom::Point2I getCtr() const
Return index of kernel's center.
Kernel & operator=(const Kernel &)=delete
void setKernelParameters(std::vector< double > const ¶ms)
Set the kernel parameters of a spatially invariant kernel.
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
void setSpatialParameters(const std::vector< std::vector< double > > params)
Set the parameters of all spatial functions.
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
std::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
~Kernel() override=default
Kernel & operator=(Kernel &&)=delete
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
lsst::afw::math::NullFunction2< double > NullSpatialFunction
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
SpatialFunctionPtr getSpatialFunction(unsigned int index) const
Return a clone of the specified spatial function (one component of the spatial model)
void setCtr(lsst::geom::Point2I ctr)
Set index of kernel's center.
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying)
void setKernelParameters(std::pair< double, double > const ¶ms)
Set the kernel parameters of a 2-component spatially invariant kernel.
lsst::geom::Box2I shrinkBBox(lsst::geom::Box2I const &bbox) const
Given a bounding box for an image one wishes to convolve with this kernel, return the bounding box fo...
int getWidth() const
Return the Kernel's width.
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
lsst::geom::Box2I growBBox(lsst::geom::Box2I const &bbox) const
Given a bounding box for pixels one wishes to compute by convolving an image with this kernel,...
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
void setHeight(int height)
void setDimensions(lsst::geom::Extent2I dims)
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const =0
Low-level version of computeImage.
Kernel()
Construct a null Kernel of size 0,0.
virtual std::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
lsst::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
virtual std::shared_ptr< Kernel > resized(int width, int height) const =0
Return a pointer to a clone with specified kernel dimensions.
A kernel that is a linear combination of fixed basis kernels.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
std::vector< double > getKernelSumList() const
Get the sum of the pixels of each fixed basis kernel.
std::shared_ptr< Kernel > refactor() const
Refactor the kernel as a linear combination of N bases where N is the number of parameters for the sp...
virtual KernelList const & getKernelList() const
Get the fixed basis kernels.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
LinearCombinationKernel()
Construct an empty LinearCombinationKernel of size 0x0.
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
~LinearCombinationKernel() override=default
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
LinearCombinationKernel & operator=(const LinearCombinationKernel &)=delete
int getNBasisKernels() const
Get the number of basis kernels.
LinearCombinationKernel & operator=(LinearCombinationKernel &&)=delete
std::vector< double > getKernelParameters() const override
Return the current kernel parameters.
LinearCombinationKernel(LinearCombinationKernel &&)=delete
LinearCombinationKernel(const LinearCombinationKernel &)=delete
bool isDeltaFunctionBasis() const
Return true if all basis kernels are instances of DeltaFunctionKernel.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
a class used in function calls to indicate that no Function2 is being provided
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
~SeparableKernel() override=default
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
SeparableKernel(SeparableKernel &&)=delete
std::vector< double > getKernelParameters() const override
Return the current kernel parameters.
std::shared_ptr< KernelFunction > KernelFunctionPtr
double getKernelParameter(unsigned int i) const override
Return a particular Kernel Parameter (no bounds checking).
int getCacheSize() const override
Get the current cache size (0 if none)
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
SeparableKernel(const SeparableKernel &)=delete
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
SeparableKernel & operator=(const SeparableKernel &)=delete
double computeVectors(std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize, double x=0.0, double y=0.0) const
Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row)
SeparableKernel & operator=(SeparableKernel &&)=delete
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
virtual void _setKernelXY() override
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
SeparableKernel()
Construct an empty spatially invariant SeparableKernel of size 0x0.
void computeCache(int const cacheSize) override
Compute a cache of Kernel values, if desired.
A CRTP facade class for subclasses of Persistable.
A base class for objects that can be persisted via afw::table::io Archive classes.
io::OutputArchiveHandle OutputArchiveHandle
An integer coordinate rectangle.
Reports invalid arguments.
Reports errors that are due to events beyond the control of the program.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Extent< int, 2 > Extent2I
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
A base class for image defects.
Kernel has only one non-zero pixel.
Tags carrying information about Kernels Kernel with no special properties.
table::Key< int > cacheSize