Skip to content

Commit 0aa0626

Browse files
authored
Merge pull request #511 from DHI/rel_1.2
Release 1.2.0
2 parents 61f4275 + f3e9acd commit 0aa0626

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

docs/examples/Metrics_custom_metric.qmd

+6-5
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ cc.skill()
2929
Some metrics has parameters, which require a bit special treatment.
3030

3131
```{python}
32-
from modelskill.metrics import hit_ratio
32+
from modelskill.metrics import hit_ratio, metric
3333
34+
@metric(best="+")
3435
def hit_ratio_05_pct(obs, model):
3536
return hit_ratio(obs, model, 0.5) * 100
3637
38+
@metric(best="+")
3739
def hit_ratio_01_pct(obs, model):
3840
return hit_ratio(obs, model, 0.1) * 100
3941
@@ -44,17 +46,16 @@ cc.skill(metrics=[hit_ratio_05_pct, hit_ratio_01_pct])
4446
And you are always free to specify your own special metric or import metrics from other libraries, e.g. scikit-learn.
4547

4648
```{python}
47-
def my_special_metric_with_long_descriptive_name(obs, model):
49+
@metric(best="-", has_units=True)
50+
def mcae(obs, model):
4851
4952
res = obs - model
5053
5154
res_clipped = np.clip(res,0,np.inf)
5255
5356
return np.mean(np.abs(res_clipped))
5457
55-
# short alias to avoid long column names in output
56-
def mcae(obs, model): return my_special_metric_with_long_descriptive_name(obs, model)
5758
58-
cc.skill(metrics=mcae)
59+
cc.skill(metrics=mcae).style()
5960
```
6061

modelskill/__init__.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from importlib.metadata import PackageNotFoundError, version
12
from pathlib import Path
23
from platform import architecture
34
from typing import Union
@@ -19,7 +20,12 @@
1920
# Dev branch marker is: 'X.Y.dev' or 'X.Y.devN' where N is an integer.
2021
# 'X.Y.dev0' is the canonical version of 'X.Y.dev'
2122
#
22-
__version__ = "1.2.dev0"
23+
try:
24+
# read version from installed package
25+
__version__ = version("modelskill")
26+
except PackageNotFoundError:
27+
# package is not installed
28+
__version__ = "dev"
2329

2430
if "64" not in architecture()[0]:
2531
raise Exception("This library has not been tested for a 32 bit system.")

modelskill/metrics.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ def add_metric(metric: Callable, has_units: bool = False) -> None:
4141

4242

4343
def metric(
44-
best: Literal["+", "-"] | None = None, has_units: bool = False
44+
best: Literal["+", "-", 0, 1] | None = None, has_units: bool = False
4545
) -> Callable[[F], F]:
4646
"""Decorator to indicate a function as a metric.
4747
4848
Parameters
4949
----------
50-
best : {"+", "-"}, optional
50+
best : {"+", "-", 0, 1}, optional
5151
Indicates whether a higher value ("+") or a lower value ("-") is better.
52+
Some "metrics" like bias or linear slope has a value where 0 or 1 is the best, and no direction.
5253
If None, no preference is specified.
5354
has_units : bool, default False
5455
Specifies whether the metric has physical units.

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ allow-direct-references = true
1212

1313
[project]
1414
name = "modelskill"
15-
version = "1.2.dev0"
15+
version = "1.2.0"
1616
dependencies = [
1717
"numpy > 1.24.4",
1818
"pandas >= 1.4",

0 commit comments

Comments
 (0)