LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
Public Types | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
lsst.afw.math::SeparableKernel Class Reference

A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y) More...

#include <Kernel.h>

Inheritance diagram for lsst.afw.math::SeparableKernel:
lsst.afw.table.io::PersistableFacade< SeparableKernel > lsst.afw.math::Kernel lsst::daf::base::Citizen lsst::daf::base::Persistable lsst.afw.table.io::PersistableFacade< Kernel > lsst.afw.table.io::Persistable lsst.afw.math::BilinearWarpingKernel lsst.afw.math::LanczosWarpingKernel lsst.afw.math::NearestWarpingKernel

Public Types

typedef boost::shared_ptr
< SeparableKernel
Ptr
 
typedef boost::shared_ptr
< SeparableKernel const > 
ConstPtr
 
typedef
lsst::afw::math::Function1
< Pixel
KernelFunction
 
typedef boost::shared_ptr
< KernelFunction
KernelFunctionPtr
 
- 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

 SeparableKernel ()
 Construct an empty spatially invariant SeparableKernel of size 0x0. More...
 
 SeparableKernel (int width, int height, KernelFunction const &kernelColFunction, KernelFunction const &kernelRowFunction, Kernel::SpatialFunction const &spatialFunction=NullSpatialFunction())
 Construct a spatially invariant SeparableKernel, or a spatially varying SeparableKernel that uses the same functional form to model each function parameter. More...
 
 SeparableKernel (int width, int height, KernelFunction const &kernelColFunction, KernelFunction const &kernelRowFunction, std::vector< Kernel::SpatialFunctionPtr > const &spatialFunctionList)
 Construct a spatially varying SeparableKernel. More...
 
virtual ~SeparableKernel ()
 
virtual boost::shared_ptr< Kernelclone () const
 Return a pointer to a deep copy of this kernel. More...
 
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) More...
 
virtual double getKernelParameter (unsigned int i) const
 
virtual std::vector< double > getKernelParameters () const
 Return the current kernel parameters. More...
 
KernelFunctionPtr getKernelColFunction () const
 Get a deep copy of the col kernel function. More...
 
KernelFunctionPtr getKernelRowFunction () const
 Get a deep copy of the row kernel function. More...
 
virtual std::string toString (std::string const &prefix="") const
 Return a string representation of the kernel. More...
 
virtual void computeCache (int const cacheSize)
 Compute a cache of Kernel values, if desired. More...
 
virtual int getCacheSize () const
 Get the current cache size (0 if none) 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...
 
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...
 
- 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 bool isPersistable () const
 Return true if this particular object can be persisted using afw::table::io. 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 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
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...
 
 Persistable ()
 
 Persistable (Persistable const &other)
 
void operator= (Persistable const &other)
 

Private Member Functions

double basicComputeVectors (std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize) const
 Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row) More...
 
template<class Archive >
void serialize (Archive &ar, unsigned int const version)
 
virtual void _setKernelXY ()
 

Private Attributes

KernelFunctionPtr _kernelColFunctionPtr
 
KernelFunctionPtr _kernelRowFunctionPtr
 
std::vector< Pixel_localColList
 
std::vector< Pixel_localRowList
 
std::vector< double > _kernelX
 
std::vector< double > _kernelY
 
std::vector< std::vector
< double > > 
_kernelRowCache
 
std::vector< std::vector
< double > > 
_kernelColCache
 

Friends

class boost::serialization::access
 

Additional Inherited Members

- Static Public Member Functions inherited from lsst.afw.table.io::PersistableFacade< SeparableKernel >
static boost::shared_ptr
< SeparableKernel > 
readFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static boost::shared_ptr
< SeparableKernel > 
readFits (std::string const &fileName, int hdu=0)
 Read an object from a regular FITS file. More...
 
static boost::shared_ptr
< SeparableKernel > 
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 described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)

The function's x, y arguments are as follows:

Note: each pixel is set to the value of the kernel function at the center of the pixel (rather than averaging the function over the area of the pixel).

Definition at line 986 of file Kernel.h.

Member Typedef Documentation

typedef boost::shared_ptr< SeparableKernel const> lsst.afw.math::SeparableKernel::ConstPtr

Definition at line 989 of file Kernel.h.

