26 #include "ndarray/eigen.h" 33 #include "lsst/afw/table/io/Persistable.cc" 47 struct GaussianPsfPersistenceHelper {
52 static GaussianPsfPersistenceHelper
const&
get() {
53 static GaussianPsfPersistenceHelper instance;
58 GaussianPsfPersistenceHelper(
const GaussianPsfPersistenceHelper&) =
delete;
59 GaussianPsfPersistenceHelper& operator=(
const GaussianPsfPersistenceHelper&) =
delete;
62 GaussianPsfPersistenceHelper(GaussianPsfPersistenceHelper&&) =
delete;
63 GaussianPsfPersistenceHelper& operator=(GaussianPsfPersistenceHelper&&) =
delete;
66 GaussianPsfPersistenceHelper()
69 "width/height of realization of Psf",
"pixel")),
70 sigma(schema.addField<
double>(
"sigma",
"radius of Gaussian",
"pixel")) {
71 schema.getCitizen().markPersistent();
75 class GaussianPsfFactory :
public afw::table::io::PersistableFactory {
78 CatalogVector
const& catalogs)
const override {
79 static GaussianPsfPersistenceHelper
const&
keys = GaussianPsfPersistenceHelper::get();
82 afw::table::BaseRecord
const& record = catalogs.front().front();
84 return std::make_shared<GaussianPsf>(record.get(keys.dimensions.getX()),
85 record.get(keys.dimensions.getY()), record.get(keys.sigma));
88 GaussianPsfFactory(
std::string const&
name) : afw::table::io::PersistableFactory(name) {}
91 GaussianPsfFactory registration(
"GaussianPsf");
94 if (dimensions.getX() % 2 == 0 || dimensions.getY() % 2 == 2) {
95 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"GaussianPsf dimensions must be odd");
102 :
Psf(true), _dimensions(width, height), _sigma(sigma) {
103 checkDimensions(_dimensions);
107 :
Psf(true), _dimensions(dimensions), _sigma(sigma) {
108 checkDimensions(_dimensions);
116 return std::make_shared<GaussianPsf>(_dimensions, _sigma);
128 static GaussianPsfPersistenceHelper
const&
keys = GaussianPsfPersistenceHelper::get();
131 (*record)[keys.dimensions.getX()] = _dimensions.getX();
132 (*record)[keys.dimensions.getY()] = _dimensions.getY();
142 for (
int yIndex = 0,
y = r->getY0(); yIndex < _dimensions.getY(); ++yIndex, ++
y) {
143 Image::Array::Reference
row = array[yIndex];
144 for (
int xIndex = 0,
x = r->getX0(); xIndex < _dimensions.getX(); ++xIndex, ++
x) {
145 sum += row[xIndex] =
std::exp(-0.5 * (
x *
x +
y *
y) / (_sigma * _sigma));
148 ndarray::asEigenMatrix(array) /= sum;
152 double GaussianPsf::doComputeApertureFlux(
double radius,
lsst::geom::Point2D const& position,
154 return 1.0 -
std::exp(-0.5 * radius * radius / (_sigma * _sigma));
An ellipse core with quadrupole moments as parameters.
afw::table::PointKey< int > dimensions
An object passed to Persistable::write to allow it to persist itself.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
GaussianPsf(int width, int height, double sigma)
Constructor for a GaussianPsf.
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
std::shared_ptr< afw::detection::Psf > resized(int width, int height) const override
Return a clone with specified kernel dimensions.
A base class for image defects.
std::shared_ptr< afw::detection::Psf > clone() const override
Polymorphic deep copy; should usually be unnecessary because Psfs are immutable.
afw::table::Key< double > sigma
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Extent< int, 2 > Extent2I
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
double getSigma() const
Return the radius of the Gaussian.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
Describe the colour of a source.
A polymorphic base class for representing an image's Point Spread Function.
lsst::geom::Box2I computeBBox(lsst::geom::Point2D position=makeNullPoint(), image::Color color=image::Color()) const
Return the bounding box of the image returned by computeKernelImage()
ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
An integer coordinate rectangle.
A circularly symmetric Gaussian Psf class with no spatial variation, intended mostly for testing purp...
image::Image< Pixel > Image
Image type returned by computeImage.
afw::table::Schema schema
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.