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
croptakes one entry per world object, withNonefor objects that should not be cropped._get_crop_itembuilt that list by popping repeated component names, which keeps the last occurrence of each object;pixel_to_worldandworld_to_pixeluse the first. So on WCSes with interleaved world objects (e.g.HPLN, WAVE, HPLT, or DKIST VISP), crop rejected points inpixel_to_worldorder, including partial ones, and the count error 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:
utils.misc.unique_sorted, as inaxis_world_coords).Noneobject is an instance of exactly one world object class (no two the same), objects are matched by class, as in astropy'sworld_to_pixel; otherwise by position.get_crop_item_from_pointssorts the pixel axes instead of usingsetorder, which swapped some bounds on cubes with nine or more dimensions.User-visible changes:
pixel_to_worldorder works, and so does Allow greater flexibility in crop bounds order #608's[spec, sky]example.WAVEandLINEARare bothQuantity) or subclasses (SpectralCoord/Quantity), the point is positional in first-appearance order, so old-order[wl, sky, None]onHPLN, WAVE, HPLT, LINEARnow raises.TypeErrornow go to the wrong slot: a same-class object in the wrong slot (as withworld_to_pixel), a plainQuantityfor a gWCSSpectralCoordslot (moved to the onlyQuantityslot), and, withwcs=cube.extra_coords, a wrongly typedQuantitymoved to a dummy pixel slot (I'll open a separate issue for theextra_coordscases).Related:
Noneplaceholders are still required.pointstosanitized_points.points[i] = point = [...]merges cleanly but must becomesanitized_points[i] = ..., otherwise it raises'tuple' object does not support item assignment;test_crop_non_contiguous_world_objectscatches this.AI Assistance Disclosure
AI tools were used for:
K