LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Classes | Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
lsst::afw::math::LinearCombinationKernel Class Reference

A kernel that is a linear combination of fixed basis kernels. More...

#include <Kernel.h>

Inheritance diagram for lsst::afw::math::LinearCombinationKernel:
lsst::afw::table::io::PersistableFacade< LinearCombinationKernel > lsst::afw::math::Kernel lsst::daf::base::Citizen lsst::daf::base::Persistable lsst::afw::table::io::PersistableFacade< Kernel > lsst::afw::table::io::Persistable

Classes

class  Factory
 

Public Types

typedef boost::shared_ptr
< LinearCombinationKernel
Ptr
 
typedef boost::shared_ptr
< LinearCombinationKernel
const > 
ConstPtr
 
- Public Types inherited from lsst::afw::math::Kernel
typedef double Pixel
 
typedef boost::shared_ptr< KernelPtr
 
typedef boost::shared_ptr
< Kernel const > 
ConstPtr
 
typedef boost::shared_ptr
< lsst::afw::math::Function2
< double > > 
SpatialFunctionPtr
 
typedef
lsst::afw::math::Function2
< double > 
SpatialFunction
 
typedef
lsst::afw::math::NullFunction2
< double > 
NullSpatialFunction
 
typedef generic_kernel_tag kernel_fill_factor
 
- Public Types inherited from lsst::daf::base::Citizen
enum  { magicSentinel = 0xdeadbeef }
 
typedef unsigned long memId
 Type of the block's ID. More...
 
typedef memId(* memNewCallback )(const memId cid)
 A function used to register a callback. More...
 
typedef memId(* memCallback )(const Citizen *ptr)
 
- Public Types inherited from lsst::daf::base::Persistable
typedef boost::shared_ptr
< Persistable
Ptr
 

Public Member Functions

 LinearCombinationKernel ()
 Construct an empty LinearCombinationKernel of size 0x0. More...
 
 LinearCombinationKernel (KernelList const &kernelList, std::vector< double > const &kernelParameters)
 Construct a spatially invariant LinearCombinationKernel. More...
 
 LinearCombinationKernel (KernelList const &kernelList, Kernel::SpatialFunction const &spatialFunction)
 Construct a spatially varying LinearCombinationKernel, where the spatial model is described by one function (that is cloned to give one per basis kernel). More...
 
 LinearCombinationKernel (KernelList const &kernelList, std::vector< Kernel::SpatialFunctionPtr > const &spatialFunctionList)
 Construct a spatially varying LinearCombinationKernel, where the spatial model is described by a list of functions (one per basis kernel). More...
 
virtual ~LinearCombinationKernel ()
 
virtual boost::shared_ptr< Kernelclone () const
 Return a pointer to a deep copy of this kernel. More...
 
virtual std::vector< double > getKernelParameters () const
 Return the current kernel parameters. More...
 
virtual KernelList const & getKernelList () const
 Get the fixed basis kernels. More...
 
std::vector< double > getKernelSumList () const
 Get the sum of the pixels of each fixed basis kernel. More...
 
int getNBasisKernels () const
 Get the number of basis kernels. More...
 
void checkKernelList (const KernelList &kernelList) const
 Check that all kernels have the same size and center and that none are spatially varying. More...
 
bool isDeltaFunctionBasis () const
 
boost::shared_ptr< Kernelrefactor () const
 Refactor the kernel as a linear combination of N bases where N is the number of parameters for the spatial model. More...
 
virtual std::string toString (std::string const &prefix="") const
 Return a string representation of the kernel. More...
 
virtual bool isPersistable () const
 Return true if this particular object can be persisted using afw::table::io. More...
 
- Public Member Functions inherited from lsst::afw::math::Kernel
 Kernel ()
 Construct a null Kernel of size 0,0. More...
 
 Kernel (int width, int height, unsigned int nKernelParams, SpatialFunction const &spatialFunction=NullSpatialFunction())
 Construct a spatially invariant Kernel or a spatially varying Kernel with one spatial function that is duplicated as needed. More...
 
 Kernel (int width, int height, const std::vector< SpatialFunctionPtr > spatialFunctionList)
 Construct a spatially varying Kernel with a list of spatial functions (one per kernel parameter) More...
 
virtual ~Kernel ()
 
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. More...
 
geom::Extent2I const getDimensions () const
 Return the Kernel's dimensions (width, height) More...
 
void setDimensions (geom::Extent2I dims)
 
void setWidth (int width)
 
void setHeight (int height)
 
int getWidth () const
 Return the Kernel's width. More...
 
int getHeight () const
 Return the Kernel's height. More...
 
lsst::afw::geom::Point2I getCtr () const
 Return index of kernel's center. More...
 
int getCtrX () const
 Return x index of kernel's center. More...
 
int getCtrY () const
 Return y index of kernel's center. More...
 
lsst::afw::geom::Box2I getBBox () const
 return parent bounding box, with XY0 = -center More...
 
unsigned int getNKernelParameters () const
 Return the number of kernel parameters (0 if none) More...
 
int getNSpatialParameters () const
 Return the number of spatial parameters (0 if not spatially varying) More...
 
SpatialFunctionPtr getSpatialFunction (unsigned int index) const
 Return a clone of the specified spatial function (one component of the spatial model) More...
 
std::vector< SpatialFunctionPtrgetSpatialFunctionList () const
 Return a list of clones of the spatial functions. More...
 
virtual double getKernelParameter (unsigned int i) const
 
lsst::afw::geom::Box2I growBBox (lsst::afw::geom::Box2I const &bbox) const
 
lsst::afw::geom::Box2I shrinkBBox (lsst::afw::geom::Box2I const &bbox) const
 
void setCtr (lsst::afw::geom::Point2I ctr)
 Set index of kernel's center. More...
 
void setCtrX (int ctrX)
 Set x index of kernel's center. More...
 
void setCtrY (int ctrY)
 Set y index of kernel's center. More...
 
std::vector< std::vector
< double > > 
getSpatialParameters () const
 Return the spatial parameters parameters (an empty vector if not spatially varying) More...
 
bool isSpatiallyVarying () const
 Return true iff the kernel is spatially varying (has a spatial function) More...
 
void setKernelParameters (std::vector< double > const &params)
 Set the kernel parameters of a spatially invariant kernel. More...
 
void setKernelParameters (std::pair< double, double > const &params)
 Set the kernel parameters of a 2-component spatially invariant kernel. More...
 
void setSpatialParameters (const std::vector< std::vector< double > > params)
 Set the parameters of all spatial functions. More...
 
void computeKernelParametersFromSpatialModel (std::vector< double > &kernelParams, double x, double y) const
 Compute the kernel parameters at a specified point. More...
 
virtual void computeCache (int const )
 Compute a cache of Kernel values, if desired. More...
 
virtual int getCacheSize () const
 Get the current size of the kernel cache (0 if none or if caches not supported) More...
 
- Public Member Functions inherited from lsst::daf::base::Citizen
 Citizen (const std::type_info &)
 
 Citizen (Citizen const &)
 
 ~Citizen ()
 
Citizenoperator= (Citizen const &)
 
std::string repr () const
 Return a string representation of a Citizen. More...
 
void markPersistent (void)
 Mark a Citizen as persistent and not destroyed until process end. More...
 
memId getId () const
 Return the Citizen's ID. More...
 
- Public Member Functions inherited from lsst::daf::base::Persistable
 Persistable (void)
 
virtual ~Persistable (void)
 
template<class Archive >
void serialize (Archive &, unsigned int const)
 
- Public Member Functions inherited from lsst::afw::table::io::Persistable
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...
 
virtual ~Persistable ()
 

Protected Member Functions

