LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Protected Types | Static Protected Member Functions | Related Functions | 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. More...
 
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). More...
 
std::string toString () const override
 Create a string representation of this object (optional operation). More...
 
std::size_t hash_value () const override
 Return a hash of this object (optional operation). More...
 
bool equals (Storable const &other) const noexcept override
 Compare this object to another Storable. More...
 
bool isPersistable () const noexcept override
 Return true if this particular object can be persisted using afw::table::io. More...
 
std::string getPersistenceName () const override
 Return the unique name used to persist this object and look up its factory. More...
 
std::string getPythonModule () const override
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered. More...
 
void write (table::io::OutputArchiveHandle &handle) const override
 Write the object to one or more catalogs. More...
 
void writeFits (std::string const &fileName, std::string const &mode="w") const
 Write the object to a regular FITS file. More...
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 Write the object to a FITS image in memory. More...
 
void writeFits (fits::Fits &fitsfile) const
 Write the object to an already-open FITS object. More...
 

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. More...
 

Related Functions

(Note that these are not member functions.)

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

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:161
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.
Definition: Persistable.cc:24

◆ 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 Function 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 }
std::ostream * os
Definition: Schema.cc:557

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