This commit is contained in:
Tobias Hölzer 2025-10-26 18:28:46 +01:00
parent 3ad332b5a8
commit eeab8fff1e
16 changed files with 536 additions and 943 deletions

17
scripts/alphaearth.sh Normal file
View file

@ -0,0 +1,17 @@
#!/bin/bash
# uv run alpha-earth download --grid hex --level 3
# uv run alpha-earth download --grid hex --level 4
# uv run alpha-earth download --grid hex --level 5
# uv run alpha-earth download --grid healpix --level 6
# uv run alpha-earth download --grid healpix --level 7
# uv run alpha-earth download --grid healpix --level 8
# uv run alpha-earth download --grid healpix --level 9
uv run alpha-earth combine-to-zarr --grid hex --level 3
uv run alpha-earth combine-to-zarr --grid hex --level 4
uv run alpha-earth combine-to-zarr --grid hex --level 5
uv run alpha-earth combine-to-zarr --grid healpix --level 6
uv run alpha-earth combine-to-zarr --grid healpix --level 7
uv run alpha-earth combine-to-zarr --grid healpix --level 8
uv run alpha-earth combine-to-zarr --grid healpix --level 9

66
scripts/cds.py Normal file
View file

@ -0,0 +1,66 @@
"""Download ERA5 data from the Copernicus Data Store.
Web platform: https://cds.climate.copernicus.eu
"""
import os
import re
from pathlib import Path
import cdsapi
import cyclopts
from rich import pretty, print, traceback
traceback.install()
pretty.install()
DATA_DIR = Path(os.environ.get("DATA_DIR", "../../data")) / "entropyc-rts"
def hourly(years: str):
"""Download ERA5 data from the Copernicus Data Store.
Args:
years (str): Years to download, seperated by a '-'.
"""
assert re.compile(r"^\d{4}-\d{4}$").match(years), "Years must be in the format 'YYYY-YYYY'"
start_year, end_year = map(int, years.split("-"))
assert 1950 <= start_year <= end_year <= 2024, "Years must be between 1950 and 2024"
dataset = "reanalysis-era5-single-levels"
client = cdsapi.Client(wait_until_complete=False)
outdir = (DATA_DIR / "era5/cds").resolve()
outdir.mkdir(parents=True, exist_ok=True)
print(f"Downloading ERA5 data from {start_year} to {end_year}...")
for y in range(start_year, end_year + 1):
for month in [f"{i:02d}" for i in range(1, 13)]:
request = {
"product_type": ["reanalysis"],
"variable": [
"2m_temperature",
"total_precipitation",
"snow_depth",
"snow_density",
"snowfall",
"lake_ice_temperature",
"surface_sensible_heat_flux",
],
"year": [str(y)],
"month": [month],
"day": [f"{i:02d}" for i in range(1, 32)],
"time": [f"{i:02d}:00" for i in range(0, 24)],
"data_format": "netcdf",
"download_format": "unarchived",
"area": [85, -180, 50, 180],
}
outpath = outdir / f"era5_{y}_{month}.zip"
client.retrieve(dataset, request).download(str(outpath))
print(f"Downloaded {dataset} for {y}-{month}")
if __name__ == "__main__":
cyclopts.run(hourly)

18
scripts/era5.sh Normal file
View file

@ -0,0 +1,18 @@
#!/bin/bash
# uv run era5 download
# uv run era5 enrich
# Can be summer, winter or yearly
agg=$1
echo "Running ERA5 spatial aggregation for aggregation type: $agg"
uv run era5 spatial-agg --grid hex --level 3 --agg $agg
uv run era5 spatial-agg --grid hex --level 4 --agg $agg
uv run era5 spatial-agg --grid hex --level 5 --agg $agg
uv run era5 spatial-agg --grid healpix --level 6 --agg $agg
uv run era5 spatial-agg --grid healpix --level 7 --agg $agg
uv run era5 spatial-agg --grid healpix --level 8 --agg $agg
uv run era5 spatial-agg --grid healpix --level 9 --agg $agg

9
scripts/rts.sh Normal file
View file

@ -0,0 +1,9 @@
#!/bin/bash
uv run rts --grid hex --level 3
uv run rts --grid hex --level 4
uv run rts --grid hex --level 5
uv run rts --grid healpix --level 6
uv run rts --grid healpix --level 7
uv run rts --grid healpix --level 8
uv run rts --grid healpix --level 9