virtual double doComputeImage (lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
 Low-level version of computeImage. More...
 
virtual std::string getPersistenceName () const
 Return the unique name used to persist this object and look up its factory. More...
 
virtual void write (OutputArchiveHandle &handle) const
 Write the object to one or more catalogs. More...
 
virtual void setKernelParameter (unsigned int ind, double value) const
 Set one kernel parameter. More...
 
- Protected Member Functions inherited from lsst::afw::math::Kernel
virtual std::string getPythonModule () const
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered. More...
 
void setKernelParametersFromSpatialModel (double x, double y) const
 Set the kernel parameters from the spatial model (if any). More...
 
- Protected Member Functions inherited from lsst::afw::table::io::Persistable
 Persistable ()
 
 Persistable (Persistable const &other)
 
void operator= (Persistable const &other)
 

Private Member Functions

void _setKernelList (KernelList const &kernelList)
 Set _kernelList by cloning each input kernel and update the kernel image cache. More...
 
template<class Archive >
void serialize (Archive &ar, unsigned int const version)
 

Private Attributes

KernelList _kernelList
 basis kernels More...
 
std::vector< boost::shared_ptr
< lsst::afw::image::Image
< Pixel > > > 
_kernelImagePtrList
 image of each basis kernel (a cache) More...
 
std::vector< double > _kernelSumList
 sum of each basis kernel (a cache) More...
 
std::vector< double > _kernelParams
 
bool _isDeltaFunctionBasis
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Static Public Member Functions inherited from lsst::afw::table::io::PersistableFacade< LinearCombinationKernel >
static boost::shared_ptr
< LinearCombinationKernel > 
readFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static boost::shared_ptr
< LinearCombinationKernel > 
readFits (std::string const &fileName, int hdu=0)
 Read an object from a regular FITS file. More...
 
static boost::shared_ptr
< LinearCombinationKernel > 
readFits (fits::MemFileManager &manager, int hdu=0)
 Read an object from a FITS file in memory. More...
 
- Static Public Member Functions inherited from lsst::daf::base::Citizen
static bool hasBeenCorrupted ()
 Check all allocated blocks for corruption. More...
 
static memId getNextMemId ()
 Return the memId of the next object to be allocated. More...
 
static int init ()
 Called once when the memory system is being initialised. More...
 
static int census (int, memId startingMemId=0)
 How many active Citizens are there? More...
 
static void census (std::ostream &stream, memId startingMemId=0)
 Print a list of all active Citizens to stream, sorted by ID. More...
 
static const std::vector
< const Citizen * > * 
census ()
 Return a (newly allocated) std::vector of active Citizens sorted by ID. More...
 
static memId setNewCallbackId (memId id)
 Call the NewCallback when block is allocated. More...
 
static memId setDeleteCallbackId (memId id)
 Call the current DeleteCallback when block is deleted. More...
 
static memNewCallback setNewCallback (memNewCallback func)
 Set the NewCallback function. More...
 
static memCallback setDeleteCallback (memCallback func)
 Set the DeleteCallback function. More...
 
static memCallback setCorruptionCallback (memCallback func)
 Set the CorruptionCallback function. More...
 
- Static Public Member Functions inherited from lsst::afw::table::io::PersistableFacade< Kernel >
static boost::shared_ptr< Kernel > readFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static boost::shared_ptr< Kernel > readFits (std::string const &fileName, int hdu=0)
 Read an object from a regular FITS file. More...
 
static boost::shared_ptr< Kernel > readFits (fits::MemFileManager &manager, int hdu=0)
 Read an object from a FITS file in memory. More...
 
- Protected Types inherited from lsst::afw::table::io::Persistable
typedef io::OutputArchiveHandle OutputArchiveHandle
 
- Protected Attributes inherited from lsst::afw::math::Kernel
std::vector< SpatialFunctionPtr_spatialFunctionList
 

Detailed Description

A kernel that is a linear combination of fixed basis kernels.

Convolution may be performed by first convolving the image with each fixed kernel, then adding the resulting images using the (possibly spatially varying) kernel coefficients.

The basis kernels are cloned (deep copied) so you may safely modify your own copies.

Warnings:

Definition at line 814 of file Kernel.h.

Member Typedef Documentation

Definition at line 819 of file Kernel.h.

Definition at line 818 of file Kernel.h.

Constructor & Destructor Documentation

lsst::afw::math::LinearCombinationKernel::LinearCombinationKernel ( )
explicit

Construct an empty LinearCombinationKernel of size 0x0.

Definition at line 42 of file LinearCombinationKernel.cc.

43 :
44  Kernel(),
45  _kernelList(),
48  _kernelParams(),
50 { }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
std::vector< double > _kernelParams
Definition: Kernel.h:953
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:950
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
lsst::afw::math::LinearCombinationKernel::LinearCombinationKernel ( KernelList const &  kernelList,
std::vector< double > const &  kernelParameters 
)
explicit

Construct a spatially invariant LinearCombinationKernel.

Parameters
kernelListlist of (shared pointers to const) basis kernels
kernelParameterskernel coefficients

Definition at line 52 of file LinearCombinationKernel.cc.

55  :
56  Kernel(kernelList[0]->getWidth(), kernelList[0]->getHeight(), kernelList.size()),
57  _kernelList(),
60  _kernelParams(kernelParameters),
62 {
63  if (kernelList.size() != kernelParameters.size()) {
64  std::ostringstream os;
65  os << "kernelList.size() = " << kernelList.size()
66  << " != " << kernelParameters.size() << " = " << "kernelParameters.size()";
67  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
68  }
69  checkKernelList(kernelList);
70  _setKernelList(kernelList);
71 }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:247
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:240
std::vector< double > _kernelParams
Definition: Kernel.h:953
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
void _setKernelList(KernelList const &kernelList)
Set _kernelList by cloning each input kernel and update the kernel image cache.
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:950
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
lsst::afw::math::LinearCombinationKernel::LinearCombinationKernel ( KernelList const &  kernelList,
Kernel::SpatialFunction const &  spatialFunction 
)
explicit

Construct a spatially varying LinearCombinationKernel, where the spatial model is described by one function (that is cloned to give one per basis kernel).

Parameters
kernelListlist of (shared pointers to const) basis kernels
spatialFunctionspatial function; one deep copy is made for each basis kernel

Definition at line 73 of file LinearCombinationKernel.cc.

76  :
77  Kernel(kernelList[0]->getWidth(), kernelList[0]->getHeight(), kernelList.size(), spatialFunction),
78  _kernelList(),
81  _kernelParams(std::vector<double>(kernelList.size())),
83 {
84  checkKernelList(kernelList);
85  _setKernelList(kernelList);
86 }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:247
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:240
std::vector< double > _kernelParams
Definition: Kernel.h:953
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
void _setKernelList(KernelList const &kernelList)
Set _kernelList by cloning each input kernel and update the kernel image cache.
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:950
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
lsst::afw::math::LinearCombinationKernel::LinearCombinationKernel ( KernelList const &  kernelList,
std::vector< Kernel::SpatialFunctionPtr > const &  spatialFunctionList 
)
explicit

Construct a spatially varying LinearCombinationKernel, where the spatial model is described by a list of functions (one per basis kernel).

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif the length of spatialFunctionList != # kernels
Parameters
kernelListlist of (shared pointers to const) kernels
spatialFunctionListlist of spatial functions, one per basis kernel

Definition at line 88 of file LinearCombinationKernel.cc.

91  :
92  Kernel(kernelList[0]->getWidth(), kernelList[0]->getHeight(), spatialFunctionList),
93  _kernelList(),
96  _kernelParams(std::vector<double>(kernelList.size())),
98 {
99  if (kernelList.size() != spatialFunctionList.size()) {
100  std::ostringstream os;
101  os << "kernelList.size() = " << kernelList.size()
102  << " != " << spatialFunctionList.size() << " = " << "spatialFunctionList.size()";
103  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
104  }
105  checkKernelList(kernelList);
106  _setKernelList(kernelList);
107 }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:247
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:240
std::vector< double > _kernelParams
Definition: Kernel.h:953
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
void _setKernelList(KernelList const &kernelList)
Set _kernelList by cloning each input kernel and update the kernel image cache.
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:950
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
virtual lsst::afw::math::LinearCombinationKernel::~LinearCombinationKernel ( )
inlinevirtual

Definition at line 856 of file Kernel.h.

856 {}

Member Function Documentation

void lsst::afw::math::LinearCombinationKernel::_setKernelList ( KernelList const &  kernelList)
private

Set _kernelList by cloning each input kernel and update the kernel image cache.

Definition at line 270 of file LinearCombinationKernel.cc.

270  {
271  _kernelSumList.clear();
272  _kernelImagePtrList.clear();
273  _kernelList.clear();
274  _isDeltaFunctionBasis = true;
275  for (KernelList::const_iterator kIter = kernelList.begin(), kEnd = kernelList.end();
276  kIter != kEnd; ++kIter) {
277  PTR(Kernel) basisKernelPtr = (*kIter)->clone();
278  if (dynamic_cast<afwMath::DeltaFunctionKernel const *>(&(*basisKernelPtr)) == 0) {
279  _isDeltaFunctionBasis = false;
280  }
281  _kernelList.push_back(basisKernelPtr);
282  PTR(afwImage::Image<Pixel>) kernelImagePtr(new afwImage::Image<Pixel>(this->getDimensions()));
283  _kernelSumList.push_back(basisKernelPtr->computeImage(*kernelImagePtr, false));
284  _kernelImagePtrList.push_back(kernelImagePtr);
285  }
286 }
geom::Extent2I const getDimensions() const
Return the Kernel&#39;s dimensions (width, height)
Definition: Kernel.h:226
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
#define PTR(...)
Definition: base.h:41
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
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.
Definition: Kernel.cc:94
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:950
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
void lsst::afw::math::LinearCombinationKernel::checkKernelList ( const KernelList kernelList) const

Check that all kernels have the same size and center and that none are spatially varying.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif the check fails

Definition at line 120 of file LinearCombinationKernel.cc.

120  {
121  if (kernelList.size() < 1) {
122  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "kernelList has no elements");
123  }
124 
125  afwGeom::Extent2I const dim0 = kernelList[0]->getDimensions();
126  afwGeom::Point2I const ctr0 = kernelList[0]->getCtr();
127 
128  for (unsigned int ii = 0; ii < kernelList.size(); ++ii) {
129  if (kernelList[ii]->getDimensions() != dim0) {
130  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
131  (boost::format("kernel %d has different size than kernel 0") % ii).str());
132  }
133  if (kernelList[ii]->getCtr() != ctr0) {
134  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
135  (boost::format("kernel %d has different center than kernel 0") % ii).str());
136  }
137  if (kernelList[ii]->isSpatiallyVarying()) {
138  throw LSST_EXCEPT(pexExcept::InvalidParameterError,
139  (boost::format("kernel %d is spatially varying") % ii).str());
140  }
141  }
142 }
geom::Extent2I const getDimensions() const
Return the Kernel&#39;s dimensions (width, height)
Definition: Kernel.h:226
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:254
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:402
boost::shared_ptr< afwMath::Kernel > lsst::afw::math::LinearCombinationKernel::clone ( ) const
virtual

