Bug #1581
Skymap pixel iterator does not work on Debian and FreeBSD
Status: | Closed | Start date: | 11/24/2015 | |
---|---|---|---|---|
Priority: | Urgent | Due date: | ||
Assigned To: | Knödlseder Jürgen | % Done: | 100% | |
Category: | - | |||
Target version: | - | |||
Duration: |
Description
On Debian and FreeBSD, the following code leads to an exception:
>>> import gammalib >>> m=gammalib.GSkyMap("CAR","CEL",0.0,0.0,1.0,1.0,2,2) >>> for pix in m: ... print(pix) ... 0.0 0.0 0.0 0.0 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/jenkins/jenkins/install/gammalib-integrate-os/lib/python2.6/site-packages/gammalib/sky.py", line 650, in __getitem__ return _sky.GSkyMap___getitem__(self, *args) RuntimeError: *** ERROR in GSkyMap::operator(int&, int&): Sky map pixel index 4 is outside the valid range [0,3].
For some reason the exception is not catched.
Recurrence
No recurrence.
Related issues
History
#1 Updated by Knödlseder Jürgen about 9 years ago
- Description updated (diff)
The SWIG version on Debian is 1.3.40.
#2 Updated by Knödlseder Jürgen about 9 years ago
The relevant code in sky_wrap.cpp
is:
try { result = (double)GSkyMap___getitem__(arg1,arg2); } catch (const GException::out_of_range& e) { SWIG_exception(SWIG_IndexError, e.what()); } catch (const GExceptionHandler& e) { SWIG_exception(SWIG_RuntimeError, e.what()); <=== THIS ONE THROWN } catch (const std::exception& e) { SWIG_exception(SWIG_RuntimeError, e.what()); }For some reason the
GException::out_of_range
is not catched, but GExceptionHandler
instead.#3 Updated by Knödlseder Jürgen about 9 years ago
- % Done changed from 0 to 50
Adding the following code to the Python interface solves the problem:
double __getitem__(int GSkyMapInx[]) {
if (GSkyMapInx[0] == 1) {
if (GSkyMapInx[1] >= 0 && GSkyMapInx[1] < self->npix()) {
return (*self)(GSkyMapInx[1]);
}
else {
throw GException::out_of_range("__getitem__(int)", "Sky map index",
GSkyMapInx[1], self->npix());
}
}
else {
return (*self)(GSkyMapInx[1], GSkyMapInx[2]);
}
}
#4 Updated by Knödlseder Jürgen about 9 years ago
- Status changed from New to Closed
- % Done changed from 50 to 100
This solved the problem. Merged into devel
.