Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ In applying this licence, ECMWF does not waive the privileges and immunities
granted to it by virtue of its status as an intergovernmental organisation
nor does it submit to any jurisdiction.
```

## Attributions

The hydrostats part of this library uses the [`scores`](https://scores.readthedocs.io) library [1], which is available under [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.txt).

[1] Leeuwenburg, T., Loveday, N., Ebert, E. E., Cook, H., Khanarmuei, M., Taggart, R. J., Ramanathan, N., Carroll, M., Chong, S., Griffiths, A., & Sharples, J. (2024). scores: A Python package for verifying and evaluating models and predictions with xarray. Journal of Open Source Software, 9(99), 6889. https://doi.org/10.21105/joss.06889
10 changes: 7 additions & 3 deletions hat/compute_hydrostats/stat_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from earthkit.hydro._readers import find_main_var
import numpy as np
import xarray as xr
from hat.compute_hydrostats import stats
import scores


def load_da(ds_config):
Expand Down Expand Up @@ -40,10 +40,14 @@ def stat_calc(config):
obs_da = load_da(obs_config)
new_coords = config["output"]["coords"]
sim_da, obs_da = find_valid_subset(sim_da, obs_da, sim_config["coords"], obs_config["coords"], new_coords)
time_dim = new_coords.get("t", "time")
stat_dict = {}
for stat in config["stats"]:
func = getattr(stats, stat)
stat_dict[stat] = func(sim_da, obs_da, new_coords.get("t", "time"))
parts = stat.split(".")
func = scores
for part in parts:
func = getattr(func, part)
stat_dict[stat] = func(sim_da, obs_da, reduce_dims=time_dim)
ds = xr.Dataset(stat_dict)
if config["output"].get("file", None) is not None:
ds.to_netcdf(config["output"]["file"])
Expand Down
83 changes: 0 additions & 83 deletions hat/compute_hydrostats/stats.py

This file was deleted.

8 changes: 4 additions & 4 deletions notebooks/workflow/hydrostats_computation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@
"source": [
"config = {\n",
" \"sim\": {\n",
" \"source\": [\"file\", \"extracted_timeseries.nc\"],\n",
" \"source\": [\"file\", \"simulated_dataset.nc\"],\n",
" \"coords\": {\n",
" \"s\": \"station\",\n",
" \"t\": \"time\"\n",
" }\n",
" },\n",
" \"obs\": {\n",
" \"source\": [\"file\", \"observations.nc\"],\n",
" \"source\": [\"file\", \"observed_dataset.nc\"],\n",
" \"coords\": {\n",
" \"s\": \"station\",\n",
" \"t\": \"time\"\n",
" }\n",
" },\n",
" \"stats\" : [\"bias\", \"apb\", \"apb2\"],\n",
" \"stats\" : [\"continuous.kge\", \"continuous.mse\"],\n",
" \"output\": {\n",
" \"file\": \"statistics.nc\",\n",
" \"coords\": {\n",
Expand All @@ -49,7 +49,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "hat",
"language": "python",
"name": "python3"
},
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ dependencies = [
"floods-html",
"geopy",
"setuptools",
"anywidget"
"anywidget",
"scores"
]

[project.urls]
Expand Down
Loading