Return a pointer to a deep copy of this kernel.

This kernel exists instead of a copy constructor so one can obtain a copy of an actual kernel instead of a useless copy of the base class.

Every kernel subclass must override this method.

Returns
a pointer to a deep copy of the kernel

Implements lsst::afw::math::Kernel.

Definition at line 109 of file LinearCombinationKernel.cc.

109  {
110  PTR(Kernel) retPtr;
111  if (this->isSpatiallyVarying()) {
112  retPtr.reset(new afwMath::LinearCombinationKernel(this->_kernelList, this->_spatialFunctionList));
113  } else {
114  retPtr.reset(new afwMath::LinearCombinationKernel(this->_kernelList, this->_kernelParams));
115  }
116  retPtr->setCtr(this->getCtr());
117  return retPtr;
118 }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
#define PTR(...)
Definition: base.h:41
std::vector< double > _kernelParams
Definition: Kernel.h:953
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:814
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:254
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:524
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:402
double lsst::afw::math::LinearCombinationKernel::doComputeImage ( lsst::afw::image::Image< Pixel > &  image,
bool  doNormalize 
) const
protectedvirtual

Low-level version of computeImage.

Before this is called the image dimensions are checked, the image's xy0 is set and the kernel's parameters are set. This routine sets the pixels, including normalization if requested.

