LSST Applications g0265f82a02+c6dfa2ddaf,g1162b98a3f+b2075782a9,g2079a07aa2+1b2e822518,g2bbee38e9b+c6dfa2ddaf,g337abbeb29+c6dfa2ddaf,g3ddfee87b4+a60788ef87,g50ff169b8f+2eb0e556e8,g52b1c1532d+90ebb246c7,g555ede804d+a60788ef87,g591dd9f2cf+ba8caea58f,g5ec818987f+864ee9cddb,g858d7b2824+9ee1ab4172,g876c692160+a40945ebb7,g8a8a8dda67+90ebb246c7,g8cdfe0ae6a+4fd9e222a8,g99cad8db69+5e309b7bc6,g9ddcbc5298+a1346535a5,ga1e77700b3+df8f93165b,ga8c6da7877+aa12a14d27,gae46bcf261+c6dfa2ddaf,gb0e22166c9+8634eb87fb,gb3f2274832+d0da15e3be,gba4ed39666+1ac82b564f,gbb8dafda3b+5dfd9c994b,gbeb006f7da+97157f9740,gc28159a63d+c6dfa2ddaf,gc86a011abf+9ee1ab4172,gcf0d15dbbd+a60788ef87,gdaeeff99f8+1cafcb7cd4,gdc0c513512+9ee1ab4172,ge79ae78c31+c6dfa2ddaf,geb67518f79+ba1859f325,geb961e4c1e+f9439d1e6f,gee10cc3b42+90ebb246c7,gf1cff7945b+9ee1ab4172,w.2024.12
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Types | Static Protected Member Functions | Related Symbols | List of all members
lsst::afw::detection::PsfTrampoline< Base > Class Template Reference

"Trampoline" for Psf to let it be used as a base class in Python. More...

#include <python.h>

Inheritance diagram for lsst::afw::detection::PsfTrampoline< Base >:
lsst::afw::typehandling::StorableHelper< Base > lsst::afw::typehandling::Storable lsst::afw::table::io::Persistable lsst::meas::algorithms::ImagePsfTrampoline< Base >

Public Types

using Image = typename Base::Image
 

Public Member Functions

template<typename... Args>
 PsfTrampoline (Args... args)
 Delegating constructor for wrapped class.
 
std::shared_ptr< Psfclone () const override
 
std::shared_ptr< Psfresized (int width, int height) const override
 
lsst::geom::Point2D getAveragePosition () const override
 
std::shared_ptr< ImagedoComputeImage (lsst::geom::Point2D const &position, image::Color const &color) const override
 
lsst::geom::Box2I doComputeImageBBox (lsst::geom::Point2D const &position, image::Color const &color) const override
 
std::shared_ptr< ImagedoComputeKernelImage (lsst::geom::Point2D const &position, image::Color const &color) const override
 
double doComputeApertureFlux (double radius, lsst::geom::Point2D const &position, image::Color const &color) const override
 
geom::ellipses::Quadrupole doComputeShape (lsst::geom::Point2D const &position, image::Color const &color) const override
 
lsst::geom::Box2I doComputeBBox (lsst::geom::Point2D const &position, image::Color const &color) const override
 
std::shared_ptr< Storable > cloneStorable () const override
 Create a new object that is a copy of this one (optional operation).
 
std::string toString () const override
 Create a string representation of this object (optional operation).
 
std::size_t hash_value () const override
 Return a hash of this object (optional operation).
 
bool equals (Storable const &other) const noexcept override
 Compare this object to another Storable.
 
bool isPersistable () const noexcept override
 Return true if this particular object can be persisted using afw::table::io.
 
std::string getPersistenceName () const override
 Return the unique name used to persist this object and look up its factory.
 
std::string getPythonModule () const override
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered.
 
void write (table::io::OutputArchiveHandle &handle) const override
 Write the object to one or more catalogs.
 
void writeFits (std::string const &fileName, std::string const &mode="w") const
 Write the object to a regular FITS file.
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 Write the object to a FITS image in memory.
 
