Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -98,6 +98,7 @@ def fetch_and_process_sdo_data(target_dt, forecast_horizon_minutes):
|
|
98 |
all_times = sorted(list(set(input_times + [target_time])))
|
99 |
|
100 |
data_maps = {}
|
|
|
101 |
total_downloads = len(all_times) * len(SDO_CHANNELS)
|
102 |
downloads_done = 0
|
103 |
yield f"Starting download of {total_downloads} data files..."
|
@@ -108,18 +109,26 @@ def fetch_and_process_sdo_data(target_dt, forecast_horizon_minutes):
|
|
108 |
yield f"Downloading [{downloads_done}/{total_downloads}]: {channel} for {t.strftime('%Y-%m-%d %H:%M')}..."
|
109 |
|
110 |
if channel in ["hmi_by", "hmi_bz"]:
|
111 |
-
if data_maps[t].get("hmi_bx"):
|
|
|
|
|
|
|
112 |
continue
|
113 |
|
114 |
-
# *** FIX: Removed the non-existent 'a.Time.nearest' attribute. ***
|
115 |
time_attr = a.Time(t - datetime.timedelta(minutes=5), t + datetime.timedelta(minutes=5))
|
116 |
instrument = a.Instrument.hmi if "hmi" in channel else a.Instrument.aia
|
117 |
query = Fido.search(time_attr, instrument, physobs, sample)
|
118 |
|
119 |
-
if
|
120 |
-
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
yield "✅ All files downloaded. Starting preprocessing..."
|
125 |
output_wcs = WCS(naxis=2)
|
@@ -254,11 +263,9 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
254 |
"""
|
255 |
<div align='center'>
|
256 |
# ☀️ Surya: Live Forecast Demo ☀️
|
257 |
-
###
|
258 |
-
**
|
259 |
-
|
260 |
-
2. Click 'Generate Forecast'. **This will be slow (5-15 minutes) as it downloads live data.**
|
261 |
-
3. Once complete, select different channels to explore the multi-spectrum forecast.
|
262 |
</div>
|
263 |
"""
|
264 |
)
|
|
|
98 |
all_times = sorted(list(set(input_times + [target_time])))
|
99 |
|
100 |
data_maps = {}
|
101 |
+
last_successful_map = {}
|
102 |
total_downloads = len(all_times) * len(SDO_CHANNELS)
|
103 |
downloads_done = 0
|
104 |
yield f"Starting download of {total_downloads} data files..."
|
|
|
109 |
yield f"Downloading [{downloads_done}/{total_downloads}]: {channel} for {t.strftime('%Y-%m-%d %H:%M')}..."
|
110 |
|
111 |
if channel in ["hmi_by", "hmi_bz"]:
|
112 |
+
if data_maps[t].get("hmi_bx"):
|
113 |
+
smap = data_maps[t]["hmi_bx"]
|
114 |
+
data_maps[t][channel] = smap
|
115 |
+
last_successful_map[channel] = smap
|
116 |
continue
|
117 |
|
|
|
118 |
time_attr = a.Time(t - datetime.timedelta(minutes=5), t + datetime.timedelta(minutes=5))
|
119 |
instrument = a.Instrument.hmi if "hmi" in channel else a.Instrument.aia
|
120 |
query = Fido.search(time_attr, instrument, physobs, sample)
|
121 |
|
122 |
+
if query:
|
123 |
+
files = Fido.fetch(query[0,0], path="./data/sdo_cache")
|
124 |
+
smap = sunpy.map.Map(files[0])
|
125 |
+
data_maps[t][channel] = smap
|
126 |
+
last_successful_map[channel] = smap
|
127 |
+
elif channel in last_successful_map:
|
128 |
+
yield f"⚠️ WARNING: No data for {channel} near {t}. Reusing previous image."
|
129 |
+
data_maps[t][channel] = last_successful_map[channel]
|
130 |
+
else:
|
131 |
+
raise ValueError(f"CRITICAL: No data found for initial image of {channel}. Cannot proceed.")
|
132 |
|
133 |
yield "✅ All files downloaded. Starting preprocessing..."
|
134 |
output_wcs = WCS(naxis=2)
|
|
|
263 |
"""
|
264 |
<div align='center'>
|
265 |
# ☀️ Surya: Live Forecast Demo ☀️
|
266 |
+
### A Foundation Model for Solar Dynamics
|
267 |
+
This demo runs NASA's **Surya**, a foundation model trained to understand the physics of the Sun.
|
268 |
+
It looks at the Sun in 13 different channels (8 from the AIA instrument, 5 from HMI) simultaneously to learn the complex relationships between solar phenomena like coronal loops, magnetic fields, and solar flares. By seeing these interconnected views, it can generate a holistic forecast of what the entire solar disk will look like in the near future.
|
|
|
|
|
269 |
</div>
|
270 |
"""
|
271 |
)
|