Skip to content

Commit

Permalink
feat(inspect cells): new feature that returns model data associated w…
Browse files Browse the repository at this point in the history
…ith specified model cells (#1140) (#1325)

* feat(inspect cells): new feature that returns model data associated with specified model cells (#1140)

* feat(inspect cells): added tests for new feature (#1140)

* feat(inspect cells)

* feat(inspect cells): dependent variable and budget inspection

* feat(inspect cells): tests

* feat(inspect cells): doc update

* feat(inspect_cells)

* feat(inspect_cells)
  • Loading branch information
spaulins-usgs authored Jan 11, 2022
1 parent 831771d commit ee009fd
Show file tree
Hide file tree
Showing 5 changed files with 585 additions and 3 deletions.
19 changes: 19 additions & 0 deletions autotest/t504_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ def test006_gwf3():
success, buff = sim.run_simulation()
assert success, f"simulation {sim.name} rerun did not run"

# inspect cells
cell_list = [(0,), (7,), (14,)]
out_file = os.path.join("temp", "inspect_test006_gwf3.csv")
model.inspect_cells(cell_list, output_file_path=out_file)

budget_obj = bf.CellBudgetFile(expected_cbc_file_a, precision="double")
budget_fjf_valid = np.array(
budget_obj.get_data(text=" FLOW JA FACE", full3D=True)
Expand Down Expand Up @@ -742,6 +747,10 @@ def test006_2models_mvr():
success, buff = sim.run_simulation()
assert success, f"simulation {sim.name} rerun did not run"

cell_list = [(0, 3, 1)]
out_file = os.path.join("temp", "inspect_test006_2models_mvr.csv")
models[0].inspect_cells(cell_list, output_file_path=out_file)

# compare output to expected results
head_new = os.path.join(save_folder, "model1.hds")
assert pymake.compare_heads(
Expand Down Expand Up @@ -850,6 +859,11 @@ def test001e_uzf_3lay():
success, buff = sim.run_simulation()
assert success, f"simulation {sim.name} rerun did not run"

# inspect cells
cell_list = [(0, 0, 1), (0, 0, 2), (2, 0, 8)]
out_file = os.path.join("temp", "inspect_test001e_uzf_3lay.csv")
model.inspect_cells(cell_list, output_file_path=out_file)

# test load_only
model_package_check = ["chd", "ic", "npf", "oc", "sto", "uzf"]
load_only_lists = [
Expand Down Expand Up @@ -941,6 +955,11 @@ def test045_lake2tr():
success, buff = sim.run_simulation()
assert success, f"simulation {sim.name} rerun did not run"

# inspect cells
cell_list = [(0, 6, 5), (0, 8, 5), (1, 18, 6)]
out_file = os.path.join("temp", "inspect_test045_lake2tr.csv")
model.inspect_cells(cell_list, output_file_path=out_file)

# compare output to expected results
head_new = os.path.join(save_folder, "lakeex2a.hds")
assert pymake.compare_heads(
Expand Down
35 changes: 35 additions & 0 deletions autotest/t505_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,13 @@ def test_np001():
if run:
sim.run_simulation()

# inspect cells
cell_list = [(0, 0, 0), (0, 0, 4), (0, 0, 9)]
out_file = os.path.join("temp", "inspect_test_np001.csv")
model.inspect_cells(
cell_list, output_file_path=out_file, stress_period=0
)

# get expected results
budget_obj = bf.CellBudgetFile(expected_cbc_file, precision="double")
budget_frf_valid = np.array(
Expand Down Expand Up @@ -1337,6 +1344,10 @@ def test_np002():
# run simulation
sim.run_simulation()

cell_list = [(0, 0, 0), (0, 0, 3), (0, 0, 4), (0, 0, 9)]
out_file = os.path.join("temp", "inspect_test_np002.csv")
model.inspect_cells(cell_list, output_file_path=out_file)

sim2 = MFSimulation.load(sim_ws=run_folder)
model_ = sim2.get_model(model_name)
npf_package = model_.get_package("npf")
Expand Down Expand Up @@ -2187,6 +2198,11 @@ def test005_advgw_tidal():
# run simulation
sim.run_simulation()

# inspect cells
cell_list = [(2, 3, 2), (0, 4, 2), (0, 2, 4), (0, 5, 5), (0, 9, 9)]
out_file = os.path.join("temp", "inspect_AdvGW_tidal.csv")
model.inspect_cells(cell_list, output_file_path=out_file)

# compare output to expected results
head_new = os.path.join(run_folder, "AdvGW_tidal.hds")
outfile = os.path.join(run_folder, "head_compare.dat")
Expand Down Expand Up @@ -2845,6 +2861,11 @@ def test006_gwf3_disv():
if run:
sim.run_simulation()

# inspect cells
cell_list = [(0, 0), (0, 7), (0, 17)]
out_file = os.path.join("temp", "inspect_test_gwf3_disv.csv")
model.inspect_cells(cell_list, output_file_path=out_file)

# compare output to expected results
head_new = os.path.join(run_folder, "flow.hds")
outfile = os.path.join(run_folder, "head_compare.dat")
Expand Down Expand Up @@ -3590,6 +3611,11 @@ def test028_sfr():
if run:
sim.run_simulation()

# inspect cells
cell_list = [(0, 2, 3), (0, 3, 4), (0, 4, 5)]
out_file = os.path.join("temp", "inspect_test028_sfr.csv")
model.inspect_cells(cell_list, output_file_path=out_file)

# compare output to expected results
head_new = os.path.join(run_folder, "test1tr.hds")
outfile = os.path.join(run_folder, "head_compare.dat")
Expand Down Expand Up @@ -3827,6 +3853,15 @@ def test_transport():
if run:
sim.run_simulation()

# inspect cells
cell_list = [
(0, 0, 0),
]
out_file = os.path.join("temp", "inspect_transport_gwf.csv")
gwf.inspect_cells(cell_list, output_file_path=out_file)
out_file = os.path.join("temp", "inspect_transport_gwt.csv")
gwt.inspect_cells(cell_list, output_file_path=out_file)

# compare output to expected results
head_new = os.path.join(run_folder, "gwf_mst03.hds")
outfile = os.path.join(run_folder, "head_compare.dat")
Expand Down
38 changes: 36 additions & 2 deletions flopy/mf6/data/mfdatautil.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
import struct


def iterable(obj):
return isinstance(obj, Iterable)
def iterable(obj, any_iterator=False):
if any_iterator:
try:
my_iter = iter(obj)
except TypeError as te:
return False
return True
else:
return isinstance(obj, Iterable)


def get_first_val(arr):
Expand All @@ -18,6 +25,15 @@ def get_first_val(arr):
return arr


def cellids_equal(cellid_1, cellid_2):
if len(cellid_1) != len(cellid_2):
return False
for id1, id2 in zip(cellid_1, cellid_2):
if id1 != id2:
return False
return True


# convert_data(data, type) : type
# converts data "data" to type "type" and returns the converted data
def convert_data(data, data_dimensions, data_type, data_item=None, sub_amt=1):
Expand Down Expand Up @@ -224,6 +240,24 @@ def to_string(
return str(val)


class DataSearchOutput:
def __init__(self, path_to_data=None, data_header=None):
self.path_to_data = path_to_data
self.data_header = data_header
self.data_entry_ids = []
self.data_entry_cellids = []
self.data_entry_stress_period = []
self.data_entries = []
self.output = False

@property
def transient(self):
if len(self.data_entry_stress_period) > 0:
if self.data_entry_stress_period[0] != -1:
return True
return False


class MFComment:
"""
Represents a variable in a MF6 input file
Expand Down
Loading

0 comments on commit ee009fd

Please sign in to comment.