REStats package
Subpackages
Submodules
REStats.circular_metrics module
- REStats.circular_metrics.circular_err(obs, pred, unit='deg', verbose=True)
Compute Root Mean Square Error (RMSE), relative RMSE, and Mean Absolute Error (MAE) in circular measurements (like angles).
- Parameters:
obs (np.ndarray) – An array of observed values.
pred (np.ndarray) – An array of predicted values.
unit (str, optional) – Unit of the error values to be printed, default is ‘deg’ (degrees).
verbose (bool, optional) – If True, print error values; default is True.
- Returns:
A tuple containing RMSE, relative RMSE (in percentage) and MAE.
- Return type:
tuple
- REStats.circular_metrics.circular_mae(true_values, predicted_values)
Calculates the Mean Absolute Error (MAE) for circular variables.
- Parameters:
true_values (np.array or pd.Series) – True values of the circular variable.
predicted_values (np.array or pd.Series) – Predicted values of the circular variable.
- Returns:
Circular MAE value.
- Return type:
float
- REStats.circular_metrics.circular_mean(data)
Calculates the circular mean of the given data.
- Parameters:
data (array-like) – Input data in degrees.
- Returns:
Circular mean in degrees.
- Return type:
float
- REStats.circular_metrics.circular_residuals(true_degrees, predicted_degrees)
Compute the circular residuals between true and predicted wind direction values in degrees.
This function takes into account the circular nature of wind direction data when calculating residuals. The residuals are computed as the angular differences between true and predicted values, resulting in values between -180 and 180 degrees.
- Parameters:
true_degrees (array_like) – A 1D array or list of true wind direction values in degrees.
predicted_degrees (array_like) – A 1D array or list of predicted wind direction values in degrees, corresponding to the true_degrees.
- Returns:
A 1D numpy array of circular residuals in degrees.
- Return type:
numpy.ndarray
- REStats.circular_metrics.circular_rmse(true_values, predicted_values)
Calculates the Root Mean Squared Error (RMSE) for circular variables.
- Parameters:
true_values (np.array or pd.Series) – True values of the circular variable.
predicted_values (np.array or pd.Series) – Predicted values of the circular variable.
- Returns:
Circular RMSE value.
- Return type:
float
- REStats.circular_metrics.circular_std(data)
Calculates the circular standard deviation of the given data.
- Parameters:
data (array-like) – Input data in degrees.
- Returns:
Circular standard deviation in degrees.
- Return type:
float
REStats.plots module
- REStats.plots.plot_circular_histogram(true_directions, predicted_directions, num_bins=36)
Plot a circular histogram of true and predicted wind direction values in degrees.
- Parameters:
true_directions (array_like) – A 1D array or list of true wind direction values in degrees.
predicted_directions (array_like) – A 1D array or list of predicted wind direction values in degrees.
num_bins (int, optional) – Number of bins for the histogram. Default is 36.
- Returns:
- A matplotlib Figure object containing the circular
histogram plot.
- Return type:
matplotlib.figure.Figure
- REStats.plots.plot_wind_rose(df, speed_col='wind_speed', direction_col='wind_dir', bins=None, cmap=None, legend=True, **kwargs)
Plot a wind rose using a pandas DataFrame and return the figure object.
- Parameters:
df (pandas.DataFrame) – DataFrame containing wind speed and direction data.
speed_col (str) – Column name for wind speed data.
direction_col (str) – Column name for wind direction data.
bins (list or int, optional) – Number of bins or a list of bins for wind speed data. Defaults to None.
cmap (list, optional) – Colormap for the plot.
legend (bool, optional) – Whether to display the legend. Defaults to True.
- Returns:
The generated figure object.
- Return type:
matplotlib.figure.Figure
- REStats.plots.save_figs(figs, format='pdf', output_dir=None)
REStats.utils module
- REStats.utils.calc_err(obs, pred, unit='m/s', verbose=True)
Calculate Root Mean Squared Error (RMSE), Relative RMSE, and Mean Absolute Error (MAE) between the observed and predicted values.
- Parameters:
obs (array_like) – A 1D array or list of observed values.
pred (array_like) – A 1D array or list of predicted values.
unit (str, optional) – The unit of the values. Default is “m/s”.
verbose (bool, optional) – If True, prints the RMSE, Relative RMSE, and MAE. Default is True.
- Returns:
A tuple containing the RMSE, Relative RMSE, and MAE.
- Return type:
tuple
- REStats.utils.downsample(df: DataFrame)
- Downsample a pandas DataFrame containing a 10-minute time series of wind speed and
wind direction data to 1 hour.
- Parameters:
df (pd.DataFrame) – DataFrame with a DatetimeIndex, containing “wind_speed” and “wind_dir” columns.
- Returns:
Downsampled DataFrame with 1-hour resolution.
- Return type:
pd.DataFrame
- REStats.utils.filter_outliers(df: DataFrame, bin_col: str = 'wind_speed', outlier_col: str = 'power', bin_size: float = 0.5) DataFrame
Filters rows by IQR outliers for outlier_col for each bin grouped by bin_col.
- Parameters:
df (pd.DataFrame) – The input DataFrame.
bin_col (str) – The column name to use for binning.
bin_size (float) – The size of each bin for binning by bin_col.
outlier_col (str) – The column name to use for filtering outliers.
- Returns:
The filtered DataFrame.
- Return type:
pd.DataFrame
- Raises:
ValueError – If bin_col or outlier_col are not columns in df.
ValueError – If bin_size is less than or equal to zero.
- REStats.utils.inv_transform(v_df, m, hr_stats)
Perform the inverse transformation of the input DataFrame.
This function descales and applies the inverse Weibull transformation (i.e., takes the m-th root) to the DataFrame obtained from the transform function.
- Parameters:
v_df (pandas.DataFrame) – DataFrame obtained from the transform function.
m (float) – The Weibull modulus used in the transform function.
hr_stats (tuple) – A tuple containing the mean and standard deviation for each hour of the day, obtained from the transform function.
- Returns:
The DataFrame after applying the inverse transformation.
- Return type:
pandas.DataFrame
- REStats.utils.load_SCADA(year=2020)
- REStats.utils.standardize(df, ref_df=None)
Standardize a DataFrame containing wind_speed, wind_dir, and power columns.
- Parameters:
df (pandas.DataFrame) – DataFrame containing wind_speed, wind_dir, and power columns.
- Returns:
Standardized DataFrame.
- Return type:
pandas.DataFrame
- REStats.utils.transform(v_df, m, field='wind_speed', hr_stats=None)
Transform the input wind speed time series using the Weibull modulus and scale it by standardizing each hour of the day.
- Parameters:
v_df (pandas.DataFrame) – DataFrame containing wind speed time series. The index
DateTimeIndex. (should be a) –
m (float) – The Weibull modulus.
field (str, optional) – The name of the column in v_df that contains the wind speed data. Defaults to “wind_speed”.
hr_stats (tuple, optional) – A tuple containing the mean and standard deviation for each hour of the day. If not provided, these statistics are computed from v_df. Defaults to None.
- Returns:
- A tuple containing:
pandas.DataFrame: The transformed and standardized DataFrame.
tuple: A tuple containing the hourly means and standard deviations.
- Return type:
tuple