-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add between_layers to calculate_resistance, and set to False #386
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
|
@@ -121,10 +121,11 @@ def calculate_transmissivity( | |
return T | ||
|
||
|
||
def calculate_resistance(ds, kv="kv", thickness="thickness", top="top", botm="botm"): | ||
"""Calculate vertical resistance (c) between model layers from the vertical | ||
conductivity (kv) and the thickness. The resistance between two layers is assigned | ||
to the top layer. The bottom model layer gets a resistance of infinity. | ||
def calculate_resistance( | ||
ds, kv="kv", thickness="thickness", top="top", botm="botm", between_layers=False | ||
): | ||
"""Calculate vertical resistance (c) of model layers from the vertical conductivity | ||
(kv) and the thickness. | ||
|
||
Parameters | ||
---------- | ||
|
@@ -142,6 +143,12 @@ def calculate_resistance(ds, kv="kv", thickness="thickness", top="top", botm="bo | |
botm : str, optional | ||
name of data variable containing bottoms, only used to calculate thickness if not | ||
available in dataset. By default "botm" | ||
between_layers : bool, optional | ||
If True, calculate the resistance between the layers, which MODFLOW uses to | ||
calculate the flow. The resistance between two layers is then assigned to the | ||
top layer, and the bottom model layer gets a resistance of infinity. | ||
If False, calculate the resistance of the layers themselves. The defauls is | ||
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. typo: default |
||
False. | ||
|
||
Returns | ||
------- | ||
|
@@ -152,26 +159,28 @@ def calculate_resistance(ds, kv="kv", thickness="thickness", top="top", botm="bo | |
thickness = ds[thickness] | ||
else: | ||
thickness = calculate_thickness(ds, top=top, bot=botm) | ||
|
||
# nan where layer does not exist (thickness is 0) | ||
thickness_nan = xr.where(thickness == 0, np.nan, thickness) | ||
kv_nan = xr.where(thickness == 0, np.nan, ds[kv]) | ||
|
||
# backfill thickness and kv to get the right value for the layer below | ||
thickness_bfill = thickness_nan.bfill(dim="layer") | ||
kv_bfill = kv_nan.bfill(dim="layer") | ||
|
||
# calculate resistance | ||
c = xr.zeros_like(thickness) | ||
for ilay in range(ds.sizes["layer"] - 1): | ||
ctop = (thickness_nan.sel(layer=ds.layer[ilay]) * 0.5) / kv_nan.sel( | ||
layer=ds.layer[ilay] | ||
) | ||
cbot = (thickness_bfill.sel(layer=ds.layer[ilay + 1]) * 0.5) / kv_bfill.sel( | ||
layer=ds.layer[ilay + 1] | ||
) | ||
c[ilay] = ctop + cbot | ||
c[ilay + 1] = np.inf | ||
if between_layers: | ||
# nan where layer does not exist (thickness is 0) | ||
thickness_nan = xr.where(thickness == 0, np.nan, thickness) | ||
kv_nan = xr.where(thickness == 0, np.nan, ds[kv]) | ||
|
||
# backfill thickness and kv to get the right value for the layer below | ||
thickness_bfill = thickness_nan.bfill(dim="layer") | ||
kv_bfill = kv_nan.bfill(dim="layer") | ||
|
||
# calculate resistance | ||
c = xr.zeros_like(thickness) | ||
for ilay in range(ds.sizes["layer"] - 1): | ||
ctop = (thickness_nan.sel(layer=ds.layer[ilay]) * 0.5) / kv_nan.sel( | ||
layer=ds.layer[ilay] | ||
) | ||
cbot = (thickness_bfill.sel(layer=ds.layer[ilay + 1]) * 0.5) / kv_bfill.sel( | ||
layer=ds.layer[ilay + 1] | ||
) | ||
c[ilay] = ctop + cbot | ||
c[ilay + 1] = np.inf | ||
else: | ||
c = thickness / ds[kv] | ||
|
||
if hasattr(c, "long_name"): | ||
c.attrs["long_name"] = "resistance" | ||
|
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.
maybe set to None, warn users that to get the default they need to set between_layers=False, and the future default will be True?