Skip to content

Commit

Permalink
update(utils): updates to zonbudget and get_specific_discharge (#1457)
Browse files Browse the repository at this point in the history
* update read_zone_file() to allow for extraneous text after zone arrays are read
* update get_specific_discharge(); add error for "faces" and "vertices" option

#1433
Closes #1340
  • Loading branch information
jlarsen-usgs committed Jul 20, 2022
1 parent cbc6fd3 commit 1757470
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
23 changes: 23 additions & 0 deletions autotest/t039_test.py
@@ -1,6 +1,7 @@
"""
Test zonbud utility
"""
import io
import os

import numpy as np
Expand Down Expand Up @@ -267,6 +268,27 @@ def test_zonbud_active_areas_zone_zero(rtol=1e-2):
return


def test_read_zone_file():
zf = (
"2 2 4\n"
"INTERNAL (4I3)\n"
" 1 1 1 0\n"
" 0 1 1 1\n"
"INTERNAL (4I3)\n"
" 1 1 1 0\n"
" 0 1 1 1\n"
" 0"
)
name = os.path.join(outpth, "zonefiletest.txt")
with open(name, "w") as foo:
foo.write(zf)
zones = flopy.utils.ZoneBudget.read_zone_file(name)
if zones.shape != (2, 2, 4):
raise AssertionError(
"zone file read failed"
)


def test_zonebudget_6():
try:
import pandas as pd
Expand Down Expand Up @@ -368,5 +390,6 @@ def test_zonebudget6_from_output_method():
test_get_budget()
test_get_model_shape()
test_zonbud_active_areas_zone_zero()
test_read_zone_file()
test_zonebudget_6()
test_zonebudget6_from_output_method()
6 changes: 3 additions & 3 deletions autotest/t078_test_lake_connections.py
Expand Up @@ -149,20 +149,20 @@ def test_base_run():
bot = gwf.dis.botm.array.squeeze()
__export_ascii_grid(
gwf.modelgrid,
os.path.join(pth, "bot.asc"),
os.path.join(model_ws, "bot.asc"),
bot,
)
top = gwf.output.head().get_data().squeeze() + 2.0
top = np.where(gwf.dis.idomain.array.squeeze() < 1.0, 0.0, top)
__export_ascii_grid(
gwf.modelgrid,
os.path.join(pth, "top.asc"),
os.path.join(model_ws, "top.asc"),
top,
)
k11 = gwf.npf.k.array.squeeze()
__export_ascii_grid(
gwf.modelgrid,
os.path.join(pth, "k11.asc"),
os.path.join(model_ws, "k11.asc"),
k11,
)

Expand Down
6 changes: 6 additions & 0 deletions flopy/utils/postprocessing.py
Expand Up @@ -701,6 +701,12 @@ def get_specific_discharge(
qz = modelgrid.array_at_verts(qz)

else:
if position != "centers":
raise ValueError(
f"MF6 vectors cannot be calculated at {position}, 'centers' "
f"is the only supported option"
)

nnodes = model.modelgrid.nnodes
qx = np.full((nnodes), np.nan, dtype=np.float64)
qy = np.full((nnodes), np.nan, dtype=np.float64)
Expand Down
4 changes: 4 additions & 0 deletions flopy/utils/zonbud.py
Expand Up @@ -1474,12 +1474,16 @@ def read_zone_file(cls, fname):
# The number of values to read before placing
# them into the zone array
datalen = nrow * ncol
totaldatalen = nlay * nrow * ncol

# List of valid values for LOCAT
locats = ["CONSTANT", "INTERNAL", "EXTERNAL"]

# ITERATE OVER THE ROWS
for line in lines:
if totlen == totaldatalen:
break

rowitems = line.strip().split()

# Skip blank lines
Expand Down

0 comments on commit 1757470

Please sign in to comment.