From cf32241afe93017a5028e56ae0019c7d2c246e61 Mon Sep 17 00:00:00 2001 From: George Breyiannis Date: Sun, 21 Jan 2024 19:59:26 +0100 Subject: [PATCH] Deal with schism bug in station output Manually set the time index of staout files Fix #174 --- pyposeidon/schism.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pyposeidon/schism.py b/pyposeidon/schism.py index 2917af86..6640549f 100644 --- a/pyposeidon/schism.py +++ b/pyposeidon/schism.py @@ -1903,6 +1903,11 @@ def get_station_sim_data(self, **kwargs): skiprows = kwargs.get("station_skiprows", 0) + try: + dt = self.parameters["dt"] + except: + dt = self.params["core"]["dt"] + dfs = [] for idx in vals.index: obs = np.loadtxt(sfiles[idx], skiprows=skiprows) @@ -1910,7 +1915,10 @@ def get_station_sim_data(self, **kwargs): df = df.set_index(0) df.index.name = "time" df.columns.name = vals.loc[idx, "variable"] - df.index = pd.to_datetime(dstamp) + pd.to_timedelta(df.index, unit="S") + # deal with schism bug + ns = np.arange(1, df.shape[0] + 1) + df.index = pd.to_datetime(dstamp) + pd.to_timedelta(ns * dt, unit="S") + # df.index = pd.to_datetime(dstamp) + pd.to_timedelta(df.index, unit="S") pindex = pd.MultiIndex.from_product([df.T.columns, df.T.index]) r = pd.DataFrame(df.values.flatten(), index=pindex, columns=[vals.loc[idx, "variable"]])