Skip to content

Commit

Permalink
iss #298 added test for momm
Browse files Browse the repository at this point in the history
  • Loading branch information
BiancaMorandi committed Mar 21, 2023
1 parent 78eb90c commit c05504b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
4 changes: 2 additions & 2 deletions brightwind/analyse/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ def _mean_of_monthly_means_seasonal_adjusted(var_series, coverage_threshold=0.8)

results.update({month: var_series_month.mean()})

average_result = (pd.Series(results) * pd.Series(number_days_month) / sum(
result = (pd.Series(results) * pd.Series(number_days_month) / sum(
number_days_month.values())).sum(skipna=True)
return average_result
return result


def momm(data, date_from: str = '', date_to: str = '', seasonal_adjustment=False, coverage_threshold=0.8):
Expand Down
23 changes: 21 additions & 2 deletions tests/test_analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ def test_monthly_means():
"For example, hourly data should not be averaged to 10 minute data."


def test_momm():
# Derive mean of monthly mean with standard method
momm_standard = bw.momm(DATA[['Spd40mN', 'Spd40mS']])
assert round(momm_standard.T['Spd40mN'].values[0], 6) == 6.802488

# Derive mean of monthly mean with standard method only using a certain period
momm_standard = bw.momm(DATA[['Spd40mN', 'Spd40mS']], date_from='2016-06-01', date_to='2017-05-31')
assert round(momm_standard.T['Spd40mS'].values[0], 6) == 6.684251

# Derive mean of monthly mean seasonal adjusted and imposing coverage_threshold
momm_seas_adj = bw.momm(DATA[['Spd40mN', 'Spd40mS']], seasonal_adjustment=True, coverage_threshold=0.7)
assert round(momm_seas_adj.T['Spd40mN'].values[0], 6) == 6.749667

# Derive mean of monthly mean seasonal adjusted with months of zero coverage
data_test = DATA.drop(DATA.loc[str(DATA.index[0].year) + '-' + str(DATA.index.month.unique()[3])].index)
momm_seas_adj = bw.momm(data_test[['Spd40mN', 'Spd40mS']], seasonal_adjustment=True, coverage_threshold=0.7)
assert round(momm_seas_adj.T['Spd40mS'].values[0], 6) == 6.864868


def test_sector_ratio():
bw.sector_ratio(DATA['Spd80mN'], DATA['Spd80mS'], DATA['Dir78mS'], sectors=72, boom_dir_1=0,
boom_dir_2=180, return_data=True)
Expand All @@ -44,8 +63,8 @@ def test_sector_ratio():
DATA[['Dir78mS', 'Dir58mS', 'Dir38mS']], boom_dir_1=0, boom_dir_2=180,
figure_size=(25,25))
bw.sector_ratio(DATA[['Spd80mN', 'Spd60mN', 'Spd40mN']], DATA[['Spd80mS', 'Spd60mS', 'Spd40mS']],
DATA[['Dir78mS', 'Dir58mS', 'Dir38mS']], boom_dir_1=0, boom_dir_2=180, figure_size=(25, 25),
return_data=True)
DATA[['Dir78mS', 'Dir58mS', 'Dir38mS']], boom_dir_1=0, boom_dir_2=180, figure_size=(25, 25),
return_data=True)
bw.sector_ratio(DATA['Spd80mN'], DATA['Spd80mS'], DATA['Dir78mS'], boom_dir_1=0, boom_dir_2=180, return_data=True)
bw.sector_ratio(DATA[['Spd80mN', 'Spd60mN']], DATA[['Spd80mS', 'Spd60mS']],
DATA[['Dir78mS', 'Dir58mS']], boom_dir_1=[0, 350], boom_dir_2=[180, 170], figure_size=(25, 25))
Expand Down

0 comments on commit c05504b

Please sign in to comment.