-
Notifications
You must be signed in to change notification settings - Fork 130
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
Refactor lazy_regrid.py for wflow diagnostics #2024
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
dda2c61
remove lazy_regrid.py because now esmvalcore takes care of it
SarahAlidoost 6269955
replace lazy_regrid with regrid from esmvalcore
SarahAlidoost d75d9cf
use correct file format for wflow dem file
SarahAlidoost 0c4e78a
sort import statements
SarahAlidoost 4a24392
change time periods
SarahAlidoost 64e5f57
revise years in hype recipe
SarahAlidoost e1c836c
Merge branch 'master' into refactor_hydro_recipes
SarahAlidoost 33bf3db
bring back lazy_regrid and refactor it
SarahAlidoost b231f03
remove recipe_hype from this PR
SarahAlidoost 19cb0fe
rename function lazy_regrid to rechunk_and_regrid
SarahAlidoost 427c473
replace iris with esmvalcore.processor.regrid
SarahAlidoost 0f90cb0
rename lazy_regrid to compute_chunks, refactor the script and wflow dβ¦
SarahAlidoost d32e806
revise the docstring in compute_chunks.py
SarahAlidoost 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
"""Re-chunk the time dimension, to be used by the regrid processor. | ||
|
||
For large cubes, regridding to a high resolution grid increases the size | ||
of the data. To reduce memory use, we re-chunk the time dimension. | ||
|
||
Related iris issue: | ||
https://github.com/SciTools/iris/issues/3808 | ||
""" | ||
import numpy as np | ||
|
||
|
||
def compute_chunks(src, tgt): | ||
"""Compute the chunk sizes needed to regrid src to tgt.""" | ||
block_bytes = 50 * (1 << 20) # 50 MB block size | ||
|
||
if src.dtype == np.float32: | ||
dtype_bytes = 4 # size of float32 in bytes | ||
else: | ||
dtype_bytes = 8 # size of float64 in bytes | ||
|
||
ntime = src.coord('time').shape[0] | ||
tgt_nlat = tgt.coord('latitude').shape[0] | ||
tgt_nlon = tgt.coord('longitude').shape[0] | ||
|
||
# Define blocks along the time dimension | ||
min_nblocks = int(ntime * tgt_nlat * tgt_nlon * dtype_bytes / block_bytes) | ||
min_nblocks = max(min_nblocks, 1) | ||
timefull = ntime // min_nblocks | ||
timepart = ntime % timefull | ||
|
||
nfullblocks = ntime // timefull | ||
npartblocks = int(timepart > 0) | ||
|
||
time_chunks = (timefull, ) * nfullblocks + (timepart, ) * npartblocks | ||
src_chunks = ( | ||
time_chunks, | ||
(src.coord('latitude').shape[0], ), | ||
(src.coord('longitude').shape[0], ), | ||
) | ||
return src_chunks |
This file was deleted.
Oops, something went wrong.
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
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 am in awe about how Codacy is not complaining about this import order π
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.
Me too, but I already asked Sarah to check something like that lately and it turns out I was the one that's wrong... This one is even more strange though!
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.
hmmm, the prospector did not complain about it, and the pylint in vscode says:
third party import "from esmvalcore.preprocessor import regrid" should be placed before "import iris"pylint
.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.
it's possible prospector didn't run the pylint bit and the CI let it pass - it does that from time to time when there are lots of commits
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.
looks better now π