Python Doppler Radar Viewer

Python Doppler Radar Viewer Documentation

Table of Contents

  1. Script Overview
  2. Dependencies
  3. Features
  4. Radar Locations
  5. Installation
  6. Usage
  7. Technical Details
  8. Supported Platforms
  9. Caveats
  10. Troubleshooting
  11. Doppler Radar Script

Script Overview

A Python script designed to download and display Doppler radar images based on user-selected locations. Currently supports Linux and Mac platforms.

Dependencies

Features

Radar Locations

The script supports the following radar locations:

Installation

No additional installation required beyond Python and mpv.

Usage

  1. Run the script in a terminal
  2. Choose from the main menu:
    • Show Doppler radar
    • Change default radar location
    • Exit

Example Workflow

Doppler Radar Script
1. Show Doppler radar
2. Change default radar
3. Exit
Select an option: 1
Doppler radar gif python

Technical Details

Supported Platforms

Caveats

Troubleshooting

Doppler Radar Script

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


def pickloc():
    print("Available radars:")
    print("1. EU:NL:NL (Netherlands)")
    print("2. EU:DE:DE (Germany)")
    print("3. NA:US:US (United States)")
    
    choices = {
        "1": "EU:NL:NL",
        "2": "EU:DE:DE",
        "3": "NA:US:US"
    }
    
    chosen = input("Select a radar by number (or enter manually in 'continent:country:radarcode' format): ")
    if chosen in choices:
        chosen = choices[chosen]
    
    try:
        continentcode, countrycode, radarcode = chosen.split(':')
        with open(RADAR_LOC, 'w') as f:
            f.write(f"{countrycode},{radarcode}\n")
    except ValueError:
        print("Invalid input format. Please try again.")
        pickloc()



# 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():
    while True:
        print("\nDoppler Radar Script")
        print("1. Show Doppler radar")
        print("2. Change default radar")
        print("3. Exit")
        choice = input("Select an option: ")

        if choice == '1':
            if not os.path.isfile(RADAR_LOC):
                print("No radar set. Please set a default radar first.")
                pickloc()
            if time.time() - os.path.getmtime(DOPPLER) > SECS:
                getdoppler()
            showdoppler()
        elif choice == '2':
            pickloc()
            getdoppler()
        elif choice == '3':
            print("Exiting...")
            break
        else:
            print("Invalid choice. Please try again.")



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