File size: 1,346 Bytes
a74054f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""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")