Spaces:
Running
Running
Commit ·
ce6dda4
1
Parent(s): c0810ea
add power colors
Browse files- modules/QuickLook/AveragePowerSpectrum.py +88 -25
- modules/QuickLook/LightCurve.py +97 -12
- modules/QuickLook/PowerColors.py +137 -0
- modules/QuickLook/PowerSpectrum.py +151 -42
- utils/sidebar.py +34 -2
modules/QuickLook/AveragePowerSpectrum.py
CHANGED
|
@@ -4,6 +4,7 @@ from utils.globals import loaded_event_data
|
|
| 4 |
import pandas as pd
|
| 5 |
import warnings
|
| 6 |
import hvplot.pandas
|
|
|
|
| 7 |
from utils.DashboardClasses import (
|
| 8 |
MainHeader,
|
| 9 |
MainArea,
|
|
@@ -17,6 +18,12 @@ from utils.DashboardClasses import (
|
|
| 17 |
)
|
| 18 |
from stingray import AveragedPowerspectrum
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Create a warning handler
|
| 22 |
def create_warning_handler():
|
|
@@ -26,8 +33,6 @@ def create_warning_handler():
|
|
| 26 |
|
| 27 |
|
| 28 |
""" Header Section """
|
| 29 |
-
|
| 30 |
-
|
| 31 |
def create_quicklook_avg_powerspectrum_header(
|
| 32 |
header_container,
|
| 33 |
main_area_container,
|
|
@@ -46,29 +51,21 @@ def create_quicklook_avg_powerspectrum_header(
|
|
| 46 |
|
| 47 |
|
| 48 |
""" Output Box Section """
|
| 49 |
-
|
| 50 |
-
|
| 51 |
def create_loadingdata_output_box(content):
|
| 52 |
return OutputBox(output_content=content)
|
| 53 |
|
| 54 |
|
| 55 |
""" Warning Box Section """
|
| 56 |
-
|
| 57 |
-
|
| 58 |
def create_loadingdata_warning_box(content):
|
| 59 |
return WarningBox(warning_content=content)
|
| 60 |
|
| 61 |
|
| 62 |
""" Float Panel """
|
| 63 |
-
|
| 64 |
-
|
| 65 |
def create_floatpanel_area(content, title):
|
| 66 |
return FloatingPlot(content=content, title=title)
|
| 67 |
|
| 68 |
|
| 69 |
""" Main Area Section """
|
| 70 |
-
|
| 71 |
-
|
| 72 |
def create_avg_powerspectrum_tab(
|
| 73 |
output_box_container,
|
| 74 |
warning_box_container,
|
|
@@ -83,12 +80,12 @@ def create_avg_powerspectrum_tab(
|
|
| 83 |
options={name: i for i, (name, event) in enumerate(loaded_event_data)},
|
| 84 |
)
|
| 85 |
|
| 86 |
-
|
| 87 |
name="Select dt",
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
)
|
| 93 |
|
| 94 |
norm_select = pn.widgets.Select(
|
|
@@ -108,12 +105,14 @@ def create_avg_powerspectrum_tab(
|
|
| 108 |
)
|
| 109 |
|
| 110 |
floatpanel_plots_checkbox = pn.widgets.Checkbox(
|
| 111 |
-
name="Add Plot to FloatingPanel", value=
|
| 112 |
)
|
| 113 |
|
| 114 |
dataframe_checkbox = pn.widgets.Checkbox(
|
| 115 |
name="Add DataFrame to FloatingPanel", value=False
|
| 116 |
)
|
|
|
|
|
|
|
| 117 |
|
| 118 |
# Internal functions to encapsulate functionality
|
| 119 |
def create_dataframe(selected_event_list_index, dt, norm, segment_size):
|
|
@@ -168,17 +167,80 @@ def create_avg_powerspectrum_tab(
|
|
| 168 |
def create_holoviews_panes(plot):
|
| 169 |
return pn.pane.HoloViews(plot, width=600, height=600)
|
| 170 |
|
| 171 |
-
def create_holoviews_plots(ps, title, dt, norm, segment_size):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
label = f"{title} (dt={dt}, norm={norm}, segment={segment_size})"
|
| 173 |
-
|
| 174 |
xlabel="Frequency (Hz)",
|
| 175 |
ylabel="Power",
|
| 176 |
-
title=f"{title} (dt={dt}, norm={norm}, segment={segment_size})",
|
| 177 |
width=600,
|
| 178 |
height=600,
|
| 179 |
shared_axes=False,
|
| 180 |
)
|
| 181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
def create_dataframe_panes(df, title, dt, norm, segment_size):
|
| 183 |
return pn.FlexBox(
|
| 184 |
pn.pane.Markdown(f"**{title} (dt={dt}, norm={norm}, segment={segment_size})**"),
|
|
@@ -203,7 +265,7 @@ def create_avg_powerspectrum_tab(
|
|
| 203 |
]
|
| 204 |
return
|
| 205 |
|
| 206 |
-
dt =
|
| 207 |
norm = norm_select.value
|
| 208 |
segment_size = segment_size_input.value
|
| 209 |
df, ps = create_dataframe(selected_event_list_index, dt, norm, segment_size)
|
|
@@ -252,7 +314,7 @@ def create_avg_powerspectrum_tab(
|
|
| 252 |
]
|
| 253 |
return
|
| 254 |
|
| 255 |
-
dt =
|
| 256 |
norm = norm_select.value
|
| 257 |
segment_size = segment_size_input.value
|
| 258 |
df, ps = create_dataframe(selected_event_list_index, dt, norm, segment_size)
|
|
@@ -262,7 +324,7 @@ def create_avg_powerspectrum_tab(
|
|
| 262 |
float_panel_container.append(
|
| 263 |
create_floatpanel_area(
|
| 264 |
content=dataframe_output,
|
| 265 |
-
title=f"DataFrame for {
|
| 266 |
)
|
| 267 |
)
|
| 268 |
else:
|
|
@@ -287,13 +349,13 @@ def create_avg_powerspectrum_tab(
|
|
| 287 |
combined_title = []
|
| 288 |
|
| 289 |
for index in selected_event_list_indices:
|
| 290 |
-
dt =
|
| 291 |
norm = norm_select.value
|
| 292 |
segment_size = segment_size_input.value
|
| 293 |
df, ps = create_dataframe(index, dt, norm, segment_size)
|
| 294 |
if df is not None:
|
| 295 |
event_list_name = loaded_event_data[index][0]
|
| 296 |
-
plot_hv =
|
| 297 |
combined_plots.append(plot_hv)
|
| 298 |
combined_title.append(event_list_name)
|
| 299 |
|
|
@@ -345,12 +407,13 @@ def create_avg_powerspectrum_tab(
|
|
| 345 |
|
| 346 |
tab_content = pn.Column(
|
| 347 |
event_list_dropdown,
|
| 348 |
-
|
| 349 |
norm_select,
|
| 350 |
segment_size_input,
|
| 351 |
multi_event_select,
|
| 352 |
floatpanel_plots_checkbox,
|
| 353 |
dataframe_checkbox,
|
|
|
|
| 354 |
pn.Row(generate_powerspectrum_button, show_dataframe_button, combine_plots_button),
|
| 355 |
)
|
| 356 |
return tab_content
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
import warnings
|
| 6 |
import hvplot.pandas
|
| 7 |
+
import holoviews.operation.datashader as hd
|
| 8 |
from utils.DashboardClasses import (
|
| 9 |
MainHeader,
|
| 10 |
MainArea,
|
|
|
|
| 18 |
)
|
| 19 |
from stingray import AveragedPowerspectrum
|
| 20 |
|
| 21 |
+
colors = [
|
| 22 |
+
"#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd", "#8c564b",
|
| 23 |
+
"#e377c2", "#7f7f7f", "#bcbd22", "#17becf", "#aec7e8", "#ffbb78",
|
| 24 |
+
"#98df8a", "#ff9896", "#c5b0d5", "#c49c94", "#f7b6d2", "#c7c7c7",
|
| 25 |
+
"#dbdb8d", "#9edae5"
|
| 26 |
+
]
|
| 27 |
|
| 28 |
# Create a warning handler
|
| 29 |
def create_warning_handler():
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
""" Header Section """
|
|
|
|
|
|
|
| 36 |
def create_quicklook_avg_powerspectrum_header(
|
| 37 |
header_container,
|
| 38 |
main_area_container,
|
|
|
|
| 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,
|
|
|
|
| 80 |
options={name: i for i, (name, event) in enumerate(loaded_event_data)},
|
| 81 |
)
|
| 82 |
|
| 83 |
+
dt_input = pn.widgets.FloatInput(
|
| 84 |
name="Select dt",
|
| 85 |
+
value=1.0,
|
| 86 |
+
step=0.0001,
|
| 87 |
+
start=0.0000000001,
|
| 88 |
+
end=1000.0,
|
| 89 |
)
|
| 90 |
|
| 91 |
norm_select = pn.widgets.Select(
|
|
|
|
| 105 |
)
|
| 106 |
|
| 107 |
floatpanel_plots_checkbox = pn.widgets.Checkbox(
|
| 108 |
+
name="Add Plot to FloatingPanel", value=True
|
| 109 |
)
|
| 110 |
|
| 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):
|
|
|
|
| 167 |
def create_holoviews_panes(plot):
|
| 168 |
return pn.pane.HoloViews(plot, width=600, height=600)
|
| 169 |
|
| 170 |
+
def create_holoviews_plots(ps, title, dt, norm, segment_size, color_key=None):
|
| 171 |
+
label = f"{title} (dt={dt}, norm={norm}, segment={segment_size})"
|
| 172 |
+
plot = hv.Curve((ps.freq, ps.power), label=label).opts(
|
| 173 |
+
xlabel="Frequency (Hz)",
|
| 174 |
+
ylabel="Power",
|
| 175 |
+
width=600,
|
| 176 |
+
height=600,
|
| 177 |
+
shared_axes=False,
|
| 178 |
+
)
|
| 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,
|
| 188 |
+
height=600,
|
| 189 |
+
colorbar=True,
|
| 190 |
+
)
|
| 191 |
+
else:
|
| 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,
|
| 201 |
+
colorbar=True,
|
| 202 |
+
cmap="Viridis",
|
| 203 |
+
)
|
| 204 |
+
else:
|
| 205 |
+
return plot
|
| 206 |
+
|
| 207 |
+
def create_holoviews_plots_no_colorbar(ps, title, dt, norm, segment_size, color_key=None):
|
| 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)",
|
| 211 |
ylabel="Power",
|
|
|
|
| 212 |
width=600,
|
| 213 |
height=600,
|
| 214 |
shared_axes=False,
|
| 215 |
)
|
| 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,
|
| 225 |
+
height=600,
|
| 226 |
+
colorbar=False,
|
| 227 |
+
)
|
| 228 |
+
else:
|
| 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,
|
| 238 |
+
colorbar=False,
|
| 239 |
+
cmap="Viridis",
|
| 240 |
+
)
|
| 241 |
+
else:
|
| 242 |
+
return plot
|
| 243 |
+
|
| 244 |
def create_dataframe_panes(df, title, dt, norm, segment_size):
|
| 245 |
return pn.FlexBox(
|
| 246 |
pn.pane.Markdown(f"**{title} (dt={dt}, norm={norm}, segment={segment_size})**"),
|
|
|
|
| 265 |
]
|
| 266 |
return
|
| 267 |
|
| 268 |
+
dt = dt_input.value
|
| 269 |
norm = norm_select.value
|
| 270 |
segment_size = segment_size_input.value
|
| 271 |
df, ps = create_dataframe(selected_event_list_index, dt, norm, segment_size)
|
|
|
|
| 314 |
]
|
| 315 |
return
|
| 316 |
|
| 317 |
+
dt = dt_input.value
|
| 318 |
norm = norm_select.value
|
| 319 |
segment_size = segment_size_input.value
|
| 320 |
df, ps = create_dataframe(selected_event_list_index, dt, norm, segment_size)
|
|
|
|
| 324 |
float_panel_container.append(
|
| 325 |
create_floatpanel_area(
|
| 326 |
content=dataframe_output,
|
| 327 |
+
title=f"DataFrame for {loaded_event_list[selected_event_list_index][0]}",
|
| 328 |
)
|
| 329 |
)
|
| 330 |
else:
|
|
|
|
| 349 |
combined_title = []
|
| 350 |
|
| 351 |
for index in selected_event_list_indices:
|
| 352 |
+
dt = dt_input.value
|
| 353 |
norm = norm_select.value
|
| 354 |
segment_size = segment_size_input.value
|
| 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(ps, title=event_list_name, dt=dt, norm=norm, segment_size=segment_size)
|
| 359 |
combined_plots.append(plot_hv)
|
| 360 |
combined_title.append(event_list_name)
|
| 361 |
|
|
|
|
| 407 |
|
| 408 |
tab_content = pn.Column(
|
| 409 |
event_list_dropdown,
|
| 410 |
+
dt_input,
|
| 411 |
norm_select,
|
| 412 |
segment_size_input,
|
| 413 |
multi_event_select,
|
| 414 |
floatpanel_plots_checkbox,
|
| 415 |
dataframe_checkbox,
|
| 416 |
+
rasterize_checkbox,
|
| 417 |
pn.Row(generate_powerspectrum_button, show_dataframe_button, combine_plots_button),
|
| 418 |
)
|
| 419 |
return tab_content
|
modules/QuickLook/LightCurve.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import panel as pn
|
| 2 |
import holoviews as hv
|
| 3 |
import holoviews.operation.datashader as hd
|
|
|
|
| 4 |
from utils.globals import loaded_event_data
|
| 5 |
import pandas as pd
|
| 6 |
import warnings
|
|
@@ -115,28 +116,108 @@ def create_lightcurve_tab(
|
|
| 115 |
)
|
| 116 |
|
| 117 |
floatpanel_plots_checkbox = pn.widgets.Checkbox(
|
| 118 |
-
name="Add Plot to FloatingPanel", value=
|
| 119 |
)
|
| 120 |
|
| 121 |
dataframe_checkbox = pn.widgets.Checkbox(
|
| 122 |
name="Add DataFrame to FloatingPanel", value=False
|
| 123 |
)
|
|
|
|
| 124 |
|
| 125 |
def create_holoviews_panes(plot):
|
| 126 |
return pn.pane.HoloViews(plot, width=600, height=600, linked_axes=False)
|
| 127 |
|
| 128 |
def create_holoviews_plots(df, label, dt, color_key=None):
|
|
|
|
| 129 |
plot = df.hvplot(
|
| 130 |
x="Time", y="Counts", shared_axes=False, label=f"{label} (dt={dt})"
|
| 131 |
)
|
|
|
|
| 132 |
if color_key:
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 136 |
else:
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
def create_dataframe_panes(df, title, dt):
|
| 142 |
return pn.FlexBox(
|
|
@@ -256,7 +337,8 @@ def create_lightcurve_tab(
|
|
| 256 |
|
| 257 |
# Define a color key for distinct colors
|
| 258 |
color_key = {
|
| 259 |
-
index: colors[i % len(colors)]
|
|
|
|
| 260 |
}
|
| 261 |
|
| 262 |
for index in selected_event_list_indices:
|
|
@@ -264,7 +346,7 @@ def create_lightcurve_tab(
|
|
| 264 |
df = create_dataframe(index, dt)
|
| 265 |
if df is not None:
|
| 266 |
event_list_name = loaded_event_data[index][0]
|
| 267 |
-
plot_hv =
|
| 268 |
df, label=event_list_name, dt=dt, color_key=color_key[index]
|
| 269 |
)
|
| 270 |
combined_plots.append(plot_hv)
|
|
@@ -272,9 +354,11 @@ def create_lightcurve_tab(
|
|
| 272 |
|
| 273 |
if combined_plots:
|
| 274 |
# Use hv.Overlay and add legend manually
|
| 275 |
-
combined_plot =
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
| 278 |
|
| 279 |
combined_pane = create_holoviews_panes(combined_plot)
|
| 280 |
|
|
@@ -318,6 +402,7 @@ def create_lightcurve_tab(
|
|
| 318 |
multi_event_select,
|
| 319 |
floatpanel_plots_checkbox,
|
| 320 |
dataframe_checkbox,
|
|
|
|
| 321 |
pn.Row(generate_lightcurve_button, show_dataframe_button, combine_plots_button),
|
| 322 |
)
|
| 323 |
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
|
| 6 |
import pandas as pd
|
| 7 |
import warnings
|
|
|
|
| 116 |
)
|
| 117 |
|
| 118 |
floatpanel_plots_checkbox = pn.widgets.Checkbox(
|
| 119 |
+
name="Add Plot to FloatingPanel", value=True
|
| 120 |
)
|
| 121 |
|
| 122 |
dataframe_checkbox = pn.widgets.Checkbox(
|
| 123 |
name="Add DataFrame to FloatingPanel", value=False
|
| 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 |
|
| 130 |
def create_holoviews_plots(df, label, dt, color_key=None):
|
| 131 |
+
|
| 132 |
plot = df.hvplot(
|
| 133 |
x="Time", y="Counts", shared_axes=False, label=f"{label} (dt={dt})"
|
| 134 |
)
|
| 135 |
+
|
| 136 |
if color_key:
|
| 137 |
+
|
| 138 |
+
if rasterize_checkbox.value:
|
| 139 |
+
|
| 140 |
+
return hd.rasterize(
|
| 141 |
+
plot,
|
| 142 |
+
aggregator=hd.ds.mean("Counts"),
|
| 143 |
+
color_key=color_key,
|
| 144 |
+
line_width=3,
|
| 145 |
+
pixel_ratio=2,
|
| 146 |
+
).opts(
|
| 147 |
+
tools=["hover"],
|
| 148 |
+
cmap=[color_key],
|
| 149 |
+
width=600,
|
| 150 |
+
height=600,
|
| 151 |
+
colorbar=True,
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
else:
|
| 155 |
+
|
| 156 |
+
return plot
|
| 157 |
+
|
| 158 |
else:
|
| 159 |
+
|
| 160 |
+
if rasterize_checkbox.value:
|
| 161 |
+
|
| 162 |
+
return hd.rasterize(
|
| 163 |
+
plot, aggregator=hd.ds.mean("Counts"), line_width=3, pixel_ratio=2
|
| 164 |
+
).opts(
|
| 165 |
+
tools=["hover"],
|
| 166 |
+
width=600,
|
| 167 |
+
height=600,
|
| 168 |
+
colorbar=True,
|
| 169 |
+
cmap="Viridis",
|
| 170 |
+
)
|
| 171 |
+
|
| 172 |
+
else:
|
| 173 |
+
|
| 174 |
+
return plot
|
| 175 |
+
|
| 176 |
+
def create_holoviews_plots_no_colorbar(df, label, dt, color_key=None):
|
| 177 |
+
|
| 178 |
+
plot = df.hvplot(
|
| 179 |
+
x="Time", y="Counts", shared_axes=False, label=f"{label} (dt={dt})"
|
| 180 |
+
)
|
| 181 |
+
|
| 182 |
+
if color_key:
|
| 183 |
+
|
| 184 |
+
if rasterize_checkbox.value:
|
| 185 |
+
|
| 186 |
+
return hd.rasterize(
|
| 187 |
+
plot,
|
| 188 |
+
aggregator=hd.ds.mean("Counts"),
|
| 189 |
+
color_key=color_key,
|
| 190 |
+
line_width=3,
|
| 191 |
+
pixel_ratio=2,
|
| 192 |
+
).opts(
|
| 193 |
+
tools=["hover"],
|
| 194 |
+
cmap=[color_key],
|
| 195 |
+
width=600,
|
| 196 |
+
height=600,
|
| 197 |
+
colorbar=False,
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
else:
|
| 201 |
+
|
| 202 |
+
return plot
|
| 203 |
+
|
| 204 |
+
else:
|
| 205 |
+
|
| 206 |
+
if rasterize_checkbox.value:
|
| 207 |
+
|
| 208 |
+
return hd.rasterize(
|
| 209 |
+
plot, aggregator=hd.ds.mean("Counts"), line_width=3, pixel_ratio=2
|
| 210 |
+
).opts(
|
| 211 |
+
tools=["hover"],
|
| 212 |
+
width=600,
|
| 213 |
+
height=600,
|
| 214 |
+
colorbar=False,
|
| 215 |
+
cmap="Viridis",
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
else:
|
| 219 |
+
|
| 220 |
+
return plot
|
| 221 |
|
| 222 |
def create_dataframe_panes(df, title, dt):
|
| 223 |
return pn.FlexBox(
|
|
|
|
| 337 |
|
| 338 |
# Define a color key for distinct colors
|
| 339 |
color_key = {
|
| 340 |
+
index: colors[i % len(colors)]
|
| 341 |
+
for i, index in enumerate(selected_event_list_indices)
|
| 342 |
}
|
| 343 |
|
| 344 |
for index in selected_event_list_indices:
|
|
|
|
| 346 |
df = create_dataframe(index, dt)
|
| 347 |
if df is not None:
|
| 348 |
event_list_name = loaded_event_data[index][0]
|
| 349 |
+
plot_hv = create_holoviews_plots_no_colorbar(
|
| 350 |
df, label=event_list_name, dt=dt, color_key=color_key[index]
|
| 351 |
)
|
| 352 |
combined_plots.append(plot_hv)
|
|
|
|
| 354 |
|
| 355 |
if combined_plots:
|
| 356 |
# Use hv.Overlay and add legend manually
|
| 357 |
+
combined_plot = (
|
| 358 |
+
hv.Overlay(combined_plots)
|
| 359 |
+
.opts(shared_axes=False, legend_position="right", width=600, height=600)
|
| 360 |
+
.collate()
|
| 361 |
+
)
|
| 362 |
|
| 363 |
combined_pane = create_holoviews_panes(combined_plot)
|
| 364 |
|
|
|
|
| 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
|
modules/QuickLook/PowerColors.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import panel as pn
|
| 2 |
+
import holoviews as hv
|
| 3 |
+
from stingray import DynamicalPowerspectrum
|
| 4 |
+
from stingray.power_colors import (
|
| 5 |
+
hue_from_power_color,
|
| 6 |
+
plot_power_colors,
|
| 7 |
+
plot_hues,
|
| 8 |
+
DEFAULT_COLOR_CONFIGURATION,
|
| 9 |
+
)
|
| 10 |
+
from utils.globals import loaded_event_data
|
| 11 |
+
import warnings
|
| 12 |
+
from utils.DashboardClasses import (
|
| 13 |
+
MainHeader,
|
| 14 |
+
MainArea,
|
| 15 |
+
OutputBox,
|
| 16 |
+
WarningBox,
|
| 17 |
+
HelpBox,
|
| 18 |
+
Footer,
|
| 19 |
+
WarningHandler,
|
| 20 |
+
FloatingPlot,
|
| 21 |
+
PlotsContainer,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
# Create a warning handler
|
| 25 |
+
def create_warning_handler():
|
| 26 |
+
warning_handler = WarningHandler()
|
| 27 |
+
warnings.showwarning = warning_handler.warn
|
| 28 |
+
return warning_handler
|
| 29 |
+
|
| 30 |
+
""" Header Section """
|
| 31 |
+
def create_quicklook_powercolors_header(
|
| 32 |
+
header_container, main_area_container, output_box_container, warning_box_container, plots_container, help_box_container, footer_container, float_panel_container
|
| 33 |
+
):
|
| 34 |
+
header_input = pn.widgets.TextInput(name="Heading", value="QuickLook Power Colors")
|
| 35 |
+
return MainHeader(heading=header_input)
|
| 36 |
+
|
| 37 |
+
""" Output Box Section """
|
| 38 |
+
def create_loadingdata_output_box(content):
|
| 39 |
+
return OutputBox(output_content=content)
|
| 40 |
+
|
| 41 |
+
""" Warning Box Section """
|
| 42 |
+
def create_loadingdata_warning_box(content):
|
| 43 |
+
return WarningBox(warning_content=content)
|
| 44 |
+
|
| 45 |
+
""" Main Area Section """
|
| 46 |
+
def create_powercolors_tab(output_box_container, warning_box_container, warning_handler, plots_container, header_container, float_panel_container):
|
| 47 |
+
event_list_dropdown = pn.widgets.Select(
|
| 48 |
+
name="Select Event List(s)",
|
| 49 |
+
options={name: i for i, (name, event) in enumerate(loaded_event_data)},
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
segment_size_input = pn.widgets.IntInput(name="Segment Size", value=256, step=1)
|
| 53 |
+
|
| 54 |
+
def create_holoviews_panes(plot):
|
| 55 |
+
return pn.pane.HoloViews(plot, width=600, height=600, linked_axes=False)
|
| 56 |
+
|
| 57 |
+
def generate_powercolors(event=None):
|
| 58 |
+
if not loaded_event_data:
|
| 59 |
+
output_box_container[:] = [pn.pane.Markdown("No loaded event data available.")]
|
| 60 |
+
return
|
| 61 |
+
|
| 62 |
+
selected_event_list_index = event_list_dropdown.value
|
| 63 |
+
if selected_event_list_index is None:
|
| 64 |
+
output_box_container[:] = [pn.pane.Markdown("No event list selected.")]
|
| 65 |
+
return
|
| 66 |
+
|
| 67 |
+
# Convert EventList to LightCurve
|
| 68 |
+
event_list = loaded_event_data[selected_event_list_index][1]
|
| 69 |
+
lightcurve = event_list.to_lc(dt=1 / 256) # Adjust dt value as needed
|
| 70 |
+
|
| 71 |
+
segment_size = segment_size_input.value
|
| 72 |
+
dynps = DynamicalPowerspectrum(
|
| 73 |
+
data=lightcurve,
|
| 74 |
+
segment_size=segment_size,
|
| 75 |
+
sample_time=1 / segment_size,
|
| 76 |
+
norm="leahy",
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
dynps_reb = dynps.rebin_by_n_intervals(2, method="average")
|
| 80 |
+
|
| 81 |
+
# Calculate power colors
|
| 82 |
+
p1, p1e, p2, p2e = dynps_reb.power_colors(
|
| 83 |
+
freq_edges=[1 / 256, 1 / 32, 0.25, 2, 16]
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
# Calculate hues from power colors
|
| 87 |
+
hues = hue_from_power_color(p1, p2)
|
| 88 |
+
|
| 89 |
+
# Plot power colors
|
| 90 |
+
configuration = DEFAULT_COLOR_CONFIGURATION
|
| 91 |
+
power_colors_plot = plot_power_colors(p1, p1e, p2, p2e, plot_spans=True, configuration=configuration)
|
| 92 |
+
hues_plot = plot_hues(hues, p1, p2, plot_spans=True, configuration=configuration)
|
| 93 |
+
|
| 94 |
+
# Create HoloViews pane for display
|
| 95 |
+
power_colors_hv = create_holoviews_panes(power_colors_plot)
|
| 96 |
+
hues_hv = create_holoviews_panes(hues_plot)
|
| 97 |
+
|
| 98 |
+
# Add to floating panel or main area
|
| 99 |
+
float_panel_container.append(
|
| 100 |
+
FloatingPlot(title="Power Colors", content=power_colors_hv)
|
| 101 |
+
)
|
| 102 |
+
plots_container.append(hues_hv)
|
| 103 |
+
|
| 104 |
+
generate_powercolors_button = pn.widgets.Button(name="Generate Power Colors", button_type="primary")
|
| 105 |
+
generate_powercolors_button.on_click(generate_powercolors)
|
| 106 |
+
|
| 107 |
+
tab_content = pn.Column(
|
| 108 |
+
event_list_dropdown,
|
| 109 |
+
segment_size_input,
|
| 110 |
+
pn.Row(generate_powercolors_button),
|
| 111 |
+
)
|
| 112 |
+
return tab_content
|
| 113 |
+
|
| 114 |
+
def create_quicklook_powercolors_main_area(
|
| 115 |
+
header_container, main_area_container, output_box_container, warning_box_container, plots_container, help_box_container, footer_container, float_panel_container
|
| 116 |
+
):
|
| 117 |
+
warning_handler = create_warning_handler()
|
| 118 |
+
tabs_content = {
|
| 119 |
+
"Power Colors": create_powercolors_tab(
|
| 120 |
+
output_box_container=output_box_container,
|
| 121 |
+
warning_box_container=warning_box_container,
|
| 122 |
+
warning_handler=warning_handler,
|
| 123 |
+
plots_container=plots_container,
|
| 124 |
+
header_container=header_container,
|
| 125 |
+
float_panel_container=float_panel_container,
|
| 126 |
+
),
|
| 127 |
+
}
|
| 128 |
+
return MainArea(tabs_content=tabs_content)
|
| 129 |
+
|
| 130 |
+
def create_quicklook_powercolors_area():
|
| 131 |
+
"""
|
| 132 |
+
Create the plots area for the quicklook power colors tab.
|
| 133 |
+
|
| 134 |
+
Returns:
|
| 135 |
+
PlotsContainer: An instance of PlotsContainer with the plots for the quicklook power colors tab.
|
| 136 |
+
"""
|
| 137 |
+
return PlotsContainer()
|
modules/QuickLook/PowerSpectrum.py
CHANGED
|
@@ -42,17 +42,13 @@ colors = [
|
|
| 42 |
"#9edae5",
|
| 43 |
]
|
| 44 |
|
| 45 |
-
|
| 46 |
# Create a warning handler
|
| 47 |
def create_warning_handler():
|
| 48 |
warning_handler = WarningHandler()
|
| 49 |
warnings.showwarning = warning_handler.warn
|
| 50 |
return warning_handler
|
| 51 |
|
| 52 |
-
|
| 53 |
""" Header Section """
|
| 54 |
-
|
| 55 |
-
|
| 56 |
def create_quicklook_powerspectrum_header(
|
| 57 |
header_container,
|
| 58 |
main_area_container,
|
|
@@ -66,30 +62,17 @@ def create_quicklook_powerspectrum_header(
|
|
| 66 |
name="Heading", value="QuickLook Power Spectrum"
|
| 67 |
)
|
| 68 |
home_subheading_input = pn.widgets.TextInput(name="Subheading", value="")
|
| 69 |
-
|
| 70 |
return MainHeader(heading=home_heading_input, subheading=home_subheading_input)
|
| 71 |
|
| 72 |
-
|
| 73 |
""" Output Box Section """
|
| 74 |
-
|
| 75 |
-
|
| 76 |
def create_loadingdata_output_box(content):
|
| 77 |
return OutputBox(output_content=content)
|
| 78 |
|
| 79 |
-
|
| 80 |
""" Warning Box Section """
|
| 81 |
-
|
| 82 |
-
|
| 83 |
def create_loadingdata_warning_box(content):
|
| 84 |
return WarningBox(warning_content=content)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
""" Main Area Section """
|
| 91 |
-
|
| 92 |
-
|
| 93 |
def create_powerspectrum_tab(
|
| 94 |
output_box_container,
|
| 95 |
warning_box_container,
|
|
@@ -124,23 +107,105 @@ def create_powerspectrum_tab(
|
|
| 124 |
)
|
| 125 |
|
| 126 |
floatpanel_plots_checkbox = pn.widgets.Checkbox(
|
| 127 |
-
name="Add Plot to FloatingPanel", value=
|
| 128 |
)
|
| 129 |
|
| 130 |
dataframe_checkbox = pn.widgets.Checkbox(
|
| 131 |
name="Add DataFrame to FloatingPanel", value=False
|
| 132 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
def create_holoviews_panes(plot):
|
| 135 |
return pn.pane.HoloViews(plot, width=600, height=600, linked_axes=False)
|
| 136 |
|
| 137 |
def create_holoviews_plots(df, label, dt, norm, color_key=None):
|
| 138 |
plot = df.hvplot(x="Frequency", y="Power", shared_axes=False, label=label)
|
|
|
|
| 139 |
if color_key:
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
else:
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
def create_dataframe_panes(df, title):
|
| 146 |
return pn.FlexBox(
|
|
@@ -168,8 +233,22 @@ def create_powerspectrum_tab(
|
|
| 168 |
return df, ps
|
| 169 |
return None, None
|
| 170 |
|
| 171 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
|
|
|
| 173 |
|
| 174 |
def create_floatpanel_area(content, title):
|
| 175 |
return FloatingPlot(content=content, title=title)
|
|
@@ -226,18 +305,45 @@ def create_powerspectrum_tab(
|
|
| 226 |
dt = dt_input.value
|
| 227 |
norm = norm_select.value
|
| 228 |
df, ps = create_dataframe(selected_event_list_index, dt, norm)
|
|
|
|
| 229 |
if df is not None:
|
| 230 |
event_list_name = loaded_event_data[selected_event_list_index][0]
|
| 231 |
-
|
| 232 |
label = f"{event_list_name} (dt={dt}, norm={norm})"
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
if floatpanel_plots_checkbox.value:
|
| 238 |
float_panel_container.append(
|
| 239 |
create_floatpanel_area(
|
| 240 |
-
content=
|
| 241 |
title=f"Power Spectrum for {event_list_name} (dt={dt}, norm={norm})",
|
| 242 |
)
|
| 243 |
)
|
|
@@ -248,7 +354,7 @@ def create_powerspectrum_tab(
|
|
| 248 |
plots_container.append(
|
| 249 |
pn.FlexBox(
|
| 250 |
pn.pane.Markdown(markdown_content),
|
| 251 |
-
|
| 252 |
align_items="center",
|
| 253 |
justify_content="center",
|
| 254 |
flex_wrap="nowrap",
|
|
@@ -260,6 +366,7 @@ def create_powerspectrum_tab(
|
|
| 260 |
create_loadingdata_output_box("Failed to create power spectrum.")
|
| 261 |
]
|
| 262 |
|
|
|
|
| 263 |
def combine_selected_plots(event=None):
|
| 264 |
selected_event_list_indices = multi_event_select.value
|
| 265 |
if not selected_event_list_indices:
|
|
@@ -272,9 +379,9 @@ def create_powerspectrum_tab(
|
|
| 272 |
combined_title = []
|
| 273 |
|
| 274 |
# Define a color key for distinct colors
|
| 275 |
-
|
| 276 |
color_key = {
|
| 277 |
-
index: colors[i % len(colors)]
|
|
|
|
| 278 |
}
|
| 279 |
|
| 280 |
for index in selected_event_list_indices:
|
|
@@ -285,17 +392,18 @@ def create_powerspectrum_tab(
|
|
| 285 |
event_list_name = loaded_event_data[index][0]
|
| 286 |
|
| 287 |
label = f"{event_list_name} (dt={dt}, norm={norm})"
|
| 288 |
-
|
| 289 |
-
plot_hv = create_holoviews_plots(
|
| 290 |
-
|
| 291 |
df, label, dt, norm, color_key=color_key[index]
|
| 292 |
-
|
| 293 |
)
|
| 294 |
combined_plots.append(plot_hv)
|
| 295 |
combined_title.append(event_list_name)
|
| 296 |
|
| 297 |
if combined_plots:
|
| 298 |
-
combined_plot =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
combined_pane = create_holoviews_panes(combined_plot)
|
| 301 |
|
|
@@ -335,19 +443,21 @@ def create_powerspectrum_tab(
|
|
| 335 |
)
|
| 336 |
show_dataframe_button.on_click(show_dataframe)
|
| 337 |
|
| 338 |
-
|
| 339 |
event_list_dropdown,
|
| 340 |
dt_input,
|
| 341 |
norm_select,
|
| 342 |
multi_event_select,
|
| 343 |
floatpanel_plots_checkbox,
|
| 344 |
dataframe_checkbox,
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
|
|
|
|
|
|
|
|
|
| 348 |
)
|
| 349 |
-
return
|
| 350 |
-
|
| 351 |
|
| 352 |
def create_quicklook_powerspectrum_main_area(
|
| 353 |
header_container,
|
|
@@ -377,7 +487,6 @@ def create_quicklook_powerspectrum_main_area(
|
|
| 377 |
def create_quicklook_powerspectrum_area():
|
| 378 |
"""
|
| 379 |
Create the plots area for the quicklook lightcurve tab.
|
| 380 |
-
|
| 381 |
Returns:
|
| 382 |
PlotsContainer: An instance of PlotsContainer with the plots for the quicklook lightcurve tab.
|
| 383 |
"""
|
|
|
|
| 42 |
"#9edae5",
|
| 43 |
]
|
| 44 |
|
|
|
|
| 45 |
# Create a warning handler
|
| 46 |
def create_warning_handler():
|
| 47 |
warning_handler = WarningHandler()
|
| 48 |
warnings.showwarning = warning_handler.warn
|
| 49 |
return warning_handler
|
| 50 |
|
|
|
|
| 51 |
""" Header Section """
|
|
|
|
|
|
|
| 52 |
def create_quicklook_powerspectrum_header(
|
| 53 |
header_container,
|
| 54 |
main_area_container,
|
|
|
|
| 62 |
name="Heading", value="QuickLook Power Spectrum"
|
| 63 |
)
|
| 64 |
home_subheading_input = pn.widgets.TextInput(name="Subheading", value="")
|
|
|
|
| 65 |
return MainHeader(heading=home_heading_input, subheading=home_subheading_input)
|
| 66 |
|
|
|
|
| 67 |
""" Output Box Section """
|
|
|
|
|
|
|
| 68 |
def create_loadingdata_output_box(content):
|
| 69 |
return OutputBox(output_content=content)
|
| 70 |
|
|
|
|
| 71 |
""" Warning Box Section """
|
|
|
|
|
|
|
| 72 |
def create_loadingdata_warning_box(content):
|
| 73 |
return WarningBox(warning_content=content)
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
""" Main Area Section """
|
|
|
|
|
|
|
| 76 |
def create_powerspectrum_tab(
|
| 77 |
output_box_container,
|
| 78 |
warning_box_container,
|
|
|
|
| 107 |
)
|
| 108 |
|
| 109 |
floatpanel_plots_checkbox = pn.widgets.Checkbox(
|
| 110 |
+
name="Add Plot to FloatingPanel", value=True
|
| 111 |
)
|
| 112 |
|
| 113 |
dataframe_checkbox = pn.widgets.Checkbox(
|
| 114 |
name="Add DataFrame to FloatingPanel", value=False
|
| 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)
|
| 121 |
+
log_rebin_checkbox = pn.widgets.Checkbox(name="Logarithmic Rebinning", value=False)
|
| 122 |
+
rebin_with_original_checkbox = pn.widgets.Checkbox(name="Plot Rebin with Original", value=False)
|
| 123 |
+
|
| 124 |
+
# Input for Rebin Size
|
| 125 |
+
rebin_size_input = pn.widgets.FloatInput(
|
| 126 |
+
name="Rebin Size",
|
| 127 |
+
value=0.1,
|
| 128 |
+
step=0.01,
|
| 129 |
+
start=0.01,
|
| 130 |
+
end=100.0,
|
| 131 |
+
)
|
| 132 |
|
| 133 |
def create_holoviews_panes(plot):
|
| 134 |
return pn.pane.HoloViews(plot, width=600, height=600, linked_axes=False)
|
| 135 |
|
| 136 |
def create_holoviews_plots(df, label, dt, norm, color_key=None):
|
| 137 |
plot = df.hvplot(x="Frequency", y="Power", shared_axes=False, label=label)
|
| 138 |
+
|
| 139 |
if color_key:
|
| 140 |
+
if rasterize_checkbox.value:
|
| 141 |
+
return hd.rasterize(
|
| 142 |
+
plot,
|
| 143 |
+
aggregator=hd.ds.mean("Power"),
|
| 144 |
+
color_key=color_key,
|
| 145 |
+
line_width=3,
|
| 146 |
+
pixel_ratio=2,
|
| 147 |
+
).opts(
|
| 148 |
+
tools=["hover"],
|
| 149 |
+
cmap=[color_key],
|
| 150 |
+
width=600,
|
| 151 |
+
height=600,
|
| 152 |
+
colorbar=True,
|
| 153 |
+
)
|
| 154 |
+
else:
|
| 155 |
+
return plot
|
| 156 |
else:
|
| 157 |
+
if rasterize_checkbox.value:
|
| 158 |
+
return hd.rasterize(
|
| 159 |
+
plot,
|
| 160 |
+
aggregator=hd.ds.mean("Power"),
|
| 161 |
+
line_width=3,
|
| 162 |
+
pixel_ratio=2,
|
| 163 |
+
).opts(
|
| 164 |
+
tools=["hover"],
|
| 165 |
+
width=600,
|
| 166 |
+
height=600,
|
| 167 |
+
cmap="Viridis",
|
| 168 |
+
colorbar=True,
|
| 169 |
+
)
|
| 170 |
+
else:
|
| 171 |
+
return plot
|
| 172 |
|
| 173 |
+
def create_holoviews_plots_no_colorbar(df, label, dt, norm, color_key=None):
|
| 174 |
+
plot = df.hvplot(x="Frequency", y="Power", shared_axes=False, label=label)
|
| 175 |
+
|
| 176 |
+
if color_key:
|
| 177 |
+
if rasterize_checkbox.value:
|
| 178 |
+
return hd.rasterize(
|
| 179 |
+
plot,
|
| 180 |
+
aggregator=hd.ds.mean("Power"),
|
| 181 |
+
color_key=color_key,
|
| 182 |
+
line_width=3,
|
| 183 |
+
pixel_ratio=2,
|
| 184 |
+
).opts(
|
| 185 |
+
tools=["hover"],
|
| 186 |
+
cmap=[color_key],
|
| 187 |
+
width=600,
|
| 188 |
+
height=600,
|
| 189 |
+
colorbar=False,
|
| 190 |
+
)
|
| 191 |
+
else:
|
| 192 |
+
return plot
|
| 193 |
+
else:
|
| 194 |
+
if rasterize_checkbox.value:
|
| 195 |
+
return hd.rasterize(
|
| 196 |
+
plot,
|
| 197 |
+
aggregator=hd.ds.mean("Power"),
|
| 198 |
+
line_width=3,
|
| 199 |
+
pixel_ratio=2,
|
| 200 |
+
).opts(
|
| 201 |
+
tools=["hover"],
|
| 202 |
+
width=600,
|
| 203 |
+
height=600,
|
| 204 |
+
colorbar=False,
|
| 205 |
+
cmap="Viridis",
|
| 206 |
+
)
|
| 207 |
+
else:
|
| 208 |
+
return plot
|
| 209 |
|
| 210 |
def create_dataframe_panes(df, title):
|
| 211 |
return pn.FlexBox(
|
|
|
|
| 233 |
return df, ps
|
| 234 |
return None, None
|
| 235 |
|
| 236 |
+
""" Rebin Functionality """
|
| 237 |
+
|
| 238 |
+
def rebin_powerspectrum(ps):
|
| 239 |
+
rebin_size = rebin_size_input.value
|
| 240 |
+
|
| 241 |
+
if linear_rebin_checkbox.value:
|
| 242 |
+
# Perform linear rebinning
|
| 243 |
+
rebinned_ps = ps.rebin(rebin_size, method="mean")
|
| 244 |
+
return rebinned_ps
|
| 245 |
+
elif log_rebin_checkbox.value:
|
| 246 |
+
# Perform logarithmic rebinning
|
| 247 |
+
rebinned_ps = ps.rebin_log(f=rebin_size)
|
| 248 |
+
return rebinned_ps
|
| 249 |
+
return None
|
| 250 |
|
| 251 |
+
""" Float Panel """
|
| 252 |
|
| 253 |
def create_floatpanel_area(content, title):
|
| 254 |
return FloatingPlot(content=content, title=title)
|
|
|
|
| 305 |
dt = dt_input.value
|
| 306 |
norm = norm_select.value
|
| 307 |
df, ps = create_dataframe(selected_event_list_index, dt, norm)
|
| 308 |
+
|
| 309 |
if df is not None:
|
| 310 |
event_list_name = loaded_event_data[selected_event_list_index][0]
|
|
|
|
| 311 |
label = f"{event_list_name} (dt={dt}, norm={norm})"
|
| 312 |
+
|
| 313 |
+
# Create the original plot
|
| 314 |
+
original_plot_hv = create_holoviews_plots(df, label, dt, norm)
|
| 315 |
+
|
| 316 |
+
# Initialize the holoviews_output variable
|
| 317 |
+
holoviews_output = original_plot_hv
|
| 318 |
+
|
| 319 |
+
# Rebin the powerspectrum if requested
|
| 320 |
+
rebinned_ps = rebin_powerspectrum(ps)
|
| 321 |
+
|
| 322 |
+
if rebinned_ps is not None:
|
| 323 |
+
# Create a DataFrame for the rebinned plot
|
| 324 |
+
rebinned_df = pd.DataFrame({
|
| 325 |
+
"Frequency": rebinned_ps.freq,
|
| 326 |
+
"Power": rebinned_ps.power,
|
| 327 |
+
})
|
| 328 |
+
rebinned_label = f"Rebinned {event_list_name} (dt={dt}, norm={norm})"
|
| 329 |
+
rebinned_plot_hv = create_holoviews_plots(rebinned_df, rebinned_label, dt, norm)
|
| 330 |
+
|
| 331 |
+
# Check if the user wants to plot rebin with the original
|
| 332 |
+
if rebin_with_original_checkbox.value:
|
| 333 |
+
# Combine the original and rebinned plots using HoloViews
|
| 334 |
+
holoviews_output = original_plot_hv * rebinned_plot_hv
|
| 335 |
+
else:
|
| 336 |
+
# Only use the rebinned plot
|
| 337 |
+
holoviews_output = rebinned_plot_hv
|
| 338 |
+
|
| 339 |
+
# Convert the combined HoloViews object to a pane
|
| 340 |
+
holoviews_output_pane = create_holoviews_panes(holoviews_output)
|
| 341 |
+
|
| 342 |
+
# Append the pane to the appropriate container
|
| 343 |
if floatpanel_plots_checkbox.value:
|
| 344 |
float_panel_container.append(
|
| 345 |
create_floatpanel_area(
|
| 346 |
+
content=holoviews_output_pane,
|
| 347 |
title=f"Power Spectrum for {event_list_name} (dt={dt}, norm={norm})",
|
| 348 |
)
|
| 349 |
)
|
|
|
|
| 354 |
plots_container.append(
|
| 355 |
pn.FlexBox(
|
| 356 |
pn.pane.Markdown(markdown_content),
|
| 357 |
+
holoviews_output_pane,
|
| 358 |
align_items="center",
|
| 359 |
justify_content="center",
|
| 360 |
flex_wrap="nowrap",
|
|
|
|
| 366 |
create_loadingdata_output_box("Failed to create power spectrum.")
|
| 367 |
]
|
| 368 |
|
| 369 |
+
|
| 370 |
def combine_selected_plots(event=None):
|
| 371 |
selected_event_list_indices = multi_event_select.value
|
| 372 |
if not selected_event_list_indices:
|
|
|
|
| 379 |
combined_title = []
|
| 380 |
|
| 381 |
# Define a color key for distinct colors
|
|
|
|
| 382 |
color_key = {
|
| 383 |
+
index: colors[i % len(colors)]
|
| 384 |
+
for i, index in enumerate(selected_event_list_indices)
|
| 385 |
}
|
| 386 |
|
| 387 |
for index in selected_event_list_indices:
|
|
|
|
| 392 |
event_list_name = loaded_event_data[index][0]
|
| 393 |
|
| 394 |
label = f"{event_list_name} (dt={dt}, norm={norm})"
|
| 395 |
+
plot_hv = create_holoviews_plots_no_colorbar(
|
|
|
|
|
|
|
| 396 |
df, label, dt, norm, color_key=color_key[index]
|
|
|
|
| 397 |
)
|
| 398 |
combined_plots.append(plot_hv)
|
| 399 |
combined_title.append(event_list_name)
|
| 400 |
|
| 401 |
if combined_plots:
|
| 402 |
+
combined_plot = (
|
| 403 |
+
hv.Overlay(combined_plots)
|
| 404 |
+
.opts(shared_axes=False, legend_position="right", width=600, height=600)
|
| 405 |
+
.collate()
|
| 406 |
+
)
|
| 407 |
|
| 408 |
combined_pane = create_holoviews_panes(combined_plot)
|
| 409 |
|
|
|
|
| 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,
|
| 451 |
floatpanel_plots_checkbox,
|
| 452 |
dataframe_checkbox,
|
| 453 |
+
rasterize_checkbox,
|
| 454 |
+
linear_rebin_checkbox,
|
| 455 |
+
log_rebin_checkbox,
|
| 456 |
+
rebin_with_original_checkbox,
|
| 457 |
+
rebin_size_input,
|
| 458 |
+
pn.Row(generate_powerspectrum_button, show_dataframe_button, combine_plots_button),
|
| 459 |
)
|
| 460 |
+
return tab_content
|
|
|
|
| 461 |
|
| 462 |
def create_quicklook_powerspectrum_main_area(
|
| 463 |
header_container,
|
|
|
|
| 487 |
def create_quicklook_powerspectrum_area():
|
| 488 |
"""
|
| 489 |
Create the plots area for the quicklook lightcurve tab.
|
|
|
|
| 490 |
Returns:
|
| 491 |
PlotsContainer: An instance of PlotsContainer with the plots for the quicklook lightcurve tab.
|
| 492 |
"""
|
utils/sidebar.py
CHANGED
|
@@ -6,7 +6,11 @@ from modules.QuickLook.Bispectrum import (
|
|
| 6 |
create_quicklook_bispectrum_main_area,
|
| 7 |
create_quicklook_bispectrum_area,
|
| 8 |
)
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
from modules.Home.HomeContent import (
|
| 12 |
create_home_header,
|
|
@@ -61,7 +65,8 @@ def create_sidebar(
|
|
| 61 |
("Averaged Power Spectrum", "QuickLookAvgPowerspectra"),
|
| 62 |
("Cross Spectrum", "QuickLookCrossSpectrum"),
|
| 63 |
("Averaged Cross Spectrum", "QuickLookAvgCrossSpectrum"),
|
| 64 |
-
|
|
|
|
| 65 |
]
|
| 66 |
|
| 67 |
# Home Button
|
|
@@ -294,6 +299,33 @@ def create_sidebar(
|
|
| 294 |
]
|
| 295 |
plots_container[:] = [create_quicklook_bispectrum_area()]
|
| 296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
|
| 298 |
quicklook_stingray_button.on_click(handle_quicklook_button_selection)
|
| 299 |
|
|
|
|
| 6 |
create_quicklook_bispectrum_main_area,
|
| 7 |
create_quicklook_bispectrum_area,
|
| 8 |
)
|
| 9 |
+
from modules.QuickLook.PowerColors import (
|
| 10 |
+
create_quicklook_powercolors_header,
|
| 11 |
+
create_quicklook_powercolors_main_area,
|
| 12 |
+
create_quicklook_powercolors_area,
|
| 13 |
+
)
|
| 14 |
|
| 15 |
from modules.Home.HomeContent import (
|
| 16 |
create_home_header,
|
|
|
|
| 65 |
("Averaged Power Spectrum", "QuickLookAvgPowerspectra"),
|
| 66 |
("Cross Spectrum", "QuickLookCrossSpectrum"),
|
| 67 |
("Averaged Cross Spectrum", "QuickLookAvgCrossSpectrum"),
|
| 68 |
+
("Bispectrum", "QuickLookBispectrum"),
|
| 69 |
+
("Power Colors", "QuickLookPowerColors"), # New menu item for Power Colors
|
| 70 |
]
|
| 71 |
|
| 72 |
# Home Button
|
|
|
|
| 299 |
]
|
| 300 |
plots_container[:] = [create_quicklook_bispectrum_area()]
|
| 301 |
|
| 302 |
+
elif clicked == "QuickLookPowerColors":
|
| 303 |
+
header[:] = [
|
| 304 |
+
create_quicklook_powercolors_header(
|
| 305 |
+
header_container=header,
|
| 306 |
+
main_area_container=main_area,
|
| 307 |
+
output_box_container=output_box,
|
| 308 |
+
warning_box_container=warning_box,
|
| 309 |
+
plots_container=plots_container,
|
| 310 |
+
help_box_container=help_box,
|
| 311 |
+
footer_container=footer,
|
| 312 |
+
float_panel_container=float_panel_container, # Ensure this is passed
|
| 313 |
+
)
|
| 314 |
+
]
|
| 315 |
+
main_area[:] = [
|
| 316 |
+
create_quicklook_powercolors_main_area(
|
| 317 |
+
header_container=header,
|
| 318 |
+
main_area_container=main_area,
|
| 319 |
+
output_box_container=output_box,
|
| 320 |
+
warning_box_container=warning_box,
|
| 321 |
+
plots_container=plots_container,
|
| 322 |
+
help_box_container=help_box,
|
| 323 |
+
footer_container=footer,
|
| 324 |
+
float_panel_container=float_panel_container, # Ensure this is passed
|
| 325 |
+
)
|
| 326 |
+
]
|
| 327 |
+
plots_container[:] = [create_quicklook_powercolors_area()]
|
| 328 |
+
|
| 329 |
|
| 330 |
quicklook_stingray_button.on_click(handle_quicklook_button_selection)
|
| 331 |
|