casacore / python-casacore

Python bindings for casacore, a library used in radio astronomy
http://casacore.github.io/python-casacore
GNU Lesser General Public License v3.0
35 stars 22 forks source link

python-casacore has implicit dependency on casadata #248

Open dmehring opened 11 months ago

dmehring commented 11 months ago

We'd like not to have to install casadata, which is a fairly large package. However, opening an image will fail without the Observatories table which is part of casadata. Can code be modified to eliminate the casadata dependency? I believe any image will reproduce the error, but if not I can make mine available.

from casacore.images import image as cimage
casa_image = cimage('demo_simulated.im')

2023-10-11 15:05:01        WARN        MeasIERS::findTab (file
/code/measures/Measures/MeasIERS.cc, line 389)        Requested data table
Observatories cannot be found in the searched directories:
2023-10-11 15:05:01        WARN        MeasIERS::findTab (file
/code/measures/Measures/MeasIERS.cc, line
389)+        /usr/share/casacore/data/ephemerides/
2023-10-11 15:05:01        WARN        MeasIERS::findTab (file
/code/measures/Measures/MeasIERS.cc, line
389)+        /usr/share/casacore/data/geodetic/
2023-10-11 15:05:01        SEVERE        MeasTable::doInitObservatories() (file
/code/measures/Measures/MeasTable.cc, line 2867)Cannot read table of
Observatories
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Cell In[7], line 1
----> 1 casa_image = cimage('demo_simulated.im')

File
~/projects/xradio/xenv/lib/python3.10/site-packages/casacore/images/image.py:159,
in image.__init__(self, imagename, axis, maskname, images, values,
coordsys, overwrite, ashdf5, mask, shape, tileshape)
    157         six.print_("Probably could not import casacore.util")
    158         pass
--> 159     Image.__init__(self, imagename, maskname, imgs)
    160 else:
    161     # Create an image from an array
    162     # The values can be a masked array
    163     #  use the mask if no explicit mask is given
    164     if isinstance(values, nma.MaskedArray):

RuntimeError: demo_simulated.im cannot be opened as image (expression):
2023-10-11 15:05:01        SEVERE        MeasTable::doInitObservatories() (file
/code/measures/Measures/MeasTable.cc, line 2867)        Cannot read table of
Observatories
tammojan commented 11 months ago

I could reproduce the error, and got the following stack trace (boost and python stuff omitted). Just from this stacktrace, it looks like this may need changes in casacore.

gdb --args python3 -c 'from casacore.images import image; image("test_image.im")'
#0  0x00007f091af104a1 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#1  0x00007f091a12c002 in void casacore::LogIO::postThenThrow<casacore::AipsError>(casacore::AipsError const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_casa-aa1f7f3c.so.7
#2  0x00007f091a12bb4a in casacore::operator<<(casacore::LogIO&, casacore::LogIO::Command) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_casa-aa1f7f3c.so.7
#3  0x00007f091c839471 in casacore::MeasTable::doInitObservatories() ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_measures-3aaf8b1f.so.7
#4  0x00007f091f9afee8 in __pthread_once_slow (once_control=0x7f091c968760 <casacore::MeasTable::theirObsInitOnceFlag>, init_routine=0x7f091af3cd50 <__once_proxy>)
    at ./nptl/pthread_once.c:116
#5  0x00007f091c83026d in casacore::MeasTable::Observatory(casacore::MPosition&, casacore::String const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_measures-3aaf8b1f.so.7
#6  0x00007f091e249aa6 in casacore::ObsInfo::setTelescope(casacore::String const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_coordinates-53a1c604.so.7
#7  0x00007f091e24c2fc in casacore::ObsInfo::fromRecord(casacore::String&, casacore::RecordInterface const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_coordinates-53a1c604.so.7
#8  0x00007f091e1ef33e in casacore::CoordinateSystem::restore(casacore::RecordInterface const&, casacore::String const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_coordinates-53a1c604.so.7
#9  0x00007f091e76e92c in casacore::PagedImage<float>::restoreAll(casacore::TableRecord const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_images-a6905fae.so.7
#10 0x00007f091e76eb60 in casacore::PagedImage<float>::PagedImage(casacore::Table&, casacore::MaskSpecifier, unsigned int) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_images-a6905fae.so.7
#11 0x00007f091e7e3884 in casacore::ImageOpener::openPagedImage(casacore::String const&, casacore::MaskSpecifier const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_images-a6905fae.so.7
#12 0x00007f091e7e3ef3 in casacore::ImageOpener::openImage(casacore::String const&, casacore::MaskSpecifier const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_images-a6905fae.so.7
#13 0x00007f091e83a3f3 in casacore::ImageProxy::openImageOrExpr(casacore::String const&, casacore::MaskSpecifier const&, casacore::Block<casacore::LatticeExprNode> const&) ()
   from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_images-a6905fae.so.7
#14 0x00007f091e83f588 in casacore::ImageProxy::openImage(casacore::String const&, casacore::String const&, std::vector<casacore::ImageProxy, std::allocator<casacore::ImageProxy> > const&) () from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_images-a6905fae.so.7
#15 0x00007f091e83f821 in casacore::ImageProxy::ImageProxy(casacore::String const&, casacore::String const&, std::vector<casacore::ImageProxy, std::allocator<casacore::ImageProxy> > const&) () from /usr/local/lib/python3.10/dist-packages/casacore/images/../../python_casacore.libs/libcasa_images-a6905fae.so.7
#16 0x00007f091f3db125 in boost::python::objects::value_holder<casacore::ImageProxy>::value_holder<boost::python::objects::reference_to_value<casacore::String>, boost::python::objects::reference_to_value<casacore::String>, boost::python::objects::reference_to_value<std::vector<casacore::ImageProxy, std::allocator<casacore::ImageProxy> > > > (a2=..., a1=...,
    a0=..., self=0x7f091f69c900, this=0x7f0917c61c58) at /opt/boost/include/boost/python/object/forward.hpp:74
dmehring commented 11 months ago

Yes, the messages come from the casacore measures code. So, maybe this ticket is more appropriate for casacore, but I don't have a sample C++ program for it :), although I'm guessing one of the casacore test programs that opens an image could be used to reproduce the error.

tammojan commented 11 months ago

Good point. Let's continue the issue in https://github.com/casacore/casacore/issues/1321

maneesh29s commented 1 day ago

Is this issue fixed? Does python-casacore 3.6.1 does not depend on casadata?