Skip to content

Conversation

@DanRyanIrish
Copy link
Member

PR Description

Resolves Issue #861

Allow length-1 inputs and convert them to scalars.
@DanRyanIrish DanRyanIrish added this to the 2.3.3 milestone Jun 24, 2025
@DanRyanIrish DanRyanIrish requested review from hayesla, nabobalis and wtbarnes and removed request for nabobalis June 24, 2025 08:13
@hayesla
Copy link
Member

hayesla commented Jun 24, 2025

i do think this was an issue raised by the map refactor that i found, can you remind me again what the issue was (not clear from the linked issue)

def test_crop_length_1_input(ndcube_2d_ln_lt):
cube = ndcube_2d_ln_lt
frame = astropy.wcs.utils.wcs_to_celestial_frame(cube.wcs)
lower_corner = SkyCoord(Tx=[0359.99667], Ty=[-0.0011111111], unit="deg", frame=frame)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are these coordinates so specific?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied them from another test. Can't remember why that test had them so specific

@DanRyanIrish
Copy link
Member Author

i do think this was an issue raised by the map refactor that i found, can you remind me again what the issue was (not clear from the linked issue)

That rings a bell but couldn't see the issue at a glance

for point in points:
# Sanitize input format
# Make point a tuple if given as a single high level coord object valid for this WCS.
if isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activates APE-14 lawyer mode

This is technically invalid if wcs.seralized_classes is True, as the first element of world_axis_object_classes will be a string. I've never actually seen a WCS in the wild which uses seralized_classes so we could just throw an error here if it's True?

Copy link
Member Author

@DanRyanIrish DanRyanIrish Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would simply not supporting this sanitization this check when wcs.seralized_classes is True be sufficient? i.e.

Suggested change
if isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())):
if not isinstance(point, (tuple, list)) and not wcs.seralized_classes and isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())):

Comment on lines 152 to 153
# If point is a length-1 object, convert it to scalar.
point = tuple(p.squeeze() if hasattr(p, "squeeze") else p for p in point)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to the tuple thing right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Here, we can assume that point is a tuple or list. So this line is about converting length-1 objects to scalar ones.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little lost why we need to do this, can't we handle multi-dimensional inputs?

for point in points:
# Sanitize input format
# Make point a tuple if given as a single high level coord object valid for this WCS.
if isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())):
if not isinstance(point, tuple) and isinstance(point, tuple(v[0] for v in wcs.world_axis_object_classes.values())):

@DanRyanIrish DanRyanIrish merged commit f823795 into sunpy:main Jun 30, 2025
18 of 20 checks passed
@Cadair
Copy link
Member

Cadair commented Jun 30, 2025

I think this got messed up before you merged it, the diff is wrong.

@nabobalis
Copy link
Member

REVERT

@Cadair
Copy link
Member

Cadair commented Jun 30, 2025

@DanRyanIrish What's this PR actually done? I'm now very confused and slightly annoyed it got merged after becoming something else?

@DanRyanIrish
Copy link
Member Author

The fix is now here and this is all that's actually required. Much simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants