Skip to content

Instantly share code, notes, and snippets.

@yannforget
Created July 15, 2024 13:13
Show Gist options
  • Select an option

  • Save yannforget/9d92930ab8f34eded0eaa075e85541b0 to your computer and use it in GitHub Desktop.

Select an option

Save yannforget/9d92930ab8f34eded0eaa075e85541b0 to your computer and use it in GitHub Desktop.
from pathlib import Path
import requests
BASE_URL = "https://storage.googleapis.com/gcp-public-data-arco-era5/raw/date-variable-single_level"
DATA_DIR = Path("data")
VARIABLE = "total_precipitation"
YEAR = 2010
MONTH = 7
for day in range(1, calendar.monthrange(YEAR, MONTH)[1] + 1):
url = f"{BASE_URL}/{YEAR}/{MONTH:02}/{day:02}/{VARIABLE}/surface.nc"
output_dir = DATA_DIR / VARIABLE / f"{YEAR:04}" / f"{MONTH:02}"
output_dir.mkdir(parents=True, exist_ok=True)
fp = output_dir / f"{VARIABLE}_{YEAR}{MONTH:02}{day:02}.nc"
with requests.get(url, stream=True) as r:
with open(fp, "wb") as f:
for chunk in r.iter_content(chunk_size=1024**2):
if chunk:
f.write(chunk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment