This Python script parses Slovenian radar data and detects storms based on specified locations. Users can input location names or addresses, and if the location is not already in the system, it can be added for future use.
Features
- Download radar images for storm detection
- Check for storms based on pixel values in the radar image
- Store and manage locations in MySQL database
- Geocode new location addresses to get their coordinates
- Flexible radius setting for storm detection
- Log historic precipitation data of certain locations
Requirements
Python 3.x with the following packages:
argparse
requests
Pillow
pandas
numpy
geopy
Install with:
pip3 install -r requirements.txt
Usage
./bin/python3 radar_main.py [-h] [-a NAME LOCATION RADIUS] [-c NAME] [-p NAME]
Add location
./bin/python3 radar_main.py -a "friendly name" "address" "radius in km"
Run continuous logging
./bin/python3 radar_main.py -p "name 1" "name 2"
Options
-h, --help— Show help message-a, --add NAME LOCATION RADIUS— Add a new location-c, --check NAME— Check precipitation for a location-p, --periodic NAME— Run periodic logging every 5 minutes
MySQL Database Setup
CREATE TABLE locations (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL,
location VARCHAR(100),
lat FLOAT,
lon FLOAT,
x FLOAT,
y FLOAT,
radius FLOAT,
radiuspx FLOAT
);
CREATE TABLE radar_precipitation (
id INT AUTO_INCREMENT PRIMARY KEY,
location_name VARCHAR(50),
precipitation FLOAT,
timestamp DATETIME,
FOREIGN KEY (location_name) REFERENCES locations(name)
);
Credentials
Edit the database credentials in radar_main.py at the RadarApp class instantiation:
db_host="localhost"
db_user="radar_user"
db_password="radar_password"
db_name="radar_db"
How It Works
- Download Radar Data — fetches the latest image from the Slovenian weather service using
requests. - Analyze Pixel Data — pixels around the specified location are analyzed for storm color values.
- Location Management — locations are stored in CSV/MySQL. New locations are geocoded via Nominatim.
- Storm Detection — if pixel values fall within the storm color range, an alert is triggered.
Storm Detection Sensitivity
Sensitivity is controlled by analyzing color values in the radar image. Pixel values in a specified range (corresponding to storm intensity) trigger alerts.
Things to Consider
Make sure locations.csv exists in the same directory. It stores name, coordinates, and radius for each location.
Sample locations.csv
name,location,lat,lon,x,y,radius,radiuspx
Ljubljana,"123 Main St, Ljubljana",46.0511,14.5051,123,456,1,2
Precipitation Graph
Live precipitation data for Ljubljana: