Skip to content

Commit

Permalink
add models as libname option to get_tmin_tmax
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonk committed Apr 15, 2024
1 parent 8f45fb9 commit 792e32f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
32 changes: 25 additions & 7 deletions pastastore/store.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
import warnings
from typing import List, Optional, Tuple, Union
from typing import List, Literal, Optional, Tuple, Union

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -384,7 +384,12 @@ def get_signatures(

return signatures_df

def get_tmin_tmax(self, libname, names=None, progressbar=False):
def get_tmin_tmax(
self,
libname: Literal["oseries", "stresses", "models"],
names: Union[str, List[str], None] = None,
progressbar: bool = False,
):
"""Get tmin and tmax for time series.
Parameters
Expand All @@ -410,12 +415,25 @@ def get_tmin_tmax(self, libname, names=None, progressbar=False):
)
desc = f"Get tmin/tmax {libname}"
for n in tqdm(names, desc=desc) if progressbar else names:
if libname == "oseries":
s = self.conn.get_oseries(n)
if libname == "models":
mld = self.conn.get_models(
n,
return_dict=True,
progressbar=False,
update_ts_settings=False,
squeeze=True,
)
tmintmax.loc[n, "tmin"] = mld["settings"]["tmin"]
tmintmax.loc[n, "tmax"] = mld["settings"]["tmax"]
else:
s = self.conn.get_stresses(n)
tmintmax.loc[n, "tmin"] = s.first_valid_index()
tmintmax.loc[n, "tmax"] = s.last_valid_index()
s = (
self.conn.get_oseries(n)
if libname == "oseries"
else self.conn.get_stresses(n)
)
tmintmax.loc[n, "tmin"] = s.first_valid_index()
tmintmax.loc[n, "tmax"] = s.last_valid_index()

return tmintmax

def get_extent(self, libname, names=None, buffer=0.0):
Expand Down
1 change: 1 addition & 0 deletions tests/test_003_pastastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def test_iter_stresses(pstore):
def test_get_tmintmax(pstore):
_ = pstore.get_tmin_tmax("oseries")
_ = pstore.get_tmin_tmax("stresses")
_ = pstore.get_tmin_tmax("models")


@pytest.mark.dependency()
Expand Down

0 comments on commit 792e32f

Please sign in to comment.