Action #2285
Add GSkyMap::array() method to Python interface
Status: | Closed | Start date: | 12/01/2017 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assigned To: | Knödlseder Jürgen | % Done: | 100% | |
Category: | - | |||
Target version: | 1.5.0 | |||
Duration: |
Description
Add a GSkyMap::array()
method to the Python interface that returns a list of lists that can be directly displayed using the matplotlib imshow()
function.
Recurrence
No recurrence.
History
#1 Updated by Knödlseder Jürgen about 7 years ago
- Status changed from New to Closed
- % Done changed from 0 to 100
I added the following code to the GSkyMap.i
interface
%extend GSkyMap {
...
// Add pixel access operator as Python array
PyObject* array(const int& imap = 0) {
if (imap < 0 || imap >= self->nmaps()) {
throw GException::out_of_range("GSkyMap::array(int&)", "Map index",
imap, self->nmaps());
}
PyObject* array = PyList_New(self->ny());
int offset = imap * self->nx() * self->ny();
for (int iy = 0; iy < self->ny(); ++iy, offset += self->nx()) {
PyObject* row = PyList_New(self->nx());
for (int ix = 0; ix < self->nx(); ++ix) {
PyList_SetItem(row, ix, PyFloat_FromDouble((self->pixels())[ix+offset]));
}
PyList_SetItem(array, iy, row);
}
return array;
}
};