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