Storm Alert - Slovenia

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.

You can find the whole code here on Github: Github repository

Features

Radarska slika slovenija
Radar image of Slovenia with precipitation

Requirements

Python 3.x

Required packages:


                argparse
                requests
                Pillow
                pandas
                numpy
                geopy
            

You can install the required packages using pip:

pip3 install -r requirements.txt

Usage

Run the script using the following command:

./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 for storm alert"

Run continuous logging for location or multiple ones:

./bin/python3 radar_main.py -p "friendly name 1" "friendly name 2"

Options

MySQL Database Setup

To use this project, you need to create the necessary database tables in MySQL. Below are the SQL commands to create the required tables.


            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)
            );
        

Note:

Make sure to edit the database credentials in radar_main.py. Locate the RadarApp class instantiation in radar_main.py and update the following parameters with your MySQL database information:


            db_host="localhost" # Database host
            db_user="radar_user" # Database username
            db_password="radar_password" # Database password
            db_name="radar_db" # Database name
        

How It Works

Here’s a behind-the-scenes look at what the script does:

  1. Download Radar Data: The script fetches the latest radar image from the Slovenian weather service using requests. It stores this image in a directory for analysis.
  2. Analyze Pixel Data: The radar image is loaded, and the pixels around the specified location are analyzed for color values that indicate storm activity.
  3. Location Management: Locations are stored in a CSV file. You can easily add new locations, and the script will geocode their latitude and longitude using the Nominatim geocoding service.
  4. Storm Detection: If the pixel analysis shows values in the storm color range, an alert is triggered, otherwise, it prints that no storm was detected.

Storm Detection Sensitivity

The sensitivity of storm detection is controlled by analyzing the color values in the radar image. If any of the pixel values fall within a specified range (which corresponds to storm intensity), an alert is triggered.

Things to Consider

Make sure your locations.csv file exists in the same directory as the script. The file stores details like the name, coordinates, and radius for each location. If you provide a new location name, the script will automatically update this file.

Sample locations.csv File


        name,location,lat,lon,x,y,radius,radiuspx
        Ljubljana,"123 Main St, Ljubljana",46.0511,14.5051,123,456,1,2
        

Conclusion

This Python script provides a practical way to monitor storm activity in Slovenia using radar data. With features like flexible location management and automatic geocoding, it's easy to customize for your needs. Give it a try and stay updated with potential storm threats!

Here you can see graph of past precipitation for Ljubljana

Back to Home