-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block-mapped resample with the help of flox #1848
Open
aulemahal
wants to merge
28
commits into
main
Choose a base branch
from
resample-map
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
30f28fe
Resample map helper
aulemahal 88fa90b
merge generic-season
aulemahal 065b4f3
New split_aux_coord func to remove aux coord and avoid dask comp on a…
aulemahal 0c8c797
Ignore missing flox dep
aulemahal 9c81ed8
Fix for bool mask
aulemahal 764d67b
Fix aux coord mngmt in lazy indexing - fix doc split aux coord
aulemahal 3d4c457
lower pin of flit
3adbf76
fix a fix that didnt fix what needed to be fixed
aulemahal befc53f
Merge branch 'resample-map' of github.com:Ouranosinc/xclim into resam…
aulemahal 0bcbe5a
merge master and heat_spell
58fe1a0
Merge branch 'heat_spell' into resample-map
c39b47e
Merge branch 'heat_spell' into resample-map
9778739
Resample before spells
a7e5bde
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b9d79b0
Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"
aulemahal b0fd634
Revert "Resample before spells"
aulemahal 5a407aa
Merge branch 'heat_spell' into resample-map
167a387
merge main
38070c8
Merge branch 'main' into resample-map
Zeitsperre cef0e25
multi reducing
aulemahal df8c792
merge main
aulemahal 90c14ef
fix deps - add minimal tests
aulemahal 03d236e
add changelog
aulemahal 1f3e82e
Dont test resample-map without flox
aulemahal b1dd2ac
Apply suggestions from code review
aulemahal 8b717b3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 881812b
Merge branch 'main' into resample-map
aulemahal 561c54a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -760,3 +760,43 @@ def _chunk_like(*inputs: xr.DataArray | xr.Dataset, chunks: dict[str, int] | Non | |
da.chunk(**{d: c for d, c in chunks.items() if d in da.dims}) | ||
) | ||
return tuple(outputs) | ||
|
||
|
||
def split_auxiliary_coordinates( | ||
obj: xr.DataArray | xr.Dataset, | ||
) -> tuple[xr.DataArray | xr.Dataset, xr.Dataset]: | ||
"""Split auxiliary coords from the dataset. | ||
|
||
An auxiliary coordinate is a coordinate variable that does not define a dimension and thus is not necessarily needed for dataset alignment. | ||
Any coordinate that has a name different than its dimension(s) is flagged as auxiliary. All scalar coordinates are flagged as auxiliary. | ||
|
||
Parameters | ||
---------- | ||
obj : DataArray or Dataset | ||
Xarray object | ||
|
||
Returns | ||
------- | ||
clean_obj : | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any? |
||
Same as `obj` but without any auxiliary coordinate. | ||
aux_coords : Dataset | ||
The auxiliary coordinates as a dataset. Might be empty. | ||
|
||
Note | ||
---- | ||
This is useful to circumvent xarray's alignment checks that will sometimes look the auxiliary coordinate's data, which can trigger | ||
unwanted dask computations. | ||
|
||
The auxiliary coordinates can be merged back with the dataset with | ||
:py:meth:`xarray.Dataset.assign_coords` or :py:meth:`xarray.DataArray.assign_coords`. | ||
|
||
>>> clean, aux = split_auxiliary_coordinates(ds) | ||
>>> merged = clean.assign_coords(da.coords) | ||
>>> merged.identical(ds) # True | ||
""" | ||
aux_crd_names = [ | ||
nm for nm, crd in obj.coords.items() if len(crd.dims) != 1 or crd.dims[0] != nm | ||
] | ||
aux_crd_ds = obj.coords.to_dataset()[aux_crd_names] | ||
clean_obj = obj.drop_vars(aux_crd_names) | ||
return clean_obj, aux_crd_ds |
This file contains 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
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have an alternative suggestion here (and would save me from opening a PR):
flox
(with a baseline pin version) to theextras
recipe.flox
andpot >=0.9.4
to theenvironment.yml
.fastnanquantile >=0.0.2
to theenvironment.yml
section for pip dependencies.flox
from the DEP001 list.