32 #include "lsst/afw/table/io/Persistable.cc" 48 namespace algorithms {
54 struct DoubleGaussianPsfPersistenceHelper {
59 afw::table::Key<double>
b;
61 static DoubleGaussianPsfPersistenceHelper
const&
get() {
62 static DoubleGaussianPsfPersistenceHelper instance;
67 DoubleGaussianPsfPersistenceHelper(
const DoubleGaussianPsfPersistenceHelper&) =
delete;
68 DoubleGaussianPsfPersistenceHelper& operator=(
const DoubleGaussianPsfPersistenceHelper&) =
delete;
71 DoubleGaussianPsfPersistenceHelper(DoubleGaussianPsfPersistenceHelper&&) =
delete;
72 DoubleGaussianPsfPersistenceHelper& operator=(DoubleGaussianPsfPersistenceHelper&&) =
delete;
75 DoubleGaussianPsfPersistenceHelper()
79 sigma1(schema.addField<
double>(
"sigma1",
"radius of inner Gaussian",
"pixel")),
80 sigma2(schema.addField<
double>(
"sigma2",
"radius of outer Gaussian",
"pixel")),
81 b(schema.addField<
double>(
"b",
"central amplitude of outer Gaussian (inner amplitude == 1)")) {
82 schema.getCitizen().markPersistent();
86 class DoubleGaussianPsfFactory :
public afw::table::io::PersistableFactory {
88 virtual PTR(afw::table::io::Persistable)
89 read(InputArchive
const& archive, CatalogVector
const& catalogs)
const {
90 static DoubleGaussianPsfPersistenceHelper
const&
keys = DoubleGaussianPsfPersistenceHelper::get();
93 afw::table::BaseRecord
const& record = catalogs.front().front();
95 return std::make_shared<DoubleGaussianPsf>(
96 record.get(keys.dimensions.getX()), record.get(keys.dimensions.getY()),
97 record.get(keys.sigma1), record.get(keys.sigma2), record.get(keys.b));
100 DoubleGaussianPsfFactory(
std::string const&
name) : afw::table::io::PersistableFactory(name) {}
105 PTR(afw::math::Kernel)
106 makeDoubleGaussianKernel(
int width,
int height,
double sigma1,
double&
sigma2,
double b) {
107 if (b == 0.0 && sigma2 == 0.0) {
110 if (sigma1 <= 0 || sigma2 <= 0) {
114 afw::math::DoubleGaussianFunction2<double> dg(sigma1, sigma2, b);
115 PTR(afw::math::Kernel)
kernel(
new afw::math::AnalyticKernel(width, height, dg));
119 std::string getDoubleGaussianPsfPersistenceName() {
return "DoubleGaussianPsf"; }
121 DoubleGaussianPsfFactory registration(getDoubleGaussianPsfPersistenceName());
125 DoubleGaussianPsf::DoubleGaussianPsf(
int width,
int height,
double sigma1,
double sigma2,
double b)
126 :
KernelPsf(makeDoubleGaussianKernel(width, height, sigma1, sigma2, b)),
132 return std::make_shared<DoubleGaussianPsf>(
getKernel()->getWidth(),
getKernel()->getHeight(), _sigma1,
137 return std::make_shared<DoubleGaussianPsf>(width, height, _sigma1, _sigma2, _b);
143 static DoubleGaussianPsfPersistenceHelper
const&
keys = DoubleGaussianPsfPersistenceHelper::get();
146 (*record).set(keys.dimensions.getX(),
getKernel()->getWidth());
147 (*record).set(keys.dimensions.getY(),
getKernel()->getHeight());
150 (*record).set(keys.b,
getB());
160 namespace detection {
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
A Psf defined by a Kernel.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
An object passed to Persistable::write to allow it to persist itself.
afw::table::PointKey< int > dimensions
boost::shared_ptr< afw::detection::Psf > clone() const override
Polymorphic deep copy. Usually unnecessary, as Psfs are immutable.
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.
double getSigma1() const
Return the radius of the inner Gaussian.
boost::shared_ptr< afw::math::Kernel const > getKernel() const
Return the Kernel used to define this Psf.
afw::table::Key< double > b
afw::table::Key< double > sigma1
A base class for image defects.
boost::shared_ptr< afw::detection::Psf > resized(int width, int height) const override
Return a clone with specified kernel dimensions.
afw::table::Schema schema
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
double getSigma2() const
Return the radius of the outer Gaussian.
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.
Base class for all records.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
afw::table::Key< double > sigma2
double getB() const
Return the ratio of Gaussian peak amplitudes: outer/inner.
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
A polymorphic base class for representing an image's Point Spread Function.
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.