void writeFits (fits::Fits &fitsfile) const
 Write the object to an already-open FITS object.
 

Protected Types

using OutputArchiveHandle = io::OutputArchiveHandle
 

Static Protected Member Functions

template<class T >
static bool singleClassEquals (T const &lhs, Storable const &rhs)
 Test if a Storable is of a particular class and equal to another object.
 

Related Symbols

(Note that these are not member symbols.)

std::ostreamoperator<< (std::ostream &os, Storable const &storable)
 Output operator for Storable.
 

Detailed Description

template<typename Base = Psf>
class lsst::afw::detection::PsfTrampoline< Base >

"Trampoline" for Psf to let it be used as a base class in Python.

Subclasses of Psf that are wrapped in pybind11 should have a similar helper that subclasses PsfTrampoline<subclass>. This helper can be skipped if the subclass neither adds any virtual methods nor implements any abstract methods.

Template Parameters
Basethe exact (most specific) class being wrapped
See also
pybind11 documentation

Definition at line 50 of file python.h.

Member Typedef Documentation

◆ Image

template<typename Base = Psf>
using lsst::afw::detection::PsfTrampoline< Base >::Image = typename Base::Image

Definition at line 52 of file python.h.

◆ OutputArchiveHandle

using lsst::afw::table::io::Persistable::OutputArchiveHandle = io::OutputArchiveHandle
protectedinherited

Definition at line 108 of file Persistable.h.

Constructor & Destructor Documentation

◆ PsfTrampoline()

template<typename Base = Psf>
template<typename... Args>
lsst::afw::detection::PsfTrampoline< Base >::PsfTrampoline ( Args... args)
inlineexplicit

Delegating constructor for wrapped class.

While we would like to simply inherit base class constructors, when doing so, we cannot change their access specifiers. One consequence is that it's not possible to use inheritance to expose a protected constructor to python. The alternative, used here, is to create a new public constructor that delegates to the base class public or protected constructor with the same signature.

Template Parameters
ArgsVariadic type specification
Parameters
...argsArguments to forward to the Base class constructor.

Definition at line 1 of file python.h.

"Trampoline" for Storable to let it be used as a base class in Python.
Definition python.h:54

Member Function Documentation

◆ clone()

template<typename Base = Psf>
std::shared_ptr< Psf > lsst::afw::detection::PsfTrampoline< Base >::clone ( ) const
inlineoverride

Definition at line 69 of file python.h.

69 {
70 /* __deepcopy__ takes an optional dict, but PYBIND11_OVERLOAD_* won't
71 * compile unless you give it arguments that work for the C++ method
72 */
73 PYBIND11_OVERLOAD_PURE_NAME(std::shared_ptr<Psf>, Base, "__deepcopy__", clone,);
74 }
std::shared_ptr< Psf > clone() const override
Definition python.h:69

◆ cloneStorable()

template<class Base = Storable>
std::shared_ptr< Storable > lsst::afw::typehandling::StorableHelper< Base >::cloneStorable ( ) const
inlineoverridevirtualinherited

Create a new object that is a copy of this one (optional operation).

This operation is required for Storables that are stored in GenericMap by value, but not for those stored by shared pointer.

Exceptions
UnsupportedOperationExceptionThrown if this object is not cloneable.
Note
If this class supports a clone operation, the two should behave identically except for the formal return type.
When called on Python classes, this method delegates to __deepcopy__ if it exists.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 73 of file python.h.

73 {
74 /* __deepcopy__ takes an optional dict, but PYBIND11_OVERLOAD_* won't
75 * compile unless you give it arguments that work for the C++ method
76 */
77 PYBIND11_OVERLOAD_NAME(std::shared_ptr<Storable>, Base, "__deepcopy__", cloneStorable, );
78 }
std::shared_ptr< Storable > cloneStorable() const override
Create a new object that is a copy of this one (optional operation).
Definition python.h:73

◆ doComputeApertureFlux()

template<typename Base = Psf>
double lsst::afw::detection::PsfTrampoline< Base >::doComputeApertureFlux ( double radius,
lsst::geom::Point2D const & position,
image::Color const & color ) const
inlineoverride

