Skip to content

Commit

Permalink
schism: Add parse_mirror_out()
Browse files Browse the repository at this point in the history
  • Loading branch information
pmav99 committed Apr 8, 2024
1 parent 7070f9e commit 965cec0
Show file tree
Hide file tree
Showing 3 changed files with 980 additions and 2 deletions.
30 changes: 30 additions & 0 deletions pyposeidon/schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# See the Licence for the specific language governing permissions and limitations under the Licence.

import os
import pathlib
import datetime
import numpy as np
import xml.dom.minidom as md
Expand Down Expand Up @@ -1944,3 +1945,32 @@ def get_station_obs_data(self, **kwargs):
def open_thalassa(self, **kwargs):
# open a Thalassa instance to visualize the output
return


def parse_mirror_out(path: os.PathLike[str] | str) -> pd.DataFrame:
etatot = []
etaavg = []
for line in pathlib.Path(path).read_text().splitlines():
if "start_year" in line:
start_year = int(line.strip().split(" ")[-1])
elif "start_month" in line:
start_month = int(line.strip().split(" ")[-1])
elif "start_day" in line:
start_day = int(line.strip().split(" ")[-1])
elif "start_hour" in line:
start_hour = float(line.strip().split(" ")[-1])
elif "time stepping begins..." in line:
periods = int(line.strip().split(" ")[-1])
elif "TIME STEP= 1;" in line:
dt = int(float(line.strip().split(" ")[-1]))
elif "etatot" in line:
parts = line.strip().split(" ")
etatot.append(parts[5])
etaavg.append(parts[-1])
else:
continue
start_date = pd.Timestamp(year=start_year, month=start_month, day=start_day, hour=start_hour)
index = pd.date_range(start_date, periods=periods, freq=f"{dt}s")
index = index[: len(etatot)]
df = pd.DataFrame({"etatot": etatot, "etaavg": etaavg}, index=index).astype(float)
return df
Loading

0 comments on commit 965cec0

Please sign in to comment.