This document describes the process of importing climate data into the PostGIS database for the BlueGreenCity-KI project.
Climate data is imported from two main sources:
Both sources provide raster data that is imported into PostGIS tables for efficient spatial queries.
import_climate_data_dwd.py)Purpose: Import NetCDF climate rasters from DWD into PostGIS
Location: scripts/import_climate_data_dwd.py
Usage:
python scripts/import_climate_data_dwd.py --dataset <dataset> --variable <variable> --year <year> [--hyras-version <version>]
Parameters:
--dataset: Dataset type (hyras, hostrada, or evaporation)--variable: Climate variable (e.g., precipitation, temperature_mean)--year: Year to import--hyras-version: HYRAS version (6-0 or 6-1, default: 6-1)--list-variables: List all available variables for a datasetExamples:
# Import HYRAS precipitation for 2023 (version 6-1)
python scripts/import_climate_data_dwd.py --dataset hyras --variable precipitation --year 2023
# Import HYRAS temperature with version 6-0
python scripts/import_climate_data_dwd.py --dataset hyras --variable temperature_mean --year 2023 --hyras-version 6-0
# Import HOSTRADA wind speed
python scripts/import_climate_data_dwd.py --dataset hostrada --variable wind_speed --year 2024
# List available HYRAS variables
python scripts/import_climate_data_dwd.py --dataset hyras --list-variables
import_climate_data_openmeteo.py)Purpose: Download and import historical weather data from Open-Meteo API
Location: scripts/import_climate_data_openmeteo.py
Usage:
python scripts/import_climate_data_openmeteo.py --variables <v1,v2> --start-date <YYYY-MM-DD> --end-date <YYYY-MM-DD> [--lat <lat>] [--lon <lon>] [--resolution hourly|daily] [--dataset-name <name>] [--dry-run]
Parameters:
--variables: Comma-separated variables (e.g., temperature_2m,precipitation)--start-date: Start date (YYYY-MM-DD)--end-date: End date (YYYY-MM-DD)--lat / --lon: Latitude/longitude in decimal degrees (default: study area center from config/config.yaml)--resolution: hourly (default) or daily--dataset-name: Dataset label for the target tables (default: weather)--dry-run: Fetch from the API but do not write to PostGIS--list-variables: List all available variablesExamples:
# Download hourly temperature + precipitation for 2023 to the default location
python scripts/import_climate_data_openmeteo.py --variables temperature_2m,precipitation --start-date 2023-01-01 --end-date 2023-12-31
# Daily resolution, custom location
python scripts/import_climate_data_openmeteo.py --variables temperature_2m --start-date 2024-01-01 --end-date 2024-12-31 --resolution daily --lat 52.5 --lon 9.8
# Check the API response without importing
python scripts/import_climate_data_openmeteo.py --variables precipitation --start-date 2025-06-01 --end-date 2025-06-30 --dry-run
# List available variables
python scripts/import_climate_data_openmeteo.py --list-variables
Imported climate data is stored in the bgcki schema with the following naming convention:
bgcki.climate_dwd_{dataset}_{version}_{variable}_{resolution}bgcki.climate_dwd_hyras_v6-1_precipitation_dailybgcki.climate_dwd_hyras_v6-0_temperature_mean_dailybgcki.climate_dwd_hostrada_temperature_hourlybgcki.climate_dwd_evaporation_evaporation_fao_dailybgcki.climate_openmeteo_{dataset-name}_{hourly|daily} (dataset name
defaults to weather)bgcki.climate_openmeteo_weather_hourlybgcki.climate_openmeteo_weather_dailyEach imported table includes a PostgreSQL comment with metadata:
Example:
COMMENT ON TABLE climate.dwd_hyras_v6_1_precipitation_daily IS
'Climate data from DWD
Variable: precipitation
Version: v6_1
Resolution: daily
Units: mm
Description: HYRAS precipitation data version 6-1
Imported: 2025-12-30 14:30:00';
Base URL: https://opendata.dwd.de/climate_environment/CDC/grids_germany/
Datasets:
API URL: https://archive-api.open-meteo.com/v1/archive
Variables:
temperature_2m: 2m air temperature (°C)precipitation: Total precipitation (mm)relative_humidity_2m: Relative humidity (%)surface_pressure: Surface pressure (hPa)--list-variables to see all)Climate data should be updated annually or as new versions become available:
Climate data is accessed in criteria modules using the AirTemperature criterion as a reference:
from bluegreencity_ki.criteria.air_temperature import AirTemperature
# In pipeline configuration (config.yaml):
criteria:
- name: air_temperature
weight: 0.2
params:
raster_key: "airtemp_raster_14h"
temp_low: 20.0
temp_high: 30.0
The raster key refers to a PostGIS raster table defined in the data sources configuration.
Error: NetCDF file not found
data/derived/weather/ or download from DWDError: PostGIS connection failed
.env file and ensure PostGIS is runningError: Version not detected for Evaporation
grids_germany_daily_evaporation_fao_2024_v1.1.netcdf)If imports are slow:
scripts/ (repo root; not part of the docs site)