Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,54 @@
|
|
1 |
"""
|
2 |
-
Radar Data Downloader via Gradio
|
3 |
-
|
4 |
|
5 |
This script mimics part of Supercell Wx’s functionality by downloading the latest
|
6 |
-
radar data file from public AWS S3 buckets. It
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
"""
|
10 |
|
11 |
import datetime
|
12 |
import io
|
|
|
13 |
|
14 |
import boto3
|
15 |
from botocore import UNSIGNED
|
16 |
from botocore.client import Config
|
17 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
|
20 |
def fetch_latest_radar_data(radar_type, station, date_str):
|
@@ -95,20 +129,23 @@ def fetch_latest_radar_data(radar_type, station, date_str):
|
|
95 |
return summary
|
96 |
|
97 |
|
98 |
-
#
|
|
|
|
|
|
|
99 |
interface = gr.Interface(
|
100 |
fn=fetch_latest_radar_data,
|
101 |
inputs=[
|
102 |
gr.Radio(choices=["Level 2", "Level 3"], label="Radar Data Type"),
|
103 |
-
gr.
|
104 |
gr.Textbox(value=datetime.datetime.utcnow().strftime("%Y-%m-%d"), label="Date (YYYY-MM-DD)")
|
105 |
],
|
106 |
outputs="text",
|
107 |
title="Radar Data Downloader",
|
108 |
description=(
|
109 |
"This tool downloads the latest radar data file from public AWS S3 buckets "
|
110 |
-
"used by Supercell Wx. Choose a radar data type (Level 2 or Level 3),
|
111 |
-
"radar station
|
112 |
"visualization using OpenStreetMap (which requires no API keys)."
|
113 |
)
|
114 |
)
|
|
|
1 |
"""
|
2 |
+
Radar Data Downloader with Station Selector via Gradio
|
3 |
+
========================================================
|
4 |
|
5 |
This script mimics part of Supercell Wx’s functionality by downloading the latest
|
6 |
+
radar data file from public AWS S3 buckets. It now downloads the list of radar sites
|
7 |
+
from the Supercell Wx GitHub repository and provides a dropdown for station selection.
|
8 |
+
|
9 |
+
Ensure you have installed required packages:
|
10 |
+
pip install gradio boto3 requests
|
11 |
"""
|
12 |
|
13 |
import datetime
|
14 |
import io
|
15 |
+
import json
|
16 |
|
17 |
import boto3
|
18 |
from botocore import UNSIGNED
|
19 |
from botocore.client import Config
|
20 |
import gradio as gr
|
21 |
+
import requests
|
22 |
+
|
23 |
+
|
24 |
+
def get_station_list():
|
25 |
+
"""
|
26 |
+
Downloads and parses the radar_sites.json file from the Supercell Wx GitHub repository.
|
27 |
+
Returns a sorted list of station identifiers.
|
28 |
+
"""
|
29 |
+
# URL for the raw radar_sites.json file from the Supercell Wx repository.
|
30 |
+
url = "https://raw.githubusercontent.com/dpaulat/supercell-wx/develop/data/radar_sites.json"
|
31 |
+
try:
|
32 |
+
response = requests.get(url)
|
33 |
+
response.raise_for_status()
|
34 |
+
data = response.json()
|
35 |
+
except Exception as e:
|
36 |
+
# Fallback: return a default list if there is an error.
|
37 |
+
print(f"Error fetching station list: {e}")
|
38 |
+
return ["KTLX", "KDOX", "KBMX"]
|
39 |
+
|
40 |
+
# The JSON is expected to be a list of station objects.
|
41 |
+
# Extract the station identifier. Assuming each object has a "station" or "id" field.
|
42 |
+
# Checking common patterns:
|
43 |
+
stations = []
|
44 |
+
for item in data:
|
45 |
+
# Try several keys:
|
46 |
+
if "station" in item:
|
47 |
+
stations.append(item["station"].upper())
|
48 |
+
elif "id" in item:
|
49 |
+
stations.append(item["id"].upper())
|
50 |
+
stations = sorted(list(set(stations)))
|
51 |
+
return stations
|
52 |
|
53 |
|
54 |
def fetch_latest_radar_data(radar_type, station, date_str):
|
|
|
129 |
return summary
|
130 |
|
131 |
|
132 |
+
# Get station list at startup.
|
133 |
+
station_list = get_station_list()
|
134 |
+
|
135 |
+
# Create the Gradio interface using updated component classes.
|
136 |
interface = gr.Interface(
|
137 |
fn=fetch_latest_radar_data,
|
138 |
inputs=[
|
139 |
gr.Radio(choices=["Level 2", "Level 3"], label="Radar Data Type"),
|
140 |
+
gr.Dropdown(choices=station_list, label="Select Radar Station"),
|
141 |
gr.Textbox(value=datetime.datetime.utcnow().strftime("%Y-%m-%d"), label="Date (YYYY-MM-DD)")
|
142 |
],
|
143 |
outputs="text",
|
144 |
title="Radar Data Downloader",
|
145 |
description=(
|
146 |
"This tool downloads the latest radar data file from public AWS S3 buckets "
|
147 |
+
"used by Supercell Wx. Choose a radar data type (Level 2 or Level 3), select a "
|
148 |
+
"radar station, and enter a date (UTC). In future iterations, you can add "
|
149 |
"visualization using OpenStreetMap (which requires no API keys)."
|
150 |
)
|
151 |
)
|