Definition at line 112 of file python.h.

115 {
116 PYBIND11_OVERLOAD_PURE_NAME(
117 double, Base, "_doComputeApertureFlux", doComputeApertureFlux, radius, position, color
118 );
119 }
double doComputeApertureFlux(double radius, lsst::geom::Point2D const &position, image::Color const &color) const override
Definition python.h:112

◆ doComputeBBox()

template<typename Base = Psf>
lsst::geom::Box2I lsst::afw::detection::PsfTrampoline< Base >::doComputeBBox ( lsst::geom::Point2D const & position,
image::Color const & color ) const
inlineoverride

Definition at line 130 of file python.h.

133 {
134 PYBIND11_OVERLOAD_PURE_NAME(
135 lsst::geom::Box2I, Base, "_doComputeBBox", doComputeBBox, position, color
136 );
137 }
lsst::geom::Box2I doComputeBBox(lsst::geom::Point2D const &position, image::Color const &color) const override
Definition python.h:130
An integer coordinate rectangle.
Definition Box.h:55

◆ doComputeImage()

template<typename Base = Psf>
std::shared_ptr< Image > lsst::afw::detection::PsfTrampoline< Base >::doComputeImage ( lsst::geom::Point2D const & position,
image::Color const & color ) const
inlineoverride

Definition at line 85 of file python.h.

88 {
89 PYBIND11_OVERLOAD_NAME(
90 std::shared_ptr<Image>, Base, "_doComputeImage", doComputeImage, position, color
91 );
92 }
std::shared_ptr< Image > doComputeImage(lsst::geom::Point2D const &position, image::Color const &color) const override
Definition python.h:85

◆ doComputeImageBBox()

template<typename Base = Psf>
lsst::geom::Box2I lsst::afw::detection::PsfTrampoline< Base >::doComputeImageBBox ( lsst::geom::Point2D const & position,
image::Color const & color ) const
inlineoverride

Definition at line 94 of file python.h.

97 {
98 PYBIND11_OVERLOAD_NAME(
99 lsst::geom::Box2I, Base, "_doComputeImageBBox", doComputeImageBBox, position, color
100 );
101 }
lsst::geom::Box2I doComputeImageBBox(lsst::geom::Point2D const &position, image::Color const &color) const override
Definition python.h:94

◆ doComputeKernelImage()

template<typename Base = Psf>
std::shared_ptr< Image > lsst::afw::detection::PsfTrampoline< Base >::doComputeKernelImage ( lsst::geom::Point2D const & position,
image::Color const & color ) const
inlineoverride

Definition at line 103 of file python.h.

106 {
107 PYBIND11_OVERLOAD_PURE_NAME(
108 std::shared_ptr<Image>, Base, "_doComputeKernelImage", doComputeKernelImage, position, color
109 );
110 }
std::shared_ptr< Image > doComputeKernelImage(lsst::geom::Point2D const &position, image::Color const &color) const override
Definition python.h:103

◆ doComputeShape()

template<typename Base = Psf>
geom::ellipses::Quadrupole lsst::afw::detection::PsfTrampoline< Base >::doComputeShape ( lsst::geom::Point2D const & position,
image::Color const & color ) const
inlineoverride

Definition at line 121 of file python.h.

124 {
125 PYBIND11_OVERLOAD_PURE_NAME(
126 geom::ellipses::Quadrupole, Base, "_doComputeShape", doComputeShape, position, color
127 );
128 }
geom::ellipses::Quadrupole doComputeShape(lsst::geom::Point2D const &position, image::Color const &color) const override
Definition python.h:121

◆ equals()

template<class Base = Storable>
bool lsst::afw::typehandling::StorableHelper< Base >::equals ( Storable const & other) const
inlineoverridevirtualnoexceptinherited

Compare this object to another Storable.

Subclasses that implement equality comparison must override this method to give results consistent with operator== for all inputs that are accepted by both.

