30 namespace pexExcept = lsst::pex::exceptions;
31 namespace afwGeom = lsst::afw::geom;
32 namespace afwMath = lsst::afw::math;
47 Kernel(width, height, kernelFunction.getNParameters(), spatialFunction),
48 _kernelFunctionPtr(kernelFunction.clone())
55 std::vector<Kernel::SpatialFunctionPtr>
const &spatialFunctionList
57 Kernel(width, height, spatialFunctionList),
58 _kernelFunctionPtr(kernelFunction.clone())
60 if (kernelFunction.
getNParameters() != spatialFunctionList.size()) {
61 std::ostringstream os;
62 os <<
"kernelFunction.getNParameters() = " << kernelFunction.
getNParameters()
63 <<
" != " << spatialFunctionList.size() <<
" = " <<
"spatialFunctionList.size()";
64 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
70 if (this->isSpatiallyVarying()) {
72 *(this->_kernelFunctionPtr), this->_spatialFunctionList));
75 *(this->_kernelFunctionPtr)));
77 retPtr->setCtr(this->getCtr());
89 if (this->isSpatiallyVarying()) {
90 this->setKernelParametersFromSpatialModel(x, y);
92 return doComputeImage(image, doNormalize);
97 return _kernelFunctionPtr->clone();
101 std::ostringstream os;
102 os << prefix <<
"AnalyticKernel:" << std::endl;
103 os << prefix <<
"..function: " << (_kernelFunctionPtr ? _kernelFunctionPtr->toString() :
"None")
110 return _kernelFunctionPtr->getParameters();
124 for (
int x = 0;
x != image.
getWidth(); ++
x, ++ptr) {
126 Pixel const pixelVal = (*_kernelFunctionPtr)(fx, fy);
132 if (doNormalize && (imSum != 1)) {
134 throw LSST_EXCEPT(pexExcept::OverflowError,
"Cannot normalize; kernel sum is 0");
144 _kernelFunctionPtr->setParameter(ind, value);
149 namespace lsst {
namespace afw {
namespace math {
156 explicit AnalyticKernelPersistenceHelper(
int nSpatialFunctions) :
157 Kernel::PersistenceHelper(nSpatialFunctions),
160 "kernelfunction",
"archive ID for analytic function used to produce kernel images"
165 explicit AnalyticKernelPersistenceHelper(table::Schema
const & schema_) :
166 Kernel::PersistenceHelper(schema_),
180 AnalyticKernelPersistenceHelper
const keys(catalogs.front().getSchema());
185 if (keys.spatialFunctions.isValid()) {
186 result = boost::make_shared<AnalyticKernel>(
187 record.get(keys.dimensions.getX()), record.get(keys.dimensions.getY()), *
kernelFunction,
188 keys.readSpatialFunctions(archive, record)
191 result = boost::make_shared<AnalyticKernel>(
192 record.get(keys.dimensions.getX()), record.get(keys.dimensions.getY()), *
kernelFunction
195 result->setCtr(record.get(keys.center));
204 std::string getAnalyticKernelPersistenceName() {
return "AnalyticKernel"; }
206 AnalyticKernel::Factory registration(getAnalyticKernelPersistenceName());
213 AnalyticKernelPersistenceHelper
const keys(_spatialFunctionList.size());
215 record->set(keys.kernelFunction, handle.
put(_kernelFunctionPtr.get()));
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.
Declare the Kernel class and subclasses.
table::Key< std::string > name
x_iterator row_begin(int y) const
An object passed to Persistable::write to allow it to persist itself.
double indexToPosition(double ind, lsst::afw::image::xOrY const xy) const
Convert image index to image position.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
int put(Persistable const *obj, bool permissive=false)
Save a nested Persistable to the same archive.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
A base class for factory classes used to reconstruct objects from records.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
A Function taking two arguments.
Factory(std::string const &name)
std::map< Citizen const *, CitizenInfo > table
table::Key< table::Array< Kernel::Pixel > > image
unsigned int getNParameters() const
Return the number of function parameters.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
A base class for objects that can be persisted via afw::table::io Archive classes.
int getWidth() const
Return the number of columns in the image.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
boost::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
void setXY0(geom::Point2I const origin)
#define LSST_EXCEPT(type,...)
A vector of catalogs used by Persistable.
Base class for all records.
table::Key< int > kernelFunction
AnalyticKernel()
Construct an empty spatially invariant AnalyticKernel of size 0x0.
int getHeight() const
Return the number of rows in the image.
A kernel described by a function.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Kernels are used for convolution with MaskedImages and (eventually) Images.
geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
Include files required for standard LSST Exception handling.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.