Skip to content

Honor quadrature_rule and order in UxDataArray.integrate() - #1842

Open
rajeeja wants to merge 4 commits into
mainfrom
rajeeja/integrate-quadrature
Open

rajeeja wants to merge 4 commits into
mainfrom
rajeeja/integrate-quadrature

Conversation

@rajeeja

@rajeeja rajeeja commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1599

Overview

integrate() accepted quadrature_rule and order but ignored them: #1379 switched to the cached face_areas property, which is always triangular/order 4. Reuse the cache only for those defaults and compute fresh areas otherwise, matching calculate_total_face_area().

None keeps selecting the default for both kwargs, as it did when they were ignored.

UxDataset.integrate() now computes areas once and raises on a bad rule/order instead of skipping every variable.

PR Checklist

General

  • An issue is created and linked
  • Filled out Overview

Testing & Benchmarking

  • There is adequate test coverage of changes from this PR
  • [N/A] If this PR could affect performance, ran ASV benchmarks

Documentation and Examples

  • Docstrings updated with any function changes
  • [N/A] User (public) functions added to docs/api.rst

AI Disclosure

AI Usage: Claude Code

  • I have tested and take responsibility for all AI-generated content in my PR.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Dataset integration suppresses quadrature validation errors, returning an empty dataset with a misleading warning.

1 open issue
What changed in this PR

Restores quadrature selection in UxDataArray.integrate() to address #1599 while preserving cached face areas for default settings.

Changes:

  • Computes fresh face areas for non-default quadrature rules or orders.
  • Documents quadrature options and HEALPix behavior.
  • Adds tests for parameter handling, default results, and lazy integration.
File Description
uxarray/​core/​dataset.py Clarifies quadrature parameter documentation.
uxarray/​core/​dataarray.py Honors quadrature arguments and documents area selection.
test/​grid/​integrate/​test_basic.py Adds quadrature and lazy-execution regression tests.

Review effort: Balanced

Comment thread uxarray/core/dataarray.py Outdated
Comment on lines +693 to +695
face_areas = self.uxgrid.compute_face_areas(
quadrature_rule=quadrature_rule, order=order, as_uxarray=True
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — DataCenteringError and DimensionError both inherit from ValueError, so the broad handler also swallowed quadrature validation failures. Narrowed the catch to those two expected skip cases and added a dataset-level regression test asserting that an invalid order propagates. Fixed in ba9e5c5; the focused integration tests pass.

The kwargs were accepted but ignored after #1379 switched to the cached
face_areas property, so integrate(order=8) silently returned the default
order-4 result. Reuse the cache only for the default rule/order and
compute fresh areas otherwise, matching calculate_total_face_area().

Closes #1599
Both kwargs were typed optional and ignored, so callers passing None got
the default result. Tightening the annotations turned that into a
ValueError from the quadrature validation; map None back to the defaults
instead.
@rajeeja
rajeeja force-pushed the rajeeja/integrate-quadrature branch from ba9e5c5 to a546ed8 Compare October 27, 2026 00:16
@rajeeja
rajeeja marked this pull request as ready for review October 27, 2026 20:14
@rajeeja
rajeeja requested a review from dylannelson October 28, 2026 17:48

@Sevans711 Sevans711 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for tackling this one! Just had a few minor inline comments here.

Comment on lines +51 to +62
def test_integrate_default_uses_cached_face_areas(gridpath):
"""The default rule/order must still reuse the cached ``face_areas``."""
uxgrid = ux.open_grid(gridpath("ugrid", "outCSne30", "outCSne30.ug"))
uxda = ux.UxDataArray(
data=np.ones(uxgrid.n_face), dims=("n_face",), uxgrid=uxgrid, name="ones"
)

expected = np.einsum("i,...i", uxgrid.face_areas.values, uxda.values)
nt.assert_array_equal(uxda.integrate().values, expected)
nt.assert_array_equal(
uxda.integrate(quadrature_rule="triangular", order=4).values, expected
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually test what the docstring claims; it could be internally re-computing face_areas and this test wouldn't complain. That said, I'm not actually convinced that a test of "make sure you are using the cached face_areas" needs to be added here, it's fine to just test the values' correctness; this test could be removed entirely.

Comment on lines +65 to +79
@pytest.mark.parametrize(
"kwargs",
[
{"quadrature_rule": None},
{"order": None},
{"quadrature_rule": None, "order": None},
],
)
def test_integrate_none_means_default(gridpath, kwargs):
"""``None`` keeps selecting the default rule/order.

Both kwargs were typed optional and ignored, so callers passing ``None``
got the default result. Honoring the kwargs must not turn that into an
error.
"""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test really necessary? This is basically just saying "make sure None is really the default", which feels almost tautological; the only thing really being tested here is the function signature itself. I don't think the test suite should necessarily be checking something like that.

Comment thread uxarray/core/dataarray.py
Comment on lines +64 to +65
def _integration_face_areas(uxgrid, quadrature_rule, order):
"""Face areas for ``integrate``; raises ValueError on a bad rule/order."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This small helper function almost certainly belongs in uxarray/grid/area.py, not the top of dataarray.py.

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.

UxDataArray.integrate() ignores quadrature_rule and order kwargs

3 participants