Support N-D table coords, subclass attr propagation, clearer crop error#938
Closed
nabobalis wants to merge 1 commit into
Closed
Support N-D table coords, subclass attr propagation, clearer crop error#938nabobalis wants to merge 1 commit into
nabobalis wants to merge 1 commit into
Conversation
Allow a single N-D Time or Quantity lookup table in extra_coords, representing one coordinate varying over several pixel dimensions. Add NDCube._extra_attrs_to_copy so subclasses can declare attributes propagated through arithmetic and to_nddata. Make the crop component-count error name the expected world objects.
Member
Author
|
Honestly, this was created to make my life easier in creating a 5D gWCS. I don't even know if these changes make logical sense in the first place. |
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
Allow a single N-D Time or Quantity lookup table in extra_coords, representing one coordinate varying over several pixel dimensions. Add NDCube._extra_attrs_to_copy so subclasses can declare attributes propagated through arithmetic and to_nddata. Make the crop component-count error name the expected world objects.
Description
This PR upstreams three improvements motivated by irispy-lmsal's gWCS raster
work, where IRIS spectrograph observations are represented as 4-D
(scan, step, slit, wavelength) cubes. Each change removes a workaround that
instrument packages currently have to carry themselves.
1. N-D
Time/Quantitylookup tables inextra_coordsTimeTableCoordinateandQuantityTableCoordinatenow accept a single N-Dtable, representing one physical coordinate that varies over N pixel
dimensions. For example, a 2-D
Timetable indexed by (raster scan, rasterstep) can now be attached with:
Previously
QuantityTableCoordinateraised "Currently all tables must be1-D" and
TimeTableCoordinatewas hardwired to one dimension, so per-exposuretimes on a multi-scan cube could not be expressed as an extra coord at all.
Implementation notes:
order).
NDCube._generate_world_coordstransposes world values assumingthe APE-14 pixel-axis convention, so an array-ordered model produces
transposed
axis_world_coordsoutput.ExtraCoords.mappingreverses theconverted axes for such coordinates to stay consistent (see the new
BaseTableCoordinate._model_inputs_are_pixel_orderedproperty).ExtraCoords._getitem_lookup_tablesnow drops integer-sliced axes from atable's axes tuple when the sliced table actually loses pixel dimensions.
Previously the axes tuple kept stale (even negative) entries; this was
latent for existing coordinate types but breaks N-D tables. Range slices
keep the table N-D, integer slices reduce it, and slicing away all table
dimensions drops the coordinate into
dropped_tablesas before.interpolatesupports N-D tables viascipy.interpolate.interpn(
TimeTableCoordinate.interpolatenow takes*new_array_grids, matchingthe other table coordinate types; the old single-grid call still works).
Length1Tabulardispatch bug: a table of shape(1, n)wasrouted to the length-1 1-D model because the check used
len(table) == 1instead of
table.shape == (1,).2.
NDCube._extra_attrs_to_copyextension pointSubclasses that carry domain-specific instance attributes (observer
coordinates, per-step WCS tables, instrument flags, ...) currently have to
override
_new_instanceandto_nddatato keep those attributes fromsilently disappearing on every derived cube. Forgetting one call site means
arithmetic or a utility function returns a cube with the metadata gone and no
error.
Subclasses can now declare:
and the attributes are propagated (by reference) through
_new_instance(arithmetic,
__neg__,fill_masked, ...) and throughto_nddatawhen thetarget
nddata_typeis a subclass carrying the same attributes. Explicitkwargs still override the automatic copy, and plain
NDDatatargets areunaffected. Slicing is deliberately not covered: shape-dependent attributes
cannot be sliced generically, so subclasses keep handling that themselves
(documented on the attribute).
3. Crop component-count error names the expected world objects
Old code written against a previous WCS fails with
"2 components in point 0 do not match WCS with 4 components.", which givesthe user no clue what the four components are. The error now reads:
The existing message prefix is preserved, so downstream tests matching on it
keep passing.
Testing
integer, full drop), interpolation, multi-N-D rejection, cube-level
axis_world_coordsthroughextra_coordsincluding after slicing,attribute propagation through arithmetic and
to_nddata, and the new croperror wording.
environment-dependent failure with a newer gwcs,
test_crop_by_extra_coords_values_all_axes_with_coord, fails identicallyon
main).against this patch, and the 2-D (scan, step) exposure-time table that
motivated change 1 attaches and slices correctly on a real 13-scan
observation.
Notes for reviewers
part most worth scrutinizing: multi-1-D-table coordinates (e.g. meshed
SkyCoordtables) keep their existing array-ordered convention, and onlysingle N-D tables use the reversed order. An alternative would be to fix
_generate_world_coordsto consult the mapping instead, but that touchesevery WCS path rather than only the new feature.
AI Assistance Disclosure
AI tools were used for: