LSSTApplications  20.0.0
LSSTDataManagementBasePackage
KernelPsf.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 #include "lsst/geom/Box.h"
7 
8 namespace lsst {
9 namespace afw {
10 namespace table {
11 namespace io {
12 
15 
16 } // namespace io
17 } // namespace table
18 } // namespace afw
19 namespace meas {
20 namespace algorithms {
21 
23 KernelPsf::doComputeKernelImage(geom::Point2D const& position, afw::image::Color const& color) const {
24  PTR(Psf::Image) im = std::make_shared<Psf::Image>(_kernel->getDimensions());
25  _kernel->computeImage(*im, true, position.getX(), position.getY());
26  return im;
27 }
28 
29 geom::Box2I KernelPsf::doComputeBBox(geom::Point2D const& position, afw::image::Color const& color) const {
30  return _kernel->getBBox();
31 }
32 
33 KernelPsf::KernelPsf(afw::math::Kernel const& kernel, geom::Point2D const& averagePosition)
34  : ImagePsf(!kernel.isSpatiallyVarying()),
35  _kernel(kernel.clone()),
36  _averagePosition(averagePosition) {}
37 
39  : ImagePsf(!kernel->isSpatiallyVarying()), _kernel(kernel), _averagePosition(averagePosition) {}
40 
41 PTR(afw::detection::Psf) KernelPsf::clone() const { return std::make_shared<KernelPsf>(*this); }
42 
43 PTR(afw::detection::Psf) KernelPsf::resized(int width, int height) const {
44  return std::make_shared<KernelPsf>(*_kernel->resized(width, height), _averagePosition);
45 }
46 
47 geom::Point2D KernelPsf::getAveragePosition() const { return _averagePosition; }
48 
49 namespace {
50 
51 KernelPsfFactory<> registration("KernelPsf");
52 
53 } // namespace
54 
56  static KernelPsfPersistenceHelper instance;
57  return instance;
58 }
59 
60 KernelPsfPersistenceHelper::KernelPsfPersistenceHelper()
61  : schema(),
62  kernel(schema.addField<int>("kernel", "archive ID of nested kernel object")),
63  averagePosition(afw::table::PointKey<double>::addFields(
64  schema, "averagePosition", "average position of stars used to make the PSF", "pixel")) {}
65 
66 bool KernelPsf::isPersistable() const noexcept { return _kernel->isPersistable(); }
67 
68 std::string KernelPsf::getPersistenceName() const { return "KernelPsf"; }
69 
70 std::string KernelPsf::getPythonModule() const { return "lsst.meas.algorithms"; }
71 
74  afw::table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
75  PTR(afw::table::BaseRecord) record = catalog.addNew();
76  record->set(keys.kernel, handle.put(_kernel));
77  record->set(keys.averagePosition, _averagePosition);
78  handle.saveCatalog(catalog);
79 }
80 
81 } // namespace algorithms
82 } // namespace meas
83 } // namespace lsst
schema
table::Schema schema
Definition: Amplifier.cc:115
lsst::meas::algorithms::KernelPsf::isPersistable
bool isPersistable() const noexcept override
Whether this object is persistable; just delegates to the kernel.
Definition: KernelPsf.cc:66
lsst::afw::math::Kernel::getBBox
lsst::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
Definition: Kernel.h:262
Box.h
std::string
STL class.
std::shared_ptr
STL class.
lsst::afw::math::Kernel::getDimensions
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
Definition: Kernel.h:213
lsst::afw::table::io::OutputArchiveHandle
An object passed to Persistable::write to allow it to persist itself.
Definition: OutputArchive.h:118
Persistable.cc
lsst::afw::table::io::OutputArchiveHandle::saveCatalog
void saveCatalog(BaseCatalog const &catalog)
Save a catalog in the archive.
Definition: OutputArchive.cc:211
lsst::meas::algorithms::KernelPsfFactory
A PersistableFactory for KernelPsf and its subclasses.
Definition: KernelPsfFactory.h:55
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::meas::algorithms::KernelPsf::clone
boost::shared_ptr< afw::detection::Psf > clone() const override
Polymorphic deep copy.
Definition: KernelPsf.cc:41
lsst::meas::algorithms::KernelPsf::resized
boost::shared_ptr< afw::detection::Psf > resized(int width, int height) const override
Return a clone with specified kernel dimensions.
Definition: KernelPsf.cc:43
astshim.keyMap.keyMapContinued.keys
def keys(self)
Definition: keyMapContinued.py:6
averagePosition
afw::table::PointKey< double > averagePosition
Definition: CoaddPsf.cc:340
lsst::afw::math::Kernel::computeImage
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
Definition: Kernel.cc:85
lsst::meas::algorithms::KernelPsfPersistenceHelper::get
static KernelPsfPersistenceHelper const & get()
Definition: KernelPsf.cc:55
lsst::meas::algorithms::KernelPsf::getAveragePosition
geom::Point2D getAveragePosition() const override
Return average position of stars; used as default position.
Definition: KernelPsf.cc:47
lsst::meas::algorithms::KernelPsf::write
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: KernelPsf.cc:72
lsst::afw::table::io::OutputArchiveHandle::makeCatalog
BaseCatalog makeCatalog(Schema const &schema)
Return a new, empty catalog with the given schema.
Definition: OutputArchive.cc:207
lsst::meas::algorithms::KernelPsf::getPersistenceName
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: KernelPsf.cc:68
KernelPsfFactory.h
lsst::afw::detection::Psf::Image
image::Image< Pixel > Image
Image type returned by computeImage.
Definition: Psf.h:83
lsst::afw::table::BaseRecord
Base class for all records.
Definition: BaseRecord.h:31
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::meas::algorithms::KernelPsf::KernelPsf
KernelPsf(afw::math::Kernel const &kernel, geom::Point2D const &averagePosition=geom::Point2D())
Construct a KernelPsf with a clone of the given kernel.
Definition: KernelPsf.cc:33
lsst::afw::table::io::PersistableFacade::dynamicCast
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
Definition: Persistable.cc:18
PTR
#define PTR(...)
Definition: base.h:41
lsst::geom::Point< double, 2 >
KernelPsf.h
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst::meas::algorithms::KernelPsfPersistenceHelper
A read-only singleton struct containing the schema and key used in persistence for KernelPsf.
Definition: KernelPsfFactory.h:25
lsst::afw::math::Kernel
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:111
lsst::afw::table::io::OutputArchiveHandle::put
int put(Persistable const *obj, bool permissive=false)
Save an object to the archive and return a unique ID that can be used to retrieve it from an InputArc...
Definition: OutputArchive.cc:216
lsst::afw::detection::Psf
A polymorphic base class for representing an image's Point Spread Function.
Definition: Psf.h:76
lsst::afw::table::CatalogT::addNew
std::shared_ptr< RecordT > addNew()
Create a new record, add it to the end of the catalog, and return a pointer to it.
Definition: Catalog.h:485
lsst::afw::table::CatalogT< BaseRecord >
lsst::afw::image.slicing.clone
clone
Definition: slicing.py:257
lsst::meas::algorithms::KernelPsf::getPythonModule
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition: KernelPsf.cc:70
lsst::meas::algorithms::ImagePsf
An intermediate base class for Psfs that use an image representation.
Definition: ImagePsf.h:40