Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,12 +11,12 @@ from bs4 import BeautifulSoup
|
|
| 11 |
|
| 12 |
# Default parameters
|
| 13 |
low_int = 10
|
| 14 |
-
high_int =
|
| 15 |
edge_thresh = 100
|
| 16 |
accum_thresh = 45
|
| 17 |
-
center_tol =
|
| 18 |
morph_dia = 3
|
| 19 |
-
min_rad =
|
| 20 |
|
| 21 |
def fetch_sdo_images(max_images, size="1024by960", tool="ccor1"):
|
| 22 |
"""Fetch SDO images from NOAA URL directory."""
|
|
@@ -171,7 +171,7 @@ def analyze_images(frames, lower_bound, upper_bound, param1, param2, center_tole
|
|
| 171 |
"output_frame": frames[i + 1]
|
| 172 |
})
|
| 173 |
|
| 174 |
-
# Find growing series
|
| 175 |
growing_circle_data = []
|
| 176 |
current_series = []
|
| 177 |
if all_circle_data:
|
|
@@ -191,24 +191,28 @@ def analyze_images(frames, lower_bound, upper_bound, param1, param2, center_tole
|
|
| 191 |
report = f"Analysis Report (as of {datetime.now().strftime('%I:%M %p PDT, %B %d, %Y')}):\n"
|
| 192 |
|
| 193 |
# Prepare output based on display mode
|
| 194 |
-
if display_mode == "
|
| 195 |
results = [Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)) for frame in frames]
|
| 196 |
-
elif display_mode == "
|
| 197 |
-
for
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
for i, frame in enumerate(frames):
|
| 205 |
if i + 1 in [c["frame"] for c in all_circle_data]:
|
| 206 |
for c in all_circle_data:
|
| 207 |
if c["frame"] == i + 1:
|
| 208 |
output_frame = cv2.cvtColor(c["output_frame"], cv2.COLOR_GRAY2RGB)
|
| 209 |
-
cv2.circle(output_frame, c["center"], c["radius"], (0, 255, 0), 2) # Green
|
| 210 |
if c["frame"] in growing_frames:
|
| 211 |
-
cv2.circle(output_frame, c["center"], c["radius"] + 2, (255,
|
| 212 |
results.append(Image.fromarray(output_frame))
|
| 213 |
break
|
| 214 |
else:
|
|
@@ -223,7 +227,7 @@ def analyze_images(frames, lower_bound, upper_bound, param1, param2, center_tole
|
|
| 223 |
report += "No circles detected.\n"
|
| 224 |
|
| 225 |
if growing_circle_data:
|
| 226 |
-
report += f"\nSeries of Frames with Growing Circles ({len(growing_circle_data)} frames):\n"
|
| 227 |
for c in growing_circle_data:
|
| 228 |
report += f"Frame {c['frame']}: Center at {c['center']}, Radius {c['radius']} pixels\n"
|
| 229 |
report += "\nConclusion: Growing concentric circles detected, indicative of a potential Earth-directed CME."
|
|
@@ -284,7 +288,7 @@ with gr.Blocks(title="Solar CME Detection") as demo:
|
|
| 284 |
gr.Markdown("""
|
| 285 |
# Solar CME Detection
|
| 286 |
Upload a GIF or fetch SDO images to detect concentric circles indicative of coronal mass ejections (CMEs).
|
| 287 |
-
|
| 288 |
""")
|
| 289 |
|
| 290 |
# State to store fetched frames
|
|
@@ -301,18 +305,18 @@ with gr.Blocks(title="Solar CME Detection") as demo:
|
|
| 301 |
morph_iterations = gr.Slider(minimum=1, maximum=5, value=morph_dia, step=1, label="Morphological Dilation Iterations")
|
| 302 |
min_rad = gr.Slider(minimum=1, maximum=100, value=min_rad, step=1, label="Minimum Circle Radius")
|
| 303 |
display_mode = gr.Dropdown(
|
| 304 |
-
choices=["
|
| 305 |
-
value="
|
| 306 |
label="Display Mode"
|
| 307 |
)
|
| 308 |
-
scale_to_512 = gr.Checkbox(label="Scale Output GIF to 512x512", value=
|
| 309 |
|
| 310 |
with gr.Row():
|
| 311 |
with gr.Column():
|
| 312 |
gr.Markdown("### Input Options")
|
| 313 |
demo_btn = gr.Button("Load Demo")
|
| 314 |
gif_input = gr.File(label="Upload Solar GIF (optional)", file_types=[".gif"])
|
| 315 |
-
max_images = gr.Slider(minimum=1, maximum=
|
| 316 |
fetch_button = gr.Button("Fetch Images from URL")
|
| 317 |
analyze_button = gr.Button("Analyze")
|
| 318 |
|
|
@@ -324,7 +328,7 @@ with gr.Blocks(title="Solar CME Detection") as demo:
|
|
| 324 |
with gr.Row():
|
| 325 |
with gr.Column():
|
| 326 |
gif_output = gr.File(label="Download Resulting GIF")
|
| 327 |
-
gallery = gr.Gallery(label="Frames with Detected Circles (Green: Detected,
|
| 328 |
|
| 329 |
with gr.Column():
|
| 330 |
total_images = gr.Textbox(label="Total Images Available in Directory", value="0")
|
|
|
|
| 11 |
|
| 12 |
# Default parameters
|
| 13 |
low_int = 10
|
| 14 |
+
high_int = 150
|
| 15 |
edge_thresh = 100
|
| 16 |
accum_thresh = 45
|
| 17 |
+
center_tol = 30
|
| 18 |
morph_dia = 3
|
| 19 |
+
min_rad = 70
|
| 20 |
|
| 21 |
def fetch_sdo_images(max_images, size="1024by960", tool="ccor1"):
|
| 22 |
"""Fetch SDO images from NOAA URL directory."""
|
|
|
|
| 171 |
"output_frame": frames[i + 1]
|
| 172 |
})
|
| 173 |
|
| 174 |
+
# Find growing series (indicative of CMEs)
|
| 175 |
growing_circle_data = []
|
| 176 |
current_series = []
|
| 177 |
if all_circle_data:
|
|
|
|
| 191 |
report = f"Analysis Report (as of {datetime.now().strftime('%I:%M %p PDT, %B %d, %Y')}):\n"
|
| 192 |
|
| 193 |
# Prepare output based on display mode
|
| 194 |
+
if display_mode == "Raw Frames":
|
| 195 |
results = [Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)) for frame in frames]
|
| 196 |
+
elif display_mode == "CME Detection":
|
| 197 |
+
for i, frame in enumerate(frames):
|
| 198 |
+
if i + 1 in growing_frames:
|
| 199 |
+
for c in growing_circle_data:
|
| 200 |
+
if c["frame"] == i + 1:
|
| 201 |
+
output_frame = cv2.cvtColor(c["output_frame"], cv2.COLOR_GRAY2RGB)
|
| 202 |
+
cv2.circle(output_frame, c["center"], c["radius"], (255, 255, 0), 2) # Yellow for CME
|
| 203 |
+
results.append(Image.fromarray(output_frame))
|
| 204 |
+
break
|
| 205 |
+
else:
|
| 206 |
+
results.append(Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_GRAY2RGB)))
|
| 207 |
+
elif display_mode == "All Detection":
|
| 208 |
for i, frame in enumerate(frames):
|
| 209 |
if i + 1 in [c["frame"] for c in all_circle_data]:
|
| 210 |
for c in all_circle_data:
|
| 211 |
if c["frame"] == i + 1:
|
| 212 |
output_frame = cv2.cvtColor(c["output_frame"], cv2.COLOR_GRAY2RGB)
|
| 213 |
+
cv2.circle(output_frame, c["center"], c["radius"], (0, 255, 0), 2) # Green for detected
|
| 214 |
if c["frame"] in growing_frames:
|
| 215 |
+
cv2.circle(output_frame, c["center"], c["radius"] + 2, (255, 255, 0), 2) # Yellow for CME
|
| 216 |
results.append(Image.fromarray(output_frame))
|
| 217 |
break
|
| 218 |
else:
|
|
|
|
| 227 |
report += "No circles detected.\n"
|
| 228 |
|
| 229 |
if growing_circle_data:
|
| 230 |
+
report += f"\nSeries of Frames with Growing Circles (CMEs) ({len(growing_circle_data)} frames):\n"
|
| 231 |
for c in growing_circle_data:
|
| 232 |
report += f"Frame {c['frame']}: Center at {c['center']}, Radius {c['radius']} pixels\n"
|
| 233 |
report += "\nConclusion: Growing concentric circles detected, indicative of a potential Earth-directed CME."
|
|
|
|
| 288 |
gr.Markdown("""
|
| 289 |
# Solar CME Detection
|
| 290 |
Upload a GIF or fetch SDO images to detect concentric circles indicative of coronal mass ejections (CMEs).
|
| 291 |
+
Yellow circles mark growing series (potential CMEs); green circles mark other detected features.
|
| 292 |
""")
|
| 293 |
|
| 294 |
# State to store fetched frames
|
|
|
|
| 305 |
morph_iterations = gr.Slider(minimum=1, maximum=5, value=morph_dia, step=1, label="Morphological Dilation Iterations")
|
| 306 |
min_rad = gr.Slider(minimum=1, maximum=100, value=min_rad, step=1, label="Minimum Circle Radius")
|
| 307 |
display_mode = gr.Dropdown(
|
| 308 |
+
choices=["Raw Frames", "CME Detection", "All Detection"],
|
| 309 |
+
value="All Detection",
|
| 310 |
label="Display Mode"
|
| 311 |
)
|
| 312 |
+
scale_to_512 = gr.Checkbox(label="Scale Output GIF to 512x512", value=False)
|
| 313 |
|
| 314 |
with gr.Row():
|
| 315 |
with gr.Column():
|
| 316 |
gr.Markdown("### Input Options")
|
| 317 |
demo_btn = gr.Button("Load Demo")
|
| 318 |
gif_input = gr.File(label="Upload Solar GIF (optional)", file_types=[".gif"])
|
| 319 |
+
max_images = gr.Slider(minimum=1, maximum=100, value=10, step=1, label="Max Images to Fetch")
|
| 320 |
fetch_button = gr.Button("Fetch Images from URL")
|
| 321 |
analyze_button = gr.Button("Analyze")
|
| 322 |
|
|
|
|
| 328 |
with gr.Row():
|
| 329 |
with gr.Column():
|
| 330 |
gif_output = gr.File(label="Download Resulting GIF")
|
| 331 |
+
gallery = gr.Gallery(label="Frames with Detected Circles (Green: Detected, Yellow: CME)")
|
| 332 |
|
| 333 |
with gr.Column():
|
| 334 |
total_images = gr.Textbox(label="Total Images Available in Directory", value="0")
|