radio-astro-tools / spectral-cube

Library for reading and analyzing astrophysical spectral data cubes
http://spectral-cube.rtfd.org
BSD 3-Clause "New" or "Revised" License
96 stars 62 forks source link

Glue integration issues #761

Open keflavich opened 2 years ago

keflavich commented 2 years ago

I was unable to load a casa-image into glue, which suggests we have some holes to fix in both spectral-cube and glue-astronomy:

In [1]: from spectral_cube import SpectralCube

In [2]: cd /orange/adamginsburg/ALMAIMF_Images/G327.29/B6/linecubes_12m/
/orange/adamginsburg/ALMA_IMF/2017.1.01355.L/RestructuredImagingResults/G327.29/B6/linecubes_12m

In [3]: cube = SpectralCube.read('G327.29_B6_spw1_12M_sio.image.pbcor', format='casa_image')
WARNING: StokesWarning: Cube is a Stokes cube, returning spectral cube for I component [spectral_cube.io.core]

In [4]: dc['g327sio'] = cube
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_37871/376271071.py in <module>
----> 1 dc['g327sio'] = cube

~/.local/lib/python3.9/site-packages/glue/core/data_collection.py in __setitem__(self, key, data)
    397         if not isinstance(data, Data):
    398 
--> 399             handler, preferred = data_translator.get_handler_for(data)
    400 
    401             data = handler.to_data(data)

~/.local/lib/python3.9/site-packages/glue/config.py in get_handler_for(self, data_or_class)
    564                                 "type Data to {0}".format(data_or_class.__name__))
    565             else:
--> 566                 raise TypeError("Could not find a class to translate objects of "
    567                                 "type {0} to Data".format(data_or_class.__class__.__name__))
    568         return handler, preferred

TypeError: Could not find a class to translate objects of type DaskVaryingResolutionSpectralCube to Data

In [5]: cube.to_glue(name='sio', glue_app=application)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_37871/1811065730.py in <module>
----> 1 cube.to_glue(name='sio', glue_app=application)

/blue/adamginsburg/adamginsburg/repos/spectral-cube/spectral_cube/spectral_cube.py in to_glue(self, name, glue_app, dataset, start_gui)
   2400                     return self._glue_app
   2401 
-> 2402             glue_app.add_datasets(self._glue_app.data_collection, result)
   2403 
   2404 

/blue/adamginsburg/adamginsburg/repos/spectral-cube/spectral_cube/spectral_cube.py in __getattribute__(self, attrname)
   3925             return self._handle_beam_areas_wrapper(origfunc)
   3926         else:
-> 3927             return super(VRSC, self).__getattribute__(attrname)
   3928 
   3929     @property

AttributeError: 'DaskVaryingResolutionSpectralCube' object has no attribute '_glue_app'
keflavich commented 2 years ago

The problem is that DaskSpectralCubes are not instances of SpectralCubes; they should be, I think?

keflavich commented 2 years ago

I've got a fix in progress, but I don't think glue can handle VaryingResolution objects yet

keflavich commented 2 years ago

https://github.com/glue-viz/glue-astronomy/pull/54