Preserve coords and attrs in topological aggregations - #1666
Open
rajeeja wants to merge 1 commit into
Open
Conversation
Node-to-face and node-to-edge aggregations rebuilt the output UxDataArray
from data/dims/name only, so every coordinate and all variable metadata were
dropped. A result keeps its 'time' dimension but loses the 'time' coordinate,
which breaks label-based indexing downstream: .sel(time=...),
groupby('time.season') and .resample(time=...) all raise KeyError, and
units/long_name are lost for plotting and CF output.
Carry over any coordinate that does not span the reduced node dimension,
along with the variable attrs. Coordinates along n_node are still dropped,
since they no longer match the length of the output dimension.
8 tasks
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
Fixes #1665.
Came across this while reviewing #1588. Node-to-face and node-to-edge aggregations dropped every coordinate and all variable metadata, so
.sel(time=...),groupby('time.season')and.resample(time=...)raisedKeyErroron the result, andunits/long_namewere lost for plotting and CF output.The fix carries over any coordinate that does not span the reduced
n_nodedimension, plus the attrs. Coordinates alongn_node(node_lonand friends) are still dropped, since after the reduction they would be the wrong length.@cmdupuis3 — this should make #1588 simpler. The dask paths you added already preserve coords/attrs via
apply_ufunc, so once this lands and you mergemain, your numpy and dask paths will agree and.chunk()goes back to being purely a performance knob.Testing
Three parametrized tests over face and edge: metadata preservation across all aggregations, the label-based indexing that was failing, and confirmation that node-spanning coords are still dropped. All 6 fail on
mainwithout the fix. Full suite 827 passed, 1 skipped; pre-commit clean.