SourceXtractorPlusPlus  0.10
Please provide a description of the project.
PythonModule.cpp
Go to the documentation of this file.
1 
17 /*
18  * @file PythonModule.cpp
19  * @author Nikolaos Apostolakos <nikoapos@gmail.com>
20  */
21 
22 #include <boost/python/class.hpp>
23 #include <boost/python/enum.hpp>
24 #include <boost/python/module.hpp>
25 #include <boost/python/suite/indexing/vector_indexing_suite.hpp>
26 
33 
34 namespace bp = boost::python;
35 
36 namespace SourceXtractor {
37 
38 BOOST_PYTHON_MODULE(_SourceXtractorPy) {
39 
40  bp::class_<PyOutputWrapper, boost::noncopyable>("OutputWrapper",
41  "A file-like object used to wrap stdout and stderr", bp::no_init)
42  .def_readonly("closed", &PyOutputWrapper::closed)
43  .def("close", &PyOutputWrapper::close)
44  .def("fileno", &PyOutputWrapper::fileno)
45  .def("flush", &PyOutputWrapper::flush)
46  .def("isatty", &PyOutputWrapper::isatty)
47  .def("readable", &PyOutputWrapper::readable)
48  .def("read", &PyOutputWrapper::read)
49  .def("readline", &PyOutputWrapper::readline)
50  .def("readlines", &PyOutputWrapper::readlines)
51  .def("seek", &PyOutputWrapper::seek)
52  .def("seekable", &PyOutputWrapper::seekable)
53  .def("tell", &PyOutputWrapper::tell)
54  .def("truncate", &PyOutputWrapper::truncate)
55  .def("writable", &PyOutputWrapper::writable)
56  .def("write", &PyOutputWrapper::write)
57  .def("writelines", &PyOutputWrapper::writelines);
58 
59  bp::class_<ObjectInfo>("ObjectInfo",
60  "A source detected by SourceXtractor++ after the segmentation and deblending", bp::init<SourceInterface&>())
61  .def("get_centroid_x", &ObjectInfo::getCentroidX, "Get the X coordinate of the pixel centroid")
62  .def("get_centroid_y", &ObjectInfo::getCentroidY, "Get the Y coordinate of the pixel centroid")
63  .def("get_iso_flux", &ObjectInfo::getIsoFlux, "Get the isophotal flux")
64  .def("get_radius", &ObjectInfo::getRadius, "Get the source semi-major axis, in pixels")
65  .def("get_angle", &ObjectInfo::getAngle, "Get the source angle, in radians")
66  .def("get_aspect_ratio", &ObjectInfo::getAspectRatio, "Get the aspect ratio");
67 
68  bp::class_<PyMeasurementImage>("MeasurementImage",
69  "C++ part of the MeasurementImage", bp::init<std::string, std::string, std::string>())
70  .def_readonly("id", &PyMeasurementImage::id)
71  .def_readonly("file", &PyMeasurementImage::file)
72  .def_readwrite("gain", &PyMeasurementImage::gain)
73  .def_readwrite("saturation", &PyMeasurementImage::saturation)
74  .def_readwrite("flux_scale", &PyMeasurementImage::flux_scale)
75  .def_readonly("psf_file", &PyMeasurementImage::psf_file)
76  .def_readonly("weight_file", &PyMeasurementImage::weight_file)
77  .def_readwrite("weight_type", &PyMeasurementImage::weight_type)
78  .def_readwrite("weight_absolute", &PyMeasurementImage::weight_absolute)
79  .def_readwrite("weight_scaling", &PyMeasurementImage::weight_scaling)
80  .def_readwrite("has_weight_threshold", &PyMeasurementImage::has_weight_threshold)
81  .def_readwrite("weight_threshold", &PyMeasurementImage::weight_threshold)
82  .def_readwrite("is_background_constant", &PyMeasurementImage::is_background_constant)
83  .def_readwrite("constant_background_value", &PyMeasurementImage::constant_background_value)
84  .def_readwrite("image_hdu", &PyMeasurementImage::image_hdu)
85  .def_readwrite("psf_hdu", &PyMeasurementImage::psf_hdu)
86  .def_readwrite("weight_hdu", &PyMeasurementImage::weight_hdu);
87 
88  bp::class_<PyId>("Id", bp::init<>())
89  .def_readonly("id", &PyId::id);
90 
91  bp::class_<PyAperture, bp::bases<PyId>>("Aperture",
92  "Set of aperture photometries", bp::init<bp::list>())
93  .def_readonly("apertures", &PyAperture::apertures, "List of aperture diameters, in pixels")
94  .def("__str__", &PyAperture::toString)
95  .def("__repr__", &PyAperture::toString);
96 
97  bp::class_<CoordinateSystem, boost::noncopyable>("CoordinateSystem",
98  "Implements transformation of coordinates between image and world coordinates", bp::no_init)
99  .def("image_to_world", &CoordinateSystem::imageToWorld)
100  .def("world_to_image", &CoordinateSystem::worldToImage);
101  bp::register_ptr_to_python<std::shared_ptr<CoordinateSystem>>();
102 
103  bp::class_<WorldCoordinate>("WorldCoordinate", "World coordinates")
104  .def(bp::init<double, double>())
105  .def_readwrite("alpha", &WorldCoordinate::m_alpha)
106  .def_readwrite("delta", &WorldCoordinate::m_delta);
107 
108  bp::class_<ImageCoordinate>("ImageCoordinate", "Image coordinates, in pixels")
109  .def(bp::init<double, double>())
110  .def_readwrite("x", &ImageCoordinate::m_x)
111  .def_readwrite("y", &ImageCoordinate::m_y);
112 
113  bp::enum_<Flags>("Flags", "Source flags")
114  .value("NONE", Flags::NONE)
115  .value("BIASED", Flags::BIASED)
116  .value("SATURATED", Flags::SATURATED)
117  .value("BOUNDARY", Flags::BOUNDARY)
118  .value("NEIGHBORS", Flags::NEIGHBORS)
119  .value("OUTSIDE", Flags::OUTSIDE)
120  .value("PARTIAL_FIT", Flags::PARTIAL_FIT)
121  .value("INSUFFICIENT_DATA", Flags::INSUFFICIENT_DATA)
122  .value("ERROR", Flags::ERROR);
123 
124  bp::class_<std::vector<double> >("_DoubleVector")
125  .def(bp::vector_indexing_suite<std::vector<double> >());
126 
127  bp::class_<std::vector<float> >("_FloatVector")
128  .def(bp::vector_indexing_suite<std::vector<float> >());
129 }
130 
131 } // namespace SourceXtractor
SourceXtractor::PyMeasurementImage::gain
double gain
Definition: PyMeasurementImage.h:36
SourceXtractor::PyMeasurementImage::saturation
double saturation
Definition: PyMeasurementImage.h:37
SourceXtractor::Flags::NEIGHBORS
@ NEIGHBORS
The object has neighbors, bright and close enough.
SourceXtractor::PyMeasurementImage::weight_scaling
double weight_scaling
Definition: PyMeasurementImage.h:43
SourceXtractor::ObjectInfo::getCentroidY
SeFloat getCentroidY() const
Definition: ObjectInfo.cpp:36
SourceXtractor::BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(_SourceXtractorPy)
Definition: PythonModule.cpp:38
SourceXtractor::PyOutputWrapper::fileno
int fileno() const
Definition: PyOutputWrapper.cpp:38
SourceXtractor::PyOutputWrapper::isatty
bool isatty() const
Definition: PyOutputWrapper.cpp:47
std::vector< double >
SourceXtractor::PyOutputWrapper::seekable
bool seekable() const
Definition: PyOutputWrapper.cpp:79
SourceXtractor::PyMeasurementImage::has_weight_threshold
bool has_weight_threshold
Definition: PyMeasurementImage.h:44
SourceXtractor::ObjectInfo::getAspectRatio
SeFloat getAspectRatio() const
Definition: ObjectInfo.cpp:53
SourceXtractor::PyOutputWrapper::writable
bool writable() const
Definition: PyOutputWrapper.cpp:94
SourceXtractor::Flags::ERROR
@ ERROR
Error flag: something bad happened during the measurement, model fitting, etc.
SourceXtractor::PyMeasurementImage::is_background_constant
bool is_background_constant
Definition: PyMeasurementImage.h:47
SourceXtractor::ObjectInfo::getAngle
SeFloat getAngle() const
Definition: ObjectInfo.cpp:49
SourceXtractor::PyOutputWrapper::truncate
void truncate(int)
Definition: PyOutputWrapper.cpp:89
SourceXtractor::WorldCoordinate::m_alpha
double m_alpha
Definition: CoordinateSystem.h:34
SourceFlags.h
SourceXtractor::PyMeasurementImage::constant_background_value
double constant_background_value
Definition: PyMeasurementImage.h:48
SourceXtractor::Flags::BOUNDARY
@ BOUNDARY
The object is truncated (too close to an image boundary)
SourceXtractor::Flags::PARTIAL_FIT
@ PARTIAL_FIT
Some/all of the model parameters could not be fitted.
SourceXtractor::WorldCoordinate::m_delta
double m_delta
Definition: CoordinateSystem.h:34
SourceXtractor::PyOutputWrapper::closed
const bool closed
Definition: PyOutputWrapper.h:42
SourceXtractor::PyOutputWrapper::readable
bool readable() const
Definition: PyOutputWrapper.cpp:51
PyOutputWrapper.h
SourceXtractor::PyId::id
const int id
Definition: PyId.h:35
SourceXtractor::PyMeasurementImage::image_hdu
int image_hdu
Definition: PyMeasurementImage.h:50
SourceXtractor::PyOutputWrapper::flush
void flush()
Definition: PyOutputWrapper.cpp:44
SourceXtractor::Flags::SATURATED
@ SATURATED
At least one pixel of the object is saturated.
SourceXtractor::PyOutputWrapper::write
int write(const boost::python::object &)
Definition: PyOutputWrapper.cpp:98
SourceXtractor::PyMeasurementImage::weight_absolute
bool weight_absolute
Definition: PyMeasurementImage.h:42
SourceXtractor::PyMeasurementImage::weight_file
std::string weight_file
Definition: PyMeasurementImage.h:40
SourceXtractor
Definition: Aperture.h:30
SourceXtractor::PyOutputWrapper::read
std::string read(int)
Definition: PyOutputWrapper.cpp:55
SourceXtractor::ImageCoordinate::m_y
double m_y
Definition: CoordinateSystem.h:43
SourceXtractor::PyMeasurementImage::weight_type
std::string weight_type
Definition: PyMeasurementImage.h:41
SourceXtractor::PyMeasurementImage::flux_scale
double flux_scale
Definition: PyMeasurementImage.h:38
ObjectInfo.h
SourceXtractor::PyAperture::toString
std::string toString() const
Definition: PyAperture.cpp:32
SourceXtractor::Flags::INSUFFICIENT_DATA
@ INSUFFICIENT_DATA
There are not enough good pixels to fit the parameters.
SourceXtractor::PyOutputWrapper::writelines
void writelines(const boost::python::list &)
Definition: PyOutputWrapper.cpp:130
SourceXtractor::PyOutputWrapper::readlines
boost::python::list readlines(int)
Definition: PyOutputWrapper.cpp:67
PyAperture.h
SourceXtractor::Flags::NONE
@ NONE
No flag is set.
SourceXtractor::Flags::OUTSIDE
@ OUTSIDE
The object is completely outside of the measurement frame.
SourceXtractor::PyMeasurementImage::psf_file
std::string psf_file
Definition: PyMeasurementImage.h:39
SourceXtractor::ImageCoordinate::m_x
double m_x
Definition: CoordinateSystem.h:43
SourceXtractor::ObjectInfo::getCentroidX
SeFloat getCentroidX() const
Definition: ObjectInfo.cpp:31
SourceXtractor::PyOutputWrapper::seek
int seek(int, int)
Definition: PyOutputWrapper.cpp:73
SourceXtractor::Flags::BIASED
@ BIASED
The object has bad pixels.
SourceXtractor::PyMeasurementImage::weight_threshold
double weight_threshold
Definition: PyMeasurementImage.h:45
SourceXtractor::PyMeasurementImage::weight_hdu
int weight_hdu
Definition: PyMeasurementImage.h:52
PythonModule.h
SourceXtractor::PyMeasurementImage::psf_hdu
int psf_hdu
Definition: PyMeasurementImage.h:51
SourceXtractor::ObjectInfo::getIsoFlux
SeFloat getIsoFlux() const
Definition: ObjectInfo.cpp:41
SourceXtractor::PyOutputWrapper::readline
std::string readline(int)
Definition: PyOutputWrapper.cpp:61
SourceXtractor::CoordinateSystem::imageToWorld
virtual WorldCoordinate imageToWorld(ImageCoordinate image_coordinate) const =0
SourceXtractor::PyOutputWrapper::tell
int tell() const
Definition: PyOutputWrapper.cpp:83
SourceXtractor::PyMeasurementImage::file
std::string file
Definition: PyMeasurementImage.h:35
SourceXtractor::PyAperture::apertures
std::vector< float > apertures
Definition: PyAperture.h:36
SourceXtractor::CoordinateSystem::worldToImage
virtual ImageCoordinate worldToImage(WorldCoordinate world_coordinate) const =0
SourceXtractor::PyOutputWrapper::close
void close()
Definition: PyOutputWrapper.cpp:33
SourceXtractor::ObjectInfo::getRadius
SeFloat getRadius() const
Definition: ObjectInfo.cpp:45
PyMeasurementImage.h