Skip to content

feat: Support slicing WCS - #16

Merged
icweaver merged 15 commits into
mainfrom
slice-wcs
Jul 11, 2026
Merged

feat: Support slicing WCS#16
icweaver merged 15 commits into
mainfrom
slice-wcs

Conversation

@cgarling

Copy link
Copy Markdown
Member

Closes #15.

Adds a new sliced WCS wrapper SlicedWCSTransform and an abstract type AbstractWCSTransform that both SlicedWCSTransform and WCSTransform are subtypes of to support common dispatch.

API:

slice_wcs(::AbstractWCSTransform, slices...) -> SlicedWCSTransform

SlicedWCSTransform contains the parent WCSTransform object and the necessary information to support translating between its own pixel space to the original parent's pixel space. Calls to e.g. pixel_to_world(swcs::SlicedWCSTransform, pixel) basically reconstruct the pixel of original parent WCS pix_parent from the provided pixel and call pixel_to_world(swcs.parent, pix_parent). There is some additional bookkeeping around dropped axes, e.g. swcs = slice_wcs(::WCSTransform, 1:10, 1:10, 1) drops the last axis (common for 3-D spectral cubes) so that now pixel_to_world(swcs, [1.0, 1.0]) works because the last dimension has been dropped. Similarly, swcs = slice_wcs(::WCSTransform, 1, 1, :) will drop the first two axes and produce a swcs with a pixel dimension of 1.

Recursive slicing slice_wcs(::SlicedWCSTransform, slices...) is supported.

slices must be of equal dimension to the input WCS or less. If dimensionality of slices is lower than dimensionality of input WCS, the missing dimensions are assumed to be passed through unaltered.

A method slice_wcs(::Dict{Char, <:AbstractWCSTransform}, slices...) -> Dict{Char, SlicedWCSTransform} is defined that just calls slice_wcs on each entry in the dictionary and returns a new dictionary with the same keys where all WCS have been sliced. This is so that downstream code that uses WCS_all can just call slice_wcs(WCS_all(hdr), slices...) and simultaneously slice all the alternate WCS.

Performance seems pretty good (<1 microsecond per slice_wcs(::AbstractWCSTransform, slices...)) but I haven't done much optimization work.

Also added some API functions pixel_n_dim, world_n_dim, axis_correlation_matrix which simplify some of the implementation. I believe these methods respect astropy's APE14 standard but I didn't cross-reference against their implementations to check if they are exactly the same or not.

@icweaver let me know how this looks and whether you need any additional features/API to support https://github.com/JuliaAstro/AstroImages.jl/pull/113/changes

If this looks good as-is, you can merge this

@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.53086% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.46%. Comparing base (8ce85fe) to head (6b6a397).

Files with missing lines Patch % Lines
src/slicing.jl 97.54% 3 Missing ⚠️
src/transforms.jl 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #16      +/-   ##
==========================================
+ Coverage   85.91%   86.46%   +0.54%     
==========================================
  Files          16       18       +2     
  Lines        3230     3376     +146     
==========================================
+ Hits         2775     2919     +144     
- Misses        455      457       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@icweaver

Copy link
Copy Markdown
Member

Nice, I'm excited to try this, thanks Chris! I'll go ahead and get this, JuliaAstro/AstroImages.jl#113, and JuliaAstro/AstroImages.jl#115 merged in so that we can explore integrating slice_wcs into AstroImages.jl in a dedicated PR

@icweaver icweaver changed the title Support slicing WCS feat: Support slicing WCS Jul 11, 2026
@icweaver
icweaver merged commit db3fa46 into main Jul 11, 2026
20 checks passed
@icweaver
icweaver deleted the slice-wcs branch July 11, 2026 02:00
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.

Proposal: Add WCS slicing (slice_wcs) to support sliced/subset images

2 participants