26 #include "ndarray/eigen.h" 42 struct GaussianPsfPersistenceHelper {
47 static GaussianPsfPersistenceHelper
const&
get() {
48 static GaussianPsfPersistenceHelper instance;
53 GaussianPsfPersistenceHelper(
const GaussianPsfPersistenceHelper&) =
delete;
54 GaussianPsfPersistenceHelper& operator=(
const GaussianPsfPersistenceHelper&) =
delete;
57 GaussianPsfPersistenceHelper(GaussianPsfPersistenceHelper&&) =
delete;
58 GaussianPsfPersistenceHelper& operator=(GaussianPsfPersistenceHelper&&) =
delete;
61 GaussianPsfPersistenceHelper()
64 "width/height of realization of Psf",
"pixel")),
65 sigma(schema.addField<
double>(
"sigma",
"radius of Gaussian",
"pixel")) {
66 schema.getCitizen().markPersistent();
70 class GaussianPsfFactory :
public afw::table::io::PersistableFactory {
72 virtual std::shared_ptr<afw::table::io::Persistable> read(InputArchive
const& archive,
73 CatalogVector
const& catalogs)
const {
74 static GaussianPsfPersistenceHelper
const& keys = GaussianPsfPersistenceHelper::get();
77 afw::table::BaseRecord
const& record = catalogs.front().front();
79 return std::make_shared<GaussianPsf>(record.get(keys.dimensions.getX()),
80 record.get(keys.dimensions.getY()), record.get(keys.sigma));
83 GaussianPsfFactory(std::string
const&
name) : afw::table::io::PersistableFactory(name) {}
86 GaussianPsfFactory registration(
"GaussianPsf");
89 if (dimensions.getX() % 2 == 0 || dimensions.getY() % 2 == 2) {
90 throw LSST_EXCEPT(pex::exceptions::InvalidParameterError,
"GaussianPsf dimensions must be odd");
97 :
Psf(true), _dimensions(width, height), _sigma(sigma) {
98 checkDimensions(_dimensions);
102 :
Psf(true), _dimensions(dimensions), _sigma(sigma) {
103 checkDimensions(_dimensions);
107 return std::make_shared<GaussianPsf>(_dimensions, _sigma);
111 return std::make_shared<GaussianPsf>(
geom::Extent2I(width, height), _sigma);
119 static GaussianPsfPersistenceHelper
const& keys = GaussianPsfPersistenceHelper::get();
121 std::shared_ptr<afw::table::BaseRecord> record = catalog.
addNew();
122 (*record)[keys.dimensions.getX()] = _dimensions.getX();
123 (*record)[keys.dimensions.getY()] = _dimensions.getY();
128 std::shared_ptr<GaussianPsf::Image> GaussianPsf::doComputeKernelImage(
geom::Point2D const&,
133 for (
int yIndex = 0, y = r->getY0(); yIndex < _dimensions.getY(); ++yIndex, ++y) {
134 Image::Array::Reference row = array[yIndex];
135 for (
int xIndex = 0,
x = r->getX0(); xIndex < _dimensions.getX(); ++xIndex, ++
x) {
136 sum += row[xIndex] = std::exp(-0.5 * (
x *
x + y * y) / (_sigma * _sigma));
139 array.asEigen() /= sum;
143 double GaussianPsf::doComputeApertureFlux(
double radius,
geom::Point2D const& position,
145 return 1.0 - std::exp(-0.5 * radius * radius / (_sigma * _sigma));
An ellipse core with quadrupole moments as parameters.
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.
table::Key< std::string > name
An object passed to Persistable::write to allow it to persist itself.
virtual std::shared_ptr< afw::detection::Psf > resized(int width, int height) const
Return a clone with specified kernel dimensions.
A custom container class for records, based on std::vector.
afw::table::Schema schema
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
GaussianPsf(int width, int height, double sigma)
Constructor for a GaussianPsf.
Extent< int, 2 > Extent2I
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
An integer coordinate rectangle.
afw::table::Key< double > sigma
afw::table::PointKey< int > dimensions
A base class for image defects.
virtual std::shared_ptr< afw::detection::Psf > clone() const
Polymorphic deep copy; should usually be unnecessary because Psfs are immutable.
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
double getSigma() const
Return the radius of the Gaussian.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
geom::Box2I computeBBox(geom::Point2D position=makeNullPoint(), image::Color color=image::Color()) const
Return the bounding box of the image returned by computeKernelImage()
Describe the colour of a source.
A polymorphic base class for representing an image's Point Spread Function.
ndarray::Array< PixelT, 2, 1 > Array
A mutable ndarray representation of the image.
image::Image< Pixel > Image
Image type returned by computeImage.
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.