kartikmandar commited on
Commit
14cf64d
·
1 Parent(s): 3ccfb66

add power spectrum

Browse files
explorer.py CHANGED
@@ -4,9 +4,9 @@ from modules.Home.HomeContent import (
4
  create_home_main_area,
5
  create_home_output_box,
6
  create_home_warning_box,
7
- create_home_plots_area,
8
  create_home_help_area,
9
- create_home_footer
 
10
  )
11
  from utils.sidebar import create_sidebar
12
 
@@ -31,23 +31,25 @@ output_box = create_home_output_box()
31
  # Create the warning box
32
  warning_box = create_home_warning_box()
33
 
34
- # Create the plots container
35
- plots_area = create_home_plots_area()
36
-
37
  # Create the help box
38
  help_box = create_home_help_area()
39
 
40
  # Create the footer
41
  footer = create_home_footer()
42
 
 
 
 
 
43
  # Containers for changing the layouts dynamically
44
  header_container = pn.Column(header)
45
  main_area_container = pn.Column(main_area)
46
  output_box_container = pn.Column(output_box)
47
  warning_box_container = pn.Column(warning_box)
48
- plots_container = pn.Column(plots_area)
49
  help_box_container = pn.Column(help_box)
50
  footer_container = pn.Column(footer)
 
51
 
52
  sidebar = create_sidebar(
53
  main_area=main_area_container,
@@ -57,6 +59,7 @@ sidebar = create_sidebar(
57
  warning_box=warning_box_container,
58
  help_box=help_box_container,
59
  plots_area=plots_container,
 
60
  )
61
 
62
 
@@ -116,9 +119,10 @@ layout.main[0:10, 0:12] = header_container
116
  layout.main[10:55, 0:8] = main_area_container
117
  layout.main[10:33, 8:12] = output_box_container
118
  layout.main[33:55, 8:12] = warning_box_container
119
- layout.main[55:85, 0:12] = plots_container
120
- layout.main[85:120, 0:12] = help_box_container
121
- layout.main[120:150, 0:12] = footer_container
 
122
 
123
 
124
  # Serve the layout
 
4
  create_home_main_area,
5
  create_home_output_box,
6
  create_home_warning_box,
 
7
  create_home_help_area,
8
+ create_home_footer,
9
+ create_home_plots_area,
10
  )
11
  from utils.sidebar import create_sidebar
12
 
 
31
  # Create the warning box
32
  warning_box = create_home_warning_box()
33
 
 
 
 
34
  # Create the help box
35
  help_box = create_home_help_area()
36
 
37
  # Create the footer
38
  footer = create_home_footer()
39
 
40
+ # Plots Area
41
+ plots_container = create_home_plots_area()
42
+
43
+
44
  # Containers for changing the layouts dynamically
45
  header_container = pn.Column(header)
46
  main_area_container = pn.Column(main_area)
47
  output_box_container = pn.Column(output_box)
48
  warning_box_container = pn.Column(warning_box)
49
+ plots_container = pn.FlexBox(plots_container, flex_direction='row', align_content='space-evenly', align_items="center", justify_content="center", flex_wrap="wrap")
50
  help_box_container = pn.Column(help_box)
51
  footer_container = pn.Column(footer)
52
+ floating_panel_container = pn.Column(pn.pane.Markdown("This is not a bug that this container is scrolling, it's a container to hold Floating Plots. You can ignore it completely."))
53
 
54
  sidebar = create_sidebar(
55
  main_area=main_area_container,
 
59
  warning_box=warning_box_container,
60
  help_box=help_box_container,
61
  plots_area=plots_container,
62
+ floating_panel=floating_panel_container
63
  )
64
 
65
 
 
119
  layout.main[10:55, 0:8] = main_area_container
120
  layout.main[10:33, 8:12] = output_box_container
121
  layout.main[33:55, 8:12] = warning_box_container
122
+ layout.main[55:100, 0:12] = plots_container
123
+ layout.main[100:140, 0:12] = help_box_container
124
+ layout.main[140:170, 0:12] = footer_container
125
+ layout.main[170:170, 0:12] = floating_panel_container
126
 
127
 
128
  # Serve the layout
modules/DataLoading/DataIngestion.py CHANGED
@@ -12,10 +12,11 @@ from utils.DashboardClasses import (
12
  MainArea,
13
  OutputBox,
14
  WarningBox,
15
- PlotsContainer,
16
- HelpBox,
17
  Footer,
18
  WarningHandler,
 
 
19
  )
20
  import param
21
  from utils.strings import LOADING_DATA_HELP_BOX_STRING
@@ -300,8 +301,8 @@ def save_loaded_files(
300
  def delete_selected_files(
301
  event,
302
  file_selector,
303
- output_box_container,
304
  warning_box_container,
 
305
  warning_handler,
306
  ):
307
  """
@@ -923,3 +924,13 @@ def create_loadingdata_help_area():
923
  """
924
  help_content = LOADING_DATA_HELP_BOX_STRING
925
  return HelpBox(help_content=help_content, title="Help Section")
 
 
 
 
 
 
 
 
 
 
 
12
  MainArea,
13
  OutputBox,
14
  WarningBox,
15
+ HelpBox,
 
16
  Footer,
17
  WarningHandler,
18
+ FloatingPlot,
19
+ PlotsContainer,
20
  )
