Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[weatherbench2] Test analytical Gaussian CRPS. #109

Merged
1 commit merged into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions weatherbench2/metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,45 @@ def test_gaussian_crps(self):
expected = np.array([0.23385455, 0.23385455])
np.testing.assert_allclose(result['2m_temperature'].values, expected)

def test_convergence_gaussian_crps(self):
"""Tests that the ensemble CRPS converges to analytical formula."""
forecast = schema.mock_forecast_data(
variables_3d=[],
variables_2d=['2m_temperature', '2m_temperature_std'],
time_start='2022-01-01',
time_stop='2022-01-02',
lead_stop='1 day',
)
ens_forecast = schema.mock_forecast_data(
variables_3d=[],
variables_2d=['2m_temperature'],
time_start='2022-01-01',
time_stop='2022-01-02',
lead_stop='1 day',
ensemble_size=5000,
)
truth = schema.mock_truth_data(
variables_3d=[],
variables_2d=['2m_temperature'],
time_start='2022-01-01',
time_stop='2022-01-20',
)
forecast['2m_temperature'] = forecast['2m_temperature'] + 0.1
forecast['2m_temperature_std'] = forecast['2m_temperature_std'] + 1.0
ens_forecast['2m_temperature'] = (
ens_forecast['2m_temperature']
+ np.random.randn(*ens_forecast['2m_temperature'].shape)
+ 0.1
)

result = metrics.GaussianCRPS().compute(forecast, truth)
result2 = metrics.CRPS().compute(ens_forecast, truth)
np.testing.assert_allclose(
result['2m_temperature'].values,
result2['2m_temperature'].values,
rtol=2e-2,
)


class GaussianVarianceTest(parameterized.TestCase):

Expand Down
Loading