kartikmandar commited on
Commit
ed9933e
1 Parent(s): 6de55c8

better comments in dataingestion

Browse files
modules/DataLoading/DataIngestion.py CHANGED
@@ -1,5 +1,3 @@
1
- # component_factories.py
2
-
3
  import panel as pn
4
  from stingray.events import EventList
5
  from stingray import Lightcurve
@@ -17,51 +15,76 @@ from utils.DashboardClasses import (
17
  PlotsContainer,
18
  HelpBox,
19
  Footer,
 
20
  )
21
  import param
22
  from utils.strings import LOADING_DATA_HELP_BOX_STRING
23
 
24
- # Path to the topmost directory for loaded-data
25
  loaded_data_path = os.path.join(os.getcwd(), "files", "loaded-data")
26
 
27
  # Create the loaded-data directory if it doesn't exist
28
  os.makedirs(loaded_data_path, exist_ok=True)
29
 
30
 
31
- # Custom warning handler
32
- class WarningHandler:
33
- def __init__(self):
34
- self.warnings = []
35
-
36
- def warn(
37
- self, message, category=None, filename=None, lineno=None, file=None, line=None
38
- ):
39
- warning_message = f"Message: {message}\nCategory: {category.__name__ if category else 'N/A'}\nFile: {filename if filename else 'N/A'}\nLine: {lineno if lineno else 'N/A'}\n"
40
- self.warnings.append(warning_message)
41
-
42
-
43
  def create_warning_handler():
44
- # Create an instance of the warning handler
45
- warning_handler = WarningHandler()
46
 
47
- # Redirect warnings to the custom handler
 
 
 
48
  warnings.showwarning = warning_handler.warn
49
-
50
  return warning_handler
51
 
52
 
 
 
 
53
  def create_loadingdata_header():
 
 
 
 
 
 
54
  home_heading_input = pn.widgets.TextInput(
55
  name="Heading", value="Data Ingestion and creation"
56
  )
57
  return MainHeader(heading=home_heading_input)
58
 
59
 
 
 
 
60
  def create_loadingdata_output_box(content):
 
 
 
 
 
 
 
 
 
61
  return OutputBox(output_content=content)
62
 
63
 
 
 
 
64
  def create_loadingdata_warning_box(content):
 
 
 
 
 
 
 
 
 
65
  return WarningBox(warning_content=content)
66
 
67
 
