ndcube
ndcube copied to clipboard
`ExtraCoords` half works if not attached to a `NDCube`
trafficstars
Describe the bug
I came across this due to this conversation. We should decide what we want the behaviour to be for a standalone ExtraCoords object.
To Reproduce
import astropy.units as u
from ndcube import ExtraCoords
ec = ExtraCoords.from_lookup_tables(('hello', 'bye'),
(1, 1),
(list(range(3)) * u.m,
list(range(3)) * u.keV,
)
)
ec.wcs
<WCS(output_frame=CompositeFrame, input_frame=PixelFrame, forward_transform=Model: CompoundModel
Inputs: ('x0', 'x1')
Outputs: ('y0', 'y1')
Model set size: 1
Expression: [0] & [1]
Components:
[0]: <Tabular1D(points=(<Quantity [0., 1., 2.] pix>,), lookup_table=[0. 1. 2.] m)>
[1]: <Tabular1D(points=(<Quantity [0., 1., 2.] pix>,), lookup_table=[0. 1. 2.] keV)>
Parameters:)>
ec.mapping
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[6], line 1
----> 1 ec.mapping
File ~/Git/ndcube/ndcube/extra_coords/extra_coords.py:264, in ExtraCoords.mapping(self)
261 # The mapping is from the array index (position in the list) to the
262 # pixel dimensions (numbers in the list)
263 lts = [list([lt[0]] if isinstance(lt[0], Integral) else lt[0]) for lt in self._lookup_tables]
--> 264 converter = partial(convert_between_array_and_pixel_axes, naxes=len(self._ndcube.shape))
265 pixel_indicies = [list(converter(np.array(ids))) for ids in lts]
266 return tuple(reduce(list.__add__, pixel_indicies))
AttributeError: 'NoneType' object has no attribute 'shape'
Screenshots
No response
System Details
No response
Installation method
No response
Would this mean ExtraCoord needs its own concept of shape that needs aligning to its _ndcube if present?
I'm not really sure what we want the behaviour to be. We could choose to just not allow ExtraCoords to work at all if it's not got a cube. At minimum we should clear up these errors to make it obvious why it's not working.