26#include "ndarray/eigen.h"
46struct GaussianPsfPersistenceHelper {
47 afw::table::Schema schema;
48 afw::table::PointKey<int> dimensions;
51 static GaussianPsfPersistenceHelper
const& get() {
52 static GaussianPsfPersistenceHelper instance;
57 GaussianPsfPersistenceHelper(
const GaussianPsfPersistenceHelper&) =
delete;
58 GaussianPsfPersistenceHelper& operator=(
const GaussianPsfPersistenceHelper&) =
delete;
61 GaussianPsfPersistenceHelper(GaussianPsfPersistenceHelper&&) =
delete;
62 GaussianPsfPersistenceHelper& operator=(GaussianPsfPersistenceHelper&&) =
delete;
65 GaussianPsfPersistenceHelper()
67 dimensions(
afw::table::PointKey<
int>::addFields(schema,
"dimensions",
68 "width/height of realization of Psf",
"pixel")),
69 sigma(schema.addField<double>(
"sigma",
"radius of Gaussian",
"pixel")) {}
72class GaussianPsfFactory :
public afw::table::io::PersistableFactory {
75 CatalogVector
const& catalogs)
const override {
76 static GaussianPsfPersistenceHelper
const&
keys = GaussianPsfPersistenceHelper::get();
79 afw::table::BaseRecord
const& record = catalogs.front().front();
81 return std::make_shared<GaussianPsf>(record.get(
keys.dimensions.getX()),
82 record.get(
keys.dimensions.getY()), record.get(
keys.sigma));
85 GaussianPsfFactory(
std::string const& name) :
afw::table::io::PersistableFactory(name) {}
88GaussianPsfFactory registration(
"GaussianPsf");
91 if (dimensions.getX() % 2 == 0 || dimensions.getY() % 2 == 2) {
92 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"GaussianPsf dimensions must be odd");
99 :
Psf(true), _dimensions(width, height), _sigma(
sigma) {
100 checkDimensions(_dimensions);
104 :
Psf(true), _dimensions(dimensions), _sigma(
sigma) {
105 checkDimensions(_dimensions);
113 return std::make_shared<GaussianPsf>(_dimensions, _sigma);
125 static GaussianPsfPersistenceHelper
const& keys = GaussianPsfPersistenceHelper::get();
128 (*record)[keys.dimensions.getX()] = _dimensions.getX();
129 (*record)[keys.dimensions.getY()] = _dimensions.getY();
139 for (
int yIndex = 0,
y = r->getY0(); yIndex < _dimensions.getY(); ++yIndex, ++
y) {
140 Image::Array::Reference
row = array[yIndex];
141 for (
int xIndex = 0,
x = r->getX0(); xIndex < _dimensions.getX(); ++xIndex, ++
x) {
142 sum +=
row[xIndex] =
std::exp(-0.5 * (
x *
x +
y *
y) / (_sigma * _sigma));
145 ndarray::asEigenMatrix(array) /= sum;
151 return 1.0 -
std::exp(-0.5 * radius * radius / (_sigma * _sigma));
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
afw::table::Key< double > sigma
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
A circularly symmetric Gaussian Psf class with no spatial variation, intended mostly for testing purp...
std::shared_ptr< afw::detection::Psf > resized(int width, int height) const override
Return a clone with specified kernel dimensions.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
geom::ellipses::Quadrupole doComputeShape(lsst::geom::Point2D const &position, image::Color const &color) const override
double getSigma() const
Return the radius of the Gaussian.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
double doComputeApertureFlux(double radius, lsst::geom::Point2D const &position, image::Color const &color) const override
std::shared_ptr< Image > doComputeKernelImage(lsst::geom::Point2D const &position, image::Color const &color) const override
These virtual member functions are private, not protected, because we only want derived classes to im...
lsst::geom::Box2I doComputeBBox(lsst::geom::Point2D const &position, image::Color const &color) const override
std::shared_ptr< afw::detection::Psf > clone() const override
Polymorphic deep copy; should usually be unnecessary because Psfs are immutable.
GaussianPsf(int width, int height, double sigma)
Constructor for a GaussianPsf.
A polymorphic base class for representing an image's Point Spread Function.
lsst::geom::Box2I computeBBox(lsst::geom::Point2D position, image::Color color=image::Color()) const
Return the bounding box of the image returned by computeKernelImage()
virtual lsst::geom::Point2D getAveragePosition() const
Return the average position of the stars used to construct the Psf.
image::Image< Pixel > Image
Image type returned by computeImage.
An ellipse core with quadrupole moments as parameters.
Describe the colour of a source.
typename ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
An object passed to Persistable::write to allow it to persist itself.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
An integer coordinate rectangle.
std::shared_ptr< table::io::Persistable > read(table::io::InputArchive const &archive, table::io::CatalogVector const &catalogs) const override