Skip to content
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

fix(obs): Modify observations to load single time step files #1559

Merged
merged 7 commits into from
Sep 29, 2022
20 changes: 20 additions & 0 deletions autotest/test_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
ModflowPcg,
)

from flopy.utils.observationfile import Mf6Obs


@requires_exe("mf2005")
def test_hob_simple(tmpdir):
Expand Down Expand Up @@ -248,6 +250,24 @@ def test_obs_load_and_write(tmpdir, example_data_path):
assert np.array_equal(drob.column, m.drob.column), s


def test_obs_single_time(tmpdir):
"""
test reading a mf6 observation file with a single time
"""

pth = str(tmpdir / "single.csv")
with open(pth, "w") as file:
file.write("time,obs01,obs02\n1.0,10.0,20.0\n")

obs = Mf6Obs(pth)
data = obs.get_data()

assert data.shape[0] == 1, "data shape != 1"
assert data["totim"][0] == 1.0, "totim[0] != 1.0"
assert data["obs01"][0] == 10.0, "obs01[0] != 10.0"
assert data["obs02"][0] == 20.0, "obs02[0] != 20.0"


def test_obs_create_and_write(tmpdir, example_data_path):
"""
test041 create and write of MODFLOW-2005 OBS example problem
Expand Down
2 changes: 2 additions & 0 deletions flopy/utils/observationfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ def read_csv(fobj, dtype, delimiter=","):
np.recarray
"""
arr = np.genfromtxt(fobj, dtype=dtype, delimiter=delimiter)
if len(arr.shape) == 0:
arr = arr.reshape((1,))
wpbonelli marked this conversation as resolved.
Show resolved Hide resolved
return arr.view(np.recarray)


Expand Down