Skip to content

Commit

Permalink
Fix fit_gev relative_fit_test check and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stellema committed Aug 21, 2024
1 parent f83dcf5 commit 7053713
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion unseen/eva.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def _fit(
result = check_gev_relative_fit(
data, L1, L2, test=relative_fit_test, alpha=alpha
)
if result is False:
if not result:
warnings.warn(
f"{relative_fit_test} test failed. Returning stationary parameters."
)
Expand Down
34 changes: 34 additions & 0 deletions unseen/tests/test_eva.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,40 @@ def test_fit_ns_gev_3d():
assert np.all(theta.isel(theta=2) > 0) # Positive trend in location


def test_fit_ns_gev_1d_relative_fit_test_bic_trend():
"""Run non-stationary fit & check 'BIC' test returns nonstationary params."""
data, _ = example_da_gev_1d()
# Add a large positive linear trend
data = add_example_gev_trend(data)
data = add_example_gev_trend(data)
covariate = np.arange(data.time.size, dtype=int)

theta = fit_gev(
data,
stationary=False,
core_dim="time",
covariate=covariate,
relative_fit_test="bic",
)
assert np.all(theta[2] > 0) # Positive trend in location


def test_fit_ns_gev_1d_relative_fit_test_bic_no_trend():
"""Run non-stationary fit & check 'BIC' test returns stationary params."""
data, _ = example_da_gev_1d()
covariate = np.arange(data.time.size, dtype=int)

theta = fit_gev(
data,
stationary=False,
core_dim="time",
covariate=covariate,
relative_fit_test="bic",
)
assert np.all(theta[2] == 0) # No trend in location
assert np.all(theta[4] == 0) # No trend in scale


def test_fit_ns_gev_3d_dask():
"""Run non-stationary fit using 3D dask array & check results."""
data, _ = example_da_gev_3d_dask()
Expand Down

0 comments on commit 7053713

Please sign in to comment.