"""Download ERA5 sample (Jan 2020) to test setup.""" import cdsapi import pandas as pd from pathlib import Path # Load station coordinates for bounding box stations = pd.read_csv('datasets/station_list.csv') lat_min = stations['lat'].min() - 0.1 lat_max = stations['lat'].max() + 0.1 lon_min = stations['lon'].min() - 0.1 lon_max = stations['lon'].max() + 0.1 print(f"Study area: [{lat_min:.2f}, {lon_min:.2f}] to [{lat_max:.2f}, {lon_max:.2f}]") print("Downloading ERA5 sample: January 2020...") c = cdsapi.Client() output_file = Path('datasets/safran/era5_2020_jan.nc') # Download sample month c.retrieve( 'reanalysis-era5-single-levels', { 'product_type': 'reanalysis', 'format': 'netcdf', 'variable': [ '2m_temperature', 'total_precipitation', 'potential_evaporation', 'surface_solar_radiation_downwards', '10m_u_component_of_wind', '10m_v_component_of_wind', ], 'year': '2020', 'month': '01', 'day': [f'{d:02d}' for d in range(1, 32)], 'time': '12:00', 'area': [lat_max, lon_min, lat_min, lon_max], }, str(output_file) ) print(f"✓ Downloaded: {output_file}") print(f"✓ Size: {output_file.stat().st_size / 1024 / 1024:.1f} MB")