`ExtraCoords` half works if not attached to a `NDCube`

Open
#753 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
python
Domain
data

Research direction

Start in ndcube/extra_coords/extra_coords.py at ExtraCoords.mapping, then run the standalone reproduction using ExtraCoords.from_lookup_tables and compare ec.wcs with ec.mapping. Determine and document the intended behavior for an ExtraCoords object without an attached NDCube, and add tests covering that behavior.

Written by the indexing model from the issue text.

Description

Discussion
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

Dominant language
Python
Stars
49
Forks
56
Avg merge
5h 54m
Merged PRs (30d)
9

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from sunpy/ndcube

All issues in sunpy/ndcube

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.