38 namespace lsst {
namespace meas {
namespace algorithms {
44 struct DoubleGaussianPsfPersistenceHelper :
private boost::noncopyable {
49 afw::table::Key<double>
b;
51 static DoubleGaussianPsfPersistenceHelper
const &
get() {
52 static DoubleGaussianPsfPersistenceHelper instance;
57 DoubleGaussianPsfPersistenceHelper() :
60 afw::table::PointKey<int>::addFields(
schema,
"dimensions",
"width/height of kernel",
"pixels")
62 sigma1(
schema.addField<double>(
"sigma1",
"radius of inner Gaussian",
"pixels")),
63 sigma2(
schema.addField<double>(
"sigma2",
"radius of outer Gaussian",
"pixels")),
64 b(
schema.addField<double>(
"b",
"central amplitude of outer Gaussian (inner amplitude == 1)"))
66 schema.getCitizen().markPersistent();
70 class DoubleGaussianPsfFactory :
public afw::table::io::PersistableFactory {
73 virtual PTR(afw::table::io::Persistable)
74 read(InputArchive const & archive, CatalogVector const & catalogs)
const {
75 static DoubleGaussianPsfPersistenceHelper
const & keys = DoubleGaussianPsfPersistenceHelper::get();
78 afw::table::BaseRecord
const & record = catalogs.front().front();
80 return boost::make_shared<DoubleGaussianPsf>(
81 record.get(keys.dimensions.getX()),
82 record.get(keys.dimensions.getY()),
83 record.get(keys.sigma1),
84 record.get(keys.sigma2),
89 DoubleGaussianPsfFactory(std::string
const &
name) : afw::table::io::PersistableFactory(name) {}
94 PTR(afw::math::Kernel) makeDoubleGaussianKernel(
95 int width,
int height,
double sigma1,
double &
sigma2,
double b
97 if (b == 0.0 && sigma2 == 0.0) {
100 if (sigma1 <= 0 || sigma2 <= 0) {
101 throw LSST_EXCEPT(lsst::pex::exceptions::DomainError,
102 (
boost::format(
"sigma may not be 0: %g, %g") % sigma1 % sigma2).str());
104 afw::math::DoubleGaussianFunction2<double> dg(sigma1, sigma2, b);
105 PTR(afw::math::Kernel) kernel(new afw::math::AnalyticKernel(width, height, dg));
109 std::
string getDoubleGaussianPsfPersistenceName() {
return "DoubleGaussianPsf"; }
111 DoubleGaussianPsfFactory registration(getDoubleGaussianPsfPersistenceName());
115 DoubleGaussianPsf::DoubleGaussianPsf(
int width,
int height,
double sigma1,
double sigma2,
double b) :
116 KernelPsf(makeDoubleGaussianKernel(width, height, sigma1, sigma2, b)),
117 _sigma1(sigma1), _sigma2(sigma2),
_b(b)
121 return boost::make_shared<DoubleGaussianPsf>(
122 getKernel()->getWidth(),
123 getKernel()->getHeight(),
131 static DoubleGaussianPsfPersistenceHelper
const & keys = DoubleGaussianPsfPersistenceHelper::get();
134 (*record).set(keys.dimensions.getX(),
getKernel()->getWidth());
135 (*record).set(keys.dimensions.getY(),
getKernel()->getHeight());
138 (*record).set(keys.b,
getB());
144 namespace lsst {
namespace afw {
namespace detection {
147 daf::persistence::FormatterRegistration
148 PsfFormatter::doubleGaussianPsfRegistration(
149 "DoubleGaussianPsf",
typeid(meas::algorithms::DoubleGaussianPsf), createInstance
A Psf defined by a Kernel.
table::Key< std::string > name
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
double getSigma2() const
Return the radius of the outer Gaussian.
An object passed to Persistable::write to allow it to persist itself.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
A custom container class for records, based on std::vector.
Define a collection of useful Functions.
boost::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Represent a Psf as a circularly symmetrical double Gaussian.
afw::table::PointKey< int > dimensions
boost::shared_ptr< afw::math::Kernel const > getKernel() const
Return the Kernel used to define this Psf.
double getB() const
Return the ratio of Gaussian peak amplitudes: outer/inner.
#define LSST_EXCEPT(type,...)
Base class for all records.
afw::table::Key< double > sigma1
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
afw::table::Key< double > b
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
double getSigma1() const
Return the radius of the inner Gaussian.
A polymorphic base class for representing an image's Point Spread Function.
afw::table::Key< double > sigma2
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
Include files required for standard LSST Exception handling.