Skip to content

Commit

Permalink
replace commonn code with weighted_average method #229
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaBurek committed Nov 8, 2022
1 parent 5b8cd36 commit deedf36
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions metcalcpy/util/ecnt_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,11 @@ def calculate_ecnt_spread(input_data, columns_names, aggregation=False):
calculated ECNT_SPREAD as float
or None if some data values are missing or invalid
"""

warnings.filterwarnings('error')
try:
total = get_total_values(input_data, columns_names, aggregation)
spread = math.sqrt(sum_column_data_by_name(input_data, columns_names, 'variance') / total)
wa = weighted_average(input_data, columns_names, 'variance', aggregation)
spread = math.sqrt(wa)
result = round_half_up(spread, PRECISION)
except (TypeError, ZeroDivisionError, Warning, ValueError):
result = None
Expand Down Expand Up @@ -377,8 +378,8 @@ def calculate_ecnt_spread_oerr(input_data, columns_names, aggregation=False):
"""
warnings.filterwarnings('error')
try:
total = get_total_values(input_data, columns_names, aggregation)
spread_oerr = math.sqrt(sum_column_data_by_name(input_data, columns_names, 'variance_oerr') / total)
wa = weighted_average(input_data, columns_names, 'variance_oerr', aggregation)
spread_oerr = math.sqrt(wa)
result = round_half_up(spread_oerr, PRECISION)
except (TypeError, ZeroDivisionError, Warning, ValueError):
result = None
Expand All @@ -402,8 +403,8 @@ def calculate_ecnt_spread_plus_oerr(input_data, columns_names, aggregation=False
"""
warnings.filterwarnings('error')
try:
total = get_total_values(input_data, columns_names, aggregation)
spread_plus_oerr = math.sqrt(sum_column_data_by_name(input_data, columns_names, 'variance_plus_oerr') / total)
wa = weighted_average(input_data, columns_names, 'variance_plus_oerr', aggregation)
spread_plus_oerr = math.sqrt(wa)
result = round_half_up(spread_plus_oerr, PRECISION)
except (TypeError, ZeroDivisionError, Warning, ValueError):
result = None
Expand Down

0 comments on commit deedf36

Please sign in to comment.