NDCollection does not support the internal representation of `aligned_axes` in the constructor
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 55/100
Research direction
Start in ndcube/utils/collection.py, especially _sanitize_aligned_axes and _sanitize_user_aligned_axes, using the traceback as the entry point. Reproduce the constructor call with a dict aligned_axes and add coverage for this representation; done means NDCollection(new_items, aligned_axes=spice.aligned_axes) no longer raises KeyError while existing aligned_axes forms continue to work.
Written by the indexing model from the issue text.
Description
Describe the bug
While I am loathed to support more permutations of the aligned_axes= keyword argument seeing as we apparently already support nearly every conceivable option, the one we don't support is the one we use internally (the dict) representation.
>>> spice.aligned_axes
{'Mg IX 706 - Peak': (np.int64(1), np.int64(2)),
'N IV 765 - Peak': (np.int64(1), np.int64(2)),
'Ne VIII 770 - Peak': (np.int64(1), np.int64(2)),
'Ly-gamma-CIII group (Merged)': (np.int64(1), np.int64(2)),
'Ly Beta 1025 (Merged)': (np.int64(1), np.int64(2)),
'O VI 1032 - Peak': (np.int64(1), np.int64(2))}
>>> new_collection = NDCollection(new_cubes, aligned_axes=spice.aligned_axes)
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[23], line 9
7 c = NDCube(cube, meta=dict(cube.meta))
8 new_items.append((key, c))
----> 9 spice = NDCollection(new_items, aligned_axes=spice.aligned_axes)
10 spice
File ~/.virtualenvs/hinode-talk/lib/python3.13/site-packages/ndcube/ndcollection.py:69, in NDCollection.__init__(self, key_data_pairs, aligned_axes, meta, **kwargs)
67 # Sanitize aligned axes unless hidden kwarg indicates not to.
68 if sanitize_inputs:
---> 69 aligned_axes = collection_utils._sanitize_aligned_axes(keys, data, aligned_axes)
70 else:
71 aligned_axes = dict(zip(keys, aligned_axes))
File ~/.virtualenvs/hinode-talk/lib/python3.13/site-packages/ndcube/utils/collection.py:23, in _sanitize_aligned_axes(keys, data, aligned_axes)
20 sanitized_axes = tuple([tuple(range(len(cube0_dims)))] * len(data))
21 else:
22 # Else, sanitize user-supplied aligned axes.
---> 23 sanitized_axes = _sanitize_user_aligned_axes(data, aligned_axes)
25 return dict(zip(keys, sanitized_axes))
File ~/.virtualenvs/hinode-talk/lib/python3.13/site-packages/ndcube/utils/collection.py:43, in _sanitize_user_aligned_axes(data, aligned_axes)
40 aligned_axes_error_message = ("aligned_axes must contain ints or "
41 "a tuple of ints for each element in data.")
42 if isinstance(data[0].shape, tuple):
---> 43 cube0_dims = np.array(data[0].shape, dtype=object)[np.array(aligned_axes[0])]
44 else:
45 cube0_dims = data[0].shape[np.array(aligned_axes[0])]
KeyError: 0
- Dominant language
- Python
- Stars
- 49
- Forks
- 56
- Avg merge
- 5h 54m
- Merged PRs (30d)
- 9
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sunpy/ndcube
-
Bug
Difficulty 4/5 3-5 days Newbie friendliness 38/100
-
Bug
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Feature Request
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Feature Request
Difficulty 4/5 3-5 days Newbie friendliness 42/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100