Skip to content

waterbalance calculation is slow...? #875

Answered by Huite
JaccoHoogewoud asked this question in Q&A
Discussion options

You must be logged in to vote

(I see I'm cross-posting with Joeri...)

Hi @JaccoHoogewoud,

That is indeed ridiculously slow. To be fair, I don't see things in your example that immediately suspicion, but there are some things which could lead to some inefficiencies and the loop isn't necessary either.

Here's how I would write it, making use of the fact that you use bitwise operators (&, |, ~) for elementwise boolean logic, and you can sum over multiple dimensions at once with xarray:

budget = imod.idf.open(f'{bdg_naam}_*.idf').sel(time=slice('2012-01-01', '2021-01-01'))
zone = imod.idf.open("zone.idf")
zone_infiltration = budget.where((zone > 0) & (budget > 0))
timeseries_infiltration = zone_infiltration.sum(["layer", "y"

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@JaccoHoogewoud
Comment options

Comment options

You must be logged in to vote
1 reply
@JaccoHoogewoud
Comment options

Answer selected by JaccoHoogewoud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #873 on February 27, 2024 08:49.