Repository navigation
Only use distance dimensions by default in laplacian for DataArrays - #4163
Open
bhaskargurram-ai wants to merge 1 commit into
Open
bhaskargurram-ai wants to merge 1 commit into
bhaskargurram-ai wants to merge 1 commit into
Conversation
When given a DataArray without axes, coordinates or deltas, laplacian summed the second derivative along every dimension. For data with a time or pressure dimension, as is usual for model and analysis fields, this raised a hard to decipher DimensionalityError. By default, only use the dimensions along which positions are distances: latitude and longitude (converted with grid deltas) and dimensions whose coordinate has units of length. If there are none, keep using all dimensions as before. Fixes Unidata#3105
bhaskargurram-ai
requested review from
dcamron
and removed request for
a team
October 18, 2026 03:57
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.
Description Of Changes
Called on a DataArray with no
axes,coordinatesordeltas,laplacianadds up the second derivative along every dimension. On a typical model or analysis field with a pressure or time dimension this fails with an error that is hard to read, e.g. for(isobaric, lat, lon)data:Following the proposal in #3105, when
fis a DataArray and none ofaxes,coordinatesanddeltasare given,laplaciannow only uses the dimensions along which positions are distances:second_derivativeTime, pressure and other dimensions are skipped. If no dimension qualifies, it uses all of them as before, so anything that worked before gives the same result (it could only work if all the dimensions had the same units). Explicit
axesare used as given. I chose to skip pressure as well as time, since a sum of second derivatives in hPa and in m isn't meaningful. The docstring describes the new default.Tests added in
tests/calc/test_calc_tools.py:(isobaric, lat, lon)and(time, isobaric, y, x)DataArrays with no axes now matchaxes=('lat', 'lon')/axes=('y', 'x'). Both fail on main with the error above.tests/calcpasses with xarray 2025.10.1. Ruff and flake8 are clean.Checklist