40 namespace algorithms {
46 struct DoubleGaussianPsfPersistenceHelper {
51 afw::table::Key<double>
b;
53 static DoubleGaussianPsfPersistenceHelper
const&
get() {
54 static DoubleGaussianPsfPersistenceHelper instance;
59 DoubleGaussianPsfPersistenceHelper(
const DoubleGaussianPsfPersistenceHelper&) =
delete;
60 DoubleGaussianPsfPersistenceHelper& operator=(
const DoubleGaussianPsfPersistenceHelper&) =
delete;
63 DoubleGaussianPsfPersistenceHelper(DoubleGaussianPsfPersistenceHelper&&) =
delete;
64 DoubleGaussianPsfPersistenceHelper& operator=(DoubleGaussianPsfPersistenceHelper&&) =
delete;
67 DoubleGaussianPsfPersistenceHelper()
71 sigma1(schema.addField<
double>(
"sigma1",
"radius of inner Gaussian",
"pixel")),
72 sigma2(schema.addField<
double>(
"sigma2",
"radius of outer Gaussian",
"pixel")),
73 b(schema.addField<
double>(
"b",
"central amplitude of outer Gaussian (inner amplitude == 1)")) {
74 schema.getCitizen().markPersistent();
78 class DoubleGaussianPsfFactory :
public afw::table::io::PersistableFactory {
80 virtual PTR(afw::table::io::Persistable)
81 read(InputArchive
const& archive, CatalogVector
const& catalogs)
const {
82 static DoubleGaussianPsfPersistenceHelper
const&
keys = DoubleGaussianPsfPersistenceHelper::get();
85 afw::table::BaseRecord
const& record = catalogs.front().front();
87 return std::make_shared<DoubleGaussianPsf>(
88 record.get(keys.dimensions.getX()), record.get(keys.dimensions.getY()),
89 record.get(keys.sigma1), record.get(keys.sigma2), record.get(keys.b));
92 DoubleGaussianPsfFactory(
std::string const&
name) : afw::table::io::PersistableFactory(name) {}
97 PTR(afw::math::Kernel)
98 makeDoubleGaussianKernel(
int width,
int height,
double sigma1,
double&
sigma2,
double b) {
99 if (b == 0.0 && sigma2 == 0.0) {
102 if (sigma1 <= 0 || sigma2 <= 0) {
104 (boost::format(
"sigma may not be 0: %g, %g") % sigma1 % sigma2).str());
106 afw::math::DoubleGaussianFunction2<double> dg(sigma1, sigma2, b);
107 PTR(afw::math::Kernel) kernel(
new afw::math::AnalyticKernel(width, height, dg));
111 std::string getDoubleGaussianPsfPersistenceName() {
return "DoubleGaussianPsf"; }
113 DoubleGaussianPsfFactory registration(getDoubleGaussianPsfPersistenceName());
118 :
KernelPsf(makeDoubleGaussianKernel(width, height, sigma1, sigma2, b)),
124 return std::make_shared<DoubleGaussianPsf>(
getKernel()->getWidth(),
getKernel()->getHeight(), _sigma1,
129 return std::make_shared<DoubleGaussianPsf>(width, height, _sigma1, _sigma2, _b);
135 static DoubleGaussianPsfPersistenceHelper
const&
keys = DoubleGaussianPsfPersistenceHelper::get();
138 (*record).set(keys.dimensions.getX(),
getKernel()->getWidth());
139 (*record).set(keys.dimensions.getY(),
getKernel()->getHeight());
142 (*record).set(keys.b,
getB());
143 handle.saveCatalog(catalog);
152 namespace detection {
A Psf defined by a Kernel.
virtual void write(OutputArchiveHandle &handle) const
#define LSST_ARCHIVE_ASSERT(EXPR)
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
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.
DoubleGaussianPsf(int width, int height, double sigma1, double sigma2=0.0, double b=0.0)
Constructor for a DoubleGaussianPsf.
Represent a Psf as a circularly symmetrical double Gaussian.
virtual std::string getPersistenceName() const
afw::table::PointKey< int > dimensions
virtual boost::shared_ptr< afw::detection::Psf > resized(int width, int height) const
Return a clone with specified kernel dimensions.
double getSigma2() const
Return the radius of the outer Gaussian.
#define LSST_EXCEPT(type,...)
afw::table::Key< double > sigma1
afw::table::Schema schema
double getB() const
Return the ratio of Gaussian peak amplitudes: outer/inner.
io::OutputArchiveHandle OutputArchiveHandle
afw::table::Key< double > b
virtual boost::shared_ptr< afw::detection::Psf > clone() const
Polymorphic deep copy. Usually unnecessary, as Psfs are immutable.
afw::table::Key< double > sigma2
std::shared_ptr< BaseRecord > addNew()