Returns
The kernel sum

Implements lsst::afw::math::Kernel.

Definition at line 238 of file LinearCombinationKernel.cc.

241  {
242  image = 0.0;
243  double imSum = 0.0;
244  std::vector<PTR(afwImage::Image<Pixel>)>::const_iterator kImPtrIter = _kernelImagePtrList.begin();
245  std::vector<double>::const_iterator kSumIter = _kernelSumList.begin();
246  std::vector<double>::const_iterator kParIter = _kernelParams.begin();
247  for ( ; kImPtrIter != _kernelImagePtrList.end(); ++kImPtrIter, ++kSumIter, ++kParIter) {
248  image.scaledPlus(*kParIter, **kImPtrIter);
249  imSum += (*kSumIter) * (*kParIter);
250  }
251 
252  if (doNormalize) {
253  if (imSum == 0) {
254  throw LSST_EXCEPT(pexExcept::OverflowError, "Cannot normalize; kernel sum is 0");
255  }
256  image /= imSum;
257  imSum = 1;
258  }
259 
260  return imSum;
261 }
void scaledPlus(double const c, Image< PixelT >const &rhs)
Add Image c*rhs to lhs.
Definition: Image.cc:677
std::vector< double > _kernelParams
Definition: Kernel.h:953
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:950
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
afwMath::KernelList const & lsst::afw::math::LinearCombinationKernel::getKernelList ( ) const
virtual

