SourceXtractorPlusPlus  0.19
SourceXtractor++, the next generation SExtractor
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
34 
35 namespace bp = boost::python;
36 
37 namespace SourceXtractor {
38 
39 BOOST_PYTHON_MODULE(_SourceXtractorPy) {
40 
41  bp::class_<PyOutputWrapper, boost::noncopyable>("OutputWrapper",
42  "A file-like object used to wrap stdout and stderr", bp::no_init)
43  .def_readonly("closed", &PyOutputWrapper::closed)
44  .def("close", &PyOutputWrapper::close)
45  .def("fileno", &PyOutputWrapper::fileno)
46  .def("flush", &PyOutputWrapper::flush)
47  .def("isatty", &PyOutputWrapper::isatty)
48  .def("readable", &PyOutputWrapper::readable)
49  .def("read", &PyOutputWrapper::read)
50  .def("readline", &PyOutputWrapper::readline)
51  .def("readlines", &PyOutputWrapper::readlines)
52  .def("seek", &PyOutputWrapper::seek)
53  .def("seekable", &PyOutputWrapper::seekable)
54  .def("tell", &PyOutputWrapper::tell)
55  .def("truncate", &PyOutputWrapper::truncate)
56  .def("writable", &PyOutputWrapper::writable)
57  .def("write", &PyOutputWrapper::write)
58  .def("writelines", &PyOutputWrapper::writelines);
59 
60  bp::class_<PyMeasurementImage>("MeasurementImage",
61  "C++ part of the MeasurementImage", bp::init<std::string, std::string, std::string>())
62  .def_readonly("id", &PyMeasurementImage::id)
63  .def_readonly("file", &PyMeasurementImage::file)
64  .def_readwrite("gain", &PyMeasurementImage::gain)
65  .def_readwrite("saturation", &PyMeasurementImage::saturation)
66  .def_readwrite("flux_scale", &PyMeasurementImage::flux_scale)
67  .def_readonly("psf_file", &PyMeasurementImage::psf_file)
68  .def_readonly("weight_file", &PyMeasurementImage::weight_file)
69  .def_readwrite("weight_type", &PyMeasurementImage::weight_type)
70  .def_readwrite("weight_absolute", &PyMeasurementImage::weight_absolute)
71  .def_readwrite("weight_scaling", &PyMeasurementImage::weight_scaling)
72  .def_readwrite("has_weight_threshold", &PyMeasurementImage::has_weight_threshold)
73  .def_readwrite("weight_threshold", &PyMeasurementImage::weight_threshold)
74  .def_readwrite("is_background_constant", &PyMeasurementImage::is_background_constant)
75  .def_readwrite("constant_background_value", &PyMeasurementImage::constant_background_value)
76  .def_readwrite("image_hdu", &PyMeasurementImage::image_hdu)
77  .def_readwrite("psf_hdu", &PyMeasurementImage::psf_hdu)
78  .def_readwrite("weight_hdu", &PyMeasurementImage::weight_hdu)
79  .def_readwrite("is_data_cube", &PyMeasurementImage::is_data_cube)
80  .def_readwrite("image_layer", &PyMeasurementImage::image_layer)
81  .def_readwrite("weight_layer", &PyMeasurementImage::weight_layer)
82  ;
83 
84  bp::class_<PyId>("Id", bp::init<>())
85  .def_readonly("id", &PyId::id);
86 
87  bp::class_<PyAperture, bp::bases<PyId>>("Aperture",
88  "Set of aperture photometries", bp::init<bp::list>())
89  .def_readonly("apertures", &PyAperture::apertures, "List of aperture diameters, in pixels")
90  .def("__str__", &PyAperture::toString)
91  .def("__repr__", &PyAperture::toString);
92 
93  bp::class_<CoordinateSystem, boost::noncopyable>("CoordinateSystem",
94  "Implements transformation of coordinates between image and world coordinates", bp::no_init)
95  .def("image_to_world", &CoordinateSystem::imageToWorld)
96  .def("world_to_image", &CoordinateSystem::worldToImage);
97  bp::register_ptr_to_python<std::shared_ptr<CoordinateSystem>>();
98 
99  bp::class_<WorldCoordinate>("WorldCoordinate", "World coordinates")
100  .def(bp::init<double, double>())
101  .def_readwrite("alpha", &WorldCoordinate::m_alpha)
102  .def_readwrite("delta", &WorldCoordinate::m_delta);
103 
104  bp::class_<ImageCoordinate>("ImageCoordinate", "Image coordinates, in pixels")
105  .def(bp::init<double, double>())
106  .def_readwrite("x", &ImageCoordinate::m_x)
107  .def_readwrite("y", &ImageCoordinate::m_y);
108 
109  bp::enum_<Flags>("Flags", "Source flags")
110  .value("NONE", Flags::NONE)
111  .value("BIASED", Flags::BIASED)
112  .value("SATURATED", Flags::SATURATED)
113  .value("BOUNDARY", Flags::BOUNDARY)
114  .value("NEIGHBORS", Flags::NEIGHBORS)
115  .value("OUTSIDE", Flags::OUTSIDE)
116  .value("PARTIAL_FIT", Flags::PARTIAL_FIT)
117  .value("INSUFFICIENT_DATA", Flags::INSUFFICIENT_DATA)
118  .value("ERROR", Flags::ERROR);
119 
120  bp::class_<std::vector<int> >("_IntVector")
121  .def(bp::vector_indexing_suite<std::vector<int> >());
122 
123  bp::class_<std::vector<unsigned int> >("_UIntVector")
124  .def(bp::vector_indexing_suite<std::vector<unsigned int> >());
125 
126  bp::class_<std::map<std::string, std::string>>("_StringStringMap")
127  .def(bp::map_indexing_suite<std::map<std::string, std::string>>());
128 
129  bp::class_<PyFitsFile>("FitsFile", "A FITS file opened by SourceXtractor++", bp::init<const std::string&>())
130  .def_readonly("filename", &PyFitsFile::getFilename)
131  .def_readonly("image_hdus", &PyFitsFile::getImageHdus)
132  .def("get_headers", &PyFitsFile::getHeaders, "get headers for hdu")
133  .def("get_dimensions", &PyFitsFile::getDimensions, "get dimensions for hdu");
134 
135 }
136 
137 } // namespace SourceXtractor
The object has neighbors, bright and close enough.
std::map< std::string, std::string > getHeaders(int hdu) const
Definition: PyFitsFile.cpp:43
The object is completely outside of the measurement frame.
std::string getFilename() const
Definition: PyFitsFile.h:36
const int id
Definition: PyId.h:35
std::vector< int > getImageHdus() const
Definition: PyFitsFile.cpp:28
std::vector< int > getDimensions(int hdu) const
Definition: PyFitsFile.cpp:38
std::vector< float > apertures
Definition: PyAperture.h:36
The object is truncated (too close to an image boundary)
virtual WorldCoordinate imageToWorld(ImageCoordinate image_coordinate) const =0
boost::python::list readlines(int)
virtual ImageCoordinate worldToImage(WorldCoordinate world_coordinate) const =0
The object has bad pixels.
BOOST_PYTHON_MODULE(_SourceXtractorPy)
int write(const boost::python::object &)
There are not enough good pixels to fit the parameters.
At least one pixel of the object is saturated.
Some/all of the model parameters could not be fitted.
void writelines(const boost::python::list &)
std::string toString() const
Definition: PyAperture.cpp:32
Error flag: something bad happened during the measurement, model fitting, etc.