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

Implement aggregation of CRPS_EMP_FAIR across multiple cases #215 #230

Merged
merged 4 commits into from
Nov 2, 2022
Merged
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
1 change: 1 addition & 0 deletions metcalcpy/agg_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def __init__(self, in_params):
'ecnt_crps_emp': ['crps_emp'],
'ecnt_crpscl_emp': ['crpscl_emp'],
'ecnt_crpss_emp': ['crpscl_emp', 'crps_emp'],
'ecnt_crps_emp_fair': ['crps_emp_fair'],

'nbr_fbs': ['fbs'],
'nbr_fss': ['fss'],
Expand Down
30 changes: 26 additions & 4 deletions metcalcpy/util/ecnt_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

from metcalcpy.util.utils import round_half_up, sum_column_data_by_name, PRECISION, get_total_values

__author__ = 'Tatiana Burek'
__version__ = '0.1.0'


def calculate_ecnt_crps(input_data, columns_names, aggregation=False):
"""Performs calculation of ECNT_CRPS - The Continuous Ranked Probability Score

Expand Down Expand Up @@ -124,6 +120,32 @@ def calculate_ecnt_crps_emp(input_data, columns_names, aggregation=False):
warnings.filterwarnings('ignore')
return result


def calculate_ecnt_crps_emp_fair(input_data, columns_names, aggregation=False):
"""Performs calculation of ECNT_CRPS_EMP_FAIR - The Continuous Ranked Probability Score
(empirical distribution) adjusted by the mean absolute difference of the ensemble members

Args:
input_data: 2-dimensional numpy array with data for the calculation
1st dimension - the row of data frame
2nd dimension - the column of data frame
columns_names: names of the columns for the 2nd dimension as Numpy array
aggregation: if the aggregation on fields was performed

Returns:
calculated ECNT_CRPS_EMP_FAIR as float
or None if some of the data values are missing or invalid
"""
warnings.filterwarnings('error')
try:
total = get_total_values(input_data, columns_names, aggregation)
crps_emp_fair = sum_column_data_by_name(input_data, columns_names, 'crps_emp_fair') / total
result = round_half_up(crps_emp_fair, PRECISION)
except (TypeError, ZeroDivisionError, Warning, ValueError):
result = None
warnings.filterwarnings('ignore')
return result

def calculate_ecnt_crpscl_emp(input_data, columns_names, aggregation=False):
"""Performs calculation of ECNT_CRPSCL_EMP - Climatological Continuous Ranked Probability Score
(empirical distribution)
Expand Down