energy_forecast.meteo module#

class energy_forecast.meteo.ArpegeSimpleAPI(date='2024-09-06', time='00:00:00', prefix='/tmp/arpege')[source]#

Bases: object

Uses the meteo.data.gouv.fr API to fetch weather forecast data.

It downloads the data in the format GRIB2 and reads it using xarray. If the file is already downloaded, it will not download it again.

Parameters:
  • date (str, optional) – the date at which the weather forecast was computed. Must be a valid date format, e.g. "YYYY-MM-DD" Default is the current date.

  • time (str, optional) – the time at which the weather forecast was computed. Can be "00:00:00", "06:00:00", "12:00:00", or "18:00:00" Default is "00:00:00"

  • prefix (str, optional) – the prefix where the files are downloaded. Used to avoid downloading the same file multiple times. Default is "/tmp/arpege"

base_url = 'https://object.data.gouv.fr/meteofrance-pnt/pnt/{date}T{time}Z/arpege/01/SP1/arpege__{resolution}__SP1__{forecast}__{date}T{time}Z.grib2'#
fetch()[source]#

Download the data from the API and save it in the prefix folder. All the forecast horizons are downloaded.

Returns:

list[Path] – The list of the files downloaded.

forecast_horizons = ['000H012H', '013H024H', '025H036H', '037H048H', '049H060H', '061H072H', '073H084H', '085H096H', '097H102H']#
get_filename(forecast_horizon)[source]#

Format the filename to save the data.

get_url(forecast_horizon)[source]#

Format the URL to fetch the data.

static read_file_as_xarray(filename, keys_filter)[source]#

Open the file as an xarray dataset.

Parameters:
  • filename (str) – the filename of the file to open.

  • keys_filter (dict) – the keys to filter the data.

Returns:

xr.Dataset – the dataset containing the weather forecast data.

read_files_as_xarray(list_files, keys_filter)[source]#

Read all the files as an xarray dataset and concatenate them along the step dimension.

Parameters:
  • list_files (list[str]) – the list of the files to open.

  • keys_filter (dict) – the keys to filter the data.

Returns:

xr.Dataset – the dataset containing the weather forecast data.

read_sspd()[source]#

Fetch the data and read the solar radiation.

Returns:

xr.Dataset – the dataset containing the solar radiation data.

read_wind()[source]#

Fetch the data and read the wind speed.

Returns:

xr.Dataset – the dataset containing the wind speed data.

region_sun()[source]#

Compute the mean sun flux for each region of France.

Returns:

pd.DataFrame – The mean sun flux for each region of France.

region_wind()[source]#

Compute the mean wind speed for each region of France.

Returns:

pd.DataFrame – The mean wind speed for each region of France.

resolution = '01'#
energy_forecast.meteo.download_historical_forecasts(s3_key, s3_secret, s3_entrypoint, s3_bucket, prefix='./', variables='all', forecast_type='all', dryrun=False)[source]#

Download the historical forecasts from the S3 bucket.

Parameters:
  • s3_key (str) – the key to access the S3 bucket.

  • s3_secret (str) – the secret to access the S3 bucket.

  • s3_entrypoint (str) – the entrypoint of the S3 bucket.

  • s3_bucket (str) – the name of the S3 bucket.

  • prefix (str) – The prefix where the files are downloaded. Should be similar to "./data/silver".

  • variables (str or list[str], optional) – the variables to download. Can be "wind_speed_hourly", "sun_flux_downward_hourly", or "temperature_hourly" or a list of these values. Default is "all", which downloads all the variables.

  • forecast_type (str or list[str], optional) – the forecast type to download. Can be "d0", "d1", "d2", or "d3", or a list of these values. Default is "all", which downloads all the forecast types.

  • dryrun (bool, optional) – if True, do not download the files. Default is False.

Returns:

list[Path] – the list of the files downloaded.

energy_forecast.meteo.warm_cache(logger, date=None, max_counter=30, sleep_duration=600)[source]#

Try to fetch the data from the API until it is successful.

Parameters:
  • logger (logging.Logger) – the logger to use.

  • date (str, optional) – the date at which the weather forecast was computed. Must be a valid date format, e.g. "YYYY-MM-DD" Default is the current date.

  • max_counter (int, optional) – the maximum number of attempts. Default is 30.

  • sleep_duration (int, optional) – the duration to sleep between each attempt in seconds. Default is 600 (10 minutes).

Raises:

TimeoutError – if the maximum number of attempts is reached.