26 #include "lsst/pex/exceptions.h" 30 namespace pexExcept = lsst::pex::exceptions;
40 :
Kernel(width, height, kernelFunction.getNParameters(), spatialFunction),
44 std::vector<Kernel::SpatialFunctionPtr>
const &spatialFunctionList)
46 if (kernelFunction.
getNParameters() != spatialFunctionList.size()) {
47 std::ostringstream os;
48 os <<
"kernelFunction.getNParameters() = " << kernelFunction.
getNParameters()
49 <<
" != " << spatialFunctionList.size() <<
" = " 50 <<
"spatialFunctionList.size()";
51 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
56 std::shared_ptr<Kernel> retPtr;
63 retPtr->setCtr(this->
getCtr());
68 std::shared_ptr<Kernel> retPtr;
91 std::ostringstream os;
92 os << prefix <<
"AnalyticKernel:" << std::endl;
108 for (
int y = 0; y != image.
getHeight(); ++y) {
111 for (
int x = 0;
x != image.
getWidth(); ++
x, ++ptr) {
113 Pixel const pixelVal = (*_kernelFunctionPtr)(fx, fy);
119 if (doNormalize && (imSum != 1)) {
121 throw LSST_EXCEPT(pexExcept::OverflowError,
"Cannot normalize; kernel sum is 0");
141 explicit AnalyticKernelPersistenceHelper(
int nSpatialFunctions)
142 :
Kernel::PersistenceHelper(nSpatialFunctions),
143 kernelFunction(
schema.addField<int>(
144 "kernelfunction",
"archive ID for analytic function used to produce kernel images")) {}
146 explicit AnalyticKernelPersistenceHelper(table::Schema
const &schema_)
158 AnalyticKernelPersistenceHelper
const keys(catalogs.front().getSchema());
162 std::shared_ptr<AnalyticKernel> result;
163 if (keys.spatialFunctions.isValid()) {
164 result = std::make_shared<AnalyticKernel>(record.get(keys.dimensions.getX()),
165 record.get(keys.dimensions.getY()), *kernelFunction,
166 keys.readSpatialFunctions(archive, record));
168 result = std::make_shared<AnalyticKernel>(record.get(keys.dimensions.getX()),
169 record.get(keys.dimensions.getY()), *kernelFunction);
171 result->setCtr(record.get(keys.center));
175 explicit Factory(std::string
const &
name) : afw::table::io::PersistableFactory(name) {}
180 std::string getAnalyticKernelPersistenceName() {
return "AnalyticKernel"; }
190 std::shared_ptr<afw::table::BaseRecord> record = keys.write(handle, *
this);
int getHeight() const
Return the Kernel's height.
void setXY0(geom::Point2I const origin)
Set the ImageBase's origin.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
int put(Persistable const *obj, bool permissive=false)
Save a nested Persistable to the same archive.
table::Key< std::string > name
An object passed to Persistable::write to allow it to persist itself.
afw::table::Schema schema
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
int getHeight() const
Return the number of rows in the image.
A base class for factory classes used to reconstruct objects from records.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
lsst::afw::geom::Point2I getCtr() const
Return index of kernel's center.
virtual std::shared_ptr< afw::table::io::Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const
Construct a new object from the given InputArchive and vector of catalogs.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
A Function taking two arguments.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
KernelFunctionPtr _kernelFunctionPtr
A base class for image defects.
virtual std::shared_ptr< Kernel > resized(int width, int height) const
Return a pointer to a clone with specified kernel dimensions.
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
int getWidth() const
Return the Kernel's width.
A vector of catalogs used by Persistable.
Factory(std::string const &name)
Base class for all records.
table::Key< int > kernelFunction
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
AnalyticKernel()
Construct an empty spatially invariant AnalyticKernel of size 0x0.
std::vector< SpatialFunctionPtr > _spatialFunctionList
int getWidth() const
Return the number of columns in the image.
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.
Kernel()
Construct a null Kernel of size 0,0.
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
std::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
Kernels are used for convolution with MaskedImages and (eventually) Images.
unsigned int getNParameters() const
Return the number of function parameters.
geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
double indexToPosition(double ind, lsst::afw::image::xOrY const xy) const
Convert image index to image position.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.