Definition at line 990 of file Kernel.h.

Definition at line 991 of file Kernel.h.

Definition at line 988 of file Kernel.h.

Constructor & Destructor Documentation

lsst.afw.math::SeparableKernel::SeparableKernel ( )
explicit

Construct an empty spatially invariant SeparableKernel of size 0x0.

Definition at line 35 of file SeparableKernel.cc.

36 :
37  Kernel(),
41  _kernelX(0), _kernelY(0),
43 {
44  _setKernelXY();
45 }
std::vector< double > _kernelY
Definition: Kernel.h:1118
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
std::vector< Pixel > _localRowList
Definition: Kernel.h:1116
std::vector< std::vector< double > > _kernelColCache
Definition: Kernel.h:1123
std::vector< Pixel > _localColList
Definition: Kernel.h:1115
std::vector< double > _kernelX
Definition: Kernel.h:1117
std::vector< std::vector< double > > _kernelRowCache
Definition: Kernel.h:1122
virtual void _setKernelXY()
Definition: Kernel.h:1138
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
lsst.afw.math::SeparableKernel::SeparableKernel ( int  width,
int  height,
KernelFunction const &  kernelColFunction,
KernelFunction const &  kernelRowFunction,
Kernel::SpatialFunction const &  spatialFunction = NullSpatialFunction() 
)
explicit

Construct a spatially invariant SeparableKernel, or a spatially varying SeparableKernel that uses the same functional form to model each function parameter.

Parameters
widthwidth of kernel
heightheight of kernel
kernelColFunctionkernel column function
kernelRowFunctionkernel row function
spatialFunctionspatial function; one deep copy is made for each kernel column and row function parameter; if omitted or set to Kernel::NullSpatialFunction then the kernel is spatially invariant

Definition at line 47 of file SeparableKernel.cc.

53  :
54  Kernel(width, height, kernelColFunction.getNParameters() + kernelRowFunction.getNParameters(),
55  spatialFunction),
56  _kernelColFunctionPtr(kernelColFunction.clone()),
57  _kernelRowFunctionPtr(kernelRowFunction.clone()),
58  _localColList(width), _localRowList(height),
59  _kernelX(width), _kernelY(height),
61 {
62  _setKernelXY();
63 }
std::vector< double > _kernelY
Definition: Kernel.h:1118
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
std::vector< Pixel > _localRowList
Definition: Kernel.h:1116
std::vector< std::vector< double > > _kernelColCache
Definition: Kernel.h:1123
std::vector< Pixel > _localColList
Definition: Kernel.h:1115
std::vector< double > _kernelX
Definition: Kernel.h:1117
std::vector< std::vector< double > > _kernelRowCache
Definition: Kernel.h:1122
virtual void _setKernelXY()
Definition: Kernel.h:1138
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
lsst.afw.math::SeparableKernel::SeparableKernel ( int  width,
int  height,
KernelFunction const &  kernelColFunction,
KernelFunction const &  kernelRowFunction,
std::vector< Kernel::SpatialFunctionPtr > const &  spatialFunctionList 
)
explicit

Construct a spatially varying SeparableKernel.

Exceptions
lsst::pex::exceptions::InvalidParameterErrorif the length of spatialFunctionList != # kernel function parameters.
Parameters
widthwidth of kernel
heightheight of kernel
kernelColFunctionkernel column function
kernelRowFunctionkernel row function
spatialFunctionListlist of spatial funcs, one per kernel column and row function parameter; a deep copy is made of each function

Definition at line 65 of file SeparableKernel.cc.

