From 234d9f5434f66344cc8d98f88b58de4d9bab599f Mon Sep 17 00:00:00 2001 From: Panos Mavrogiorgos Date: Thu, 2 May 2024 22:32:07 +0300 Subject: [PATCH] schism: Add `parse_station_in()` --- pyposeidon/schism.py | 5 +++++ tests/data/station.in | 3 +++ tests/test_schism.py | 12 ++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/data/station.in diff --git a/pyposeidon/schism.py b/pyposeidon/schism.py index 6ce34faa..bda59300 100644 --- a/pyposeidon/schism.py +++ b/pyposeidon/schism.py @@ -1984,3 +1984,8 @@ def parse_staout(path: os.PathLike[str] | str, start: pd.Timestamp = pd.NaT): index = index.rename("time") df = df.set_index(index) return df + + +def parse_station_in(path: os.PathLike[str] | str = "station.in") -> pd.DataFrame: + df = pd.read_csv(path, skiprows=2, header=None, names=["lon", "lat", "layer"], sep="\s+") + return df diff --git a/tests/data/station.in b/tests/data/station.in new file mode 100644 index 00000000..ac872db4 --- /dev/null +++ b/tests/data/station.in @@ -0,0 +1,3 @@ +1 0 0 0 0 0 0 0 0 +1 +1 -21.9435235194 64.1473641012 0 diff --git a/tests/test_schism.py b/tests/test_schism.py index d1449154..24796cca 100644 --- a/tests/test_schism.py +++ b/tests/test_schism.py @@ -186,3 +186,15 @@ def test_parse_staout_with_start_date(): assert isinstance(df.index, pd.DatetimeIndex) assert df.index.name == "time" assert df.index[0] == pd.Timestamp("2017-10-01T00:02:30") # that's 150 seconds after midnight + + +def test_parse_station_in(): + path = DATA_DIR / "station.in" + df = pyposeidon.schism.parse_station_in(path) + assert isinstance(df, pd.DataFrame) + assert len(df) == 1 + assert len(df.columns) == 3 + assert df.columns.equals(pd.Index(["lon", "lat", "layer"])) + assert df.iloc[0].lon == -21.9435235194 + assert df.iloc[0].lat == 64.1473641012 + assert df.iloc[0].layer == 0