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 7a4cbfb commit bc33656
Show file tree
Hide file tree
Showing 3 changed files with 982 additions and 8 deletions.
38 changes: 32 additions & 6 deletions pyposeidon/schism.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@
# Unless required by applicable law or agreed to in writing, software distributed under the Licence is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the Licence for the specific language governing permissions and limitations under the Licence.

from __future__ import annotations

import os
import pathlib
import datetime
import numpy as np
import xml.dom.minidom as md
from shutil import copy2
import subprocess
import shlex
import sys
import json
from collections import OrderedDict
import pandas as pd
import glob
from shutil import copyfile
import xarray as xr
import geopandas as gp
import shapely
import f90nml
import errno
import dask
from searvey import ioc
from tqdm.auto import tqdm
Expand Down Expand Up @@ -1944,3 +1941,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 bc33656

Please sign in to comment.