Skip to content

Commit

Permalink
small fix for tests :'(
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrakenhoff committed Aug 15, 2024
1 parent a5b70f7 commit a8e3780
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
45 changes: 24 additions & 21 deletions pastastore/extensions/hpd.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ def add_observation(
return

if normalize_datetime_index and o.index.size > 1:
o = self._normalize_datetime_index(o)
else:
o = self._normalize_datetime_index(o).dropna()
elif normalize_datetime_index and o.index.size <= 1:
raise ValueError(
"Must have minimum of 2 observations for timestep_weighted_resample."
)
Expand Down Expand Up @@ -202,7 +202,7 @@ def add_observation(
def download_knmi_precipitation(
self,
stns: Optional[list[int]] = None,
meteo_var: str = "RH",
meteo_var: str = "RD",
tmin: TimeType = None,
tmax: TimeType = None,
unit_multiplier: float = 1e3,
Expand All @@ -217,7 +217,7 @@ def download_knmi_precipitation(
stns : list of int/str, optional
list of station numbers to download data for, by default None
meteo_var : str, optional
variable to download, by default "RH", valid options are ["RD", "RH"].
variable to download, by default "RD", valid options are ["RD", "RH"].
tmin : TimeType, optional
start time, by default None
tmax : TimeType, optional
Expand Down Expand Up @@ -359,9 +359,9 @@ def update_knmi_meteo(
names: Optional[List[str]] = None,
tmin: TimeType = None,
tmax: TimeType = None,
fill_missing_obs=True,
normalize_datetime_index=True,
raise_on_error=False,
fill_missing_obs: bool = True,
normalize_datetime_index: bool = True,
raise_on_error: bool = False,
**kwargs,
):
"""Update meteorological data from KNMI in PastaStore.
Expand Down Expand Up @@ -398,24 +398,27 @@ def update_knmi_meteo(
logger.info(f"All KNMI stresses are up to date to {tmax}.")
return

maxtmax_rd = _check_latest_measurement_date_de_bilt("RD")
maxtmax_ev24 = _check_latest_measurement_date_de_bilt("EV24")
# NOTE: this check is very flaky (15 august 2024), perhaps I annoyed the
# KNMI server... Trying to skip this check and just attempt downloading data.
# maxtmax_rd = _check_latest_measurement_date_de_bilt("RD")
# maxtmax_ev24 = _check_latest_measurement_date_de_bilt("EV24")
maxtmax = Timestamp.today() - Timedelta(days=1)

for name in tqdm(names, desc="Updating KNMI meteo stresses"):
meteo_var = self._store.stresses.loc[name, "meteo_var"]
if meteo_var == "RD":
maxtmax = maxtmax_rd
elif meteo_var == "EV24":
maxtmax = maxtmax_ev24
else:
maxtmax = maxtmax_rd

# if meteo_var == "RD":
# maxtmax = maxtmax_rd
# elif meteo_var == "EV24":
# maxtmax = maxtmax_ev24
# else:
# maxtmax = maxtmax_rd

# 1 days extra to ensure computation of daily totals using
# timestep_weighted_resample
if tmin is None:
# 1 days extra to ensure computation of daily totals using
# timestep_weighted_resample
itmin = tmintmax.loc[name, "tmax"] - Timedelta(days=1)
else:
itmin = tmin
itmin = tmin - Timedelta(days=1)

# ensure 2 observations at least
if itmin >= (maxtmax + Timedelta(days=1)):
Expand All @@ -425,7 +428,7 @@ def update_knmi_meteo(
if tmax is None:
itmax = maxtmax
else:
itmax = tmax
itmax = Timestamp(tmax)

unit = self._store.stresses.loc[name, "unit"]
kind = self._store.stresses.loc[name, "kind"]
Expand Down Expand Up @@ -464,7 +467,7 @@ def update_knmi_meteo(
try:
self.add_observation(
"stresses",
obs.loc[tmintmax.loc[name, "tmax"] :],
obs,
name=name,
kind=kind,
data_column=meteo_var,
Expand Down
2 changes: 1 addition & 1 deletion pastastore/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
PASTAS_LEQ_022 = PASTAS_VERSION <= parse_version("0.22.0")
PASTAS_GEQ_150 = PASTAS_VERSION >= parse_version("1.5.0")

__version__ = "1.6.0"
__version__ = "1.6.1"


def show_versions(optional=False) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_007_hpdextension.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def test_update_stresses():
activate_hydropandas_extension()

pstore = pst.PastaStore.from_zip("tests/data/test_hpd_update.zip")
pstore.hpd.update_knmi_meteo(tmax="2024-01-31")
pstore.hpd.update_knmi_meteo(tmax="2024-01-31", normalize_datetime_index=False)
tmintmax = pstore.get_tmin_tmax("stresses")
assert (tmintmax["tmax"] >= Timestamp("2024-01-31")).all()

0 comments on commit a8e3780

Please sign in to comment.