environmentaltools.download.download_era5_data

environmentaltools.download.download_era5_data(config: dict[str, Any]) dict[str, Any][source]

Download and process ERA5 data from Climate Data Store.

Main function that orchestrates the complete workflow for downloading and processing ERA5 data. Accepts a configuration dictionary and returns processing results including download statistics and output file paths.

Parameters:

config (dict) – Configuration dictionary with keys: - start_year (int): First year to download (required) - end_year (int): Last year to download (required) - area_bounds (list): Geographic bounds [North, West, South, East] (required) - output_directory (str): Directory for output files (required) - variable (str, optional): CDS variable name - file_prefix (str, optional): Prefix for output filenames - export_csv (bool, optional): Export data to CSV format (default: True)

Returns:

Results dictionary containing:
  • config (ERA5DataDownloadConfig): Configuration object used

  • download_results (dict): Download status for each year

  • validation_results (dict): Validation status for each file

  • data (pd.DataFrame): Processed data

  • csv_path (str, optional): Path to exported CSV file

Return type:

dict

Raises:
  • ValueError – If required configuration parameters are missing or invalid.

  • ConnectionError – If CDS API client cannot be initialized.

Example

>>> from environmentaltools.download import marine_copernicus
>>>
>>> # Define configuration
>>> config = {
...     'start_year': 2018,
...     'end_year': 2020,
...     'area_bounds': [41.4, -9.0, 41.0, -8.65],
...     'output_directory': './era5_data',
...     'variable': 'significant_height_of_combined_wind_waves_and_swell',
...     'export_csv': True
... }
>>>
>>> # Download and process data
>>> results = marine_copernicus.download_era5_data(config)
>>> print(f"Downloaded {results['download_results']} years")
>>> print(f"Data saved to: {results['csv_path']}")