Conversation
NDCube.rebin resampled lookup-table extra coords with offset 0, so they
were sampled at the first pixel of each bin (0, 2, 4) while the rebinned
WCS describes the bin centres (0.5, 2.5, 4.5). Pass a bin-centre offset
for lookup tables; WCS-backed extra coords keep the pixel-edge offset
that ResampledLowLevelWCS expects. test_rebin already expected the
bin-centre times, but np.allclose's default rtol on MJD values (about
half a day) hid the error, so tighten it.
ExtraCoords.resample also packed the new grids into an object array,
which numpy turns into a 2-D object array when all grids have the same
length, so rebinning a 1-D cube, or any cube whose axes all have the
same length after rebinning, raised "Cannot cast array data from
dtype('O')". Keep the grids in a list.
TimeTableCoordinate.interpolate interpolated absolute MJD floats,
quantising times to ~0.6 us, and dropped reference_time. Interpolate
second offsets from the first time and keep reference_time.
Split out of sunpy#967; none of this depends on N-D lookup tables.
QuantityTableCoordinate always holds a mesh of 1-D tables and interpolates each table along its own grid, but interpolate still required every grid to have the same shape. So NDCube.rebin raised "New array grids must all be same shape" for a Quantity lookup table spanning several axes whose lengths differ after rebinning. Drop the check.
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
Split out of #967. None of this depends on N-D lookup tables; it all reproduces on main and 2.4 with 1-D tables.
NDCube.rebinhad three problems with lookup-table extra coords:offset=0, so each new pixel got the value at the first pixel of its bin, while the rebinned WCS gives the bin centre.rebinnow passes(bin_shape - 1) / 2for lookup tables. WCS-backed extra coords keep 0, becauseResampledLowLevelWCStreats the offset as a pixel-edge shift. Nothing public tells the two apart, so this checks the private_lookup_tables.ExtraCoords.resampleput the new grids in an object array. When they all have the same length (every 1-D cube, for example) numpy makes a 2-D object array andnp.interpraisesTypeError. They are now a list.TimeTableCoordinate.interpolateinterpolated absolute MJD floats (about 0.6 µs resolution for current dates) and droppedreference_time. It now interpolates seconds from the first time and keepsreference_time.test_rebinalready expected bin-centre times, butnp.allclose's defaultrtol=1e-5is about half a day at MJD 51544, so the 30 s error passed. It now usesrtol=0, atol=1e-8.The second commit drops the "New array grids must all be same shape" check from
QuantityTableCoordinate.interpolate, so a mesh Quantity table works when its axes are rebinned to different lengths. It is separate in case you'd rather not take it.For direct callers of
TimeTableCoordinate.interpolate, orExtraCoords.resamplewith kwargs, a numericleft/rightis now seconds fromtable[0]rather than an absolute MJD, andleft=right=np.nangives a NaNTimeinstead of raisingValueError.rebinpasses no kwargs.main:
this branch:
Not in this PR:
rebin, for unrelated reasons: WCS-backed extra coords are unusable after NDCube.rebin #981.SkyCoordlookup table still collapses to its diagonal when rebinned (also on 2.4). I'll open a separate PR for that.This adds one small conflict with #950 in
ExtraCoords.resample; resolving it means keeping both changes.AI Assistance Disclosure
AI tools were used for:
K.