79#if PY_MAJOR_VERSION == 2
80 using py_argv_char_t = char;
81#define py_argv_assign(d, s, l) d = strndup(s, l)
83 using py_argv_char_t = wchar_t;
84#define py_argv_assign(d, s, l) d = Py_DecodeLocale(s, &(l))
87 py_argv_char_t** py_argv =
static_cast<py_argv_char_t**
>(PyMem_MALLOC((argv.
size() + 1) *
sizeof(py_argv_char_t*)));
88 size_t wlen = filename.size();
90 for (
size_t i = 0; i < argv.
size(); ++i) {
91 wlen = argv[i].
size();
94 PySys_SetArgv(argv.
size() + 1, py_argv);
97 py::import(
"_SourceXtractorPy");
100 PySys_SetObject(
"stdout", py::object(boost::ref(
m_out_wrapper)).ptr());
101 PySys_SetObject(
"stderr", py::object(boost::ref(
m_err_wrapper)).ptr());
104 py::object main_module = py::import(
"__main__");
105 py::setattr(main_module,
"__file__", py::object(filename));
106 py::object main_namespace = main_module.attr(
"__dict__");
116 py::exec(pycode.
c_str(), main_namespace);
117 }
catch (
const py::error_already_set& e) {
119 throw Elements::Exception() <<
"An error occured while running the Python configuration script";
177 py::list output = py::extract<py::list>(
m_measurement_config.attr(
"model_fitting_parameter_columns"));
179 for (
int i = 0; i < py::len(output); ++i) {
180 py::tuple t = py::extract<py::tuple>(output[i]);
182 auto extract_list = py::extract<py::list>(t[1]);
185 if (extract_list.check()) {
186 py::list cs = extract_list;
187 for (
int j = 0; j < py::len(cs); ++j) {
188 int c = py::extract<int>(cs[j].attr(
"id"));
192 int c = py::extract<int>(t[1]);
198 }
catch (
const py::error_already_set& e) {
200 throw Elements::Exception() <<
"An error occurred while retrieving model fitting output columns";
210 for (
int i = 0; i < py::len(output); ++i) {
211 py::tuple t = py::extract<py::tuple>(output[i]);
213 auto extract_list = py::extract<py::list>(t[1]);
215 if (extract_list.check()) {
216 py::list cs = extract_list;
217 for (
int j = 0; j < py::len(cs); ++j) {
218 int c = py::extract<int>(cs[j].attr(
"id"));
219 result[name].push_back(c);
222 int c = py::extract<int>(t[1]);
223 result[name].push_back(c);
227 }
catch (
const py::error_already_set& e) {
229 throw Elements::Exception() <<
"An error occurred while retrieving aperture output columns";
300 py::dict frame_dict = py::extract<py::dict>(model_fitting.attr(
"frame_models_dict"));
301 py::list frame_ids = frame_dict.keys();
302 for (
int i = 0; i < py::len(frame_ids); ++i) {
303 int frame_id = py::extract<int>(frame_ids[i]);
304 py::list model_ids = py::extract<py::list>(frame_dict[frame_ids[i]]);
305 for (
int j = 0; j < py::len(model_ids); ++j) {
306 int model_id = py::extract<int>(model_ids[j]);
307 result[frame_id].push_back(model_id);
311 }
catch (
const py::error_already_set& e) {