Fix stale per-radian magnitude assumptions after sphere-radius scaling#1536
Open
rajeeja wants to merge 3 commits into
Open
Fix stale per-radian magnitude assumptions after sphere-radius scaling#1536rajeeja wants to merge 3 commits into
rajeeja wants to merge 3 commits into
Conversation
After #1517 made scale_by_radius=True the default for gradient() and curl(), several places still assumed unit-sphere (per-radian) magnitudes. - divergence(): add scale_by_radius parameter (forwarded to the underlying gradient() calls) and infer units from the input field and scaling instead of hardcoding '1/s'. - gradient()/curl()/divergence() docstrings: document output units and the default radius scaling. - vector_calculus.ipynb: correct the curl(grad(f)) residual wording (now O(1e-13) with default scaling vs O(1-10) on the unit sphere), update the vortex/radial examples to scientific notation, and drop hardcoded clim on the curl/divergence plots that rendered flat at the new scale. - test_vector_calculus.py: tighten the now-vacuous curl(grad) (<10.0) and antisymmetry (<200.0) thresholds to the actual scaled magnitudes, and add a divergence scale_by_radius test. Closes #1534
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates UXarray’s vector-calculus operators and documentation to be consistent with the post-#1517 default behavior (scale_by_radius=True), eliminating stale “unit-sphere magnitude” assumptions and making the docs/tests reflect physically scaled magnitudes.
Changes:
- Add
scale_by_radiustoUxDataArray.divergence()and forward it through the underlying gradient computations; infer divergence output units instead of hardcoding. - Expand
gradient()/curl()/divergence()docstrings to describe default radius scaling and resulting units. - Update the vector calculus user-guide notebook and tighten related test tolerances; add a divergence radius-scaling test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| uxarray/core/dataarray.py | Adds scale_by_radius to divergence() and updates units/scaling documentation for vector calculus APIs. |
| test/core/test_vector_calculus.py | Tightens curl-related tolerances and adds a divergence scaling test to match scaled magnitudes. |
| docs/user-guide/vector_calculus.ipynb | Updates narrative/formatting and plot scaling to reflect default radius scaling and new residual magnitudes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Overview
After #1517 made
scale_by_radius=Truethe default forgradient()andcurl(), several places still assumed unit-sphere (per-radian) magnitudes. This surfaced in the docs as a confusingcurl(grad(f))example (see #1522, where the documented O(1–10) residual is now ~1e-13).Closes #1534. Refs #1522, #1516, #1517.
Changes
Code (
uxarray/core/dataarray.py)divergence(): add ascale_by_radiusparameter (previously missing, unlikegradient/curl) and forward it to the underlyinggradient()calls. Infer units from the input field and scaling instead of hardcoding"1/s".gradient(),curl(), anddivergence()docstrings.Docs (
docs/user-guide/vector_calculus.ipynb)curl(grad(f))residual wording: ~O(1e-13) with the default radius scaling (the curl stencil applies a 1/radius² factor) vs ~O(1–10) on the unit sphere.:.2fprinted0.00) and reword the "≈ 2" annotations.clim=(-1e-10, 1e-10)on the curl/divergence plots, which rendered flat at the new ~1e-13 scale.Tests (
test/core/test_vector_calculus.py)curl(grad)(< 10.0) and antisymmetry (< 200.0) thresholds to the actual scaled magnitudes (< 1e-9and< 1e-3).test_divergence_scales_by_radiuscovering the new parameter and units.Verification
curl(grad)~1.1e-13, vortex curl/radial divergence ~5.4e-5 (positive). Outputs stripped per repo convention.pytest test/core/test_vector_calculus.py→ 28 passed.pre-commit run --all-files→ all hooks pass.