71  :
72  Kernel(width, height, spatialFunctionList),
73  _kernelColFunctionPtr(kernelColFunction.clone()),
74  _kernelRowFunctionPtr(kernelRowFunction.clone()),
75  _localColList(width), _localRowList(height),
76  _kernelX(width), _kernelY(height),
78 {
79  if (kernelColFunction.getNParameters() + kernelRowFunction.getNParameters()
80  != spatialFunctionList.size()) {
81  std::ostringstream os;
82  os << "kernelColFunction.getNParameters() + kernelRowFunction.getNParameters() = "
83  << kernelColFunction.getNParameters() << " + " << kernelRowFunction.getNParameters()
84  << " != " << spatialFunctionList.size() << " = " << "spatialFunctionList.size()";
85  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
86  }
87 
88  _setKernelXY();
89 }
std::vector< double > _kernelY
Definition: Kernel.h:1118
Kernel()
Construct a null Kernel of size 0,0.
Definition: Kernel.cc:51
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
std::vector< Pixel > _localRowList
Definition: Kernel.h:1116
std::vector< std::vector< double > > _kernelColCache
Definition: Kernel.h:1123
std::vector< Pixel > _localColList
Definition: Kernel.h:1115
std::vector< double > _kernelX
Definition: Kernel.h:1117
std::vector< std::vector< double > > _kernelRowCache
Definition: Kernel.h:1122
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
virtual void _setKernelXY()
Definition: Kernel.h:1138
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
virtual lsst.afw.math::SeparableKernel::~SeparableKernel ( )
inlinevirtual

Definition at line 1026 of file Kernel.h.

1026 {}

Member Function Documentation

virtual void lsst.afw.math::SeparableKernel::_setKernelXY ( )
inlineprivatevirtual

Reimplemented from lsst.afw.math::Kernel.

Definition at line 1138 of file Kernel.h.

1138  {
1140  lsst::afw::geom::Point2I const ctr = getCtr();
1141 
1142  assert (dim[0] == static_cast<int>(_kernelX.size()));
1143  for (int i = 0; i != dim.getX(); ++i) {
1144  _kernelX[i] = i - ctr.getX();
1145  }
1146 
1147  assert (dim[1] == static_cast<int>(_kernelY.size()));
1148  for (int i = 0; i != dim.getY(); ++i) {
1149  _kernelY[i] = i - ctr.getY();
1150  }
1151  }
std::vector< double > _kernelY
Definition: Kernel.h:1118
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:254
std::vector< double > _kernelX
Definition: Kernel.h:1117
geom::Extent2I const getDimensions() const
Return the Kernel&#39;s dimensions (width, height)
Definition: Kernel.h:226
double lsst.afw.math::SeparableKernel::basicComputeVectors ( std::vector< Pixel > &  colList,
std::vector< Pixel > &  rowList,
bool  doNormalize 
) const
private

Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row)

Returns
the kernel sum (1.0 if doNormalize true)

Warning: the length of colList and rowList are not verified!

Exceptions
lsst::pex::exceptions::OverflowErrorif doNormalize is true and the kernel sum is exactly 0
Parameters
colListcolumn vector
rowListrow vector
doNormalizenormalize the arrays (so sum of each is 1)?

Definition at line 190 of file SeparableKernel.cc.

