The backend service of the EKAPEx Weather Demo application. A FastAPI-based API for weather data processing and visualization, supporting multiple AI weather forecasting models.
This is the backend component of the EKAPEx Weather Demo project. It provides a RESTful API for accessing weather forecast data from multiple models (GraphCast, Cerrora), processes weather datasets, and generates high-quality map visualizations.
- Weather Data Processing: Loads and processes weather data from Zarr datasets
- Multiple Model Support: Supports GraphCast and Cerrora weather forecasting models
- Visualization Generation: Creates weather map visualizations using Cartopy
- RESTful API: Provides endpoints for weather data access and retrieval
- Static File Serving: Serves generated visualization images
- Weather Parameters:
- Temperature & Wind
- Geopotential Height
- Sea Level Pressure
weather_api/
│
├── app/ # Main application package
│ ├── __init__.py
│ ├── main.py # FastAPI application instance and configuration
│ ├── config.py # Configuration settings
│ ├── api/ # API endpoints and models
│ │ ├── __init__.py
│ │ ├── routes.py # API route definitions
│ │ └── models.py # Pydantic models for request/response
│ ├── core/ # Core business logic
│ │ ├── __init__.py
│ │ ├── visualization.py # Data visualization logic
│ │ └── data_loader.py # Data loading and processing
│ └── utils/ # Utility functions
│ ├── __init__.py
│ └── helpers.py # Helper functions
│
├── streaming/ # Generated visualization images
├── tests/ # Test directory
│ └── __init__.py
│
├── requirements.txt # Project dependencies
├── README.md # This documentation
└── run.py # Application entry point
- Python 3.9+
- Conda (recommended for environment management)
- Clone the repository:
git clone https://github.com/HPI-DeepLearning/EKAPEx-Demo.git
cd EKAPEx-Demo/weather_api- Create and activate a conda environment:
conda create --name ekapex python=3.9
conda activate ekapex- Install dependencies:
pip install -r requirements.txt- Configure environment variables:
- Create a
.envfile in the project root - Add your configuration based on the project Wiki
- Create a
Start the server using the run script:
python run.py --host 0.0.0.0 --port 8999Optional command line arguments:
--host: Server host (default: 0.0.0.0)--port: Server port (default: 8999)--reload: Enable auto-reload for development--log-level: Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
Example with options:
python run.py --host 0.0.0.0 --port 8999 --reload --log-level DEBUGThe API will be available at http://localhost:8999/api/v1
Key endpoints:
GET /api/v1/base-times: Get available base times for a variable typePOST /api/v1/data/{variable_type}: Get weather data for specific time ranges- Static files served at
/backend-fast-api/streaming/
import requests
import json
# Get temperature and wind data
url = "http://localhost:8999/api/v1/data/temp_wind"
payload = {
"baseTime": 1609459200,
"validTime": [1609459200, 1609462800]
}
headers = {
'Content-Type': 'application/json'
}
response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.json())# Get base times
curl -X GET "http://localhost:8999/api/v1/base-times?variableType=temp_wind"
# Get temperature and wind data
curl -X POST "http://localhost:8999/api/v1/data/temp_wind" \
-H "Content-Type: application/json" \
-d '{
"baseTime": 1609459200,
"validTime": [1609459200, 1609462800]
}'This backend service is designed to work with the frontend application located in weather_ui/. For full application setup, see the main project README.
The frontend connects to this API using:
NEXT_PUBLIC_API_BASE_URL: API endpoint base URL (e.g.,http://localhost:8999/api/v1)NEXT_PUBLIC_IMAGE_BASE_URL: Image serving base URL (e.g.,http://localhost:8999/backend-fast-api/streaming)
- GraphCast: Google's graph neural network weather model
- Cerrora: Model created by the HPI EKAPEx team
Run tests using pytest:
pytest tests/See the main project README for license information.
- Weather data provided by WeatherBench2
- Map visualizations powered by Cartopy
- Built with FastAPI