Skip to content

Commit

Permalink
added test
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Oct 28, 2024
1 parent 4f05a87 commit fecf354
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
4 changes: 3 additions & 1 deletion examples/KWK_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
# compute and plot tidal indicators
dict_wltidalindicators = kw.calc_wltidalindicators(df_meas=df_meas_todate, min_coverage=min_coverage)
dict_HWLWtidalindicators = kw.calc_HWLWtidalindicators(df_ext=df_ext_todate, min_coverage=min_coverage)
dict_HWLW_springneap = kw.calc_HWLW_springneap(df_ext=df_ext_todate, min_coverage=min_coverage)

# add hat/lat
hat, lat = kw.calc_hat_lat_frommeasurements(df_meas_todate)
Expand All @@ -108,6 +109,7 @@

# merge dictionaries
dict_wltidalindicators.update(dict_HWLWtidalindicators)
dict_wltidalindicators.update(dict_HWLW_springneap)

# csv for yearlymonthly indicators
for key in ['wl_mean_peryear','wl_mean_permonth']:
Expand All @@ -119,7 +121,7 @@
fig.savefig(os.path.join(dir_indicators,f'kw{year_slotgem}-tidalindicators-{current_station}.png'))



continue

#### SLOTGEMIDDELDEN
# TODO: more data is needed for proper working of fitting for some stations (2011: BAALHK, BRESKVHVN, GATVBSLE, SCHAARVDND) >> still after linear?
Expand Down
16 changes: 10 additions & 6 deletions kenmerkendewaarden/havengetallen.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def calc_havengetallen(
raise_extremes_with_aggers(df_ext)
df_ext_10y = crop_timeseries_last_nyears(df=df_ext, nyears=10)

# check if coverage is high enough for havengetallen
# check if coverage is high enough
if min_coverage is not None:
check_min_coverage_extremes(df_ext=df_ext_10y, min_coverage=min_coverage)

Expand All @@ -96,8 +96,12 @@ def calc_HWLW_springneap(
raise_extremes_with_aggers(df_ext)

# TODO: moonculminations cannot be computed before 1900
df_ext = df_ext.loc["1901":]
if df_ext.index.min().year < 1901:
logger.warning("calc_HWLW_springneap() only supports timestamps after 1900 "
"all older data will be ignored")
df_ext = df_ext.loc["1901":]

# check if coverage is high enough
if min_coverage is not None:
check_min_coverage_extremes(df_ext=df_ext, min_coverage=min_coverage)

Expand Down Expand Up @@ -127,10 +131,10 @@ def calc_HWLW_springneap(

# merge in dict
dict_hwlw_springneap = {
"hw_spring_peryear": hw_spring_peryear,
"lw_spring_peryear": lw_spring_peryear,
"hw_neap_peryear": hw_neap_peryear,
"lw_neap_peryear": lw_neap_peryear,
"HW_spring_peryear": hw_spring_peryear,
"LW_spring_peryear": lw_spring_peryear,
"HW_neap_peryear": hw_neap_peryear,
"LW_neap_peryear": lw_neap_peryear,
}
return dict_hwlw_springneap

Expand Down
29 changes: 29 additions & 0 deletions tests/test_havengetallen.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,35 @@ def test_calc_havengetallen_toolittle_data(df_ext_12_2010_2014):
assert "coverage of some years is lower than min_coverage" in str(e.value)


@pytest.mark.unittest
def test_calc_HWLW_springneap(df_ext_12_2010_2014):
dict_spnp = kw.calc_HWLW_springneap(df_ext_12_2010_2014)
df_columns = ['HW_spring_peryear', 'LW_spring_peryear',
'HW_neap_peryear', 'LW_neap_peryear']
assert set(dict_spnp.keys()) == set(df_columns)

for key in df_columns:
years_act = dict_spnp[key].index.year.tolist()
years_exp = [2010, 2011, 2012, 2013, 2014]
assert years_act == years_exp

vals_act = dict_spnp['HW_spring_peryear'].values
vals_exp = np.array([1.33551724, 1.28111111, 1.29563636, 1.33185185, 1.37745455])
assert np.allclose(vals_act, vals_exp)

vals_act = dict_spnp['LW_spring_peryear'].values
vals_exp = np.array([-0.59724138, -0.6212963, -0.61872727, -0.60407407, -0.60145455])
assert np.allclose(vals_act, vals_exp)

vals_act = dict_spnp['HW_neap_peryear'].values
vals_exp = np.array([0.83887097, 0.95854839, 0.86225806, 0.87903226, 0.9696875])
assert np.allclose(vals_act, vals_exp)

vals_act = dict_spnp['LW_neap_peryear'].values
vals_exp = np.array([-0.62919355, -0.46758065, -0.5633871 , -0.60193548, -0.51421875])
assert np.allclose(vals_act, vals_exp)


@pytest.mark.unittest
def test_calc_HWLW_culmhr_summary_tidalcoeff(df_ext_12_2010):
"""
Expand Down

0 comments on commit fecf354

Please sign in to comment.