194  {
195  double colSum = 0.0;
196  if (_kernelColCache.empty()) {
197  for (unsigned int i = 0; i != colList.size(); ++i) {
198  double colFuncValue = (*_kernelColFunctionPtr)(_kernelX[i]);
199  colList[i] = colFuncValue;
200  colSum += colFuncValue;
201  }
202  } else {
203  int const cacheSize = _kernelColCache.size();
204 
205  int const indx = this->getKernelParameter(0)*cacheSize;
206 
207  std::vector<double> &cachedValues = _kernelColCache.at(indx);
208  for (unsigned int i = 0; i != colList.size(); ++i) {
209  double colFuncValue = cachedValues[i];
210  colList[i] = colFuncValue;
211  colSum += colFuncValue;
212  }
213  }
214 
215  double rowSum = 0.0;
216  if (_kernelRowCache.empty()) {
217  for (unsigned int i = 0; i != rowList.size(); ++i) {
218  double rowFuncValue = (*_kernelRowFunctionPtr)(_kernelY[i]);
219  rowList[i] = rowFuncValue;
220  rowSum += rowFuncValue;
221  }
222  } else {
223  int const cacheSize = _kernelRowCache.size();
224 
225  int const indx = this->getKernelParameter(1)*cacheSize;
226 
227  std::vector<double> &cachedValues = _kernelRowCache.at(indx);
228  for (unsigned int i = 0; i != rowList.size(); ++i) {
229  double rowFuncValue = cachedValues[i];
230  rowList[i] = rowFuncValue;
231  rowSum += rowFuncValue;
232 
233 #if 0
234  if (indx == cacheSize/2) {
235  if (::fabs(rowFuncValue - (*_kernelRowFunctionPtr)(_kernelX[i])) > 1e-2) {
236  std::cout << indx << " " << i << " "
237  << rowFuncValue << " "
238  << (*_kernelRowFunctionPtr)(_kernelX[i])
239  << std::endl;
240  }
241  }
242 #endif
243  }
244  }
245 
246  double imSum = colSum * rowSum;
247  if (doNormalize) {
248  if ((colSum == 0) || (rowSum == 0)) {
249  throw LSST_EXCEPT(pexExcept::OverflowError, "Cannot normalize; kernel sum is 0");
250  }
251  for (std::vector<Pixel>::iterator colIter = colList.begin(); colIter != colList.end(); ++colIter) {
252  *colIter /= colSum;
253  }
254 
255  for (std::vector<Pixel>::iterator rowIter = rowList.begin(); rowIter != rowList.end(); ++rowIter) {
256  *rowIter /= rowSum;
257  }
258  imSum = 1.0;
259  }
260  return imSum;
261 }
std::vector< double > _kernelY
Definition: Kernel.h:1118
std::vector< std::vector< double > > _kernelColCache
Definition: Kernel.h:1123
tbl::Key< int > cacheSize
Definition: CoaddPsf.cc:318
std::vector< double > _kernelX
Definition: Kernel.h:1117
std::vector< std::vector< double > > _kernelRowCache
Definition: Kernel.h:1122
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
virtual double getKernelParameter(unsigned int i) const
Definition: Kernel.h:1049
boost::shared_ptr< afwMath::Kernel > lsst.afw.math::SeparableKernel::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.

Reimplemented in lsst.afw.math::NearestWarpingKernel, lsst.afw.math::BilinearWarpingKernel, and lsst.afw.math::LanczosWarpingKernel.

Definition at line 91 of file SeparableKernel.cc.

91  {
92  PTR(afwMath::Kernel) retPtr;
93  if (this->isSpatiallyVarying()) {
94  retPtr.reset(new afwMath::SeparableKernel(this->getWidth(), this->getHeight(),
96  } else {
97  retPtr.reset(new afwMath::SeparableKernel(this->getWidth(), this->getHeight(),
98  *(this->_kernelColFunctionPtr), *(this->_kernelRowFunctionPtr)));
99  }
100  retPtr->setCtr(this->getCtr());
101  retPtr->computeCache(this->getCacheSize());
102  return retPtr;
103 }
virtual int getCacheSize() const
Get the current cache size (0 if none)
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:240
#define PTR(...)
Definition: base.h:41
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:247
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
std::vector< SpatialFunctionPtr > _spatialFunctionList
Definition: Kernel.h:524
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:986
lsst::afw::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:254
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:402
virtual void computeCache(int const )
Compute a cache of Kernel values, if desired.
Definition: Kernel.h:469
if(width!=gim.getWidth()||height!=gim.getHeight()||x0!=gim.getX0()||y0!=gim.getY0())
Definition: saturated.cc:47
void setCtr(lsst::afw::geom::Point2I ctr)
Set index of kernel&#39;s center.
Definition: Kernel.h:361
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134
void lsst.afw.math::SeparableKernel::computeCache ( int const  const)
virtual

Compute a cache of Kernel values, if desired.

Warning
: few kernel classes actually support this, in which case this is a no-op and getCacheSize always returns 0.
Parameters
constcache size (number of double precision array elements in the x and y caches)

Reimplemented from lsst.afw.math::Kernel.

Definition at line 308 of file SeparableKernel.cc.

310  {
312 
313  func = getKernelColFunction();
314  _computeCache(cacheSize, _kernelY, func, &_kernelColCache);
315 
316  func = getKernelRowFunction();
317  _computeCache(cacheSize, _kernelX, func, &_kernelRowCache);
318 }
std::vector< double > _kernelY
Definition: Kernel.h:1118
std::vector< std::vector< double > > _kernelColCache
Definition: Kernel.h:1123
tbl::Key< int > cacheSize
Definition: CoaddPsf.cc:318
std::vector< double > _kernelX
Definition: Kernel.h:1117
std::vector< std::vector< double > > _kernelRowCache
Definition: Kernel.h:1122
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
boost::shared_ptr< KernelFunction > KernelFunctionPtr
Definition: Kernel.h:991
double lsst.afw.math::SeparableKernel::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)

x, y are ignored if there is no spatial function.

Returns
the kernel sum (1.0 if doNormalize true)
Exceptions
lsst::pex::exceptions::InvalidParameterErrorif colList or rowList is the wrong size
lsst::pex::exceptions::OverflowErrorif doNormalize is true and the kernel sum is exactly 0
Parameters
colListcolumn vector
rowListrow vector
doNormalizenormalize the image (so sum of each is 1)?
xx (column position) at which to compute spatial function
yy (row position) at which to compute spatial function

Definition at line 105 of file SeparableKernel.cc.

111  {
112  if (static_cast<int>(colList.size()) != this->getWidth()
113  || static_cast<int>(rowList.size()) != this->getHeight()) {
114  std::ostringstream os;
115  os << "colList.size(), rowList.size() = ("
116  << colList.size() << ", " << rowList.size()
117  << ") != ("<< this->getWidth() << ", " << this->getHeight()
118  << ") = " << "kernel dimensions";
119  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
120  }
121  if (this->isSpatiallyVarying()) {
123  }
124 
125  return basicComputeVectors(colList, rowList, doNormalize);
126 }
int y
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:240
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
Definition: Kernel.cc:257
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:247
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
Definition: Kernel.h:402
int x
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
double basicComputeVectors(std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize) const
Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row) ...
double lsst.afw.math::SeparableKernel::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 160 of file SeparableKernel.cc.

