Spaces:
Running
Running
Commit ·
f00a555
1
Parent(s): ce6dda4
time info widget, rebinning and lightcurves save
Browse files- modules/DataLoading/DataIngestion.py +52 -27
- modules/Home/HomeContent.py +14 -5
- modules/QuickLook/AveragePowerSpectrum.py +136 -32
- modules/QuickLook/LightCurve.py +72 -5
- modules/QuickLook/PowerSpectrum.py +27 -2
- utils/globals.py +1 -0
modules/DataLoading/DataIngestion.py
CHANGED
|
@@ -7,7 +7,7 @@ import os
|
|
| 7 |
import stat
|
| 8 |
import numpy as np
|
| 9 |
from bokeh.models import Tooltip
|
| 10 |
-
from utils.globals import loaded_event_data
|
| 11 |
from utils.DashboardClasses import (
|
| 12 |
MainHeader,
|
| 13 |
MainArea,
|
|
@@ -359,7 +359,7 @@ def preview_loaded_files(
|
|
| 359 |
time_limit=10,
|
| 360 |
):
|
| 361 |
"""
|
| 362 |
-
Preview the loaded event data files.
|
| 363 |
|
| 364 |
Args:
|
| 365 |
event: The event object triggering the function.
|
|
@@ -368,29 +368,38 @@ def preview_loaded_files(
|
|
| 368 |
warning_handler (WarningHandler): The handler for warnings.
|
| 369 |
time_limit (int): The number of time entries to preview.
|
| 370 |
"""
|
| 371 |
-
if not loaded_event_data:
|
| 372 |
-
output_box_container[:] = [
|
| 373 |
-
create_loadingdata_output_box("No files loaded to preview.")
|
| 374 |
-
]
|
| 375 |
-
return
|
| 376 |
-
|
| 377 |
preview_data = []
|
| 378 |
-
for file_name, event_list in loaded_event_data:
|
| 379 |
-
try:
|
| 380 |
-
time_data = f"Times (first {time_limit}): {event_list.time[:time_limit]}"
|
| 381 |
-
mjdref = f"MJDREF: {event_list.mjdref}"
|
| 382 |
-
gti = f"GTI: {event_list.gti}"
|
| 383 |
-
preview_data.append(f"File: {file_name}\n{time_data}\n{mjdref}\n{gti}\n")
|
| 384 |
-
except Exception as e:
|
| 385 |
-
warning_handler.warn(str(e), category=RuntimeWarning)
|
| 386 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
if preview_data:
|
| 388 |
output_box_container[:] = [
|
| 389 |
create_loadingdata_output_box("\n\n".join(preview_data))
|
| 390 |
]
|
| 391 |
else:
|
| 392 |
output_box_container[:] = [
|
| 393 |
-
create_loadingdata_output_box("No valid files loaded for preview.")
|
| 394 |
]
|
| 395 |
|
| 396 |
if warning_handler.warnings:
|
|
@@ -405,26 +414,42 @@ def preview_loaded_files(
|
|
| 405 |
|
| 406 |
def clear_loaded_files(event, output_box_container, warning_box_container):
|
| 407 |
"""
|
| 408 |
-
Clear all loaded event data files from memory.
|
| 409 |
|
| 410 |
Args:
|
| 411 |
event: The event object triggering the function.
|
| 412 |
output_box_container (OutputBox): The container for output messages.
|
| 413 |
warning_box_container (WarningBox): The container for warning messages.
|
| 414 |
"""
|
| 415 |
-
global loaded_event_data
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
loaded_event_data.clear()
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
warning_box_container[:] = [create_loadingdata_warning_box("No warnings.")]
|
| 426 |
|
| 427 |
|
|
|
|
| 428 |
def create_event_list(
|
| 429 |
event,
|
| 430 |
times_input,
|
|
|
|
| 7 |
import stat
|
| 8 |
import numpy as np
|
| 9 |
from bokeh.models import Tooltip
|
| 10 |
+
from utils.globals import loaded_event_data, loaded_light_curve
|
| 11 |
from utils.DashboardClasses import (
|
| 12 |
MainHeader,
|
| 13 |
MainArea,
|
|
|
|
| 359 |
time_limit=10,
|
| 360 |
):
|
| 361 |
"""
|
| 362 |
+
Preview the loaded event data files and light curves.
|
| 363 |
|
| 364 |
Args:
|
| 365 |
event: The event object triggering the function.
|
|
|
|
| 368 |
warning_handler (WarningHandler): The handler for warnings.
|
| 369 |
time_limit (int): The number of time entries to preview.
|
| 370 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
preview_data = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
|
| 373 |
+
# Preview EventList data
|
| 374 |
+
if loaded_event_data:
|
| 375 |
+
for file_name, event_list in loaded_event_data:
|
| 376 |
+
try:
|
| 377 |
+
time_data = f"Times (first {time_limit}): {event_list.time[:time_limit]}"
|
| 378 |
+
mjdref = f"MJDREF: {event_list.mjdref}"
|
| 379 |
+
gti = f"GTI: {event_list.gti}"
|
| 380 |
+
preview_data.append(f"Event List - {file_name}:\n{time_data}\n{mjdref}\n{gti}\n")
|
| 381 |
+
except Exception as e:
|
| 382 |
+
warning_handler.warn(str(e), category=RuntimeWarning)
|
| 383 |
+
|
| 384 |
+
# Preview Lightcurve data
|
| 385 |
+
if loaded_light_curve:
|
| 386 |
+
for lc_name, lightcurve in loaded_light_curve:
|
| 387 |
+
try:
|
| 388 |
+
time_data = f"Times (first {time_limit}): {lightcurve.time[:time_limit]}"
|
| 389 |
+
counts_data = f"Counts (first {time_limit}): {lightcurve.counts[:time_limit]}"
|
| 390 |
+
dt = f"dt: {lightcurve.dt}"
|
| 391 |
+
preview_data.append(f"Light Curve - {lc_name}:\n{time_data}\n{counts_data}\n{dt}\n")
|
| 392 |
+
except Exception as e:
|
| 393 |
+
warning_handler.warn(str(e), category=RuntimeWarning)
|
| 394 |
+
|
| 395 |
+
# Display preview data or message if no data available
|
| 396 |
if preview_data:
|
| 397 |
output_box_container[:] = [
|
| 398 |
create_loadingdata_output_box("\n\n".join(preview_data))
|
| 399 |
]
|
| 400 |
else:
|
| 401 |
output_box_container[:] = [
|
| 402 |
+
create_loadingdata_output_box("No valid files or light curves loaded for preview.")
|
| 403 |
]
|
| 404 |
|
| 405 |
if warning_handler.warnings:
|
|
|
|
| 414 |
|
| 415 |
def clear_loaded_files(event, output_box_container, warning_box_container):
|
| 416 |
"""
|
| 417 |
+
Clear all loaded event data files and light curves from memory.
|
| 418 |
|
| 419 |
Args:
|
| 420 |
event: The event object triggering the function.
|
| 421 |
output_box_container (OutputBox): The container for output messages.
|
| 422 |
warning_box_container (WarningBox): The container for warning messages.
|
| 423 |
"""
|
| 424 |
+
global loaded_event_data, loaded_light_curve
|
| 425 |
+
event_data_cleared = False
|
| 426 |
+
light_curve_data_cleared = False
|
| 427 |
+
|
| 428 |
+
# Clear EventList data
|
| 429 |
+
if loaded_event_data:
|
| 430 |
loaded_event_data.clear()
|
| 431 |
+
event_data_cleared = True
|
| 432 |
+
|
| 433 |
+
# Clear Lightcurve data
|
| 434 |
+
if loaded_light_curve:
|
| 435 |
+
loaded_light_curve.clear()
|
| 436 |
+
light_curve_data_cleared = True
|
| 437 |
+
|
| 438 |
+
# Create appropriate messages based on what was cleared
|
| 439 |
+
messages = []
|
| 440 |
+
if event_data_cleared:
|
| 441 |
+
messages.append("Loaded event files have been cleared.")
|
| 442 |
+
if light_curve_data_cleared:
|
| 443 |
+
messages.append("Loaded light curves have been cleared.")
|
| 444 |
+
if not messages:
|
| 445 |
+
messages.append("No files or light curves loaded to clear.")
|
| 446 |
+
|
| 447 |
+
# Update the output and warning containers
|
| 448 |
+
output_box_container[:] = [create_loadingdata_output_box("\n".join(messages))]
|
| 449 |
warning_box_container[:] = [create_loadingdata_warning_box("No warnings.")]
|
| 450 |
|
| 451 |
|
| 452 |
+
|
| 453 |
def create_event_list(
|
| 454 |
event,
|
| 455 |
times_input,
|
modules/Home/HomeContent.py
CHANGED
|
@@ -53,17 +53,26 @@ def create_home_main_area():
|
|
| 53 |
|
| 54 |
# Path to the data files
|
| 55 |
data_dir = os.path.join(os.getcwd(), "files", "data")
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# Check if the file is already loaded
|
| 60 |
if not any(file_name == "nomission" for file_name, _ in loaded_event_data):
|
| 61 |
try:
|
| 62 |
-
event_list = EventList.read(
|
| 63 |
loaded_event_data.append(("nomission", event_list))
|
| 64 |
-
print(f"File '{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
except Exception as e:
|
| 66 |
-
print(f"Failed to load file '{
|
| 67 |
|
| 68 |
tab1_content = pn.pane.Markdown(HOME_STINGRAY_TAB_STRING)
|
| 69 |
tab2_content = pn.pane.Markdown(HOME_HOLOVIZ_TAB_STRING)
|
|
|
|
| 53 |
|
| 54 |
# Path to the data files
|
| 55 |
data_dir = os.path.join(os.getcwd(), "files", "data")
|
| 56 |
+
target_file1 = "nomission.evt"
|
| 57 |
+
file_path1 = os.path.join(data_dir, target_file1)
|
| 58 |
+
target_file2 = "xte_test.evt.gz"
|
| 59 |
+
file_path2 = os.path.join(data_dir, target_file2)
|
| 60 |
|
| 61 |
# Check if the file is already loaded
|
| 62 |
if not any(file_name == "nomission" for file_name, _ in loaded_event_data):
|
| 63 |
try:
|
| 64 |
+
event_list = EventList.read(file_path1, "ogip")
|
| 65 |
loaded_event_data.append(("nomission", event_list))
|
| 66 |
+
print(f"File '{target_file1}' loaded successfully.")
|
| 67 |
+
except Exception as e:
|
| 68 |
+
print(f"Failed to load file '{target_file1}': {e}")
|
| 69 |
+
if not any(file_name == "xte_test" for file_name, _ in loaded_event_data):
|
| 70 |
+
try:
|
| 71 |
+
event_list = EventList.read(file_path2, "ogip")
|
| 72 |
+
loaded_event_data.append(("xte_test.evt.gz", event_list))
|
| 73 |
+
print(f"File '{target_file2}' loaded successfully.")
|
| 74 |
except Exception as e:
|
| 75 |
+
print(f"Failed to load file '{target_file2}': {e}")
|
| 76 |
|
| 77 |
tab1_content = pn.pane.Markdown(HOME_STINGRAY_TAB_STRING)
|
| 78 |
tab2_content = pn.pane.Markdown(HOME_HOLOVIZ_TAB_STRING)
|
modules/QuickLook/AveragePowerSpectrum.py
CHANGED
|
@@ -19,12 +19,29 @@ from utils.DashboardClasses import (
|
|
| 19 |
from stingray import AveragedPowerspectrum
|
| 20 |
|
| 21 |
colors = [
|
| 22 |
-
"#1f77b4",
|
| 23 |
-
"#
|
| 24 |
-
"#
|
| 25 |
-
"#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
]
|
| 27 |
|
|
|
|
| 28 |
# Create a warning handler
|
| 29 |
def create_warning_handler():
|
| 30 |
warning_handler = WarningHandler()
|
|
@@ -33,6 +50,8 @@ def create_warning_handler():
|
|
| 33 |
|
| 34 |
|
| 35 |
""" Header Section """
|
|
|
|
|
|
|
| 36 |
def create_quicklook_avg_powerspectrum_header(
|
| 37 |
header_container,
|
| 38 |
main_area_container,
|
|
@@ -51,21 +70,29 @@ def create_quicklook_avg_powerspectrum_header(
|
|
| 51 |
|
| 52 |
|
| 53 |
""" Output Box Section """
|
|
|
|
|
|
|
| 54 |
def create_loadingdata_output_box(content):
|
| 55 |
return OutputBox(output_content=content)
|
| 56 |
|
| 57 |
|
| 58 |
""" Warning Box Section """
|
|
|
|
|
|
|
| 59 |
def create_loadingdata_warning_box(content):
|
| 60 |
return WarningBox(warning_content=content)
|
| 61 |
|
| 62 |
|
| 63 |
""" Float Panel """
|
|
|
|
|
|
|
| 64 |
def create_floatpanel_area(content, title):
|
| 65 |
return FloatingPlot(content=content, title=title)
|
| 66 |
|
| 67 |
|
| 68 |
""" Main Area Section """
|
|
|
|
|
|
|
| 69 |
def create_avg_powerspectrum_tab(
|
| 70 |
output_box_container,
|
| 71 |
warning_box_container,
|
|
@@ -94,9 +121,7 @@ def create_avg_powerspectrum_tab(
|
|
| 94 |
value="leahy",
|
| 95 |
)
|
| 96 |
|
| 97 |
-
segment_size_input = pn.widgets.FloatInput(
|
| 98 |
-
name="Segment Size", value=10, step=1
|
| 99 |
-
)
|
| 100 |
|
| 101 |
multi_event_select = pn.widgets.MultiSelect(
|
| 102 |
name="Or Select Event List(s) to Combine",
|
|
@@ -111,9 +136,59 @@ def create_avg_powerspectrum_tab(
|
|
| 111 |
dataframe_checkbox = pn.widgets.Checkbox(
|
| 112 |
name="Add DataFrame to FloatingPanel", value=False
|
| 113 |
)
|
| 114 |
-
|
| 115 |
rasterize_checkbox = pn.widgets.Checkbox(name="Rasterize Plots", value=True)
|
| 116 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
# Internal functions to encapsulate functionality
|
| 118 |
def create_dataframe(selected_event_list_index, dt, norm, segment_size):
|
| 119 |
if selected_event_list_index is not None:
|
|
@@ -160,7 +235,8 @@ def create_avg_powerspectrum_tab(
|
|
| 160 |
create_loadingdata_output_box(
|
| 161 |
f"Error generating Averaged Power Spectrum: {e}. "
|
| 162 |
"Try using a different segment size."
|
| 163 |
-
)
|
|
|
|
| 164 |
return None, None
|
| 165 |
return None, None
|
| 166 |
|
|
@@ -179,9 +255,7 @@ def create_avg_powerspectrum_tab(
|
|
| 179 |
|
| 180 |
if color_key:
|
| 181 |
if rasterize_checkbox.value:
|
| 182 |
-
return hd.rasterize(
|
| 183 |
-
plot, line_width=3, pixel_ratio=2
|
| 184 |
-
).opts(
|
| 185 |
tools=["hover"],
|
| 186 |
cmap=[color_key],
|
| 187 |
width=600,
|
|
@@ -192,9 +266,7 @@ def create_avg_powerspectrum_tab(
|
|
| 192 |
return plot
|
| 193 |
else:
|
| 194 |
if rasterize_checkbox.value:
|
| 195 |
-
return hd.rasterize(
|
| 196 |
-
plot, line_width=3, pixel_ratio=2
|
| 197 |
-
).opts(
|
| 198 |
tools=["hover"],
|
| 199 |
width=600,
|
| 200 |
height=600,
|
|
@@ -204,7 +276,23 @@ def create_avg_powerspectrum_tab(
|
|
| 204 |
else:
|
| 205 |
return plot
|
| 206 |
|
| 207 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
label = f"{title} (dt={dt}, norm={norm}, segment={segment_size})"
|
| 209 |
plot = hv.Curve((ps.freq, ps.power), label=label).opts(
|
| 210 |
xlabel="Frequency (Hz)",
|
|
@@ -216,9 +304,7 @@ def create_avg_powerspectrum_tab(
|
|
| 216 |
|
| 217 |
if color_key:
|
| 218 |
if rasterize_checkbox.value:
|
| 219 |
-
return hd.rasterize(
|
| 220 |
-
plot, line_width=3, pixel_ratio=2
|
| 221 |
-
).opts(
|
| 222 |
tools=["hover"],
|
| 223 |
cmap=[color_key],
|
| 224 |
width=600,
|
|
@@ -229,9 +315,7 @@ def create_avg_powerspectrum_tab(
|
|
| 229 |
return plot
|
| 230 |
else:
|
| 231 |
if rasterize_checkbox.value:
|
| 232 |
-
return hd.rasterize(
|
| 233 |
-
plot, line_width=3, pixel_ratio=2
|
| 234 |
-
).opts(
|
| 235 |
tools=["hover"],
|
| 236 |
width=600,
|
| 237 |
height=600,
|
|
@@ -243,7 +327,9 @@ def create_avg_powerspectrum_tab(
|
|
| 243 |
|
| 244 |
def create_dataframe_panes(df, title, dt, norm, segment_size):
|
| 245 |
return pn.FlexBox(
|
| 246 |
-
pn.pane.Markdown(
|
|
|
|
|
|
|
| 247 |
pn.pane.DataFrame(df, width=600, height=600),
|
| 248 |
align_items="center",
|
| 249 |
justify_content="center",
|
|
@@ -271,14 +357,14 @@ def create_avg_powerspectrum_tab(
|
|
| 271 |
df, ps = create_dataframe(selected_event_list_index, dt, norm, segment_size)
|
| 272 |
if df is not None:
|
| 273 |
plot_title = f"Averaged Power Spectrum for {loaded_event_data[selected_event_list_index][0]}"
|
| 274 |
-
plot_hv = create_holoviews_plots(
|
|
|
|
|
|
|
| 275 |
holoviews_output = create_holoviews_panes(plot_hv)
|
| 276 |
|
| 277 |
if floatpanel_plots_checkbox.value:
|
| 278 |
float_panel_container.append(
|
| 279 |
-
create_floatpanel_area(
|
| 280 |
-
content=holoviews_output, title=plot_title
|
| 281 |
-
)
|
| 282 |
)
|
| 283 |
else:
|
| 284 |
markdown_content = f"## {plot_title}"
|
|
@@ -293,11 +379,15 @@ def create_avg_powerspectrum_tab(
|
|
| 293 |
)
|
| 294 |
)
|
| 295 |
output_box_container[:] = [
|
| 296 |
-
create_loadingdata_output_box(
|
|
|
|
|
|
|
| 297 |
]
|
| 298 |
else:
|
| 299 |
output_box_container[:] = [
|
| 300 |
-
create_loadingdata_output_box(
|
|
|
|
|
|
|
| 301 |
]
|
| 302 |
|
| 303 |
def show_dataframe(event=None):
|
|
@@ -319,7 +409,13 @@ def create_avg_powerspectrum_tab(
|
|
| 319 |
segment_size = segment_size_input.value
|
| 320 |
df, ps = create_dataframe(selected_event_list_index, dt, norm, segment_size)
|
| 321 |
if df is not None:
|
| 322 |
-
dataframe_output = create_dataframe_panes(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 323 |
if dataframe_checkbox.value:
|
| 324 |
float_panel_container.append(
|
| 325 |
create_floatpanel_area(
|
|
@@ -355,7 +451,13 @@ def create_avg_powerspectrum_tab(
|
|
| 355 |
df, ps = create_dataframe(index, dt, norm, segment_size)
|
| 356 |
if df is not None:
|
| 357 |
event_list_name = loaded_event_data[index][0]
|
| 358 |
-
plot_hv = create_holoviews_plots_no_colorbar(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 359 |
combined_plots.append(plot_hv)
|
| 360 |
combined_title.append(event_list_name)
|
| 361 |
|
|
@@ -414,7 +516,9 @@ def create_avg_powerspectrum_tab(
|
|
| 414 |
floatpanel_plots_checkbox,
|
| 415 |
dataframe_checkbox,
|
| 416 |
rasterize_checkbox,
|
| 417 |
-
pn.Row(
|
|
|
|
|
|
|
| 418 |
)
|
| 419 |
return tab_content
|
| 420 |
|
|
|
|
| 19 |
from stingray import AveragedPowerspectrum
|
| 20 |
|
| 21 |
colors = [
|
| 22 |
+
"#1f77b4",
|
| 23 |
+
"#ff7f0e",
|
| 24 |
+
"#2ca02c",
|
| 25 |
+
"#d62728",
|
| 26 |
+
"#9467bd",
|
| 27 |
+
"#8c564b",
|
| 28 |
+
"#e377c2",
|
| 29 |
+
"#7f7f7f",
|
| 30 |
+
"#bcbd22",
|
| 31 |
+
"#17becf",
|
| 32 |
+
"#aec7e8",
|
| 33 |
+
"#ffbb78",
|
| 34 |
+
"#98df8a",
|
| 35 |
+
"#ff9896",
|
| 36 |
+
"#c5b0d5",
|
| 37 |
+
"#c49c94",
|
| 38 |
+
"#f7b6d2",
|
| 39 |
+
"#c7c7c7",
|
| 40 |
+
"#dbdb8d",
|
| 41 |
+
"#9edae5",
|
| 42 |
]
|
| 43 |
|
| 44 |
+
|
| 45 |
# Create a warning handler
|
| 46 |
def create_warning_handler():
|
| 47 |
warning_handler = WarningHandler()
|
|
|
|
| 50 |
|
| 51 |
|
| 52 |
""" Header Section """
|
| 53 |
+
|
| 54 |
+
|
| 55 |
def create_quicklook_avg_powerspectrum_header(
|
| 56 |
header_container,
|
| 57 |
main_area_container,
|
|
|
|
| 70 |
|
| 71 |
|
| 72 |
""" Output Box Section """
|
| 73 |
+
|
| 74 |
+
|
| 75 |
def create_loadingdata_output_box(content):
|
| 76 |
return OutputBox(output_content=content)
|
| 77 |
|
| 78 |
|
| 79 |
""" Warning Box Section """
|
| 80 |
+
|
| 81 |
+
|
| 82 |
def create_loadingdata_warning_box(content):
|
| 83 |
return WarningBox(warning_content=content)
|
| 84 |
|
| 85 |
|
| 86 |
""" Float Panel """
|
| 87 |
+
|
| 88 |
+
|
| 89 |
def create_floatpanel_area(content, title):
|
| 90 |
return FloatingPlot(content=content, title=title)
|
| 91 |
|
| 92 |
|
| 93 |
""" Main Area Section """
|
| 94 |
+
|
| 95 |
+
|
| 96 |
def create_avg_powerspectrum_tab(
|
| 97 |
output_box_container,
|
| 98 |
warning_box_container,
|
|
|
|
| 121 |
value="leahy",
|
| 122 |
)
|
| 123 |
|
| 124 |
+
segment_size_input = pn.widgets.FloatInput(name="Segment Size", value=10, step=1)
|
|
|
|
|
|
|
| 125 |
|
| 126 |
multi_event_select = pn.widgets.MultiSelect(
|
| 127 |
name="Or Select Event List(s) to Combine",
|
|
|
|
| 136 |
dataframe_checkbox = pn.widgets.Checkbox(
|
| 137 |
name="Add DataFrame to FloatingPanel", value=False
|
| 138 |
)
|
| 139 |
+
|
| 140 |
rasterize_checkbox = pn.widgets.Checkbox(name="Rasterize Plots", value=True)
|
| 141 |
|
| 142 |
+
# New Checkboxes for Rebinning
|
| 143 |
+
|
| 144 |
+
linear_rebin_checkbox = pn.widgets.Checkbox(name="Linear Rebinning", value=False)
|
| 145 |
+
|
| 146 |
+
log_rebin_checkbox = pn.widgets.Checkbox(name="Logarithmic Rebinning", value=False)
|
| 147 |
+
|
| 148 |
+
rebin_with_original_checkbox = pn.widgets.Checkbox(
|
| 149 |
+
name="Plot Rebin with Original", value=False
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
# Input for Rebin Size
|
| 153 |
+
|
| 154 |
+
rebin_size_input = pn.widgets.FloatInput(
|
| 155 |
+
name="Rebin Size",
|
| 156 |
+
value=0.1,
|
| 157 |
+
step=0.000001,
|
| 158 |
+
start=0.01,
|
| 159 |
+
end=1000.0,
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
time_info_pane = pn.pane.Markdown(
|
| 163 |
+
"Select an event list to see time range", width=600
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
# Update time info when an event list is selected
|
| 167 |
+
|
| 168 |
+
def update_time_info(event):
|
| 169 |
+
|
| 170 |
+
selected_index = event_list_dropdown.value
|
| 171 |
+
|
| 172 |
+
if selected_index is not None:
|
| 173 |
+
|
| 174 |
+
event_list_name = loaded_event_data[selected_index][0]
|
| 175 |
+
|
| 176 |
+
event_list = loaded_event_data[selected_index][1]
|
| 177 |
+
|
| 178 |
+
start_time = event_list.time[0]
|
| 179 |
+
|
| 180 |
+
end_time = event_list.time[-1]
|
| 181 |
+
|
| 182 |
+
time_info_pane.object = (
|
| 183 |
+
f"**Event List:** {event_list_name} \n"
|
| 184 |
+
f"**Start Time:** {start_time} \n"
|
| 185 |
+
f"**End Time:** {end_time}"
|
| 186 |
+
)
|
| 187 |
+
|
| 188 |
+
else:
|
| 189 |
+
|
| 190 |
+
time_info_pane.object = "Select an event list to see time range"
|
| 191 |
+
|
| 192 |
# Internal functions to encapsulate functionality
|
| 193 |
def create_dataframe(selected_event_list_index, dt, norm, segment_size):
|
| 194 |
if selected_event_list_index is not None:
|
|
|
|
| 235 |
create_loadingdata_output_box(
|
| 236 |
f"Error generating Averaged Power Spectrum: {e}. "
|
| 237 |
"Try using a different segment size."
|
| 238 |
+
)
|
| 239 |
+
]
|
| 240 |
return None, None
|
| 241 |
return None, None
|
| 242 |
|
|
|
|
| 255 |
|
| 256 |
if color_key:
|
| 257 |
if rasterize_checkbox.value:
|
| 258 |
+
return hd.rasterize(plot, line_width=3, pixel_ratio=2).opts(
|
|
|
|
|
|
|
| 259 |
tools=["hover"],
|
| 260 |
cmap=[color_key],
|
| 261 |
width=600,
|
|
|
|
| 266 |
return plot
|
| 267 |
else:
|
| 268 |
if rasterize_checkbox.value:
|
| 269 |
+
return hd.rasterize(plot, line_width=3, pixel_ratio=2).opts(
|
|
|
|
|
|
|
| 270 |
tools=["hover"],
|
| 271 |
width=600,
|
| 272 |
height=600,
|
|
|
|
| 276 |
else:
|
| 277 |
return plot
|
| 278 |
|
| 279 |
+
def rebin_powerspectrum(ps):
|
| 280 |
+
|
| 281 |
+
rebin_size = rebin_size_input.value
|
| 282 |
+
|
| 283 |
+
if linear_rebin_checkbox.value:
|
| 284 |
+
|
| 285 |
+
return ps.rebin(rebin_size, method="mean")
|
| 286 |
+
|
| 287 |
+
elif log_rebin_checkbox.value:
|
| 288 |
+
|
| 289 |
+
return ps.rebin_log(f=rebin_size)
|
| 290 |
+
|
| 291 |
+
return None
|
| 292 |
+
|
| 293 |
+
def create_holoviews_plots_no_colorbar(
|
| 294 |
+
ps, title, dt, norm, segment_size, color_key=None
|
| 295 |
+
):
|
| 296 |
label = f"{title} (dt={dt}, norm={norm}, segment={segment_size})"
|
| 297 |
plot = hv.Curve((ps.freq, ps.power), label=label).opts(
|
| 298 |
xlabel="Frequency (Hz)",
|
|
|
|
| 304 |
|
| 305 |
if color_key:
|
| 306 |
if rasterize_checkbox.value:
|
| 307 |
+
return hd.rasterize(plot, line_width=3, pixel_ratio=2).opts(
|
|
|
|
|
|
|
| 308 |
tools=["hover"],
|
| 309 |
cmap=[color_key],
|
| 310 |
width=600,
|
|
|
|
| 315 |
return plot
|
| 316 |
else:
|
| 317 |
if rasterize_checkbox.value:
|
| 318 |
+
return hd.rasterize(plot, line_width=3, pixel_ratio=2).opts(
|
|
|
|
|
|
|
| 319 |
tools=["hover"],
|
| 320 |
width=600,
|
| 321 |
height=600,
|
|
|
|
| 327 |
|
| 328 |
def create_dataframe_panes(df, title, dt, norm, segment_size):
|
| 329 |
return pn.FlexBox(
|
| 330 |
+
pn.pane.Markdown(
|
| 331 |
+
f"**{title} (dt={dt}, norm={norm}, segment={segment_size})**"
|
| 332 |
+
),
|
| 333 |
pn.pane.DataFrame(df, width=600, height=600),
|
| 334 |
align_items="center",
|
| 335 |
justify_content="center",
|
|
|
|
| 357 |
df, ps = create_dataframe(selected_event_list_index, dt, norm, segment_size)
|
| 358 |
if df is not None:
|
| 359 |
plot_title = f"Averaged Power Spectrum for {loaded_event_data[selected_event_list_index][0]}"
|
| 360 |
+
plot_hv = create_holoviews_plots(
|
| 361 |
+
ps, title=plot_title, dt=dt, norm=norm, segment_size=segment_size
|
| 362 |
+
)
|
| 363 |
holoviews_output = create_holoviews_panes(plot_hv)
|
| 364 |
|
| 365 |
if floatpanel_plots_checkbox.value:
|
| 366 |
float_panel_container.append(
|
| 367 |
+
create_floatpanel_area(content=holoviews_output, title=plot_title)
|
|
|
|
|
|
|
| 368 |
)
|
| 369 |
else:
|
| 370 |
markdown_content = f"## {plot_title}"
|
|
|
|
| 379 |
)
|
| 380 |
)
|
| 381 |
output_box_container[:] = [
|
| 382 |
+
create_loadingdata_output_box(
|
| 383 |
+
"Averaged Power Spectrum generated successfully."
|
| 384 |
+
)
|
| 385 |
]
|
| 386 |
else:
|
| 387 |
output_box_container[:] = [
|
| 388 |
+
create_loadingdata_output_box(
|
| 389 |
+
"Failed to create averaged power spectrum."
|
| 390 |
+
)
|
| 391 |
]
|
| 392 |
|
| 393 |
def show_dataframe(event=None):
|
|
|
|
| 409 |
segment_size = segment_size_input.value
|
| 410 |
df, ps = create_dataframe(selected_event_list_index, dt, norm, segment_size)
|
| 411 |
if df is not None:
|
| 412 |
+
dataframe_output = create_dataframe_panes(
|
| 413 |
+
df,
|
| 414 |
+
f"{loaded_event_data[selected_event_list_index][0]}",
|
| 415 |
+
dt,
|
| 416 |
+
norm,
|
| 417 |
+
segment_size,
|
| 418 |
+
)
|
| 419 |
if dataframe_checkbox.value:
|
| 420 |
float_panel_container.append(
|
| 421 |
create_floatpanel_area(
|
|
|
|
| 451 |
df, ps = create_dataframe(index, dt, norm, segment_size)
|
| 452 |
if df is not None:
|
| 453 |
event_list_name = loaded_event_data[index][0]
|
| 454 |
+
plot_hv = create_holoviews_plots_no_colorbar(
|
| 455 |
+
ps,
|
| 456 |
+
title=event_list_name,
|
| 457 |
+
dt=dt,
|
| 458 |
+
norm=norm,
|
| 459 |
+
segment_size=segment_size,
|
| 460 |
+
)
|
| 461 |
combined_plots.append(plot_hv)
|
| 462 |
combined_title.append(event_list_name)
|
| 463 |
|
|
|
|
| 516 |
floatpanel_plots_checkbox,
|
| 517 |
dataframe_checkbox,
|
| 518 |
rasterize_checkbox,
|
| 519 |
+
pn.Row(
|
| 520 |
+
generate_powerspectrum_button, show_dataframe_button, combine_plots_button
|
| 521 |
+
),
|
| 522 |
)
|
| 523 |
return tab_content
|
| 524 |
|
modules/QuickLook/LightCurve.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import panel as pn
|
| 2 |
import holoviews as hv
|
| 3 |
import holoviews.operation.datashader as hd
|
| 4 |
-
from holoviews.operation.timeseries import rolling, rolling_outlier_std
|
| 5 |
-
from utils.globals import loaded_event_data
|
| 6 |
import pandas as pd
|
| 7 |
import warnings
|
| 8 |
import hvplot.pandas
|
|
@@ -124,6 +124,35 @@ def create_lightcurve_tab(
|
|
| 124 |
)
|
| 125 |
rasterize_checkbox = pn.widgets.Checkbox(name="Rasterize Plots", value=True)
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
def create_holoviews_panes(plot):
|
| 128 |
return pn.pane.HoloViews(plot, width=600, height=600, linked_axes=False)
|
| 129 |
|
|
@@ -229,10 +258,38 @@ def create_lightcurve_tab(
|
|
| 229 |
flex_direction="column",
|
| 230 |
)
|
| 231 |
|
| 232 |
-
def create_dataframe(selected_event_list_index, dt):
|
| 233 |
if selected_event_list_index is not None:
|
| 234 |
event_list = loaded_event_data[selected_event_list_index][1]
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
|
| 237 |
df = pd.DataFrame(
|
| 238 |
{
|
|
@@ -296,7 +353,11 @@ def create_lightcurve_tab(
|
|
| 296 |
return
|
| 297 |
|
| 298 |
dt = dt_input.value
|
| 299 |
-
df = create_dataframe(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
if df is not None:
|
| 301 |
event_list_name = loaded_event_data[selected_event_list_index][0]
|
| 302 |
plot_hv = create_holoviews_plots(df, label=event_list_name, dt=dt)
|
|
@@ -396,13 +457,19 @@ def create_lightcurve_tab(
|
|
| 396 |
)
|
| 397 |
show_dataframe_button.on_click(show_dataframe)
|
| 398 |
|
|
|
|
|
|
|
|
|
|
| 399 |
tab1_content = pn.Column(
|
| 400 |
event_list_dropdown,
|
|
|
|
| 401 |
dt_input,
|
|
|
|
| 402 |
multi_event_select,
|
| 403 |
floatpanel_plots_checkbox,
|
| 404 |
dataframe_checkbox,
|
| 405 |
rasterize_checkbox,
|
|
|
|
| 406 |
pn.Row(generate_lightcurve_button, show_dataframe_button, combine_plots_button),
|
| 407 |
)
|
| 408 |
return tab1_content
|
|
|
|
| 1 |
import panel as pn
|
| 2 |
import holoviews as hv
|
| 3 |
import holoviews.operation.datashader as hd
|
| 4 |
+
from holoviews.operation.timeseries import rolling, rolling_outlier_std
|
| 5 |
+
from utils.globals import loaded_event_data, loaded_light_curve
|
| 6 |
import pandas as pd
|
| 7 |
import warnings
|
| 8 |
import hvplot.pandas
|
|
|
|
| 124 |
)
|
| 125 |
rasterize_checkbox = pn.widgets.Checkbox(name="Rasterize Plots", value=True)
|
| 126 |
|
| 127 |
+
save_lightcurve_checkbox = pn.widgets.Checkbox(
|
| 128 |
+
name="Save Generated Light Curve in RAM", value=False
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
time_info_pane = pn.pane.Markdown(
|
| 132 |
+
"Select an event list to see time range", width=600
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
gti_input = pn.widgets.TextInput(
|
| 136 |
+
name="Specify GTIs (Good Time Intervals)",
|
| 137 |
+
placeholder="e.g., 0 4; 6 10",
|
| 138 |
+
)
|
| 139 |
+
|
| 140 |
+
# Callback to update the time information
|
| 141 |
+
def update_time_info(event):
|
| 142 |
+
selected_index = event_list_dropdown.value
|
| 143 |
+
if selected_index is not None:
|
| 144 |
+
event_list_name = loaded_event_data[selected_index][0]
|
| 145 |
+
event_list = loaded_event_data[selected_index][1]
|
| 146 |
+
start_time = event_list.time[0]
|
| 147 |
+
end_time = event_list.time[-1]
|
| 148 |
+
time_info_pane.object = (
|
| 149 |
+
f"**Event List:** {event_list_name} \n"
|
| 150 |
+
f"**Start Time:** {start_time} \n"
|
| 151 |
+
f"**End Time:** {end_time}"
|
| 152 |
+
)
|
| 153 |
+
else:
|
| 154 |
+
time_info_pane.object = "Select an event list to see time range"
|
| 155 |
+
|
| 156 |
def create_holoviews_panes(plot):
|
| 157 |
return pn.pane.HoloViews(plot, width=600, height=600, linked_axes=False)
|
| 158 |
|
|
|
|
| 258 |
flex_direction="column",
|
| 259 |
)
|
| 260 |
|
| 261 |
+
def create_dataframe(selected_event_list_index, dt, eventlist_name):
|
| 262 |
if selected_event_list_index is not None:
|
| 263 |
event_list = loaded_event_data[selected_event_list_index][1]
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
# Parse GTIs from input if provided
|
| 267 |
+
gti = None
|
| 268 |
+
if gti_input.value:
|
| 269 |
+
try:
|
| 270 |
+
gti = [
|
| 271 |
+
[float(start), float(end)]
|
| 272 |
+
for start, end in (
|
| 273 |
+
interval.split() for interval in gti_input.value.split(";")
|
| 274 |
+
)
|
| 275 |
+
]
|
| 276 |
+
except ValueError:
|
| 277 |
+
output_box_container[:] = [
|
| 278 |
+
create_loadingdata_output_box("Invalid GTI format. Use 'start end; start end'.")
|
| 279 |
+
]
|
| 280 |
+
return None
|
| 281 |
+
|
| 282 |
+
if gti_input.value:
|
| 283 |
+
lc_new = event_list.to_lc(dt=dt).apply_gtis(gti)
|
| 284 |
+
else:
|
| 285 |
+
lc_new = event_list.to_lc(dt=dt)
|
| 286 |
+
|
| 287 |
+
|
| 288 |
+
lightcurve_name = f"{eventlist_name}_lightcurve"
|
| 289 |
+
|
| 290 |
+
# Append the generated light curve to loaded_light_curve if the checkbox is checked
|
| 291 |
+
if save_lightcurve_checkbox.value:
|
| 292 |
+
loaded_light_curve.append((lightcurve_name, lc_new))
|
| 293 |
|
| 294 |
df = pd.DataFrame(
|
| 295 |
{
|
|
|
|
| 353 |
return
|
| 354 |
|
| 355 |
dt = dt_input.value
|
| 356 |
+
df = create_dataframe(
|
| 357 |
+
selected_event_list_index,
|
| 358 |
+
dt,
|
| 359 |
+
loaded_event_data[selected_event_list_index][0],
|
| 360 |
+
)
|
| 361 |
if df is not None:
|
| 362 |
event_list_name = loaded_event_data[selected_event_list_index][0]
|
| 363 |
plot_hv = create_holoviews_plots(df, label=event_list_name, dt=dt)
|
|
|
|
| 457 |
)
|
| 458 |
show_dataframe_button.on_click(show_dataframe)
|
| 459 |
|
| 460 |
+
event_list_dropdown.param.watch(update_time_info, 'value')
|
| 461 |
+
|
| 462 |
+
|
| 463 |
tab1_content = pn.Column(
|
| 464 |
event_list_dropdown,
|
| 465 |
+
time_info_pane,
|
| 466 |
dt_input,
|
| 467 |
+
gti_input,
|
| 468 |
multi_event_select,
|
| 469 |
floatpanel_plots_checkbox,
|
| 470 |
dataframe_checkbox,
|
| 471 |
rasterize_checkbox,
|
| 472 |
+
save_lightcurve_checkbox,
|
| 473 |
pn.Row(generate_lightcurve_button, show_dataframe_button, combine_plots_button),
|
| 474 |
)
|
| 475 |
return tab1_content
|
modules/QuickLook/PowerSpectrum.py
CHANGED
|
@@ -115,6 +115,11 @@ def create_powerspectrum_tab(
|
|
| 115 |
)
|
| 116 |
|
| 117 |
rasterize_checkbox = pn.widgets.Checkbox(name="Rasterize Plots", value=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
# New Checkboxes for Rebinning
|
| 120 |
linear_rebin_checkbox = pn.widgets.Checkbox(name="Linear Rebinning", value=False)
|
|
@@ -125,11 +130,27 @@ def create_powerspectrum_tab(
|
|
| 125 |
rebin_size_input = pn.widgets.FloatInput(
|
| 126 |
name="Rebin Size",
|
| 127 |
value=0.1,
|
| 128 |
-
step=0.
|
| 129 |
start=0.01,
|
| 130 |
-
end=
|
| 131 |
)
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
def create_holoviews_panes(plot):
|
| 134 |
return pn.pane.HoloViews(plot, width=600, height=600, linked_axes=False)
|
| 135 |
|
|
@@ -443,8 +464,12 @@ def create_powerspectrum_tab(
|
|
| 443 |
)
|
| 444 |
show_dataframe_button.on_click(show_dataframe)
|
| 445 |
|
|
|
|
|
|
|
|
|
|
| 446 |
tab_content = pn.Column(
|
| 447 |
event_list_dropdown,
|
|
|
|
| 448 |
dt_input,
|
| 449 |
norm_select,
|
| 450 |
multi_event_select,
|
|
|
|
| 115 |
)
|
| 116 |
|
| 117 |
rasterize_checkbox = pn.widgets.Checkbox(name="Rasterize Plots", value=True)
|
| 118 |
+
|
| 119 |
+
time_info_pane = pn.pane.Markdown(
|
| 120 |
+
"Select an event list to see time range", width=600
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
|
| 124 |
# New Checkboxes for Rebinning
|
| 125 |
linear_rebin_checkbox = pn.widgets.Checkbox(name="Linear Rebinning", value=False)
|
|
|
|
| 130 |
rebin_size_input = pn.widgets.FloatInput(
|
| 131 |
name="Rebin Size",
|
| 132 |
value=0.1,
|
| 133 |
+
step=0.000001,
|
| 134 |
start=0.01,
|
| 135 |
+
end=1000.0,
|
| 136 |
)
|
| 137 |
|
| 138 |
+
def update_time_info(event):
|
| 139 |
+
selected_index = event_list_dropdown.value
|
| 140 |
+
if selected_index is not None:
|
| 141 |
+
event_list_name = loaded_event_data[selected_index][0]
|
| 142 |
+
event_list = loaded_event_data[selected_index][1]
|
| 143 |
+
start_time = event_list.time[0]
|
| 144 |
+
end_time = event_list.time[-1]
|
| 145 |
+
time_info_pane.object = (
|
| 146 |
+
f"**Event List:** {event_list_name} \n"
|
| 147 |
+
f"**Start Time:** {start_time} \n"
|
| 148 |
+
f"**End Time:** {end_time}"
|
| 149 |
+
)
|
| 150 |
+
else:
|
| 151 |
+
time_info_pane.object = "Select an event list to see time range"
|
| 152 |
+
|
| 153 |
+
|
| 154 |
def create_holoviews_panes(plot):
|
| 155 |
return pn.pane.HoloViews(plot, width=600, height=600, linked_axes=False)
|
| 156 |
|
|
|
|
| 464 |
)
|
| 465 |
show_dataframe_button.on_click(show_dataframe)
|
| 466 |
|
| 467 |
+
event_list_dropdown.param.watch(update_time_info, 'value')
|
| 468 |
+
|
| 469 |
+
|
| 470 |
tab_content = pn.Column(
|
| 471 |
event_list_dropdown,
|
| 472 |
+
time_info_pane,
|
| 473 |
dt_input,
|
| 474 |
norm_select,
|
| 475 |
multi_event_select,
|
utils/globals.py
CHANGED
|
@@ -1,2 +1,3 @@
|
|
| 1 |
# Global variable to store loaded event data
|
| 2 |
loaded_event_data = []
|
|
|
|
|
|
| 1 |
# Global variable to store loaded event data
|
| 2 |
loaded_event_data = []
|
| 3 |
+
loaded_light_curve = []
|