kartikmandar commited on
Commit
9cc56a6
·
1 Parent(s): a092765

change load to read files, add tooltip

Browse files
modules/DataLoading/DataIngestion.py CHANGED
@@ -1,12 +1,20 @@
1
- import panel as pn
2
- import asyncio
3
- from stingray.events import EventList
4
- from stingray import Lightcurve
5
- import warnings
6
  import os
7
  import stat
8
  import numpy as np
 
9
  from bokeh.models import Tooltip
 
 
 
 
 
 
 
 
 
 
 
10
  from utils.globals import loaded_event_data, loaded_light_curve
11
  from utils.DashboardClasses import (
12
  MainHeader,
@@ -14,14 +22,15 @@ from utils.DashboardClasses import (
14
  OutputBox,
15
  WarningBox,
16
  HelpBox,
17
- Footer,
18
  WarningHandler,
19
- FloatingPlot,
20
  PlotsContainer,
21
  )
22
- import param
 
23
  from utils.strings import LOADING_DATA_HELP_BOX_STRING
24
 
 
 
25
  # Path to the topmost directory for loaded data
26
  loaded_data_path = os.path.join(os.getcwd(), "files", "loaded-data")
27
 
@@ -81,7 +90,7 @@ def create_loadingdata_header(
81
  'Data Ingestion and creation'
82
  """
83
  home_heading_input = pn.widgets.TextInput(
84
- name="Heading", value="Data Ingestion and creation"
85
  )
86
  return MainHeader(heading=home_heading_input)
87
 
@@ -391,6 +400,12 @@ def delete_selected_files(
391
  >>> os.path.exists('/path/to/deleted/file')
392
  False # Assuming the file was deleted successfully
393
  """
 
 
 
 
 
 
394
  if not file_selector.value:
395
  output_box_container[:] = [
396
  create_loadingdata_output_box(
@@ -401,11 +416,12 @@ def delete_selected_files(
401
 
402
  file_paths = file_selector.value
403
  deleted_files = []
 
404
  for file_path in file_paths:
405
- if file_path.endswith(".py"):
406
- deleted_files.append(
407
- f"Cannot delete file '{file_path}': Deleting .py files is not allowed."
408
- )
409
  continue
410
 
411
  try:
@@ -415,6 +431,17 @@ def delete_selected_files(
415
  deleted_files.append(f"File '{file_path}' deleted successfully.")
416
  except Exception as e:
417
  deleted_files.append(f"An error occurred while deleting '{file_path}': {e}")
 
 
 
 
 
 
 
 
 
 
 
418
  output_box_container[:] = [create_loadingdata_output_box("\n".join(deleted_files))]
419
  if warning_handler.warnings:
420
  warning_box_container[:] = [
@@ -885,7 +912,7 @@ def create_loading_tab(output_box_container, warning_box_container, warning_hand
885
  clear_button.on_click(on_clear_click)
886
 
887
  first_column = pn.Column(
888
- pn.pane.Markdown("# Load Files"),
889
  file_selector,
890
  pn.Row(filename_input, tooltip_file),
891
  pn.Row(format_input, tooltip_format),
@@ -1077,7 +1104,7 @@ def create_loadingdata_main_area(
1077
  """
1078
  warning_handler = create_warning_handler()
1079
  tabs_content = {
1080
- "Load Event List": create_loading_tab(
1081
  output_box_container=output_box_container,
1082
  warning_box_container=warning_box_container,
1083
  warning_handler=warning_handler,
 
1
+ # Standard Imports
 
 
 
 
2
  import os
3
  import stat
4
  import numpy as np
5
+ import warnings
6
  from bokeh.models import Tooltip
7
+
8
+
9
+ # HoloViz Imports
10
+ import panel as pn
11
+
12
+ # Stingray Imports
13
+ from stingray.events import EventList
14
+ from stingray import Lightcurve
15
+ from stingray.io import get_file_extension
16
+
17
+ # Dashboard Classes and Event Data Imports
18
  from utils.globals import loaded_event_data, loaded_light_curve
19
  from utils.DashboardClasses import (
20
  MainHeader,
 
22
  OutputBox,
23
  WarningBox,
24
  HelpBox,
 
25
  WarningHandler,
 
26
  PlotsContainer,
27
  )
28
+
29
+ # Strings Imports
30
  from utils.strings import LOADING_DATA_HELP_BOX_STRING
31
 
32
+
33
+
34
  # Path to the topmost directory for loaded data
35
  loaded_data_path = os.path.join(os.getcwd(), "files", "loaded-data")
36
 
 
90
  'Data Ingestion and creation'
91
  """
92
  home_heading_input = pn.widgets.TextInput(
93
+ name="Heading", value="Data Ingestion"
94
  )
95
  return MainHeader(heading=home_heading_input)
96
 
 
400
  >>> os.path.exists('/path/to/deleted/file')
401
  False # Assuming the file was deleted successfully
402
  """
403
+
404
+ # Define allowed extensions for deletion
405
+ allowed_extensions = {
406
+ ".pkl", ".pickle", ".fits", ".evt", ".h5", ".hdf5",
407
+ ".ecsv", ".txt", ".dat", ".csv", ".vot", ".tex", ".html"
408
+ }
409
  if not file_selector.value:
410
  output_box_container[:] = [
411
  create_loadingdata_output_box(
 
416
 
417
  file_paths = file_selector.value
418
  deleted_files = []
419
+ restricted_files = []
420
  for file_path in file_paths:
421
+ # Check the file extension
422
+ _, ext = os.path.splitext(file_path)
423
+ if ext not in allowed_extensions:
424
+ restricted_files.append(file_path)
425
  continue
426
 
427
  try:
 
431
  deleted_files.append(f"File '{file_path}' deleted successfully.")
432
  except Exception as e:
433
  deleted_files.append(f"An error occurred while deleting '{file_path}': {e}")
434
+
435
+ # Create messages for deleted and restricted files
436
+ messages = []
437
+ if deleted_files:
438
+ messages.append("\n".join(deleted_files))
439
+ if restricted_files:
440
+ messages.append(
441
+ "The following files were not deleted because their extensions are not allowed:\n" +
442
+ "\n".join(restricted_files)
443
+ )
444
+
445
  output_box_container[:] = [create_loadingdata_output_box("\n".join(deleted_files))]
446
  if warning_handler.warnings:
447
  warning_box_container[:] = [
 
912
  clear_button.on_click(on_clear_click)
913
 
914
  first_column = pn.Column(
915
+ pn.Row(pn.pane.Markdown("<h2> Read an EventList object from File</h2>"),pn.widgets.TooltipIcon(value=Tooltip(content="Supported Formats: pickle, hea or ogip, any other astropy.table.Table", position="center"))),
916
  file_selector,
917
  pn.Row(filename_input, tooltip_file),
918
  pn.Row(format_input, tooltip_format),
 
1104
  """
1105
  warning_handler = create_warning_handler()
1106
  tabs_content = {
1107
+ "Read Event List from File": create_loading_tab(
1108
  output_box_container=output_box_container,
1109
  warning_box_container=warning_box_container,
1110
  warning_handler=warning_handler,
modules/Home/HomeContent.py CHANGED
@@ -11,8 +11,6 @@ import panel as pn
11
  # Stingray Imports
12
  from stingray.events import EventList
13
  from stingray.gti import get_gti_lengths, get_btis, get_total_gti_length
14
- from stingray import EventList
15
-
16
 
17
  # Dashboard Classes and Event Data Imports
18
  from utils.globals import loaded_event_data
 
11
  # Stingray Imports
12
  from stingray.events import EventList
13
  from stingray.gti import get_gti_lengths, get_btis, get_total_gti_length
 
 
14
 
15
  # Dashboard Classes and Event Data Imports
16
  from utils.globals import loaded_event_data
utils/sidebar.py CHANGED
@@ -83,7 +83,7 @@ def create_sidebar(
83
  load_data_button = pn.widgets.Button(
84
  icon=LOAD_DATA_ICON_SVG,
85
  icon_size="20px",
86
- name="Load Data",
87
  button_type="warning",
88
  styles={"width": "100"},
89
  description="Loading EventList",
 
83
  load_data_button = pn.widgets.Button(
84
  icon=LOAD_DATA_ICON_SVG,
85
  icon_size="20px",
86
+ name="Read Data",
87
  button_type="warning",
88
  styles={"width": "100"},
89
  description="Loading EventList",