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
98 stars 65 forks source link

differing data structures of spatial and spectral extrema #664

Open drtobybrown opened 4 years ago

drtobybrown commented 4 years ago

Is there a reason that the spatial and spectral extrema attributes store different data structures?

In [6]: cube.spectral_extrema                                                                                                                                                                
Out[6]: (<Quantity 340.0 km / s>, <Quantity 933.0 km / s>)

In [7]: cube.longitude_extrema                                                                                                                                                               
Out[7]: <Quantity [83.95, 84.00 ] deg>

I often want to perform arithmetic on these values and the tuple in particular doesn't lend itself doing this concisely.

In [8]: np.subtract(cubeA.spectral_extrema, cubeB.spectral_extrema)
...
UnitConversionError: 'Unit("km / s")' is not a scaled version of 'Unit(dimensionless)'
During handling of the above exception, another exception occurred:
...
TypeError: only dimensionless scalar quantities can be converted to Python scalars
keflavich commented 4 years ago

No obvious reason. This seems like an easy fix to just return u.Quantity(the tuple) instead of the tuple as is.