-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Features * calc_mbe: mean bias error * calc_threshold_hit_ratio ## Fix * drop_nan: The problem that if input as list, the result is unexpect. ## Tests * add test for: * calc_mae * calc_mbe * calc_threshold_hit_ratio * calc_threshold_false_alarm_ratio * calc_threshold_ts * calc_linregress
- Loading branch information
Showing
7 changed files
with
282 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# 贡献指南 | ||
|
||
感谢您考虑为本项目做出贡献!为了帮助您入手并快速贡献,本文提供了一些基本的指导。 | ||
|
||
## Issue | ||
|
||
如果您发现了一个 bug 或者有一个新的功能请求,可以在我们的 [GitHub Issues](https://github.com/example-project/issues) 页面上创建一个 issue,我们会及时查看并回复您的问题。 | ||
|
||
## Pull Request | ||
|
||
我们非常欢迎您为本项目提交 Pull Request。在提交 PR 之前,请确保您已经遵循了以下步骤: | ||
|
||
1. 从主分支(`main`)拉取最新的代码并创建一个新的分支(比如 `feature/new-feature`)。 | ||
2. 在新分支上开发您的代码,确保您的代码风格符合项目的编码规范。 | ||
3. 通过测试用例,确保代码能够正常运行并且不会影响其他部分。 | ||
4. 通过测试后,提交您的 Pull Request。在 PR 描述中,请详细描述您的代码变更,包括对相关 issue 的引用。 | ||
|
||
## Coding Style | ||
|
||
本项目的代码风格遵循 [PEP 8](https://www.python.org/dev/peps/pep-0008/) 规范。在提交代码前,请确保您的代码风格符合这个规范。 | ||
|
||
## License | ||
|
||
本项目采用 [MIT License](./LICENSE) 协议。在为本项目做出贡献之前,请确保您已经完全了解了该协议内容并同意遵守该协议的所有规定。 | ||
|
||
如果您有任何问题,请随时在 GitHub Issues 页面上发起讨论。我们非常感谢您的贡献! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from .core import * | ||
|
||
__version__ = "0.1.0.beta.7" | ||
__version__ = "0.1.0.beta.8" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,175 @@ | ||
import numpy as np | ||
|
||
from cyeva.core.statistic import ( | ||
calc_mae, | ||
calc_mbe, | ||
calc_threshold_hit_ratio, | ||
calc_threshold_false_alarm_ratio, | ||
calc_threshold_ts, | ||
calc_linregress, | ||
) | ||
|
||
|
||
def test_calc_mae(): | ||
MAE_CASE = [ | ||
{"obs": [1, 2, 3, 4, 5], "fct": [1, 2, 3, 4, 5], "result": 0.0}, | ||
{"obs": [1, 2, 3, 4, 5], "fct": [3, 3, 3, 3, 3], "result": 1.2}, | ||
] | ||
for case in MAE_CASE: | ||
obs = case["obs"] | ||
fct = case["fct"] | ||
result = case["result"] | ||
_result = calc_mae(obs, fct) | ||
if not np.isnan(result): | ||
assert _result == result | ||
else: | ||
assert np.isnan(_result) | ||
|
||
|
||
def test_calc_mbe(): | ||
MBE_CASE = [ | ||
{"obs": [1, 2, 3, 4, 5], "fct": [1, 2, 3, 4, 5], "result": 0.0}, | ||
{"obs": [1, 2, 3, 4, 5], "fct": [3, 3, 3, 3, 3], "result": 0.0}, | ||
{"obs": [1, 2, 3, 4, 5], "fct": [1, 1, 1, 1, 1], "result": -2.0}, | ||
{"obs": [1, 2, 3, 4, 5], "fct": [5, 5, 5, 5, 5], "result": 2.0}, | ||
] | ||
for case in MBE_CASE: | ||
obs = case["obs"] | ||
fct = case["fct"] | ||
result = case["result"] | ||
_result = calc_mbe(obs, fct) | ||
if not np.isnan(result): | ||
assert _result == result | ||
else: | ||
assert np.isnan(_result) | ||
|
||
|
||
def test_calc_threshold_hit_ratio(): | ||
THRESHOLD_HIT_RATIO_CASE = [ | ||
{ | ||
"obs": [1, 2, 2, 2, 2], | ||
"fct": [1, 1, 1, 1, 1], | ||
"threshold": 2, | ||
"result": 0.0, | ||
}, | ||
{ | ||
"obs": [1, 2, 2, 2, 2], | ||
"fct": [1, 2, 1, 1, 1], | ||
"threshold": 2, | ||
"result": 25, | ||
}, | ||
{"obs": [1, 2, 2, 2, 2], "fct": [1, 2, 2, 1, 1], "threshold": 2, "result": 50}, | ||
{ | ||
"obs": [1, 2, 2, 2, 2], | ||
"fct": [1, 2, 2, 2, 1], | ||
"threshold": 2, | ||
"result": 75, | ||
}, | ||
{"obs": [1, 2, 2, 2, 2], "fct": [1, 2, 2, 2, 2], "threshold": 2, "result": 100}, | ||
] | ||
for case in THRESHOLD_HIT_RATIO_CASE: | ||
obs = case["obs"] | ||
fct = case["fct"] | ||
threshold = case["threshold"] | ||
result = case["result"] | ||
_result = calc_threshold_hit_ratio(obs, fct, threshold) | ||
if not np.isnan(result): | ||
assert _result == result | ||
else: | ||
assert np.isnan(_result) | ||
|
||
|
||
def test_calc_threshold_false_alarm_ratio(): | ||
THRESHOLD_FAR_CASE = [ | ||
{ | ||
"obs": [1, 2, 2, 2, 2], | ||
"fct": [1, 1, 1, 1, 1], | ||
"threshold": 2, | ||
"result": np.nan, | ||
}, | ||
{ | ||
"obs": [1, 2, 2, 2, 2], | ||
"fct": [1, 2, 1, 1, 1], | ||
"threshold": 2, | ||
"result": 0, | ||
}, | ||
{"obs": [1, 2, 1, 2, 2], "fct": [1, 2, 2, 1, 1], "threshold": 2, "result": 50}, | ||
{ | ||
"obs": [1, 2, 1, 1, 1], | ||
"fct": [1, 2, 2, 2, 2], | ||
"threshold": 2, | ||
"result": 75, | ||
}, | ||
{"obs": [1, 1, 1, 1, 1], "fct": [1, 2, 2, 2, 2], "threshold": 2, "result": 100}, | ||
] | ||
for case in THRESHOLD_FAR_CASE: | ||
obs = case["obs"] | ||
fct = case["fct"] | ||
threshold = case["threshold"] | ||
result = case["result"] | ||
_result = calc_threshold_false_alarm_ratio(obs, fct, threshold) | ||
if not np.isnan(result): | ||
assert _result == result | ||
else: | ||
assert np.isnan(_result) | ||
|
||
|
||
def test_calc_threshold_ts(): | ||
THRESHOLD_TS_CASE = [ | ||
{ | ||
"obs": [1, 2, 2, 2, 2], | ||
"fct": [1, 1, 1, 1, 1], | ||
"threshold": 2, | ||
"result": 0, | ||
}, | ||
{ | ||
"obs": [1, 2, 2, 2, 2], | ||
"fct": [1, 2, 1, 1, 1], | ||
"threshold": 2, | ||
"result": 0.25, | ||
}, | ||
{"obs": [1, 2, 2, 2, 2], "fct": [2, 2, 1, 1, 1], "threshold": 2, "result": 0.2}, | ||
{ | ||
"obs": [1, 2, 1, 1, 1], | ||
"fct": [1, 2, 2, 2, 2], | ||
"threshold": 2, | ||
"result": 0.25, | ||
}, | ||
{"obs": [1, 1, 1, 1, 1], "fct": [1, 2, 2, 2, 2], "threshold": 2, "result": 0}, | ||
] | ||
for case in THRESHOLD_TS_CASE: | ||
obs = case["obs"] | ||
fct = case["fct"] | ||
threshold = case["threshold"] | ||
result = case["result"] | ||
_result = calc_threshold_ts(obs, fct, threshold) | ||
if not np.isnan(result): | ||
assert _result == result | ||
else: | ||
assert np.isnan(_result) | ||
|
||
|
||
def calc_correlation_coefficient(): | ||
THRESHOLD_TS_CASE = [ | ||
{ | ||
"obs": [1, 2, 3, 4, 5], | ||
"fct": [1, 2, 3, 4, 5], | ||
"result": 1, | ||
}, | ||
{ | ||
"obs": [1, 2, 3, 4, 5], | ||
"fct": [5, 4, 3, 2, 1], | ||
"result": -1, | ||
}, | ||
{"obs": [1, 1, 1, 1, 1], "fct": [2, 2, 2, 2, 2], "result": 0}, | ||
] | ||
for case in THRESHOLD_TS_CASE: | ||
obs = case["obs"] | ||
fct = case["fct"] | ||
threshold = case["threshold"] | ||
result = case["result"] | ||
_, _, _result, _ = calc_linregress(obs, fct) | ||
if not np.isnan(result): | ||
assert _result == result | ||
else: | ||
assert np.isnan(_result) |