Skip to content

Commit

Permalink
iss #298 small edits
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenholleran committed Mar 22, 2023
1 parent 3003b93 commit 4420b7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ Additional labels for pre-release and build metadata are available as extensions
is not equal to the derived temporal resolution.
2. Added `data_resolution` argument to `average_data_by_period`, `monthly_means`, `coverage` and
`merge_datasets_by_period` functions (Issue #[297](https://github.com/brightwind-dev/brightwind/issues/297))
3. Update to work with Pandas 1.3.2. This mostly includes depreciating pd.Timedelta and using pd.DateOffset instead. (Pull request [#312](https://github.com/brightwind-dev/brightwind/pull/312)).
3. Update to work with Pandas 1.3.2. This mostly includes depreciating pd.Timedelta and using pd.DateOffset instead. (Pull request #[312](https://github.com/brightwind-dev/brightwind/pull/312)).
4. In`Correl` fix issue when duplicate column names are sent to `SpeedSort` (Issue #[304](https://github.com/brightwind-dev/brightwind/issues/304))
5. Added subplotting functionality to `sector_ratio` and improved user control of plotting (Issue #[309](https://github.com/brightwind-dev/brightwind/issues/309))
6. Allow `dist()` function to take a pd.DataFrame so user can plot multiple distributions on the same plot. (Issue #[264](https://github.com/brightwind-dev/brightwind/issues/264))
1. As part of this added subplotting functionality for bar plots
7. Allow 'freq_table()' function to derive a seasonal adjusted frequency distribution if user sets 'seasonal_adjustment'
to true. (Issue # [334](https://github.com/brightwind-dev/brightwind/issues/334))
to true. (Issue #[334](https://github.com/brightwind-dev/brightwind/issues/334))
1. As part of this, added 'monthly_coverage_threshold' option for the user to ensure good coverage months.
8. Update to work with matplotlib 3.5.2 and bug fix for plot_freq_distribution and dist functions (Issue #[315](https://github.com/brightwind-dev/brightwind/issues/315)).
9. Update to work with numpy>=1.20.0 when pandas=0.25.3. (Issue #[344](https://github.com/brightwind-dev/brightwind/issues/344)).
Expand All @@ -39,7 +39,7 @@ _line_colors_, _legend_ and _figure_size_. (Issue #[349](https://github.com/brig
16. Updated `LoadBrightHub` URL and generalised functions used for connecting to BrightHub platform without using `boto3` (Issue #[355](https://github.com/brightwind-dev/brightwind/issues/355)).
17. Removed hardcoded colours for `Shear.TimeOfDay` plots when `plot_type` is 'step' or 'line' and added a colour map. (Issue #[376](https://github.com/brightwind-dev/brightwind/issues/376)).
18: Fixed bug for `SpeedSort` where the `sector_predict` function was not interpolating data using two fit lines. (Issue #[377](https://github.com/brightwind-dev/brightwind/issues/377)).
19: Allow `momm` function to derive a seasonal adjusted mean of monthly mean if user sets `seasonal_adjustment` to true. (Issue # [298](https://github.com/brightwind-dev/brightwind/issues/298))
19: Allow `momm` function to derive a seasonal adjusted mean of monthly mean if user sets `seasonal_adjustment` to true. (Issue #[298](https://github.com/brightwind-dev/brightwind/issues/298))


## [2.0.0]
Expand Down
23 changes: 12 additions & 11 deletions brightwind/analyse/analyse.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,23 +387,24 @@ def _mean_of_monthly_means_seasonal_adjusted(var_series, coverage_threshold=0.8)

def momm(data, date_from: str = '', date_to: str = '', seasonal_adjustment=False, coverage_threshold=0.8):
"""
Calculates and returns the mean of monthy mean speed. Accepts a DataFrame with timestamps as index column and
another column with wind-speed. You can also specify date_from and date_to to calculate the mean of monthly
Calculates and returns the mean of monthly mean speed. This accepts a DataFrame with timestamps as index column and
another column with wind speed. You can also specify date_from and date_to to calculate the mean of monthly
mean speed for only that period.
If 'seasonal_adjustment' input is set to True then the mean of monthly mean value is seasonally adjusted.
NOTE; that if the input datasets ('data') don't have data for each calendar month then the seasonal adjustment
is not derived and the function will raise an error.
The seasonal adjusted mean of monthly mean is derived as for method below:
1) calculate monthly coverage
2) filter out any months with coverage lower than the input 'coverage_threshold'
3) derive the monthly mean for each calendar month (i.e. all January)
3) derive the monthly mean for each calendar month (i.e. all Januaries)
4) weighted average each monthly mean value based on the number of days in each month
(i.e. 31 days for January) - number of days for February are derived as average of actual days for the year
of the dataset. This to take into account leap years.
of the dataset. This is to take into account leap years.
NOTE; that if the input datasets ('data') don't have data for each calendar month then the seasonal adjustment
is not derived and the function will raise an error.
:param data: Pandas DataFrame or Series with timestamp as index and a column with wind-speed
:param data: Pandas DataFrame or Series with timestamp as index and a column with wind speed
:type data: pd.DataFrame or pd.Series
:param date_from: Start date as string in format YYYY-MM-DD
:type: str
Expand All @@ -412,9 +413,9 @@ def momm(data, date_from: str = '', date_to: str = '', seasonal_adjustment=False
:param seasonal_adjustment: Optional, False by default. If True, returns the mean of monthly mean seasonal
adjusted
:type seasonal_adjustment: bool
:param coverage_threshold: In this case monthly coverage threshold. It is used only if seasonal_adjustment=True.
Coverage is defined as the ratio of the number of data points present in the month and
the maximum number of data points that a month should have.
:param coverage_threshold: In this case this is a coverage threshold applied to a month. It is used only if
seasonal_adjustment=True. Coverage is defined as the ratio of the number of data points
present in the month and the maximum number of data points that a month should have.
Example, for 10 minute data for June, the maximum number of data points is
43,200. But if the number if data points available is only 30,000 the coverage is
0.69. A coverage_threshold value of 0.8 will filter out any months with a coverage less
Expand Down Expand Up @@ -445,7 +446,7 @@ def momm(data, date_from: str = '', date_to: str = '', seasonal_adjustment=False
momm_data = data.copy()
sliced_data = utils.slice_data(momm_data, date_from, date_to)
if seasonal_adjustment:
output = pd.DataFrame([np.nan * np.ones(len(momm_data.columns))], columns=momm_data.columns,index=['MOMM'])
output = pd.DataFrame([np.nan * np.ones(len(momm_data.columns))], columns=momm_data.columns, index=['MOMM'])
for col in momm_data.columns:
output[col] = _mean_of_monthly_means_seasonal_adjusted(sliced_data[col],
coverage_threshold=coverage_threshold)
Expand Down

0 comments on commit 4420b7b

Please sign in to comment.