REStats.models package
Submodules
REStats.models.iec_power_curve module
- REStats.models.iec_power_curve.fit(data: DataFrame, bin_size: float = 0.5) DataFrame
Calculates the IEC power curve for wind turbine data.
- Parameters:
data (pd.DataFrame) – The input DataFrame containing wind turbine data, with columns “wind_speed” and “power”.
bin_size (float, optional) – The size of each bin. Defaults to 0.5.
- Returns:
- The IEC power curve DataFrame, with columns “wind_speed” and
”power”.
- Return type:
pd.DataFrame
- Raises:
ValueError – If “wind_speed” or “power” columns are not in data.
REStats.models.power_curve module
- class REStats.models.power_curve.ExactGPModel(train_x, train_y, likelihood, dims=None)
Bases:
ExactGPThe simplest form of GP model that uses exact inference.
- Parameters:
train_x (torch.Tensor) – Training input data.
train_y (torch.Tensor) – Training output data.
likelihood (gpytorch.likelihoods.Likelihood) – Likelihood function.
- forward(x)
Forward pass through the model.
- Parameters:
x (torch.Tensor) – Input data.
- Returns:
Multivariate normal distribution.
- Return type:
gpytorch.distributions.MultivariateNormal
- prior_predictive_samples(x, n_samples=1)
Generate prior predictive samples for the given inputs.
- Parameters:
x (torch.Tensor) – Input data.
n_samples (int) – Number of samples to generate.
- Returns:
Prior predictive samples.
- Return type:
torch.Tensor
- training: bool
- REStats.models.power_curve.fit(X_train, y_train, dims=None)
Fits the GP model to the training data.
- Parameters:
X_train (torch.Tensor) – Training input data.
y_train (torch.Tensor) – Training output data.
- Returns:
Tuple of the trained model and the likelihood function.
- Return type:
tuple
- REStats.models.power_curve.predict(model, likelihood, data)
Generates predictions for the input data.
- Parameters:
model (ExactGPModel) – Trained GP model.
likelihood (gpytorch.likelihoods.Likelihood) – Likelihood function.
data (torch.Tensor) – Input data for which predictions are to be made.
- Returns:
Multivariate normal distribution.
- Return type:
gpytorch.distributions.MultivariateNormal
REStats.models.turbulence_intensity module
REStats.models.weibull module
- REStats.models.weibull.calc_m(shape)
Calculate the Weibull modulus (m) from the shape parameter.
- Parameters:
shape (float) – The shape parameter of a Weibull distribution.
- Returns:
The Weibull modulus (m).
- Return type:
float
- REStats.models.weibull.fit(ws)
Fit a Weibull distribution to wind speed data using Pyro and MCMC.
- Parameters:
ws (List[float]) – A list of wind speed data points.
- Returns:
- The fitted Weibull distribution in an arviz.InferenceData
object.
- Return type:
arviz.InferenceData
- REStats.models.weibull.get_params(idata_wb)
Extract the shape and scale parameters from the fitted Weibull distribution.
- Parameters:
idata_wb (arviz.InferenceData) – An arviz.InferenceData object containing the fitted Weibull distribution.
- Returns:
A tuple containing the shape and scale parameters.
- Return type:
Tuple[float, float]
- REStats.models.weibull.plot_prior_samples(shape_prior_params, scale_prior_params, num_samples)
- REStats.models.weibull.weibull_model(data)
Define the Pyro model for fitting a Weibull distribution.
- Parameters:
data (torch.Tensor) – A tensor of data samples from a Weibull distribution.
- Returns:
None
REStats.models.wind_dir module
- REStats.models.wind_dir.backtest(wd_train, wd_test, steps=1)
Perform a backtest of wind direction forecasting, by training ARMA models on the training data and sequentially predicting the wind direction on the test data.
- Parameters:
wd_train (pd.Series) – The wind direction training data in degrees.
wd_test (pd.Series) – The wind direction test data in degrees.
steps (int, optional) – The number of steps to forecast at each iteration. Default is 1.
- Returns:
- A tuple containing two elements:
- pd.DataFrame: A DataFrame with columns ‘mean’ (predicted wind direction),
’lower_ci’ (lower bound of confidence interval), and ‘upper_ci’ (upper bound of confidence interval).
- tuple: A tuple containing RMSE, relative RMSE, and MAE calculated by
comparing the forecasted values with the actual test data.
- Return type:
tuple
- REStats.models.wind_dir.calc_persistence(wind_dir, steps=1)
Calculate a persistence forecast for wind direction. The persistence model assumes that the conditions at the time of forecasting will stay the same for the period of the forecast.
- Parameters:
wind_dir (np.ndarray) – An array of wind direction measurements.
steps (int, optional) – Number of steps forward for the forecast. Default is 1.
- Returns:
- A tuple where the first element is an array with the persistence forecast
and the second element is the error calculated using circular_err function.
- Return type:
tuple
- REStats.models.wind_dir.fit(wind_dir_data)
Fit ARMA models to the sine and cosine components of wind direction data.
- Parameters:
wind_dir_data (array_like) – A 1D array or list of observed wind direction values in degrees.
- Returns:
- A tuple containing two ARIMAResults objects, one for the sine model and
one for the cosine model.
- Return type:
tuple
- REStats.models.wind_dir.predict(sin_model, cos_model, wind_dir_data)
Forecast wind direction from trained sine and cosine ARMA models, and compute the confidence intervals.
- Parameters:
sin_model (ARIMAResults) – The trained sine ARMA model.
cos_model (ARIMAResults) – The trained cosine ARMA model.
wind_dir_data (array_like) – A 1D array or list of observed wind direction values in degrees.
- Returns:
- A DataFrame with columns ‘wind_dir_pred’ (predicted wind
direction in degrees), ‘wind_dir_obs’ (observed wind direction in degrees), ‘lower_bound’ (lower confidence interval in degrees), and ‘upper_bound’ (upper confidence interval in degrees).
- Return type:
pandas.DataFrame
REStats.models.wind_speed module
- REStats.models.wind_speed.backtest(v_train, v_test, idata_wb=None, steps=1)
Performs a backtest of wind speed forecasting using the Weibull distribution and ARIMA models.
This function fits the Weibull distribution to the training data, scales the data using the shape parameter of the fitted distribution, fits an ARIMA model to the transformed training data, and then performs one-step ahead forecasting iteratively over the test data.
- Parameters:
v_train (pandas.DataFrame) – The training data containing the wind speed.
v_test (pandas.DataFrame) – The testing data containing the wind speed.
idata_wb (arviz.InferenceData, optional) – An InferenceData object from Arviz based on a Weibull distribution fit. If None, the Weibull distribution is fitted to the training data. Defaults to None.
steps (int, optional) – The number of steps ahead to forecast. Defaults to 1.
- Returns:
- A tuple containing two elements:
- pandas.DataFrame: A DataFrame with the full forecasts for the testing
data.
- tuple: A tuple containing the RMSE, Relative RMSE, and MAE between the
observed and predicted values in the test set.
- Return type:
tuple
- REStats.models.wind_speed.calc_persistence(v_test, steps=1)
Calculate a persistence forecast for the wind speed and evaluate the forecast accuracy.
The persistence forecast method uses the wind speed at the current time step as the forecast for the next time step.
- Parameters:
v_test (array_like) – A 1D array or list of observed wind speed values.
steps (int, optional) – The forecast horizon in number of steps. Default is 1.
- Returns:
A tuple containing the persistence forecast and a tuple of forecast accuracy metrics (RMSE, relative RMSE, MAE).
- Return type:
tuple
- REStats.models.wind_speed.fit(ws_tf, order=(2, 0, 2), trend='n', **kwargs)
Fit an ARIMA model to the preprocessed and transformed wind speed data.
The order of the ARIMA model and the trend component can be customized. Additional keyword arguments can be passed to the ARIMA model instantiation.
- Parameters:
ws_tf (pandas.DataFrame) – Preprocessed and transformed wind speed data, obtained from the preprocess function.
order (tuple, optional) – A tuple of three integers specifying the order of the ARIMA model. Default is (2, 0, 2).
trend (str, optional) – The trend component to include in the model. Default is ‘n’, which indicates no trend.
**kwargs – Additional keyword arguments to pass to the ARIMA model instantiation.
- Returns:
The fitted ARIMA model.
- Return type:
ARIMAResults
- REStats.models.wind_speed.preprocess(ws)
Preprocess the wind speed data by fitting a Weibull distribution, extracting its parameters and transforming the data.
The function returns the shape and scale parameters of the Weibull distribution, the modulus of the Weibull distribution, the transformed wind speed data, and the hour-wise statistics of the transformed wind speed data.
- Parameters:
ws (pandas.Series or numpy.ndarray) – The wind speed data to preprocess.
- Returns:
- A dictionary containing the following keys:
’wb_shape’: The shape parameter of the fitted Weibull distribution.
’wb_scale’: The scale parameter of the fitted Weibull distribution.
’wb_m’: The modulus of the Weibull distribution.
’ws_tf’: The transformed wind speed data as a DataFrame.
’hr_stats’: The hour-wise statistics of the transformed wind speed data.
- Return type:
dict