Returns
This implementation returns whether the two objects are the same.
Warning
This method compares an object to any type of Storable, although cross-class comparisons should usually return false. If cross-class comparisons are valid, implementers should take care that they are symmetric and will give the same result no matter what the compile-time types of the left- and right-hand sides are.
See also
singleClassEquals
Note
When called on Python classes, this method delegates to __eq__ if it exists.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 88 of file python.h.

88 {
89 PYBIND11_OVERLOAD_NAME(bool, Base, "__eq__", equals, other);
90 }
bool equals(Storable const &other) const noexcept override
Compare this object to another Storable.
Definition python.h:88

◆ getAveragePosition()

template<typename Base = Psf>
lsst::geom::Point2D lsst::afw::detection::PsfTrampoline< Base >::getAveragePosition ( ) const
inlineoverride

Definition at line 80 of file python.h.

80 {
81 PYBIND11_OVERLOAD(lsst::geom::Point2D, Base, getAveragePosition,);
82 }
lsst::geom::Point2D getAveragePosition() const override
Definition python.h:80

◆ getPersistenceName()

template<class Base = Storable>
std::string lsst::afw::typehandling::StorableHelper< Base >::getPersistenceName ( ) const
inlineoverridevirtualinherited

Return the unique name used to persist this object and look up its factory.

Must be less than ArchiveIndexSchema::MAX_NAME_LENGTH characters.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 98 of file python.h.

98 {
99 PYBIND11_OVERLOAD_NAME(
100 std::string, Base, "_getPersistenceName", getPersistenceName
101 );
102 }
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition python.h:98

◆ getPythonModule()

template<class Base = Storable>
std::string lsst::afw::typehandling::StorableHelper< Base >::getPythonModule ( ) const
inlineoverridevirtualinherited

Return the fully-qualified Python module that should be imported to guarantee that its factory is registered.

Must be less than ArchiveIndexSchema::MAX_MODULE_LENGTH characters.

Will be ignored if empty.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 104 of file python.h.

104 {
105 PYBIND11_OVERLOAD_NAME(
106 std::string, Base, "_getPythonModule", getPythonModule
107 );
108 }
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
Definition python.h:104

◆ hash_value()

template<class Base = Storable>
std::size_t lsst::afw::typehandling::StorableHelper< Base >::hash_value ( ) const
inlineoverridevirtualinherited

Return a hash of this object (optional operation).

Exceptions
UnsupportedOperationExceptionThrown if this object is not hashable.
Note
C++ subclass authors are responsible for any associated specializations of std::hash.
When called on Python classes, this method delegates to __hash__ if it exists.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 84 of file python.h.

84 {
85 PYBIND11_OVERLOAD_NAME(std::size_t, Base, "__hash__", hash_value, );
86 }
std::size_t hash_value() const override
Return a hash of this object (optional operation).
Definition python.h:84

◆ isPersistable()

template<class Base = Storable>
bool lsst::afw::typehandling::StorableHelper< Base >::isPersistable ( ) const
inlineoverridevirtualnoexceptinherited

Return true if this particular object can be persisted using afw::table::io.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 92 of file python.h.

92 {
93 PYBIND11_OVERLOAD(
94 bool, Base, isPersistable
95 );
96 }
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
Definition python.h:92

◆ resized()

template<typename Base = Psf>
std::shared_ptr< Psf > lsst::afw::detection::PsfTrampoline< Base >::resized ( int width,
int height ) const
inlineoverride

Definition at line 76 of file python.h.

76 {
77 PYBIND11_OVERLOAD_PURE(std::shared_ptr<Psf>, Base, resized, width, height);
78 }
std::shared_ptr< Psf > resized(int width, int height) const override
Definition python.h:76

◆ singleClassEquals()

template<class T >
static bool lsst::afw::typehandling::Storable::singleClassEquals ( T const & lhs,
Storable const & rhs )
inlinestaticprotectedinherited

Test if a Storable is of a particular class and equal to another object.

This method template simplifies implementations of equals that delegate to operator== without supporting cross-class comparisons.

