Skip to content

Weight ctis.regrid by the voxel volume to conserve the integral - #22

Merged
roytsmart merged 1 commit into
mainfrom
feature/regrid-volume
Jul 28, 2026
Merged

Weight ctis.regrid by the voxel volume to conserve the integral#22
roytsmart merged 1 commit into
mainfrom
feature/regrid-volume

Conversation

@roytsmart

Copy link
Copy Markdown
Contributor

Summary

Makes ctis.regrid integral-conserving (density-preserving) instead of sum-conserving.

Each input voxel is weighted by its volume — the wavelength bin width times the field-pixel area, from the new SpectralPositionalVectorArray.volume_cell (named-arrays 2.3) — before the two-stage conservative regridding, and the output is divided by the output voxel volume. So values_input is treated as a density (e.g. a spectral radiance), and a resampled uniform field stays uniform.

values = values_input * coordinates_input.volume_cell(axis)
values = <1D conservative along wavelength>
values = <2D conservative along the spatial axes>
values = values / coordinates_output.volume_cell(axis)

Notes

  • Bumps the pin named-arrays~=2.2~=2.3 for volume_cell.
  • The test now checks that the volume-weighted integral is preserved (to within the tolerance of the perturbation applied by the 2D conservative step).

Tests

ctis/_regrid_test.py: refine and coarsen cases, checking shape, finiteness, and integral conservation. Verified against a clean/released regridding (conservation is exact there).

🤖 Generated with Claude Code

https://claude.ai/code/session_01CtdKmedevWkDab6BWupXqQ

Multiply each input voxel by its volume (via
`SpectralPositionalVectorArray.volume_cell`) before the two-stage
conservative regridding and divide by the output voxel volume afterward, so
`ctis.regrid` preserves the integral of the field and treats `values_input` as
a density (such as a spectral radiance) rather than a per-voxel total. Update
the test to check integral conservation and bump the named-arrays pin to ~=2.3.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CtdKmedevWkDab6BWupXqQ
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2eb14d0) to head (ecfdeb5).

Additional details and impacted files
@@            Coverage Diff            @@
##              main       #22   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines          697       704    +7     
=========================================
+ Hits           697       704    +7     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

@roytsmart
roytsmart merged commit 310231d into main Jul 28, 2026
12 checks passed
@roytsmart
roytsmart deleted the feature/regrid-volume branch July 28, 2026 21:38
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.

1 participant