Get the fixed basis kernels.

Definition at line 144 of file LinearCombinationKernel.cc.

144  {
145  return _kernelList;
146 }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
std::vector< double > lsst::afw::math::LinearCombinationKernel::getKernelParameters ( ) const
virtual

Return the current kernel parameters.

If the kernel is spatially varying then the parameters are those last computed. See also computeKernelParametersFromSpatialModel. If there are no kernel parameters then returns an empty vector.

Reimplemented from lsst::afw::math::Kernel.

Definition at line 152 of file LinearCombinationKernel.cc.

152  {
153  return _kernelParams;
154 }
std::vector< double > _kernelParams
Definition: Kernel.h:953
std::vector< double > lsst::afw::math::LinearCombinationKernel::getKernelSumList ( ) const

Get the sum of the pixels of each fixed basis kernel.

Definition at line 148 of file LinearCombinationKernel.cc.

148  {
149  return _kernelSumList;
150 }
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
int lsst::afw::math::LinearCombinationKernel::getNBasisKernels ( ) const
inline

Get the number of basis kernels.

Definition at line 875 of file Kernel.h.

875 { return static_cast<int>(_kernelList.size()); };
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
std::string lsst::afw::math::LinearCombinationKernel::getPersistenceName ( ) const
protectedvirtual

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 367 of file LinearCombinationKernel.cc.

367  {
368  return getLinearCombinationKernelPersistenceName();
369 }
bool lsst::afw::math::LinearCombinationKernel::isDeltaFunctionBasis ( ) const
inline

Return true if all basis kernels are instances of DeltaFunctionKernel

Definition at line 887 of file Kernel.h.

virtual bool lsst::afw::math::LinearCombinationKernel::isPersistable ( ) const
inlinevirtual

Return true if this particular object can be persisted using afw::table::io.

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

Definition at line 927 of file Kernel.h.

927 { return true; }
boost::shared_ptr< afwMath::Kernel > lsst::afw::math::LinearCombinationKernel::refactor ( ) const

Refactor the kernel as a linear combination of N bases where N is the number of parameters for the spatial model.

Refactoring is only possible if all of the following are true:

  • Kernel is spatially varying
  • The spatial functions are a linear combination of coefficients (return isLinearCombination() true).
  • The spatial functions all are the same class (and so have the same functional form) Refactoring produces a kernel that is faster to compute only if the number of basis kernels is greater than the number of parameters in the spatial model.

Details: A spatially varying LinearCombinationKernel consisting of M basis kernels and using a spatial model that is a linear combination of N coefficients can be expressed as: K(x,y) = K0 (C00 F0(x,y) + C10 F1(x,y) + C20 F2(x,y) + ... + CN0 FN(x,y))

  • K1 (C01 F0(x,y) + C11 F1(x,y) + C21 F2(x,y) + ... + CN1 FN(x,y))
  • K2 (C02 F0(x,y) + C12 F1(x,y) + C22 F2(x,y) + ... + CN2 FN(x,y))
  • ...
  • KM (C0M F0(x,y) + C1M F1(x,y) + C2M F2(x,y) + ... + CNM FN(x,y))

This is equivalent to the following linear combination of N basis kernels:

    =      K0' F0(x,y) + K1' F1(x,y) + K2' F2(x,y) + ... + KN' FN(x,y)

      where Ki' = sum over j of Kj Cij

This is what refactor returns provided the required conditions are met. However, the spatial functions for the refactored kernel are the same as those for the original kernel (for generality and simplicity) with all coefficients equal to 0 except one that is set to 1; hence they are not computed optimally.

Thanks to Kresimir Cosic for inventing or reinventing this useful technique.

Returns
a shared pointer to new kernel, or empty pointer if refactoring not possible

Definition at line 156 of file LinearCombinationKernel.cc.