@@ -75,6 +98,19 @@ def load_event_data(
75
  warning_box_container,
76
  warning_handler,
77
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  if not file_selector.value:
79
  output_box_container[:] = [
80
  create_loadingdata_output_box(
@@ -156,6 +192,18 @@ def save_loaded_files(
156
  warning_box_container,
157
  warning_handler,
158
  ):
 
 
 
 
 
 
 
 
 
 
 
 
159
  if not loaded_event_data:
160
  output_box_container[:] = [
161
  create_loadingdata_output_box("No files loaded to save.")
@@ -248,6 +296,16 @@ def delete_selected_files(
248
  warning_box_container,
249
  warning_handler,
250
  ):
 
 
 
 
 
 
 
 
 
 
251
  if not file_selector.value:
252
  output_box_container[:] = [
253
  create_loadingdata_output_box(
@@ -290,6 +348,16 @@ def preview_loaded_files(
290
  warning_handler,
291
  time_limit=10,
292
  ):
 
 
 
 
 
 
 
 
 
 
293
  if not loaded_event_data:
294
  output_box_container[:] = [
295
  create_loadingdata_output_box("No files loaded to preview.")
@@ -325,10 +393,33 @@ def preview_loaded_files(
325
  warning_handler.warnings.clear()
326
 
327
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
328
  def create_event_list(
329
  event,
330
  times_input,
331
  energy_input,
 
332
  gti_input,
333
  mjdref_input,
334
  name_input,
@@ -336,6 +427,21 @@ def create_event_list(
336
  warning_box_container,
337
  warning_handler,
338
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  # Clear previous warnings
340
  warning_handler.warnings.clear()
341
  warnings.resetwarnings()
@@ -356,6 +462,7 @@ def create_event_list(
356
  if energy_input.value
357
  else None
358
  )
 
359
  gti = (
360
  [
361
  [float(g) for g in interval.split()]
@@ -377,13 +484,13 @@ def create_event_list(
377
  else:
378
  name = f"event_list_{len(loaded_event_data)}"
379
 
380
- event_list = EventList(times, energy=energy, gti=gti, mjdref=mjdref)
381
 
382
  loaded_event_data.append((name, event_list))
383
 
384
  output_box_container[:] = [
385
  create_loadingdata_output_box(
386
- f"Event List created successfully!\nSaved as: {name}\nTimes: {event_list.time}\nMJDREF: {event_list.mjdref}\nGTI: {event_list.gti}\nEnergy: {event_list.energy if energy else 'Not provided'}"
387
  )
388
  ]
389
  except ValueError as ve:
@@ -412,6 +519,20 @@ def simulate_event_list(
412
  warning_box_container,
413
  warning_handler,
414
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  # Clear previous warnings
416
  warning_handler.warnings.clear()
417
  warnings.resetwarnings()
@@ -467,6 +588,17 @@ def simulate_event_list(
467
 
468
 
469
  def create_loading_tab(output_box_container, warning_box_container, warning_handler):
 
 
 
 
 
 
 
 
 
 
 
470
  file_selector = pn.widgets.FileSelector(
471
  os.getcwd(), only_files=True, name="Select File", show_hidden=True
472
  )
@@ -491,6 +623,7 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
491
  preview_button = pn.widgets.Button(
492
  name="Preview Loaded Files", button_type="default"
493
  )
 
494
 
495
  tooltip_format = pn.widgets.TooltipIcon(
496
  value=Tooltip(
@@ -508,8 +641,8 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
508
 
509
  def on_load_click(event):
510
  # Clear previous outputs and warnings
511
- output_box_container[:] = [create_loadingdata_output_box("")]
512
- warning_box_container[:] = [create_loadingdata_warning_box("")]
513
  warning_handler.warnings.clear()
514
  warnings.resetwarnings()
515
 
@@ -526,8 +659,8 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
526
 
527
  def on_save_click(event):
528
  # Clear previous outputs and warnings
529
- output_box_container[:] = [create_loadingdata_output_box("")]
530
- warning_box_container[:] = [create_loadingdata_warning_box("")]
531
  warning_handler.warnings.clear()
532
  warnings.resetwarnings()
533
 
@@ -543,8 +676,8 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
543
 
544
  def on_delete_click(event):
545
  # Clear previous outputs and warnings
546
- warning_box_container[:] = [create_loadingdata_warning_box("")]
547
- output_box_container[:] = [create_loadingdata_output_box("")]
548
  warning_handler.warnings.clear()
549
  warnings.resetwarnings()
550
 
@@ -558,8 +691,8 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
558
 
559
  def on_preview_click(event):
560
  # Clear previous outputs and warnings
561
- output_box_container[:] = [create_loadingdata_output_box("")]
562
- warning_box_container[:] = [create_loadingdata_warning_box("")]
563
  warning_handler.warnings.clear()
564
  warnings.resetwarnings()
565
 
@@ -567,10 +700,19 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
567
  event, output_box_container, warning_box_container, warning_handler
568
  )
569
 
 
 
 
 
 
 
 
 
570
  load_button.on_click(on_load_click)
571
  save_button.on_click(on_save_click)
572
  delete_button.on_click(on_delete_click)
573
  preview_button.on_click(on_preview_click)
 
574
 
575
  first_column = pn.Column(
576
  pn.pane.Markdown("# Load Files"),
@@ -578,7 +720,8 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
578
  pn.Row(filename_input, tooltip_file),
579
  pn.Row(format_input, tooltip_format),
580
  format_checkbox,
581
- pn.Row(load_button, save_button, delete_button, preview_button),
 
582
  width_policy="min",
583
  )
584
 
@@ -591,13 +734,17 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
591
 
592
 
593
  def create_event_list_tab(output_box_container, warning_box_container, warning_handler):
594
- output = pn.widgets.TextAreaInput(
595
- name="Output", value="", disabled=True, height=200
596
- )
597
- warning_output = pn.widgets.TextAreaInput(
598
- name="Warnings", value="", disabled=True, height=200
599
- )
 
600
 
 
 
 
601
  times_input = pn.widgets.TextInput(
602
  name="Photon Arrival Times", placeholder="e.g., 0.5, 1.1, 2.2, 3.7"
603
  )
@@ -605,6 +752,9 @@ def create_event_list_tab(output_box_container, warning_box_container, warning_h
605
  energy_input = pn.widgets.TextInput(
606
  name="Energy (optional)", placeholder="e.g., 0., 3., 4., 20."
607
  )
 
 
 
608
  gti_input = pn.widgets.TextInput(
609
  name="GTIs (optional)", placeholder="e.g., 0 4; 5 10"
610
  )
@@ -613,11 +763,18 @@ def create_event_list_tab(output_box_container, warning_box_container, warning_h
613
  )
614
  create_button = pn.widgets.Button(name="Create Event List", button_type="primary")
615
 
616
- create_button.on_click(
617
- lambda event: create_event_list(
 
 
 
 
 
 
618
  event,
619
  times_input,
620
  energy_input,
 
621
  gti_input,
622
  mjdref_input,
623
  name_input,
@@ -625,13 +782,15 @@ def create_event_list_tab(output_box_container, warning_box_container, warning_h
625
  warning_box_container,
626
  warning_handler,
627
  )
628
- )
 
629
 
630
  tab_content = pn.Column(
631
  pn.pane.Markdown("# Create Event List"),
632
  times_input,
633
  mjdref_input,
634
  energy_input,
 
635
  gti_input,
636
  name_input,
637
  create_button,
@@ -642,7 +801,17 @@ def create_event_list_tab(output_box_container, warning_box_container, warning_h
642
  def create_simulate_event_list_tab(
643
  output_box_container, warning_box_container, warning_handler
644
  ):
 
 
 
 
 
 
 
645
 
 
 
 
646
  simulation_title = pn.pane.Markdown("# Simulating Event Lists")
647
  time_slider = pn.widgets.IntSlider(
648
  name="Number of Time Bins", start=1, end=10000, value=10
@@ -663,8 +832,15 @@ def create_simulate_event_list_tab(
663
  name="Simulate Event List", button_type="primary"
664
  )
665
 
666
- simulate_button.on_click(
667
- lambda event: simulate_event_list(
 
 
 
 
 
 
 
668
  event,
669
  time_slider,
670
  count_slider,
@@ -675,7 +851,8 @@ def create_simulate_event_list_tab(
675
  warning_box_container,
676
  warning_handler,
677
  )
678
- )
 
679
 
680
  tab_content = pn.Column(
681
  simulation_title,
@@ -690,6 +867,16 @@ def create_simulate_event_list_tab(
690
 
691
 
692
  def create_loadingdata_main_area(output_box, warning_box):
 
 
 
 
 
 
 
 
 
 
693
  warning_handler = create_warning_handler()
694
  tabs_content = {
695
  "Load Event List": create_loading_tab(
@@ -712,6 +899,11 @@ def create_loadingdata_main_area(output_box, warning_box):
712
 
713
 
714
  def create_loadingdata_help_area():
 
 
 
 
 
 
715
  help_content = LOADING_DATA_HELP_BOX_STRING
716
  return HelpBox(help_content=help_content, title="Help Section")
717
-
 
 
 
1
  import panel as pn
2
  from stingray.events import EventList
3
  from stingray import Lightcurve
 
15
  PlotsContainer,
16
  HelpBox,
17
  Footer,
18
+ WarningHandler,
19
  )
20
  import param
21
  from utils.strings import LOADING_DATA_HELP_BOX_STRING
22
 
23
+ # Path to the topmost directory for loaded data
24
  loaded_data_path = os.path.join(os.getcwd(), "files", "loaded-data")
25
 
26
  # Create the loaded-data directory if it doesn't exist
27
  os.makedirs(loaded_data_path, exist_ok=True)
28
 
29
 
30
+ # Create a warning handler
 
 
 
 
 
 
 
 
 
 
 
31
  def create_warning_handler():
32
+ """
33
+ Create an instance of WarningHandler and redirect warnings to this custom handler.
34
 
35
+ Returns:
36
+ warning_handler (WarningHandler): An instance of WarningHandler to handle warnings.
37
+ """
38
+ warning_handler = WarningHandler()
39
  warnings.showwarning = warning_handler.warn
 
40
  return warning_handler
41
 
42
 
43
+ """ Header Section """
44
+
45
+
46
  def create_loadingdata_header():
47
+ """
48
+ Create the header for the data loading section.
49
+
50
+ Returns:
51
+ MainHeader: An instance of MainHeader with the specified heading.
52
+ """
53
  home_heading_input = pn.widgets.TextInput(
54
  name="Heading", value="Data Ingestion and creation"
55
  )
56
  return MainHeader(heading=home_heading_input)
57
 
58
 
59
+ """ Output Box Section """
60
+
61
+
62
  def create_loadingdata_output_box(content):
63
+ """
64
+ Create an output box to display messages.
65
+
66
+ Args:
67
+ content (str): The content to be displayed in the output box.
68
+
69
+ Returns:
70
+ OutputBox: An instance of OutputBox with the specified content.
71
+ """
72
  return OutputBox(output_content=content)
73
 
74
 
75
+ """ Warning Box Section """
76
+
77
+
78
  def create_loadingdata_warning_box(content):
79
+ """
80
+ Create a warning box to display warnings.
81
+
82
+ Args:
83
+ content (str): The content to be displayed in the warning box.
84
+
85
+ Returns:
86
+ WarningBox: An instance of WarningBox with the specified content.
87
+ """
88
  return WarningBox(warning_content=content)
89
 
90
 
 
98
  warning_box_container,
99
  warning_handler,
100
  ):
101
+ """
102
+ Load event data from selected files.
103
+
104
+ Args:
105
+ event: The event object triggering the function.
106
+ file_selector (FileSelector): The file selector widget.
107
+ filename_input (TextInput): The input widget for filenames.
108
+ format_input (TextInput): The input widget for formats.
109
+ format_checkbox (Checkbox): The checkbox for default format.
110
+ output_box_container (OutputBox): The container for output messages.
111
+ warning_box_container (WarningBox): The container for warning messages.
112
+ warning_handler (WarningHandler): The handler for warnings.
113
+ """
114
  if not file_selector.value:
115
  output_box_container[:] = [
116
  create_loadingdata_output_box(
 
192
  warning_box_container,
193
  warning_handler,
194
  ):
195
+ """
196
+ Save loaded event data to specified file formats.
197
+
198
+ Args:
199
+ event: The event object triggering the function.
200
+ filename_input (TextInput): The input widget for filenames.
201
+ format_input (TextInput): The input widget for formats.
202
+ format_checkbox (Checkbox): The checkbox for default format.
203
+ output_box_container (OutputBox): The container for output messages.
204
+ warning_box_container (WarningBox): The container for warning messages.
205
+ warning_handler (WarningHandler): The handler for warnings.
206
+ """
207
  if not loaded_event_data:
208
  output_box_container[:] = [
209
  create_loadingdata_output_box("No files loaded to save.")
 
296
  warning_box_container,
297
  warning_handler,
298
  ):
299
+ """
300
+ Delete selected files from the file system.
301
+
302
+ Args:
303
+ event: The event object triggering the function.
304
+ file_selector (FileSelector): The file selector widget.
305
+ output_box_container (OutputBox): The container for output messages.
306
+ warning_box_container (WarningBox): The container for warning messages.
307
+ warning_handler (WarningHandler): The handler for warnings.
308
+ """
309
  if not file_selector.value:
310
  output_box_container[:] = [
311
  create_loadingdata_output_box(
 
348
  warning_handler,
349
  time_limit=10,
350
  ):
351
+ """
352
+ Preview the loaded event data files.
353
+
354
+ Args:
355
+ event: The event object triggering the function.
356
+ output_box_container (OutputBox): The container for output messages.
357
+ warning_box_container (WarningBox): The container for warning messages.
358
+ warning_handler (WarningHandler): The handler for warnings.
359
+ time_limit (int): The number of time entries to preview.
360
+ """
361
  if not loaded_event_data:
362
  output_box_container[:] = [
363
  create_loadingdata_output_box("No files loaded to preview.")
 
393
  warning_handler.warnings.clear()
394
 
395
 
396
+ def clear_loaded_files(event, output_box_container, warning_box_container):
397
+ """
398
+ Clear all loaded event data files from memory.
399
+
400
+ Args:
401
+ event: The event object triggering the function.
402
+ output_box_container (OutputBox): The container for output messages.
403
+ warning_box_container (WarningBox): The container for warning messages.
404
+ """
405
+ global loaded_event_data
406
+ if not loaded_event_data:
407
+ output_box_container[:] = [
408
+ create_loadingdata_output_box("No files loaded to clear.")
409
+ ]
410
+ else:
411
+ loaded_event_data.clear()
412
+ output_box_container[:] = [
413
+ create_loadingdata_output_box("Loaded files have been cleared.")
414
+ ]
415
+ warning_box_container[:] = [create_loadingdata_warning_box("No warnings.")]
416
+
417
+
418
  def create_event_list(
419
  event,
420
  times_input,
421
  energy_input,
422
+ pi_input,
423
  gti_input,
424
  mjdref_input,
425
  name_input,
 
427
  warning_box_container,
428
  warning_handler,
429
  ):
430
+ """
431
+ Create an event list from user input.
432
+
433
+ Args:
434
+ event: The event object triggering the function.
435
+ times_input (TextInput): The input widget for photon arrival times.
436
+ energy_input (TextInput): The input widget for energy values (optional).
437
+ pi_input (TextInput): The input widget for PI values (optional).
438
+ gti_input (TextInput): The input widget for GTIs (optional).
439
+ mjdref_input (TextInput): The input widget for MJDREF value.
440
+ name_input (TextInput): The input widget for the event list name.
441
+ output_box_container (OutputBox): The container for output messages.
442
+ warning_box_container (WarningBox): The container for warning messages.
443
+ warning_handler (WarningHandler): The handler for warnings.
444
+ """
445
  # Clear previous warnings
446
  warning_handler.warnings.clear()
447
  warnings.resetwarnings()
 
462
  if energy_input.value
463
  else None
464
  )
465
+ pi = [int(p) for p in pi_input.value.split(",")] if pi_input.value else None
466
  gti = (
467
  [
468
  [float(g) for g in interval.split()]
 
484
  else:
485
  name = f"event_list_{len(loaded_event_data)}"
486
 
487
+ event_list = EventList(times, energy=energy, pi=pi, gti=gti, mjdref=mjdref)
488
 
489
  loaded_event_data.append((name, event_list))
490
 
491
  output_box_container[:] = [
492
  create_loadingdata_output_box(
493
+ f"Event List created successfully!\nSaved as: {name}\nTimes: {event_list.time}\nMJDREF: {event_list.mjdref}\nGTI: {event_list.gti}\nEnergy: {event_list.energy if energy else 'Not provided'}\nPI: {event_list.pi if pi else 'Not provided'}"
494
  )
495
  ]
496
  except ValueError as ve:
 
519
  warning_box_container,
520
  warning_handler,
521
  ):
522
+ """
523
+ Simulate an event list based on user-defined parameters.
524
+
525
+ Args:
526
+ event: The event object triggering the function.
527
+ time_slider (IntSlider): The slider for the number of time bins.
528
+ count_slider (IntSlider): The slider for the maximum counts per bin.
529
+ dt_input (FloatSlider): The slider for delta time (dt).
530
+ name_input (TextInput): The input widget for the simulated event list name.
531
+ method_selector (Select): The selector for the simulation method.
532
+ output_box_container (OutputBox): The container for output messages.
533
+ warning_box_container (WarningBox): The container for warning messages.
534
+ warning_handler (WarningHandler): The handler for warnings.
535
+ """
536
  # Clear previous warnings
537
  warning_handler.warnings.clear()
538
  warnings.resetwarnings()
 
588
 
589
 
590
  def create_loading_tab(output_box_container, warning_box_container, warning_handler):
591
+ """
592
+ Create the tab for loading event data files.
593
+
594
+ Args:
595
+ output_box_container (OutputBox): The container for output messages.
596
+ warning_box_container (WarningBox): The container for warning messages.
597
+ warning_handler (WarningHandler): The handler for warnings.
598
+
599
+ Returns:
600
+ tab_content (Column): A Panel Column containing the widgets and layout for the loading tab.
601
+ """
602
  file_selector = pn.widgets.FileSelector(
603
  os.getcwd(), only_files=True, name="Select File", show_hidden=True
604
  )
 
623
  preview_button = pn.widgets.Button(
624
  name="Preview Loaded Files", button_type="default"
625
  )
626
+ clear_button = pn.widgets.Button(name="Clear Loaded Files", button_type="warning")
627
 
628
  tooltip_format = pn.widgets.TooltipIcon(
629
  value=Tooltip(
 
641
 
642
  def on_load_click(event):
643
  # Clear previous outputs and warnings
644
+ output_box_container[:] = [create_loadingdata_output_box("N.A.")]
645
+ warning_box_container[:] = [create_loadingdata_warning_box("N.A.")]
646
  warning_handler.warnings.clear()
647
  warnings.resetwarnings()
648
 
 
659
 
660
  def on_save_click(event):
661
  # Clear previous outputs and warnings
662
+ output_box_container[:] = [create_loadingdata_output_box("N.A.")]
663
+ warning_box_container[:] = [create_loadingdata_warning_box("N.A.")]
664
  warning_handler.warnings.clear()
665
  warnings.resetwarnings()
666
 
 
676
 
677
  def on_delete_click(event):
678
  # Clear previous outputs and warnings
679
+ warning_box_container[:] = [create_loadingdata_warning_box("N.A.")]
680
+ output_box_container[:] = [create_loadingdata_output_box("N.A.")]
681
  warning_handler.warnings.clear()
682
  warnings.resetwarnings()
683
 
 
691
 
692
  def on_preview_click(event):
693
  # Clear previous outputs and warnings
694
+ output_box_container[:] = [create_loadingdata_output_box("N.A.")]
695
+ warning_box_container[:] = [create_loadingdata_warning_box("N.A.")]
696
  warning_handler.warnings.clear()
697
  warnings.resetwarnings()
698
 
 
700
  event, output_box_container, warning_box_container, warning_handler
701
  )
702
 
703
+ def on_clear_click(event):
704
+ # Clear the loaded files list
705
+ output_box_container[:] = [create_loadingdata_output_box("N.A.")]
706
+ warning_box_container[:] = [create_loadingdata_warning_box("N.A.")]
707
+ warning_handler.warnings.clear()
708
+ warnings.resetwarnings()
709
+ clear_loaded_files(event, output_box_container, warning_box_container)
710
+
711
  load_button.on_click(on_load_click)
712
  save_button.on_click(on_save_click)
713
  delete_button.on_click(on_delete_click)
714
  preview_button.on_click(on_preview_click)
715
+ clear_button.on_click(on_clear_click)
716
 
717
  first_column = pn.Column(
718
  pn.pane.Markdown("# Load Files"),
 
720
  pn.Row(filename_input, tooltip_file),
721
  pn.Row(format_input, tooltip_format),
722
  format_checkbox,
723
+ pn.Row(load_button, save_button, delete_button, preview_button, clear_button),
724
+ pn.pane.Markdown("<br/>"),
725
  width_policy="min",
726
  )
727
 
 
734
 
735
 
736
  def create_event_list_tab(output_box_container, warning_box_container, warning_handler):
737
+ """
738
+ Create the tab for creating an event list.
739
+
740
+ Args:
741
+ output_box_container (OutputBox): The container for output messages.
742
+ warning_box_container (WarningBox): The container for warning messages.
743
+ warning_handler (WarningHandler): The handler for warnings.
744
 
745
+ Returns:
746
+ tab_content (Column): A Panel Column containing the widgets and layout for the event list creation tab.
747
+ """
748
  times_input = pn.widgets.TextInput(
749
  name="Photon Arrival Times", placeholder="e.g., 0.5, 1.1, 2.2, 3.7"
750
  )
 
752
  energy_input = pn.widgets.TextInput(
753
  name="Energy (optional)", placeholder="e.g., 0., 3., 4., 20."
754
  )
755
+ pi_input = pn.widgets.TextInput(
756
+ name="PI (optional)", placeholder="e.g., 100, 200, 300, 400"
757
+ )
758
  gti_input = pn.widgets.TextInput(
759
  name="GTIs (optional)", placeholder="e.g., 0 4; 5 10"
760
  )
 
763
  )
764
  create_button = pn.widgets.Button(name="Create Event List", button_type="primary")
765
 
766
+ def on_create_button_click(event):
767
+ # Clear previous output and warnings
768
+ output_box_container.clear()
769
+ warning_box_container.clear()
770
+ warning_handler.warnings.clear()
771
+ warnings.resetwarnings()
772
+
773
+ create_event_list(
774
  event,
775
  times_input,
776
  energy_input,
777
+ pi_input,
778
  gti_input,
779
  mjdref_input,
780
  name_input,
 
782
  warning_box_container,
783
  warning_handler,
784
  )
785
+
786
+ create_button.on_click(on_create_button_click)
787
 
788
  tab_content = pn.Column(
789
  pn.pane.Markdown("# Create Event List"),
790
  times_input,
791
  mjdref_input,
792
  energy_input,
793
+ pi_input,
794
  gti_input,
795
  name_input,
796
  create_button,
 
801
  def create_simulate_event_list_tab(
802
  output_box_container, warning_box_container, warning_handler
803
  ):
804
+ """
805
+ Create the tab for simulating event lists.
806
+
807
+ Args:
808
+ output_box_container (OutputBox): The container for output messages.
809
+ warning_box_container (WarningBox): The container for warning messages.
810
+ warning_handler (WarningHandler): The handler for warnings.
811
 
812
+ Returns:
813
+ tab_content (Column): A Panel Column containing the widgets and layout for the event list simulation tab.
814
+ """
815
  simulation_title = pn.pane.Markdown("# Simulating Event Lists")
816
  time_slider = pn.widgets.IntSlider(
817
  name="Number of Time Bins", start=1, end=10000, value=10
 
832
  name="Simulate Event List", button_type="primary"
833
  )
834
 
835
+ def on_simulate_button_click(event):
836
+ # Clear previous output and warnings
837
+ output_box_container[:] = [create_loadingdata_output_box("N.A.")]
838
+ warning_box_container[:] = [create_loadingdata_warning_box("N.A.")]
839
+ warning_handler.warnings.clear()
840
+ warnings.resetwarnings()
841
+
842
+ # Simulate the event list
843
+ simulate_event_list(
844
  event,
845
  time_slider,
846
  count_slider,
 
851
  warning_box_container,
852
  warning_handler,
853
  )
854
+
855
+ simulate_button.on_click(on_simulate_button_click)
856
 
857
  tab_content = pn.Column(
858
  simulation_title,
 
867
 
868
 
869
  def create_loadingdata_main_area(output_box, warning_box):
870
+ """
871
+ Create the main area for the data loading tab, including all sub-tabs.
872
+
873
+ Args:
874
+ output_box (OutputBox): The container for output messages.
875
+ warning_box (WarningBox): The container for warning messages.
876
+
877
+ Returns:
878
+ MainArea: An instance of MainArea with all the necessary tabs for data loading.
879
+ """
880
  warning_handler = create_warning_handler()
881
  tabs_content = {
882
  "Load Event List": create_loading_tab(
 
899
 
900
 
901
  def create_loadingdata_help_area():
902
+ """
903
+ Create the help area for the data loading tab.
904
+
905
+ Returns:
906
+ HelpBox: An instance of HelpBox with the help content.
907
+ """
908
  help_content = LOADING_DATA_HELP_BOX_STRING
909
  return HelpBox(help_content=help_content, title="Help Section")
 
modules/QuickLook/LightCurve.py CHANGED
@@ -1,5 +1,9 @@
1
  import panel as pn
2
-
 
 
 
 
3
  from utils.DashboardClasses import (
4
  MainHeader,
5
  MainArea,
@@ -8,17 +12,66 @@ from utils.DashboardClasses import (
8
  PlotsContainer,
9
  HelpBox,
10
  Footer,
 
11
  )
12
 
13
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
 
16
  def create_quicklook_lightcurve_header():
17
  home_heading_input = pn.widgets.TextInput(
18
  name="Heading", value="QuickLook Light Curve"
19
  )
20
- home_subheading_input = pn.widgets.TextInput(
21
- name="Subheading", value=""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  )
23
 
24
- return MainHeader(heading=home_heading_input, subheading=home_subheading_input)
 
 
 
 
 
 
1
  import panel as pn
2
+ import holoviews as hv
3
+ from utils.globals import loaded_event_data
4
+ import numpy as np
5
+ import pandas as pd
6
+ import hvplot.pandas
7
  from utils.DashboardClasses import (
8
  MainHeader,
9
  MainArea,
 
12
  PlotsContainer,
13
  HelpBox,
14
  Footer,
15
+ WarningHandler,
16
  )
17
 
18
 
19
+ # Create a warning handler
20
+ def create_warning_handler():
21
+ # Create an instance of the warning handler
22
+ warning_handler = WarningHandler()
23
+
24
+ # Redirect warnings to the custom handler
25
+ warnings.showwarning = warning_handler.warn
26
+
27
+ return warning_handler
28
+
29
+
30
+ """ Header Section """
31
 
32
 
33
  def create_quicklook_lightcurve_header():
34
  home_heading_input = pn.widgets.TextInput(
35
  name="Heading", value="QuickLook Light Curve"
36
  )
37
+ home_subheading_input = pn.widgets.TextInput(name="Subheading", value="")
38
+
39
+ return MainHeader(heading=home_heading_input, subheading=home_subheading_input)
40
+
41
+
42
+ """ Output Box Section """
43
+
44
+
45
+ def create_loadingdata_output_box(content):
46
+ return OutputBox(output_content=content)
47
+
48
+
49
+ """ Warning Box Section """
50
+
51
+
52
+ def create_loadingdata_warning_box(content):
53
+ return WarningBox(warning_content=content)
54
+
55
+
56
+ """ Main Area Section """
57
+
58
+ def create_lightcurve_tab(output_box_container, warning_box_container, warning_handler):
59
+ event_list_dropdown = pn.widgets.Select(
60
+ name="Select Event List",
61
+ options={name: i for i, (name, event) in enumerate(loaded_event_data)},
62
+ )
63
+
64
+ dt_slider = pn.widgets.FloatSlider(
65
+ name="Select dt",
66
+ start=0.1,
67
+ end=100,
68
+ step=0.1,
69
+ value=1,
70
  )
71
 
72
+
73
+ def create_quicklook_lightcurve_main_area(output_box, warning_box):
74
+ warning_handler = create_warning_handler()
75
+ tabs_content = {
76
+ "Light Curve": create_lightcurve_tab(output_box, warning_box, warning_handler),
77
+ }
utils/dashboardClasses.py CHANGED
@@ -530,3 +530,15 @@ class Footer(pn.viewable.Viewer):
530
  )
531
 
532
  return footer
 
 
 
 
 
 
 
 
 
 
 
 
 
530
  )
531
 
532
  return footer
533
+
534
+
535
+ # Custom warning handler
536
+ class WarningHandler:
537
+ def __init__(self):
538
+ self.warnings = []
539
+
540
+ def warn(
541
+ self, message, category=None, filename=None, lineno=None, file=None, line=None
542
+ ):
543
+ warning_message = f"Message: {message}\nCategory: {category.__name__ if category else 'N/A'}\nFile: {filename if filename else 'N/A'}\nLine: {lineno if lineno else 'N/A'}\n"
544
+ self.warnings.append(warning_message)
utils/globals.py CHANGED
@@ -1 +1,2 @@
 
1
  loaded_event_data = []
 
1
+ # Global variable to store loaded event data
2
  loaded_event_data = []
utils/strings.py CHANGED
@@ -251,11 +251,12 @@ ev.write("events.hdf5", "hdf5")
251
 
252
  ### Functionality
253
 
254
- The "Creation" tab allows you to create new event lists or simulate event lists from light curves. Here is a detailed explanation of each component and its functionality:
255
 
256
  - **Photon Arrival Times**: Enter photon arrival times in seconds from a reference MJD.
257
  - **MJDREF**: Enter the MJD reference for the photon arrival times.
258
  - **Energy (optional)**: Enter the energy values associated with the photons.
 
259
  - **GTIs (optional)**: Enter the Good Time Intervals (GTIs) for the event list.
260
  - **Event List Name**: Specify a name for the new event list.
261
  - **Create Event List**: Create a new event list with the specified parameters.
 
251
 
252
  ### Functionality
253
 
254
+ The "Creation" tab allows you to create new event lists. Here is a detailed explanation of each component and its functionality:
255
 
256
  - **Photon Arrival Times**: Enter photon arrival times in seconds from a reference MJD.
257
  - **MJDREF**: Enter the MJD reference for the photon arrival times.
258
  - **Energy (optional)**: Enter the energy values associated with the photons.
259
+ Default is
260
  - **GTIs (optional)**: Enter the Good Time Intervals (GTIs) for the event list.
261
  - **Event List Name**: Specify a name for the new event list.
262
  - **Create Event List**: Create a new event list with the specified parameters.