Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

load_measurement.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. from abc import abstractmethod
  2. from PyQt5.QtCore import pyqtSignal, pyqtSlot
  3. from PyQt5.QtWidgets import QMainWindow, QVBoxLayout, QPushButton, QHBoxLayout, QAbstractItemView, QMessageBox, \
  4. QDesktopWidget, QWidget
  5. from view.python_core.measurement_list import MeasurementList, get_importer_class
  6. from .custom_widgets import QTableWidgetPandasDF
  7. from .file_selector_combobox import get_file_selector_combobox_using_settings
  8. class LoadMeasurementsFromFileWindow(QMainWindow):
  9. send_data_signal = pyqtSignal(MeasurementList, list,
  10. name="Measurement Selected")
  11. def __init__(self, LE_loadExp, default_directory_path, measurement_list=None):
  12. super().__init__()
  13. self.lst_file = None
  14. self.lst_df = None
  15. self.lst_df_filter = None
  16. self.lst_file_selector = None
  17. self.lst_display_table = None
  18. self.LE_loadExp = LE_loadExp
  19. self.measurement_list = measurement_list
  20. self.default_directory_path = default_directory_path
  21. self.init_UI()
  22. if measurement_list is not None:
  23. self.refresh_display()
  24. @abstractmethod
  25. def get_file_selector_combobox(self):
  26. pass
  27. def init_UI(self):
  28. main_vbox = QVBoxLayout()
  29. self.lst_file_selector = self.get_file_selector_combobox()
  30. self.lst_file_selector.return_filename_signal.connect(self.load_lst_from_file)
  31. main_vbox.addWidget(self.lst_file_selector)
  32. self.lst_display_table = QTableWidgetPandasDF(self)
  33. self.lst_display_table.setSelectionBehavior(QAbstractItemView.SelectRows)
  34. self.lst_display_table.setSelectionMode(QAbstractItemView.MultiSelection)
  35. main_vbox.addWidget(self.lst_display_table)
  36. finish_buttons = QHBoxLayout()
  37. cancel_button = QPushButton("Cancel")
  38. cancel_button.clicked.connect(self.cancel)
  39. finish_buttons.addWidget(cancel_button)
  40. load_measurement_button = QPushButton("Load Measurement")
  41. load_measurement_button.clicked.connect(self.row_selected)
  42. finish_buttons.addWidget(load_measurement_button)
  43. main_vbox.addLayout(finish_buttons)
  44. centralWidget = QWidget(self)
  45. centralWidget.setLayout(main_vbox)
  46. self.setCentralWidget(centralWidget)
  47. self.setWindowTitle('Load Measurement')
  48. self.setGeometry(300, 300, 500, 700)
  49. self.center()
  50. def center(self):
  51. qr = self.frameGeometry()
  52. cp = QDesktopWidget().availableGeometry().center()
  53. qr.moveCenter(cp)
  54. self.move(qr.topLeft())
  55. @abstractmethod
  56. def load_lst_from_file(self, lst_file):
  57. pass
  58. def refresh_display(self):
  59. self.lst_display_table.refresh(self.measurement_list.measurement_list_df)
  60. def cancel(self):
  61. self.close()
  62. def row_selected(self):
  63. row_selection_model = self.lst_display_table.selectionModel()
  64. try:
  65. measu_header_ind = self.lst_display_table.get_headers().index("Measu")
  66. except ValueError as ve:
  67. raise ValueError("Something went wrong in loading data. Could not find the column 'Measu' in "
  68. "measurement selection table")
  69. if row_selection_model.hasSelection():
  70. selected_measus_widget_items = [
  71. self.lst_display_table.item(x.row(), measu_header_ind) for x in row_selection_model.selectedRows()]
  72. selected_measus = [int(float(x.text())) for x in selected_measus_widget_items]
  73. self.send_data_signal.emit(self.measurement_list, selected_measus)
  74. self.close()
  75. else:
  76. QMessageBox.critical(self, "IO Error", "No rows selected. Please select one!")
  77. class LoadMeasurementsFromListWindow(LoadMeasurementsFromFileWindow):
  78. def __init__(self, LE_loadExp, default_directory_path, measurement_list=None):
  79. super().__init__(LE_loadExp, default_directory_path, measurement_list)
  80. def get_file_selector_combobox(self):
  81. lst_file_selector = \
  82. get_file_selector_combobox_using_settings()(
  83. parent=self,
  84. groupbox_title="Choose a measurement List File "
  85. "(.lst, .settings.xls/x, .lst.xls/x)",
  86. file_type="LST/settings",
  87. file_filter="Measurement List files"
  88. " (*.lst *.xls *.xlsx)",
  89. use_list_in_settings="lst_file_list",
  90. default_directory=str(self.default_directory_path),
  91. settings_list_value_filter=
  92. lambda x: x.find(str(self.default_directory_path)) >= 0
  93. )
  94. return lst_file_selector
  95. @pyqtSlot(str, name="load lst file")
  96. def load_lst_from_file(self, lst_file):
  97. self.measurement_list = MeasurementList.create_from_lst_file(lst_file, self.LE_loadExp)
  98. self.refresh_display()
  99. def measurement_filter(s):
  100. # exclude blocks with less than two frames or no calibration
  101. atleast_two_frames = False
  102. if type(s["Timing_ms"]) is str:
  103. if len(s["Timing_ms"].split(' ')) >= 2 and s["Timing_ms"].find("(No calibration available)") < 0:
  104. atleast_two_frames = True
  105. return atleast_two_frames
  106. class LoadMeasurementsFromVWSLogWindow(LoadMeasurementsFromFileWindow):
  107. def __init__(self, LE_loadExp, default_directory_path, measurement_list=None):
  108. super().__init__(LE_loadExp, default_directory_path, measurement_list)
  109. def get_file_selector_combobox(self):
  110. lst_file_selector = \
  111. get_file_selector_combobox_using_settings()(
  112. parent=self,
  113. groupbox_title="Choose a VWS.LOG File "
  114. "(.vws.log)",
  115. file_type="VWS.LOG",
  116. file_filter="Till VISION VWS.LOG files"
  117. " (*.log)",
  118. use_list_in_settings="vws_log_files",
  119. default_directory=str(self.default_directory_path),
  120. settings_list_value_filter=
  121. lambda x: x.find(str(self.default_directory_path)) >= 0
  122. )
  123. return lst_file_selector
  124. @pyqtSlot(str, name="load lst file")
  125. def load_lst_from_file(self, lst_file):
  126. # initialize importer
  127. importer_class = get_importer_class(self.LE_loadExp)
  128. importer = importer_class(default_values={}) # no default values specified
  129. # automatically parse metadata
  130. metadata_df = importer.import_metadata(raw_data_files=[lst_file],
  131. measurement_filter=measurement_filter)
  132. self.measurement_list = MeasurementList.create_from_df(LE_loadExp=self.LE_loadExp, df=metadata_df)
  133. self.measurement_list.last_measurement_list_fle = lst_file
  134. self.refresh_display()