156  {
157  if (!this->isSpatiallyVarying()) {
158  return PTR(Kernel)();
159  }
160  Kernel::SpatialFunctionPtr const firstSpFuncPtr = this->_spatialFunctionList[0];
161  if (!firstSpFuncPtr->isLinearCombination()) {
162  return PTR(Kernel)();
163  }
164 
165  typedef lsst::afw::image::Image<Kernel::Pixel> KernelImage;
166  typedef boost::shared_ptr<KernelImage> KernelImagePtr;
167  typedef std::vector<KernelImagePtr> KernelImageList;
168 
169  // create kernel images for new refactored basis kernels
170  int const nSpatialParameters = this->getNSpatialParameters();
171  KernelImageList newKernelImagePtrList;
172  newKernelImagePtrList.reserve(nSpatialParameters);
173  for (int i = 0; i < nSpatialParameters; ++i) {
174  KernelImagePtr kernelImagePtr(new KernelImage(this->getDimensions()));
175  newKernelImagePtrList.push_back(kernelImagePtr);
176  }
177  KernelImage kernelImage(this->getDimensions());
178  std::vector<Kernel::SpatialFunctionPtr>::const_iterator spFuncPtrIter =
179  this->_spatialFunctionList.begin();
180  afwMath::KernelList::const_iterator kIter = _kernelList.begin();
181  afwMath::KernelList::const_iterator const kEnd = _kernelList.end();
182  for ( ; kIter != kEnd; ++kIter, ++spFuncPtrIter) {
183  if (typeid(**spFuncPtrIter) != typeid(*firstSpFuncPtr)) {
184  return PTR(Kernel)();
185  }
186 
187  (**kIter).computeImage(kernelImage, false);
188  for (int i = 0; i < nSpatialParameters; ++i) {
189  double spParam = (*spFuncPtrIter)->getParameter(i);
190  newKernelImagePtrList[i]->scaledPlus(spParam, kernelImage);
191  }
192  }
193 
194  // create new kernel; the basis kernels are fixed kernels computed above
195  // and the corresponding spatial model is the same function as the original kernel,
196  // but with all coefficients zero except coeff_i = 1.0
197  afwMath::KernelList newKernelList;
198  newKernelList.reserve(nSpatialParameters);
199  KernelImageList::iterator newKImPtrIter = newKernelImagePtrList.begin();
200  KernelImageList::iterator const newKImPtrEnd = newKernelImagePtrList.end();
201  for ( ; newKImPtrIter != newKImPtrEnd; ++newKImPtrIter) {
202  newKernelList.push_back(PTR(Kernel)(new afwMath::FixedKernel(**newKImPtrIter)));
203  }
204  std::vector<SpatialFunctionPtr> newSpFunctionPtrList;
205  for (int i = 0; i < nSpatialParameters; ++i) {
206  std::vector<double> newSpParameters(nSpatialParameters, 0.0);
207  newSpParameters[i] = 1.0;
208  SpatialFunctionPtr newSpFunctionPtr = firstSpFuncPtr->clone();
209  newSpFunctionPtr->setParameters(newSpParameters);
210  newSpFunctionPtrList.push_back(newSpFunctionPtr);
211  }
212  PTR(LinearCombinationKernel) refactoredKernel(
213  new LinearCombinationKernel(newKernelList, newSpFunctionPtrList));
214  refactoredKernel->setCtr(this->getCtr());
215  return refactoredKernel;
216 }
boost::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
Definition: Kernel.h:143
geom::Extent2I const getDimensions() const
Return the Kernel&#39;s dimensions (width, height)
Definition: Kernel.h:226
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
Definition: Kernel.h:296
#define PTR(...)
Definition: base.h:41
LinearCombinationKernel()
Construct an empty LinearCombinationKernel of size 0x0.
void setCtr(lsst::afw::geom::Point2I ctr)
Set index of kernel&#39;s center.
Definition: Kernel.h:361
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:254
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:524
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
A kernel created from an Image.
Definition: Kernel.h:551
std::vector< boost::shared_ptr< Kernel > > KernelList
Definition: Kernel.h:542
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:402
template<class Archive >
void lsst::afw::math::LinearCombinationKernel::serialize ( Archive &  ar,
unsigned int const  version 
)
inlineprivate

Definition at line 958 of file Kernel.h.