21
  import param
22
  from utils.strings import LOADING_DATA_HELP_BOX_STRING
 
301
  def delete_selected_files(
302
  event,
303
  file_selector,
 
304
  warning_box_container,
305
+ output_box_container,
306
  warning_handler,
307
  ):
308
  """
 
924
  """
925
  help_content = LOADING_DATA_HELP_BOX_STRING
926
  return HelpBox(help_content=help_content, title="Help Section")
927
+
928
+
929
+ def create_loadingdata_plots_area():
930
+ """
931
+ Create the plots area for the data loading tab.
932
+
933
+ Returns:
934
+ PlotsContainer: An instance of PlotsContainer with the plots for the data loading tab.
935
+ """
936
+ return PlotsContainer()
modules/Home/HomeContent.py CHANGED
@@ -1,14 +1,18 @@
 
1
  import panel as pn
2
  import holoviews as hv
 
 
 
3
  from utils.DashboardClasses import (
4
  MainHeader,
5
  MainArea,
6
  OutputBox,
7
  WarningBox,
8
- PlotsContainer,
9
  HelpBox,
10
  Footer,
11
  FloatingPlot,
 
12
  )
13
  from utils.strings import (
14
  HOME_HEADER_STRING,
@@ -21,6 +25,14 @@ from utils.strings import (
21
  HOME_WARNING_BOX_STRING,
22
  HOME_HELP_BOX_STRING,
23
  )
 
 
 
 
 
 
 
 
24
 
25
  """ Header Section """
26
 
@@ -54,28 +66,43 @@ def create_home_main_area():
54
 
55
  """ Output Box Section """
56
 
57
-
58
  def create_home_output_box():
59
  return OutputBox(output_content=HOME_OUTPUT_BOX_STRING)
60
 
61
 
62
  """ Warning Box Section """
63
 
64
-
65
  def create_home_warning_box():
66
  return WarningBox(warning_content=HOME_WARNING_BOX_STRING)
67
 
68
 
69
- """ Plots Area Section """
70
 
 
71
 
72
  def create_home_plots_area():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- return PlotsContainer(
75
- flexbox_contents=[],
76
- titles=[],
77
- sizes=[],
78
- )
79
 
80
 
81
  """ Help Area Section """
 
1
+ from matplotlib import pyplot as plt
2
  import panel as pn
3
  import holoviews as hv
4
+ import os
5
+ import numpy as np
6
+ from bokeh.plotting import figure
7
  from utils.DashboardClasses import (
8
  MainHeader,
9
  MainArea,
10
  OutputBox,
11
  WarningBox,
 
12
  HelpBox,
13
  Footer,
14
  FloatingPlot,
15
+ PlotsContainer,
16
  )
17
  from utils.strings import (
18
  HOME_HEADER_STRING,
 
25
  HOME_WARNING_BOX_STRING,
26
  HOME_HELP_BOX_STRING,
27
  )
28
+ from stingray.gti import create_gti_from_condition, gti_border_bins, time_intervals_from_gtis, cross_two_gtis
29
+ from stingray.utils import show_progress
30
+ from stingray.fourier import avg_cs_from_events, avg_pds_from_events, poisson_level, get_average_ctrate
31
+ from stingray import AveragedPowerspectrum, AveragedCrossspectrum, EventList, Lightcurve
32
+ from stingray.modeling.parameterestimation import PSDLogLikelihood
33
+
34
+
35
+
36
 
37
  """ Header Section """
38
 
 
66
 
67
  """ Output Box Section """
68
 
 
69
  def create_home_output_box():
70
  return OutputBox(output_content=HOME_OUTPUT_BOX_STRING)
71
 
72
 
73
  """ Warning Box Section """
74
 
 
75
  def create_home_warning_box():
76
  return WarningBox(warning_content=HOME_WARNING_BOX_STRING)
77
 
78
 
 
79
 
80
+ """ Plots Area Section """
81
 
82
  def create_home_plots_area():
83
+ # Generate sample data
84
+ times = np.arange(500)
85
+ counts = np.floor(np.random.rand(500) * 50000)
86
+
87
+ # Create a Lightcurve object
88
+ lc = Lightcurve(times, counts, skip_checks=True, dt=1.0)
89
+ lc2 = Lightcurve(times, counts, skip_checks=True, dt=1.0)
90
+ lc3 = Lightcurve(times, counts, skip_checks=True, dt=1.0)
91
+ lc4 = Lightcurve(times, counts, skip_checks=True, dt=1.0)
92
+
93
+ # Create a Bokeh figure
94
+ plot = figure(title="Demo Lightcurve", width=500, height=500)
95
+ plot2 = figure(title="Demo Lightcurve 2", width=500, height=500)
96
+ plot3 = figure(title="Demo Lightcurve 3", width=500, height=500)
97
+ plot4 = figure(title="Demo Lightcurve 4", width=500, height=500)
98
+
99
+ plot.line(lc.time, lc.counts, line_width=2)
100
+ plot2.line(lc2.time, lc2.counts, line_width=2)
101
+ plot3.line(lc3.time, lc3.counts, line_width=2)
102
+ plot4.line(lc4.time, lc4.counts, line_width=2)
103
+
104
+ return PlotsContainer(plot, plot2, plot3, plot4)
105
 
 
 
 
 
 
106
 
107
 
108
  """ Help Area Section """
modules/QuickLook/LightCurve.py CHANGED
@@ -9,20 +9,23 @@ from utils.DashboardClasses import (
9
  MainArea,
10
  OutputBox,
11
  WarningBox,
12
- PlotsContainer,
13
  HelpBox,
14
  Footer,
15
  WarningHandler,
16
- FloatingPlot
17
  )
18
 
 
19
  # Create a warning handler
20
  def create_warning_handler():
21
  warning_handler = WarningHandler()
22
  warnings.showwarning = warning_handler.warn
23
  return warning_handler
24
 
 
25
  """ Header Section """
 
 
26
  def create_quicklook_lightcurve_header(
27
  header_container,
28
  main_area_container,
@@ -39,33 +42,41 @@ def create_quicklook_lightcurve_header(
39
 
40
  return MainHeader(heading=home_heading_input, subheading=home_subheading_input)
41
 
 
42
  """ Output Box Section """
 
 
43
  def create_loadingdata_output_box(content):
44
  return OutputBox(output_content=content)
45
 
 
46
  """ Warning Box Section """
 
 
47
  def create_loadingdata_warning_box(content):
48
  return WarningBox(warning_content=content)
49
 
50
- """ Plots Area """
51
- def create_lightcurve_plots_area():
52
- return PlotsContainer()
53
 
54
  """ Float Panel """
 
 
55
  def create_floatpanel_area(content, title):
56
  return FloatingPlot(content, title)
57
 
 
58
  """ Main Area Section """
 
 
59
  def create_lightcurve_tab(
60
  output_box_container,
61
  warning_box_container,
62
  warning_handler,
63
  plots_container,
64
- header_container
65
  ):
66
 
67
  event_list_dropdown = pn.widgets.Select(
68
- name="Select Event List",
69
  options={name: i for i, (name, event) in enumerate(loaded_event_data)},
70
  )
71
 
@@ -77,19 +88,17 @@ def create_lightcurve_tab(
77
  value=1,
78
  )
79
 
80
- tstart_input = pn.widgets.FloatInput(
81
- name="Start Time (tstart)",
82
- value=None,
83
- step=0.1,
84
- )
85
 
86
  combine_plots_checkbox = pn.widgets.Checkbox(
87
  name="Combine with Existing Plot", value=False
88
  )
89
 
90
- plots_checkbox = pn.widgets.Checkbox(
91
- name="Add Plot to FloatingPanel", value=False
92
- )
93
 
94
  dataframe_checkbox = pn.widgets.Checkbox(
95
  name="Add DataFrame to FloatingPanel", value=False
@@ -104,12 +113,10 @@ def create_lightcurve_tab(
104
  def create_dataframe_panes():
105
  return pn.pane.DataFrame(width=600, height=500)
106
 
107
-
108
-
109
- def create_dataframe(selected_event_list_index, dt, tstart):
110
  if selected_event_list_index is not None:
111
  event_list = loaded_event_data[selected_event_list_index][1]
112
- lc_new = event_list.to_lc(dt=dt, tstart=tstart)
113
 
114
  df = pd.DataFrame(
115
  {
@@ -135,8 +142,7 @@ def create_lightcurve_tab(
135
  return
136
 
137
  dt = dt_slider.value
138
- tstart = tstart_input.value
139
- df = create_dataframe(selected_event_list_index, dt, tstart=tstart)
140
  if df is not None:
141
  dataframe_output = create_dataframe_panes()
142
  dataframe_output.object = df
@@ -149,7 +155,7 @@ def create_lightcurve_tab(
149
  position="center",
150
  height=350,
151
  width=500,
152
- theme="primary"
153
  )
154
  )
155
  else:
@@ -157,7 +163,7 @@ def create_lightcurve_tab(
157
  else:
158
  output_box_container[:] = [
159
  create_loadingdata_output_box("Failed to create dataframe.")
160
- ]
161
 
162
  def generate_lightcurve(event=None):
163
  if not loaded_event_data:
@@ -174,8 +180,7 @@ def create_lightcurve_tab(
174
  return
175
 
176
  dt = dt_slider.value
177
- tstart = tstart_input.value
178
- df = create_dataframe(selected_event_list_index, dt, tstart=tstart)
179
  if df is not None:
180
  holoviews_output = create_holoviews_panes()
181
  plot_hv = create_holoviews_plots(df)
@@ -183,11 +188,15 @@ def create_lightcurve_tab(
183
 
184
  if combine_plots_checkbox.value:
185
  # If combining, we need to get all existing plots and combine with the new one
186
- existing_plots = [p.object for p in plots_container if isinstance(p, pn.pane.HoloViews)]
 
 
 
 
187
  combined_plot = hv.Overlay(existing_plots + [plot_hv])
188
  combined_pane = pn.pane.HoloViews(combined_plot, width=500, height=500)
189
-
190
- if plots_checkbox.value:
191
  header_container.append(
192
  pn.layout.FloatPanel(
193
  combined_pane,
@@ -200,7 +209,7 @@ def create_lightcurve_tab(
200
  else:
201
  plots_container.append(combined_pane)
202
  else:
203
- if plots_checkbox.value:
204
  header_container.append(
205
  pn.layout.FloatPanel(
206
  holoviews_output,
@@ -217,8 +226,6 @@ def create_lightcurve_tab(
217
  create_loadingdata_output_box("Failed to create dataframe.")
218
  ]
219
 
220
-
221
-
222
  generate_lightcurve_button = pn.widgets.Button(
223
  name="Generate Light Curve", button_type="primary"
224
  )
@@ -232,14 +239,14 @@ def create_lightcurve_tab(
232
  tab1_content = pn.Column(
233
  event_list_dropdown,
234
  dt_slider,
235
- tstart_input,
236
  combine_plots_checkbox,
237
- plots_checkbox,
238
  dataframe_checkbox,
239
  pn.Row(generate_lightcurve_button, show_dataframe_button),
240
  )
241
  return tab1_content
242
 
 
243
  def create_quicklook_lightcurve_main_area(
244
  header_container,
245
  main_area_container,
@@ -260,4 +267,4 @@ def create_quicklook_lightcurve_main_area(
260
  ),
261
  }
262
 
263
- return MainArea(tabs_content=tabs_content)
 
9
  MainArea,
10
  OutputBox,
11
  WarningBox,
 
12
  HelpBox,
13
  Footer,
14
  WarningHandler,
15
+ FloatingPlot,
16
  )
17
 
18
+
19
  # Create a warning handler
20
  def create_warning_handler():
21
  warning_handler = WarningHandler()
22
  warnings.showwarning = warning_handler.warn
23
  return warning_handler
24
 
25
+
26
  """ Header Section """
27
+
28
+
29
  def create_quicklook_lightcurve_header(
30
  header_container,
31
  main_area_container,
 
42
 
43
  return MainHeader(heading=home_heading_input, subheading=home_subheading_input)
44
 
45
+
46
  """ Output Box Section """
47
+
48
+
49
  def create_loadingdata_output_box(content):
50
  return OutputBox(output_content=content)
51
 
52
+
53
  """ Warning Box Section """
54
+
55
+
56
  def create_loadingdata_warning_box(content):
57
  return WarningBox(warning_content=content)
58
 
 
 
 
59
 
60
  """ Float Panel """
61
+
62
+
63
  def create_floatpanel_area(content, title):
64
  return FloatingPlot(content, title)
65
 
66
+
67
  """ Main Area Section """
68
+
69
+
70
  def create_lightcurve_tab(
71
  output_box_container,
72
  warning_box_container,
73
  warning_handler,
74
  plots_container,
75
+ header_container,
76
  ):
77
 
78
  event_list_dropdown = pn.widgets.Select(
79
+ name="Select Event List(s)",
80
  options={name: i for i, (name, event) in enumerate(loaded_event_data)},
81
  )
82
 
 
88
  value=1,
89
  )
90
 
91
+ # tstart_input = pn.widgets.FloatInput(
92
+ # name="Start Time (tstart)",
93
+ # value=None,
94
+ # step=0.1,
95
+ # )
96
 
97
  combine_plots_checkbox = pn.widgets.Checkbox(
98
  name="Combine with Existing Plot", value=False
99
  )
100
 
101
+ floatpanel_plots_checkbox = pn.widgets.Checkbox(name="Add Plot to FloatingPanel", value=False)
 
 
102
 
103
  dataframe_checkbox = pn.widgets.Checkbox(
104
  name="Add DataFrame to FloatingPanel", value=False
 
113
  def create_dataframe_panes():
114
  return pn.pane.DataFrame(width=600, height=500)
115
 
116
+ def create_dataframe(selected_event_list_index, dt):
 
 
117
  if selected_event_list_index is not None:
118
  event_list = loaded_event_data[selected_event_list_index][1]
119
+ lc_new = event_list.to_lc(dt=dt)
120
 
121
  df = pd.DataFrame(
122
  {
 
142
  return
143
 
144
  dt = dt_slider.value
145
+ df = create_dataframe(selected_event_list_index, dt)
 
146
  if df is not None:
147
  dataframe_output = create_dataframe_panes()
148
  dataframe_output.object = df
 
155
  position="center",
156
  height=350,
157
  width=500,
158
+ theme="primary",
159
  )
160
  )
161
  else:
 
163
  else:
164
  output_box_container[:] = [
165
  create_loadingdata_output_box("Failed to create dataframe.")
166
+ ]
167
 
168
  def generate_lightcurve(event=None):
169
  if not loaded_event_data:
 
180
  return
181
 
182
  dt = dt_slider.value
183
+ df = create_dataframe(selected_event_list_index, dt)
 
184
  if df is not None:
185
  holoviews_output = create_holoviews_panes()
186
  plot_hv = create_holoviews_plots(df)
 
188
 
189
  if combine_plots_checkbox.value:
190
  # If combining, we need to get all existing plots and combine with the new one
191
+ existing_plots = [
192
+ p.object
193
+ for p in plots_container
194
+ if isinstance(p, pn.pane.HoloViews)
195
+ ]
196
  combined_plot = hv.Overlay(existing_plots + [plot_hv])
197
  combined_pane = pn.pane.HoloViews(combined_plot, width=500, height=500)
198
+
199
+ if floatpanel_plots_checkbox.value:
200
  header_container.append(
201
  pn.layout.FloatPanel(
202
  combined_pane,
 
209
  else:
210
  plots_container.append(combined_pane)
211
  else:
212
+ if floatpanel_plots_checkbox.value:
213
  header_container.append(
214
  pn.layout.FloatPanel(
215
  holoviews_output,
 
226
  create_loadingdata_output_box("Failed to create dataframe.")
227
  ]
228
 
 
 
229
  generate_lightcurve_button = pn.widgets.Button(
230
  name="Generate Light Curve", button_type="primary"
231
  )
 
239
  tab1_content = pn.Column(
240
  event_list_dropdown,
241
  dt_slider,
 
242
  combine_plots_checkbox,
243
+ floatpanel_plots_checkbox,
244
  dataframe_checkbox,
245
  pn.Row(generate_lightcurve_button, show_dataframe_button),
246
  )
247
  return tab1_content
248
 
249
+
250
  def create_quicklook_lightcurve_main_area(
251
  header_container,
252
  main_area_container,
 
267
  ),
268
  }
269
 
270
+ return MainArea(tabs_content=tabs_content)
modules/QuickLook/PowerSpectrum.py ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import panel as pn
2
+ import holoviews as hv
3
+ 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,
10
+ OutputBox,
11
+ WarningBox,
12
+ HelpBox,
13
+ Footer,
14
+ WarningHandler,
15
+ FloatingPlot,
16
+ )
17
+ from stingray import Powerspectrum
18
+
19
+ # Create a warning handler
20
+ def create_warning_handler():
21
+ warning_handler = WarningHandler()
22
+ warnings.showwarning = warning_handler.warn
23
+ return warning_handler
24
+
25
+ """ Header Section """
26
+
27
+ def create_quicklook_powerspectrum_header(
28
+ header_container,
29
+ main_area_container,
30
+ output_box_container,
31
+ warning_box_container,
32
+ plots_container,
33
+ help_box_container,
34
+ footer_container,
35
+ ):
36
+ home_heading_input = pn.widgets.TextInput(
37
+ name="Heading", value="QuickLook Power Spectrum"
38
+ )
39
+ home_subheading_input = pn.widgets.TextInput(name="Subheading", value="")
40
+
41
+ return MainHeader(heading=home_heading_input, subheading=home_subheading_input)
42
+
43
+ """ Output Box Section """
44
+
45
+ def create_loadingdata_output_box(content):
46
+ return OutputBox(output_content=content)
47
+
48
+ """ Warning Box Section """
49
+
50
+ def create_loadingdata_warning_box(content):
51
+ return WarningBox(warning_content=content)
52
+
53
+ """ Float Panel """
54
+
55
+ def create_floatpanel_area(content, title):
56
+ return FloatingPlot(content, title)
57
+
58
+ """ Main Area Section """
59
+
60
+ def create_powerspectrum_tab(
61
+ output_box_container,
62
+ warning_box_container,
63
+ warning_handler,
64
+ plots_container,
65
+ header_container,
66
+ ):
67
+ event_list_dropdown = pn.widgets.Select(
68
+ name="Select Event List(s)",
69
+ options={name: i for i, (name, event) in enumerate(loaded_event_data)},
70
+ )
71
+
72
+ dt_slider = pn.widgets.FloatSlider(
73
+ name="Select dt",
74
+ start=0.1,
75
+ end=1000,
76
+ step=0.1,
77
+ value=1,
78
+ )
79
+
80
+ combine_plots_checkbox = pn.widgets.Checkbox(
81
+ name="Combine with Existing Plot", value=False
82
+ )
83
+
84
+ floatpanel_plots_checkbox = pn.widgets.Checkbox(name="Add Plot to FloatingPanel", value=False)
85
+
86
+ def create_holoviews_panes():
87
+ return pn.pane.HoloViews(width=600, height=500)
88
+
89
+ def create_holoviews_plots(ps):
90
+ return hv.Curve((ps.freq, ps.power)).opts(
91
+ xlabel='Frequency (Hz)', ylabel='Power',
92
+ title='Power Spectrum',
93
+ width=600, height=500
94
+ )
95
+
96
+ def create_dataframe_panes():
97
+ return pn.pane.DataFrame(width=600, height=500)
98
+
99
+ def create_dataframe(selected_event_list_index, dt):
100
+ if selected_event_list_index is not None:
101
+ event_list = loaded_event_data[selected_event_list_index][1]
102
+ lc_new = event_list.to_lc(dt=dt)
103
+
104
+ # Create a PowerSpectrum object
105
+ ps = Powerspectrum.from_lightcurve(lc_new, norm="leahy")
106
+
107
+ df = pd.DataFrame(
108
+ {
109
+ "Frequency": ps.freq,
110
+ "Power": ps.power,
111
+ }
112
+ )
113
+ return df, ps
114
+ return None, None
115
+
116
+ def show_dataframe(event=None):
117
+ if not loaded_event_data:
118
+ output_box_container[:] = [
119
+ create_loadingdata_output_box("No loaded event data available.")
120
+ ]
121
+ return
122
+
123
+ selected_event_list_index = event_list_dropdown.value
124
+ if selected_event_list_index is None:
125
+ output_box_container[:] = [
126
+ create_loadingdata_output_box("No event list selected.")
127
+ ]
128
+ return
129
+
130
+ dt = dt_slider.value
131
+ df, ps = create_dataframe(selected_event_list_index, dt)
132
+ if df is not None:
133
+ dataframe_output = create_dataframe_panes()
134
+ dataframe_output.object = df
135
+
136
+ if floatpanel_plots_checkbox.value:
137
+ header_container.append(
138
+ pn.layout.FloatPanel(
139
+ dataframe_output,
140
+ contained=False,
141
+ position="center",
142
+ height=350,
143
+ width=500,
144
+ theme="primary",
145
+ )
146
+ )
147
+ else:
148
+ plots_container.append(dataframe_output)
149
+ else:
150
+ output_box_container[:] = [
151
+ create_loadingdata_output_box("Failed to create dataframe.")
152
+ ]
153
+
154
+ def generate_powerspectrum(event=None):
155
+ if not loaded_event_data:
156
+ output_box_container[:] = [
157
+ create_loadingdata_output_box("No loaded event data available.")
158
+ ]
159
+ return
160
+
161
+ selected_event_list_index = event_list_dropdown.value
162
+ if selected_event_list_index is None:
163
+ output_box_container[:] = [
164
+ create_loadingdata_output_box("No event list selected.")
165
+ ]
166
+ return
167
+
168
+ dt = dt_slider.value
169
+ df, ps = create_dataframe(selected_event_list_index, dt)
170
+ if df is not None:
171
+ holoviews_output = create_holoviews_panes()
172
+ plot_hv = create_holoviews_plots(ps)
173
+ holoviews_output.object = plot_hv
174
+
175
+ if combine_plots_checkbox.value:
176
+ # If combining, we need to get all existing plots and combine with the new one
177
+ existing_plots = [
178
+ p.object
179
+ for p in plots_container
180
+ if isinstance(p, pn.pane.HoloViews)
181
+ ]
182
+ combined_plot = hv.Overlay(existing_plots + [plot_hv])
183
+ combined_pane = pn.pane.HoloViews(combined_plot, width=500, height=500)
184
+
185
+ if floatpanel_plots_checkbox.value:
186
+ header_container.append(
187
+ pn.layout.FloatPanel(
188
+ combined_pane,
189
+ contained=False,
190
+ position="center",
191
+ height=350,
192
+ theme="primary",
193
+ )
194
+ )
195
+ else:
196
+ plots_container.append(combined_pane)
197
+ else:
198
+ if floatpanel_plots_checkbox.value:
199
+ header_container.append(
200
+ pn.layout.FloatPanel(
201
+ holoviews_output,
202
+ contained=False,
203
+ position="center",
204
+ height=350,
205
+ theme="primary",
206
+ )
207
+ )
208
+ else:
209
+ plots_container.append(holoviews_output)
210
+ else:
211
+ output_box_container[:] = [
212
+ create_loadingdata_output_box("Failed to create power spectrum.")
213
+ ]
214
+
215
+ generate_powerspectrum_button = pn.widgets.Button(
216
+ name="Generate Power Spectrum", button_type="primary"
217
+ )
218
+ generate_powerspectrum_button.on_click(generate_powerspectrum)
219
+
220
+ show_dataframe_button = pn.widgets.Button(
221
+ name="Show DataFrame", button_type="primary"
222
+ )
223
+ show_dataframe_button.on_click(show_dataframe)
224
+
225
+ tab1_content = pn.Column(
226
+ event_list_dropdown,
227
+ dt_slider,
228
+ combine_plots_checkbox,
229
+ floatpanel_plots_checkbox,
230
+ pn.Row(generate_powerspectrum_button, show_dataframe_button),
231
+ )
232
+ return tab1_content
233
+
234
+ def create_quicklook_powerspectrum_main_area(
235
+ header_container,
236
+ main_area_container,
237
+ output_box_container,
238
+ warning_box_container,
239
+ plots_container,
240
+ help_box_container,
241
+ footer_container,
242
+ ):
243
+ warning_handler = create_warning_handler()
244
+ tabs_content = {
245
+ "Power Spectrum": create_powerspectrum_tab(
246
+ output_box_container=output_box_container,
247
+ warning_box_container=warning_box_container,
248
+ warning_handler=warning_handler,
249
+ plots_container=plots_container,
250
+ header_container=header_container,
251
+ ),
252
+ }
253
+
254
+ return MainArea(tabs_content=tabs_content)
utils/dashboardClasses.py CHANGED
@@ -2,7 +2,8 @@ import panel as pn
2
  import param
3
  from typing import List, Tuple
4
 
5
- pn.extension('floatpanel')
 
6
 
7
  class MainHeader(pn.viewable.Viewer):
8
  """
@@ -345,57 +346,26 @@ class PlotsContainer(pn.viewable.Viewer):
345
  PlotsContainer class represents a container for displaying multiple plots.
346
  """
347
 
348
- # Parameters for the contents, titles, and sizes of the FlexBox containers
349
- flexbox_contents: List[pn.viewable.Viewer] = param.List(
350
- default=[], doc="Contents for FlexBox containers", allow_refs=True
351
- )
352
- titles: List[str] = param.List(
353
- default=[], doc="Titles for FlexBox containers", allow_refs=True
354
- )
355
- sizes: List[Tuple[int, int]] = param.List(
356
- default=[],
357
- doc="Sizes for FlexBox containers as (height, width)",
358
- allow_refs=True,
359
- )
360
 
361
- def __init__(self, **params):
362
- """
363
- Initializes thePlotsContainer class with the provided parameters.
364
- """
365
  super().__init__(**params)
 
366
 
367
  def __panel__(self):
368
  """
369
- Returns the Panel layout for the plots container, including the plots with their respective titles and sizes.
370
  """
 
371
  flexbox_container = pn.FlexBox(
372
- align_items="center", justify_content="flex-start", flex_wrap="wrap"
 
 
 
 
 
373
  )
374
-
375
- for idx, content in enumerate(self.flexbox_contents):
376
- if idx < len(self.titles):
377
- title = self.titles[idx]
378
- else:
379
- title = f"FlexBox {idx+1}"
380
-
381
- heading = pn.pane.Markdown(f"<h2> {title} </h2>", align="center")
382
- flexbox = pn.Column(
383
- heading,
384
- content,
385
- )
386
-
387
- if idx < len(self.sizes):
388
- height, width = self.sizes[idx]
389
- flexbox.height = height
390
- flexbox.width = width
391
- else:
392
- flexbox.height = 300
393
- flexbox.width = 300
394
-
395
- flexbox_container.append(flexbox)
396
-
397
- return flexbox_container
398
-
399
 
400
  class HelpBox(pn.viewable.Viewer):
401
  """
@@ -554,9 +524,7 @@ class FloatingPlot(pn.viewable.Viewer):
554
  content: pn.viewable.Viewer = param.Parameter(
555
  default=None, doc="Content for Floating Panel"
556
  )
557
- title: str = param.String(
558
- default="", doc="Title for Floating Panel"
559
- )
560
 
561
  def __init__(self, content=None, title="", **params):
562
  """
@@ -572,7 +540,7 @@ class FloatingPlot(pn.viewable.Viewer):
572
  """
573
  if not self.content or not self.title:
574
  raise ValueError("Content and title must be provided.")
575
-
576
  # Debugging information
577
  print(f"Creating FloatingPanel with title: {self.title}")
578
  print(f"Content: {self.content}")
@@ -586,7 +554,6 @@ class FloatingPlot(pn.viewable.Viewer):
586
  height=500,
587
  margin=20,
588
  )
589
-
590
  print("FloatPanel created successfully.")
591
  return float_panel
592
-
 
2
  import param
3
  from typing import List, Tuple
4
 
5
+ pn.extension("floatpanel")
6
+
7
 
8
  class MainHeader(pn.viewable.Viewer):
9
  """
 
346
  PlotsContainer class represents a container for displaying multiple plots.
347
  """
348
 
349
+ flexbox_contents: list = param.List(default=[], doc="Contents for FlexBox containers", allow_refs=True)
 
 
 
 
 
 
 
 
 
 
 
350
 
351
+ def __init__(self, *contents, **params):
 
 
 
352
  super().__init__(**params)
353
+ self.flexbox_contents = list(contents)
354
 
355
  def __panel__(self):
356
  """
357
+ Returns the Panel layout for the plots container.
358
  """
359
+ title = pn.pane.Markdown("<h2> Plots </h2>", align="center")
360
  flexbox_container = pn.FlexBox(
361
+ *self.flexbox_contents,
362
+ flex_direction='row',
363
+ align_content='space-evenly',
364
+ align_items="center",
365
+ justify_content="center",
366
+ flex_wrap="wrap"
367
  )
368
+ return pn.Column(title, flexbox_container, sizing_mode="stretch_both")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
 
370
  class HelpBox(pn.viewable.Viewer):
371
  """
 
524
  content: pn.viewable.Viewer = param.Parameter(
525
  default=None, doc="Content for Floating Panel"
526
  )
527
+ title: str = param.String(default="", doc="Title for Floating Panel")
 
 
528
 
529
  def __init__(self, content=None, title="", **params):
530
  """
 
540
  """
541
  if not self.content or not self.title:
542
  raise ValueError("Content and title must be provided.")
543
+
544
  # Debugging information
545
  print(f"Creating FloatingPanel with title: {self.title}")
546
  print(f"Content: {self.content}")
 
554
  height=500,
555
  margin=20,
556
  )
557
+
558
  print("FloatPanel created successfully.")
559
  return float_panel
 
utils/sidebar.py CHANGED
@@ -6,9 +6,9 @@ from modules.Home.HomeContent import (
6
  create_home_main_area,
7
  create_home_output_box,
8
  create_home_warning_box,
9
- create_home_plots_area,
10
  create_home_help_area,
11
  create_home_footer,
 
12
  )
13
  from modules.DataLoading.DataIngestion import (
14
  create_loadingdata_header,
@@ -16,16 +16,20 @@ from modules.DataLoading.DataIngestion import (
16
  create_loadingdata_output_box,
17
  create_loadingdata_warning_box,
18
  create_loadingdata_help_area,
 
19
  )
20
  from modules.QuickLook.LightCurve import (
21
  create_quicklook_lightcurve_header,
22
  create_quicklook_lightcurve_main_area,
23
  )
 
 
 
 
24
  from assets.icons.svg import HOME_ICON_SVG, LOAD_DATA_ICON_SVG
25
 
26
-
27
  def create_sidebar(
28
- main_area, header, footer, output_box, warning_box, help_box, plots_area
29
  ):
30
  menu_items_quicklook_stingray = [
31
  ("Light Curve", "QuickLookLightCurve"),
@@ -68,6 +72,7 @@ def create_sidebar(
68
  warning_box[:] = [create_home_warning_box()]
69
  help_box[:] = [create_home_help_area()]
70
  footer[:] = [create_home_footer()]
 
71
 
72
  home_button.on_click(handle_home_button_selection)
73
 
@@ -98,6 +103,7 @@ def create_sidebar(
98
  output_box[:] = [create_home_output_box()]
99
  warning_box[:] = [create_home_warning_box()]
100
  help_box[:] = [create_loadingdata_help_area()]
 
101
 
102
  load_data_button.on_click(load_data)
103
 
@@ -127,6 +133,29 @@ def create_sidebar(
127
  footer_container=footer,
128
  )
129
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
  quicklook_stingray_button.on_click(handle_quicklook_button_selection)
132
 
 
6
  create_home_main_area,
7
  create_home_output_box,
8
  create_home_warning_box,
 
9
  create_home_help_area,
10
  create_home_footer,
11
+ create_home_plots_area,
12
  )
13
  from modules.DataLoading.DataIngestion import (
14
  create_loadingdata_header,
 
16
  create_loadingdata_output_box,
17
  create_loadingdata_warning_box,
18
  create_loadingdata_help_area,
19
+ create_loadingdata_plots_area,
20
  )
21
  from modules.QuickLook.LightCurve import (
22
  create_quicklook_lightcurve_header,
23
  create_quicklook_lightcurve_main_area,
24
  )
25
+ from modules.QuickLook.PowerSpectrum import (
26
+ create_quicklook_powerspectrum_header,
27
+ create_quicklook_powerspectrum_main_area,
28
+ )
29
  from assets.icons.svg import HOME_ICON_SVG, LOAD_DATA_ICON_SVG
30
 
 
31
  def create_sidebar(
32
+ main_area, header, footer, output_box, warning_box, help_box, plots_area, floating_panel
33
  ):
34
  menu_items_quicklook_stingray = [
35
  ("Light Curve", "QuickLookLightCurve"),
 
72
  warning_box[:] = [create_home_warning_box()]
73
  help_box[:] = [create_home_help_area()]
74
  footer[:] = [create_home_footer()]
75
+ plots_area[:] = [create_home_plots_area()]
76
 
77
  home_button.on_click(handle_home_button_selection)
78
 
 
103
  output_box[:] = [create_home_output_box()]
104
  warning_box[:] = [create_home_warning_box()]
105
  help_box[:] = [create_loadingdata_help_area()]
106
+ plots_area[:] = [create_loadingdata_plots_area()]
107
 
108
  load_data_button.on_click(load_data)
109
 
 
133
  footer_container=footer,
134
  )
135
  ]
136
+ elif clicked == "QuickLookPowerspectra":
137
+ header[:] = [
138
+ create_quicklook_powerspectrum_header(
139
+ header_container=header,
140
+ main_area_container=main_area,
141
+ output_box_container=output_box,
142
+ warning_box_container=warning_box,
143
+ plots_container=plots_area,
144
+ help_box_container=help_box,
145
+ footer_container=footer,
146
+ )
147
+ ]
148
+ main_area[:] = [
149
+ create_quicklook_powerspectrum_main_area(
150
+ header_container=header,
151
+ main_area_container=main_area,
152
+ output_box_container=output_box,
153
+ warning_box_container=warning_box,
154
+ plots_container=plots_area,
155
+ help_box_container=help_box,
156
+ footer_container=footer,
157
+ )
158
+ ]
159
 
160
  quicklook_stingray_button.on_click(handle_quicklook_button_selection)
161