Conversation
When a crop point has the wrong number of entries, or an entry of the wrong class, the error now lists the expected world objects in order, so users migrating from a WCS with fewer world objects, or passing objects in the wrong order, learn the fix from the error itself.
The component dedup in NDCube._get_crop_item popped entries while enumerating, which kept the last occurrence of each world object. WCSes whose object components are not adjacent (e.g. HPLN, WAVE, HPLT, or DKIST VISP's lon, wl, lat, time, stokes) then rejected points given in the order pixel_to_world returns, including partial points with None. Keep the first occurrence instead. As astropy's world_to_pixel does, also match objects to components by class when each object in a point matches exactly one class and no two objects match the same one (sunpy#608). Points in the old order therefore keep working when the world objects have distinct classes, none a subclass of another, as in dkist's VISP crop tests. Otherwise, for example when objects share a class or their classes are related by subclassing (Quantity and SpectralCoord), the whole point is matched by position. Also sort the pixel axes with input in get_crop_item_from_points: iterating a set swapped the bounds of pixel axes (e.g. 3 and 8) on cubes with nine or more dimensions.
This was referenced Sep 27, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Description
crop takes one entry per world object, with None for objects that aren't cropped. It ordered the objects by where each one last appears in the WCS, but pixel_to_world and world_to_pixel use where each first appears. So on WCSes with interleaved world objects (e.g. HPLN, WAVE, HPLT, or DKIST VISP), crop rejected points in pixel_to_world order, including partial ones. The error for a point of the wrong length also didn't say what it expected.
[sky, wl](pixel_to_worldorder)TypeError: <class '...SkyCoord'> of component 0 in point 0 is incompatible with WCS component spectral <class '...Quantity'>.(2, 3, 3)[sky, None]TypeError(2, 5, 3)[None, wl]TypeError: <class '...SpectralCoord'> of component 1 in point 0 is incompatible with WCS component celestial <class '...SkyCoord'>.(4, 3, 6)[wl, None]ValueError: Expected the following order of world arguments: SkyCoord(4, 3, 6)[wl, sky](old order)(2, 3, 3)(2, 3, 3)[sky]ValueError: 1 components in point 0 do not match WCS with 2 components.Each point must have one entry per world object (use None for a component that should not be cropped), in order: celestial (SkyCoord), spectral (Quantity).Changes:
User-visible changes:
AI Assistance Disclosure
AI tools were used for:
K