Skip to content

Commit

Permalink
Run black
Browse files Browse the repository at this point in the history
  • Loading branch information
Steph-Chong committed Sep 17, 2024
1 parent 0d5b93e commit dd06e29
Showing 1 changed file with 12 additions and 25 deletions.
37 changes: 12 additions & 25 deletions src/scores/categorical/contingency_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ def frequency_bias(self) -> xr.DataArray:
"""
# Note - bias_score calls this method
cd = self.counts
freq_bias = (cd["tp_count"] + cd["fp_count"]) / (
cd["tp_count"] + cd["fn_count"]
)
freq_bias = (cd["tp_count"] + cd["fp_count"]) / (cd["tp_count"] + cd["fn_count"])

return freq_bias

Expand Down Expand Up @@ -302,7 +300,7 @@ def bias_score(self) -> xr.DataArray:

def hit_rate(self) -> xr.DataArray:
"""
Identical to :py:func:`true_positive_rate`, :py:func:`probability_of_detection <BasicContingencyManager.probability_of_detection>`,
Identical to :py:func:`true_positive_rate`, :py:func:`probability_of_detection <BasicContingencyManager.probability_of_detection>`,
:py:func:`sensitivity` and :py:func:`recall`.
Calculates the proportion of the observed events that were correctly forecast.
Expand All @@ -325,7 +323,7 @@ def hit_rate(self) -> xr.DataArray:

def probability_of_detection(self) -> xr.DataArray:
"""
Probability of detection (POD) is identical to :py:func:`hit_rate`, :py:func:`true_positive_rate`,
Probability of detection (POD) is identical to :py:func:`hit_rate`, :py:func:`true_positive_rate`,
:py:func:`sensitivity` and :py:func:`recall`.
Calculates the proportion of the observed events that were correctly forecast.
Expand All @@ -352,8 +350,8 @@ def probability_of_detection(self) -> xr.DataArray:

def true_positive_rate(self) -> xr.DataArray:
"""
Identical to :py:func:`hit_rate`, :py:func:`probability_of_detection <BasicContingencyManager.probability_of_detection>`,
:py:func:`sensitivity` and :py:func:`recall`.
Identical to :py:func:`hit_rate`, :py:func:`probability_of_detection <BasicContingencyManager.probability_of_detection>`,
:py:func:`sensitivity` and :py:func:`recall`.
The proportion of the observed events that were correctly forecast.
Expand Down Expand Up @@ -612,7 +610,7 @@ def hanssen_and_kuipers_discriminant(self) -> xr.DataArray:

def sensitivity(self) -> xr.DataArray:
"""
Identical to :py:func:`hit_rate`, :py:func:`probability_of_detection <BasicContingencyManager.probability_of_detection>`,
Identical to :py:func:`hit_rate`, :py:func:`probability_of_detection <BasicContingencyManager.probability_of_detection>`,
:py:func:`true_positive_rate`, and :py:func:`recall`.
Calculates the proportion of the observed events that were correctly forecast.
Expand Down Expand Up @@ -681,7 +679,7 @@ def true_negative_rate(self) -> xr.DataArray:

def recall(self) -> xr.DataArray:
"""
Identical to :py:func:`hit_rate`, :py:func:`probability_of_detection <BasicContingencyManager.probability_of_detection>`,
Identical to :py:func:`hit_rate`, :py:func:`probability_of_detection <BasicContingencyManager.probability_of_detection>`,
:py:func:`true_positive_rate`, and :py:func:`sensitivity`.
Calculates the proportion of the observed events that were correctly forecast.
Expand Down Expand Up @@ -786,14 +784,8 @@ def equitable_threat_score(self) -> xr.DataArray:
Weather and Forecasting, 25(2), pp.710-726. https://doi.org/10.1175/2009WAF2222350.1
"""
cd = self.counts
hits_random = (
(cd["tp_count"] + cd["fn_count"])
* (cd["tp_count"] + cd["fp_count"])
/ cd["total_count"]
)
ets = (cd["tp_count"] - hits_random) / (
cd["tp_count"] + cd["fn_count"] + cd["fp_count"] - hits_random
)
hits_random = (cd["tp_count"] + cd["fn_count"]) * (cd["tp_count"] + cd["fp_count"]) / cd["total_count"]
ets = (cd["tp_count"] - hits_random) / (cd["tp_count"] + cd["fn_count"] + cd["fp_count"] - hits_random)

return ets

Expand Down Expand Up @@ -880,9 +872,7 @@ def heidke_skill_score(self) -> xr.DataArray:
(cd["tp_count"] + cd["fn_count"]) * (cd["tp_count"] + cd["fp_count"])
+ ((cd["tn_count"] + cd["fn_count"]) * (cd["tn_count"] + cd["fp_count"]))
)
hss = ((cd["tp_count"] + cd["tn_count"]) - exp_correct) / (
cd["total_count"] - exp_correct
)
hss = ((cd["tp_count"] + cd["tn_count"]) - exp_correct) / (cd["total_count"] - exp_correct)
return hss

def cohens_kappa(self) -> xr.DataArray:
Expand Down Expand Up @@ -972,11 +962,8 @@ def odds_ratio(self) -> xr.DataArray:
Weather and Forecasting, 15(2), pp.221-232. \
https://doi.org/10.1175/1520-0434(2000)015%3C0221:UOTORF%3E2.0.CO;2
"""
odds_r = (
self.probability_of_detection() / (1 - self.probability_of_detection())
) / (
self.probability_of_false_detection()
/ (1 - self.probability_of_false_detection())
odds_r = (self.probability_of_detection() / (1 - self.probability_of_detection())) / (
self.probability_of_false_detection() / (1 - self.probability_of_false_detection())
)
return odds_r

Expand Down

0 comments on commit dd06e29

Please sign in to comment.