163  {
164  double imSum = basicComputeVectors(_localColList, _localRowList, doNormalize);
165 
166  for (int y = 0; y != image.getHeight(); ++y) {
168  for (std::vector<Pixel>::iterator colIter = _localColList.begin();
169  colIter != _localColList.end(); ++colIter, ++imPtr) {
170  *imPtr = (*colIter)*_localRowList[y];
171  }
172  }
173 
174  return imSum;
175 }
int y
x_iterator row_begin(int y) const
Definition: Image.h:319
std::vector< Pixel > _localRowList
Definition: Kernel.h:1116
std::vector< Pixel > _localColList
Definition: Kernel.h:1115
double basicComputeVectors(std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize) const
Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row) ...
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:239
A class to represent a 2-dimensional array of pixels.
Definition: PSF.h:43
int lsst.afw.math::SeparableKernel::getCacheSize ( ) const
virtual

Get the current cache size (0 if none)

Reimplemented from lsst.afw.math::Kernel.

Definition at line 320 of file SeparableKernel.cc.

320  {
321  return _kernelColCache.size();
322 };
std::vector< std::vector< double > > _kernelColCache
Definition: Kernel.h:1123
afwMath::SeparableKernel::KernelFunctionPtr lsst.afw.math::SeparableKernel::getKernelColFunction ( ) const

Get a deep copy of the col kernel function.

Definition at line 128 of file SeparableKernel.cc.

129  {
130  return _kernelColFunctionPtr->clone();
131 }
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
virtual double lsst.afw.math::SeparableKernel::getKernelParameter ( unsigned int  i) const
inlinevirtual

Return a particular Kernel Parameter (no bounds checking). This version is slow, but specialisations may be faster

Reimplemented from lsst.afw.math::Kernel.

Definition at line 1049 of file Kernel.h.

1049  {
1050  unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
1051  if (i < ncol) {
1052  return _kernelColFunctionPtr->getParameter(i);
1053  } else {
1054  i -= ncol;
1055  return _kernelRowFunctionPtr->getParameter(i);
1056  }
1057  }
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
std::vector< double > lsst.afw.math::SeparableKernel::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 149 of file SeparableKernel.cc.

149  {
150  std::vector<double> allParams = _kernelColFunctionPtr->getParameters();
151  std::vector<double> yParams = _kernelRowFunctionPtr->getParameters();
152  std::copy(yParams.begin(), yParams.end(), std::back_inserter(allParams));
153  return allParams;
154 }
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
SelectEigenView< T >::Type copy(Eigen::EigenBase< T > const &other)
Copy an arbitrary Eigen expression into a new EigenView.
Definition: eigen.h:390
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
afwMath::SeparableKernel::KernelFunctionPtr lsst.afw.math::SeparableKernel::getKernelRowFunction ( ) const

