SourceXtractorPlusPlus  0.13
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
SourceXtractor::PyMeasurementImage::gain
double gain
Definition: PyMeasurementImage.h:36
SourceXtractor::PyMeasurementImage::saturation
double saturation
Definition: PyMeasurementImage.h:37
SourceXtractor::PyMeasurementImage::weight_scaling
double weight_scaling
Definition: PyMeasurementImage.h:43
PyFitsFile.h
SourceXtractor::PyFitsFile::getHeaders
std::map< std::string, std::string > getHeaders(int hdu) const
Definition: PyFitsFile.cpp:41
SourceXtractor::ObjectInfo::getCentroidY
SeFloat getCentroidY() const
Definition: ObjectInfo.cpp:36
SourceXtractor::BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(_SourceXtractorPy)
Definition: PythonModule.cpp:40
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::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::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::PyFitsFile::getImageHdus
std::vector< int > getImageHdus() const
Definition: PyFitsFile.cpp:31
SourceXtractor::PyMeasurementImage::image_hdu
int image_hdu
Definition: PyMeasurementImage.h:50
SourceXtractor::PyOutputWrapper::flush
void flush()
Definition: PyOutputWrapper.cpp:44
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::PyFitsFile::getFilename
std::string getFilename() const
Definition: PyFitsFile.h:45
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
std::map< std::string, std::string >
SourceXtractor::PyAperture::toString
std::string toString() const
Definition: PyAperture.cpp:32
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::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::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