Deltares / hatyan

Harmonic tidal analysis and prediction
https://deltares.github.io/hatyan/
GNU General Public License v3.0
13 stars 2 forks source link

fix `calc_HWLWnumbering()` for IJMBTHVN #329

Open veenstrajelmer opened 3 months ago

veenstrajelmer commented 3 months ago

Within the kenmerkendewaarden project, some extremes timeseries raised "Exception: tidal wave numbering: HW numbers not always increasing". This was often due to invalid additional extremes reported in https://github.com/Rijkswaterstaat/wm-ws-dl/issues/43. However, at least for IJMBTHVN, there is a valid but strongly asymmetric extreme that causes this error.

It is only an issue after shifting the timezone (which is what happens in kw.calc_gemiddeldgetij()), but it comes from hatyan.calc_HWLWnumbering() already. So even if for kenmerkendewaarden we move to another way of matching culminations and extremes, we will probably want to solve this in hatyan.

import matplotlib.pyplot as plt
plt.close('all')
import hatyan
import kenmerkendewaarden as kw # pip install git+https://github.com/Deltares-research/kenmerkendewaarden
import ddlpy

locs_meas_ts, locs_meas_ext, locs_meas_exttype = kw.data_retrieve.retrieve_catalog()

tstart = "2018-01-17"
tstop = "2018-01-19"
station = "IJMDBTHVN"
df_meas_ddlpy = ddlpy.measurements(locs_meas_ts.loc[station], start_date=tstart, end_date=tstop)
df_ext_ddlpy = ddlpy.measurements(locs_meas_ext.loc[station], start_date=tstart, end_date=tstop)
df_exttyp_ddlpy = ddlpy.measurements(locs_meas_exttype.loc[station], start_date=tstart, end_date=tstop)
df_meas = hatyan.ddlpy_to_hatyan(df_meas_ddlpy)
df_ext = hatyan.ddlpy_to_hatyan(df_ext_ddlpy, df_exttyp_ddlpy)

df_ext = hatyan.calc_HWLWnumbering(df_ext)
fig,ax = plt.subplots()
df_meas['values'].loc[tstart:tstop].plot(ax=ax)
df_ext['values'].loc[tstart:tstop].plot(ax=ax, marker='x', linestyle='')
for irow, row in df_ext.loc[tstart:tstop].iterrows():
    ax.text(row.name, row['values'], row["HWLWno"])

Gives: image

If we shift the timeseries with 1 hour (which is done in kw.calc_havengetallen()) it raises "Exception: tidal wave numbering: HW numbers not always increasing" because HW 12737 is interpreted as HW 12738:

if df_ext.index.tz is not None:
    df_ext = df_ext.tz_localize(None)
df_num = hatyan.calc_HWLWnumbering(df_ext)

Note: in https://github.com/Deltares/hatyan/issues/311, it was also noted that hatyan.calc_HWLWnumbering() fails for "long 1870-2024 timeseries for HOEKVHLD, even not when providing station argument".