Template Parameters
TThe class expected of the two objects to be compared.
Parameters
lhs,rhsThe objects to compare. Note that rhs need not be a T, while lhs must be.
Returns
true if rhs is a T and lhs == rhs; false otherwise.
Exception Safety
Provides the same level of exception safety as operator==. Most implementations of operator== do not throw.
Note
This method template calls operator== with both arguments of compile-time type T const&. Its use is not recommended if there would be any ambiguity as to which operator== gets picked by overload resolution.

This method template is typically called from equals as:

bool MyType::equals(Storable const& other) const noexcept {
    return singleClassEquals(*this, other);
}

Definition at line 151 of file Storable.h.

151 {
152 auto typedRhs = dynamic_cast<T const*>(&rhs);
153 if (typedRhs != nullptr) {
154 return lhs == *typedRhs;
155 } else {
156 return false;
157 }
158 }

◆ toString()

template<class Base = Storable>
std::string lsst::afw::typehandling::StorableHelper< Base >::toString ( ) const
inlineoverridevirtualinherited

Create a string representation of this object (optional operation).

Exceptions
UnsupportedOperationExceptionThrown if this object does not have a string representation.
Note
When called on Python classes, this method delegates to __repr__.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 80 of file python.h.

80 {
81 PYBIND11_OVERLOAD_NAME(std::string, Base, "__repr__", toString, );
82 }
std::string toString() const override
Create a string representation of this object (optional operation).
Definition python.h:80

◆ write()

template<typename Base >
void StorableHelper::write ( table::io::OutputArchiveHandle & handle) const
overridevirtualinherited

Write the object to one or more catalogs.

The handle object passed to this function provides an interface for adding new catalogs and adding nested objects to the same archive (while checking for duplicates). See OutputArchiveHandle for more information.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 193 of file python.h.

193 {
194 pybind11::gil_scoped_acquire gil;
195 pybind11::function overload = pybind11::get_overload(static_cast<const Base *>(this), "_write");
196 if (!overload)
197 throw std::runtime_error("Cannot find StorableHelper _write overload");
198 auto o = overload().cast<std::string>();
199 auto const &keys = StorableHelperPersistenceHelper::get();
200 table::BaseCatalog cat = handle.makeCatalog(keys.schema);
201 std::shared_ptr<table::BaseRecord> record = cat.addNew();
202 record->set(keys.bytes, formatters::stringToBytes(o));
203 handle.saveCatalog(cat);
204}
ndarray::Array< std::uint8_t, 1, 1 > stringToBytes(std::string const &str)
Encode a std::string as a vector of uint8.
Definition Utils.cc:43
CatalogT< BaseRecord > BaseCatalog
Definition fwd.h:72

◆ writeFits() [1/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::Fits & fitsfile) const
inherited

Write the object to an already-open FITS object.

Parameters
[in]fitsfileOpen FITS object to write to.

Definition at line 18 of file Persistable.cc.

18 {
19 OutputArchive archive;
20 archive.put(this);
21 archive.writeFits(fitsfile);
22}

◆ writeFits() [2/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::MemFileManager & manager,
std::string const & mode = "w" ) const
inherited

Write the object to a FITS image in memory.

Parameters
[in]managerName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

Definition at line 29 of file Persistable.cc.

29 {
30 fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
31 writeFits(fitsfile);
32}
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.

◆ writeFits() [3/3]

void lsst::afw::table::io::Persistable::writeFits ( std::string const & fileName,
std::string const & mode = "w" ) const
inherited

Write the object to a regular FITS file.

Parameters
[in]fileNameName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

Definition at line 24 of file Persistable.cc.

24 {
25 fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
26 writeFits(fitsfile);
27}

Friends And Related Symbol Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream & os,
Storable const & storable )
related

Output operator for Storable.

Parameters
osthe desired output stream
storablethe object to print
Returns
a reference to os
Exceptions
UnsupportedOperationExceptionThrown if storable does not have an implementation of Storable::toString.

Definition at line 174 of file Storable.h.

174 {
175 return os << storable.toString();
176}

The documentation for this class was generated from the following file: