Python Doppler Radar Viewer

Python Doppler Radar Viewer Documentation

Script Overview

This Python script is designed to download and display Doppler radar images based on user-selected locations. Currently, the script supports only Linux and Mac.

Dependencies

The script requires no additional dependencies beyond the Python standard library and mpv.

Application UI

The script operates from the command line and prompts the user to select a radar location. It then downloads and displays the Doppler radar image.

Doppler radar gif python

How to Use

  1. Run the script in a Python environment.
  2. Follow the prompts to select a radar location.
  3. The Doppler radar image will be automatically downloaded and displayed.

Running the Application

To run the application, execute the Python script in a terminal or command prompt environment. Ensure that the necessary dependencies are installed, and the script has permission to write to the cache directory.

Notes

The Doppler App in Action

Python Script for Doppler Radar Viewer Application

import os
import subprocess
import time

# Define constants
SECS = 600
RADAR_LOC = os.path.join(os.getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache')), 'radar')
DOPPLER = os.path.join(os.getenv('XDG_CACHE_HOME', os.path.expanduser('~/.cache')), 'doppler.gif')

# Function to pick location
def pickloc():
    chosen = input("Select a radar to use as default:")
    continentcode, countrycode, radarcode = chosen.split(':')
    # Print codes to radar location file
    with open(RADAR_LOC, 'w') as f:
        f.write(f"{countrycode},{radarcode}\n")

# Function to get Doppler
def getdoppler():
    with open(RADAR_LOC, 'r') as f:
        country, province = f.readline().strip().split(',')
    
    print(f"Pulling most recent Doppler RADAR for {province}.")
    if country == 'US':
        subprocess.run(["curl", "-sL", f"https://radar.weather.gov/ridge/standard/{province}_loop.gif", "-o", DOPPLER])
    elif country == 'DE':
        province = province.lower()
        subprocess.run(["curl", "-sL", f"https://www.dwd.de/DWD/wetter/radar/radfilm_{province}_akt.gif", "-o", DOPPLER])
    elif country == 'NL':
        subprocess.run(["curl", "-sL", "https://cdn.knmi.nl/knmi/map/general/weather-map.gif", "-o", DOPPLER])

# Function to show Doppler
def showdoppler():
    subprocess.Popen(["mpv", "--no-osc", "--loop=inf", "--no-terminal", DOPPLER])

# Main function
def main():
    if not os.path.isfile(RADAR_LOC):
        pickloc()
        getdoppler()
    elif time.time() - os.path.getmtime(DOPPLER) > SECS:
        getdoppler()
    showdoppler()

if __name__ == "__main__":
    main()
Related
Software