958  {
959  ar & make_nvp("k", boost::serialization::base_object<Kernel>(*this));
960  ar & make_nvp("klist", _kernelList);
961  ar & make_nvp("kimglist", _kernelImagePtrList);
962  ar & make_nvp("ksumlist", _kernelSumList);
963  ar & make_nvp("params", _kernelParams);
964  if (version > 0) {
965  ar & make_nvp("deltaBasis", _isDeltaFunctionBasis);
966  }
967  else if (Archive::is_loading::value) {
968  _isDeltaFunctionBasis = false;
969  }
970  }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
std::vector< double > _kernelParams
Definition: Kernel.h:953
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
Definition: Kernel.h:950
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Definition: Kernel.h:952
void lsst::afw::math::LinearCombinationKernel::setKernelParameter ( unsigned int  ind,
double  value 
) const
protectedvirtual

Set one kernel parameter.

Classes that have kernel parameters must subclass this function.

This function is marked "const", despite modifying unimportant internals, so that computeImage can be const.

Exceptions
lsst::pex::exceptions::InvalidParameterErroralways (unless subclassed)

Reimplemented from lsst::afw::math::Kernel.

Definition at line 263 of file LinearCombinationKernel.cc.

263  {
264  this->_kernelParams[ind] = value;
265 }
std::vector< double > _kernelParams
Definition: Kernel.h:953
std::string lsst::afw::math::LinearCombinationKernel::toString ( std::string const &  prefix = "") const
virtual

Return a string representation of the kernel.

Reimplemented from lsst::afw::math::Kernel.

Definition at line 218 of file LinearCombinationKernel.cc.

218  {
219  std::ostringstream os;
220  os << prefix << "LinearCombinationKernel:" << std::endl;
221  os << prefix << "..Kernels:" << std::endl;
222  for (KernelList::const_iterator i = _kernelList.begin(); i != _kernelList.end(); ++i) {
223  os << (*i)->toString(prefix + "\t");
224  }
225  os << "..parameters: [ ";
226  for (std::vector<double>::const_iterator i = _kernelParams.begin(); i != _kernelParams.end(); ++i) {
227  if (i != _kernelParams.begin()) os << ", ";
228  os << *i;
229  }
230  os << " ]" << std::endl;
231  os << Kernel::toString(prefix + "\t");
232  return os.str();
233 }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:224
std::vector< double > _kernelParams
Definition: Kernel.h:953
void lsst::afw::math::LinearCombinationKernel::write ( OutputArchiveHandle handle) const
protectedvirtual

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 371 of file LinearCombinationKernel.cc.

371  {
372  bool isVarying = isSpatiallyVarying();
373  LinearCombinationKernelPersistenceHelper const keys(getNBasisKernels(), isVarying);
374  PTR(afw::table::BaseRecord) record = keys.write(handle, *this);
375  if (isVarying) {
376  for (int n = 0; n < keys.components.getSize(); ++n) {
377  record->set(keys.components[n], handle.put(_kernelList[n]));
378  record->set(keys.spatialFunctions[n], handle.put(_spatialFunctionList[n]));
379  }
380  } else {
381  for (int n = 0; n < keys.components.getSize(); ++n) {
382  record->set(keys.components[n], handle.put(_kernelList[n]));
383  record->set(keys.amplitudes[n], _kernelParams[n]);
384  }
385  }
386 }
KernelList _kernelList
basis kernels
Definition: Kernel.h:949
#define PTR(...)
Definition: base.h:41
int getNBasisKernels() const
Get the number of basis kernels.
Definition: Kernel.h:875
std::vector< double > _kernelParams
Definition: Kernel.h:953
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:524
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:402

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 956 of file Kernel.h.

Member Data Documentation

bool lsst::afw::math::LinearCombinationKernel::_isDeltaFunctionBasis
private

Definition at line 954 of file Kernel.h.

std::vector<boost::shared_ptr< lsst::afw::image::Image<Pixel> > > lsst::afw::math::LinearCombinationKernel::_kernelImagePtrList
private

image of each basis kernel (a cache)

Definition at line 950 of file Kernel.h.

KernelList lsst::afw::math::LinearCombinationKernel::_kernelList
private

basis kernels

Definition at line 949 of file Kernel.h.

std::vector<double> lsst::afw::math::LinearCombinationKernel::_kernelParams
mutableprivate

Definition at line 953 of file Kernel.h.

std::vector<double> lsst::afw::math::LinearCombinationKernel::_kernelSumList
private

sum of each basis kernel (a cache)

Definition at line 952 of file Kernel.h.


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