io_functions

This module provides input/output functions for handling wind power and electricity price data. It includes functions to replace NaN values with the mean, make API requests to renewables.ninja and ENTSO-E, and save/load data to/from JSON files.

Functions:

replace_nan_with_mean: Replace NaN values in the array with the mean value of the series. api_request_rninja: Makes an API request to renewables.ninja to retrieve wind speed and power data. api_request_entsoe: Fetches day-ahead electricity prices from the ENTSO-E API for a specified country zone and date range. get_power_price_data: Fetches (wind) power and price data for a specified location and time period. save_power_price_to_json: Save power and price data to a JSON file. get_power_price_from_json: Load power and price data from a JSON file.

Module Contents

Functions

replace_nan_with_mean

Replace NaN values in the array with the mean value of the series.

api_request_rninja

Makes an API request to renewables.ninja to retrieve wind speed and power data.

api_request_entsoe

Fetches day-ahead electricity prices from the ENTSO-E API for a specified country zone and date range.

get_power_price_data

Fetches (wind) power and price data for a specified location and time period.

save_power_price_to_json

Save power and price data to a JSON file.

get_power_price_from_json

Load power and price data from a JSON file.

API

io_functions.replace_nan_with_mean(data: numpy.ndarray) numpy.ndarray

Replace NaN values in the array with the mean value of the series.

Parameters:

data (np.ndarray) – Input array with potential NaN values.

Returns:

Array with NaN values replaced by the mean value of the series.

Return type:

np.ndarray

io_functions.api_request_rninja(token: str, latitude: float, longitude: float, date_start: str, date_end: str, capacity: float = 8000, height: float = 164, turbine: str = 'Vestas V164 8000') tuple[numpy.ndarray, numpy.ndarray]

Makes an API request to renewables.ninja to retrieve wind speed and power data.

Parameters:
  • latitude (float) – Latitude of the location.

  • longitude (float) – Longitude of the location.

  • date_start (str) – Start date for the data in ‘YYYY-MM-DD’ format.

  • date_end (str) – End date for the data in ‘YYYY-MM-DD’ format.

  • capacity (float) – Capacity of the wind turbine/farm in kW.

  • height (float) – Height of the wind turbine in meters.

  • turbine (str) – Type of wind turbine.

  • token (str) – API token for authentication.

Returns:

Array of wind speed data and array of wind power data in MW.

Return type:

tuple[np.ndarray, np.ndarray]

Raises:

Exception – If there is an error during the API request

io_functions.api_request_entsoe(token: str, date_start: str, date_end: str, country_code: str = 'NL') numpy.ndarray

Fetches day-ahead electricity prices from the ENTSO-E API for a specified country zone and date range.

Parameters:
  • token (str) – The API token for authenticating with the ENTSO-E API.

  • country_code (str) – The country code for which to fetch the day-ahead prices (e.g., ‘DE’ for Germany).

  • date_start (str) – The start date for the data request in ‘YYYY-MM-DD’ format.

  • date_end (str) – The end date for the data request in ‘YYYY-MM-DD’ format.

Returns:

An array of day-ahead electricity prices for the specified country and date range [EUR/MWh].

Return type:

np.ndarray

Raises:

Exception – If there is an error while requesting data from the ENTSO-E API.

io_functions.get_power_price_data(token_rninja: str, token_entsoe: str, date_start: str, date_end: str, latitude: float, longitude: float, capacity: float = 8000, height: float = 164, turbine: str = 'Vestas V164 8000', country_code: str = 'NL') tuple[numpy.ndarray, numpy.ndarray]

Fetches (wind) power and price data for a specified location and time period.

Parameters:
  • token (str) – Authentication token for API requests.

  • date_start (str) – Start date for the data retrieval in ‘YYYY-MM-DD’ format.

  • date_end (str) – End date for the data retrieval in ‘YYYY-MM-DD’ format.

  • latitude (float) – Latitude of the location.

  • longitude (float) – Longitude of the location.

  • capacity (float, optional) – Capacity of the wind turbine in kW. Default is 8000.

  • height (float, optional) – Height of the wind turbine in meters. Default is 164.

  • turbine (str, optional) – Model of the wind turbine. Default is ‘Vestas V164 8000’.

  • country_code (str, optional) – Country zone for price data. Default is ‘NL’.

Returns:

Wind power [MW] and price data [EUR/MWh].

Return type:

tuple[np.ndarray, np.ndarray]

io_functions.save_power_price_to_json(filename: str, data_power: numpy.ndarray, data_price: numpy.ndarray)

Save power and price data to a JSON file.

Parameters:
  • filename (str) – Name of the file to save the data.

  • data_power (np.ndarray) – Power data.

  • data_price (np.ndarray) – Price data.

io_functions.get_power_price_from_json(filename: str) tuple[numpy.ndarray, numpy.ndarray]

Load power and price data from a JSON file.

Parameters:

filename (str) – Name of the file to load the data from.

Returns:

Power and price data.

Return type:

tuple[np.ndarray, np.ndarray]