Get a deep copy of the row kernel function.

Definition at line 133 of file SeparableKernel.cc.

134  {
135  return _kernelRowFunctionPtr->clone();
136 }
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
template<class Archive >
void lsst.afw.math::SeparableKernel::serialize ( Archive &  ar,
unsigned int const  version 
)
inlineprivate

Definition at line 1127 of file Kernel.h.

1127  {
1128  ar & make_nvp("k",
1129  boost::serialization::base_object<Kernel>(*this));
1130  ar & make_nvp("colfn", _kernelColFunctionPtr);
1131  ar & make_nvp("rowfn", _kernelRowFunctionPtr);
1132  ar & make_nvp("cols", _localColList);
1133  ar & make_nvp("rows", _localRowList);
1134  ar & make_nvp("kernelX", _kernelX);
1135  ar & make_nvp("kernelY", _kernelY);
1136  }
std::vector< double > _kernelY
Definition: Kernel.h:1118
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
std::vector< Pixel > _localRowList
Definition: Kernel.h:1116
std::vector< Pixel > _localColList
Definition: Kernel.h:1115
std::vector< double > _kernelX
Definition: Kernel.h:1117
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
void lsst.afw.math::SeparableKernel::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.

Reimplemented in lsst.afw.math::NearestWarpingKernel, lsst.afw.math::BilinearWarpingKernel, and lsst.afw.math::LanczosWarpingKernel.

Definition at line 177 of file SeparableKernel.cc.

177  {
178  unsigned int const nColParams = _kernelColFunctionPtr->getNParameters();
179  if (ind < nColParams) {
180  _kernelColFunctionPtr->setParameter(ind, value);
181  } else {
182  _kernelRowFunctionPtr->setParameter(ind - nColParams, value);
183  }
184 }
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114
std::string lsst.afw.math::SeparableKernel::toString ( std::string const &  prefix = "") const
virtual

Return a string representation of the kernel.

Reimplemented from lsst.afw.math::Kernel.

Definition at line 138 of file SeparableKernel.cc.

138  {
139  std::ostringstream os;
140  os << prefix << "SeparableKernel:" << std::endl;
141  os << prefix << "..x (width) function: "
142  << (_kernelColFunctionPtr ? _kernelColFunctionPtr->toString() : "None") << std::endl;
143  os << prefix << "..y (rows) function: "
144  << (_kernelRowFunctionPtr ? _kernelRowFunctionPtr->toString() : "None") << std::endl;
145  os << Kernel::toString(prefix + "\t");
146  return os.str();
147 }
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:224
KernelFunctionPtr _kernelColFunctionPtr
Definition: Kernel.h:1113
KernelFunctionPtr _kernelRowFunctionPtr
Definition: Kernel.h:1114

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 1125 of file Kernel.h.

Member Data Documentation

std::vector<std::vector<double> > lsst.afw.math::SeparableKernel::_kernelColCache
mutableprivate

Definition at line 1123 of file Kernel.h.

KernelFunctionPtr lsst.afw.math::SeparableKernel::_kernelColFunctionPtr
private

Definition at line 1113 of file Kernel.h.

std::vector<std::vector<double> > lsst.afw.math::SeparableKernel::_kernelRowCache
mutableprivate

Definition at line 1122 of file Kernel.h.

KernelFunctionPtr lsst.afw.math::SeparableKernel::_kernelRowFunctionPtr
private

Definition at line 1114 of file Kernel.h.

std::vector<double> lsst.afw.math::SeparableKernel::_kernelX
mutableprivate

Definition at line 1117 of file Kernel.h.

std::vector<double> lsst.afw.math::SeparableKernel::_kernelY
mutableprivate

Definition at line 1118 of file Kernel.h.

std::vector<Pixel> lsst.afw.math::SeparableKernel::_localColList
mutableprivate

Definition at line 1115 of file Kernel.h.

std::vector<Pixel> lsst.afw.math::SeparableKernel::_localRowList
mutableprivate

Definition at line 1116 of file Kernel.h.


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