Skip to content

Commit

Permalink
feat(CellBudgetFile): add reverse() method
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Jun 13, 2023
1 parent 2fa3d65 commit 10d3659
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 76 deletions.
53 changes: 53 additions & 0 deletions autotest/test_binaryfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,56 @@ def test_cellbudgetfile_readrecord_waux(example_data_path):
record
)
v.close()


@pytest.mark.skip(
reason="failing, need to modify CellBudgetFile.reverse to support mf2005?"
)
def test_cellbudgetfile_reverse_mf2005(example_data_path, function_tmpdir):
mf2005_model_path = example_data_path / "mf2005_test"
cbc_fname = mf2005_model_path / "test1tr.gitcbc"
f = CellBudgetFile(cbc_fname)
assert isinstance(f, CellBudgetFile)

rf_name = "test1tr_rev.gitcbc"
f.reverse(function_tmpdir / rf_name)
rf = CellBudgetFile(function_tmpdir / rf_name)
assert isinstance(rf, CellBudgetFile)


def test_cellbudgetfile_reverse_mf6(example_data_path, function_tmpdir):
cbc_name = "flow_adj"
mf6_model_path = example_data_path / "mf6" / "test006_gwf3"
cbc_fname = mf6_model_path / "expected_output" / f"{cbc_name}.cbc"
f = CellBudgetFile(cbc_fname)
assert isinstance(f, CellBudgetFile)

rf_name = f"{cbc_name}_rev.cbc"
f.reverse(function_tmpdir / rf_name)
rf = CellBudgetFile(function_tmpdir / rf_name)
assert isinstance(rf, CellBudgetFile)

# check that both files have the same number of records
nrecords = f.get_nrecords()
assert nrecords == rf.get_nrecords()

# check that the data is reversed
for idx in range(nrecords - 1, -1, -1):
# check headers
# todo: figure out disagreement
# f_header = f.recordarray[idx]
# rf_header = rf.recordarray[idx]
# assert np.array_equal(f_header, rf_header)

# check data
f_data = f.get_data(idx=idx)[0]
rf_data = rf.get_data(idx=nrecords - idx - 1)[0]
assert f_data.shape == rf_data.shape
if f_data.ndim == 1:
for row in range(len(f_data)):
f_datum = f_data[row]
rf_datum = rf_data[row]
rf_datum[2] = -rf_datum[2]
assert f_datum == rf_datum
else:
assert np.array_equal(f_data[0][0], -rf_data[0][0])
Loading

0 comments on commit 10d3659

Please sign in to comment.