diff --git a/Desarrollo/ReDS/mainA_window.py b/Desarrollo/ReDS/mainA_window.py index b8a42f80..c8b6926b 100644 --- a/Desarrollo/ReDS/mainA_window.py +++ b/Desarrollo/ReDS/mainA_window.py @@ -48,8 +48,6 @@ class UIMainAWindow(QtWidgets.QMainWindow): Attributes ---------- - launcher : QMainWindow - Main window of the application. global_variables : dict Dictionary with global variables. directories : dict @@ -1857,7 +1855,6 @@ def verify_parameters(self, uploaded_directories): ''' Verify parameters for experiments. ''' - if not uploaded_directories: return False diff --git a/Desarrollo/ReDS/mainB_window.py b/Desarrollo/ReDS/mainB_window.py index 6f95edd1..7550978c 100644 --- a/Desarrollo/ReDS/mainB_window.py +++ b/Desarrollo/ReDS/mainB_window.py @@ -36,13 +36,34 @@ def solve_path(relative_path): + """Solve the path of the file in the different operative systems""" if hasattr(sys, '_MEIPASS'): return os.path.join(sys._MEIPASS, relative_path) return os.path.join(os.path.abspath('.'), relative_path) class UIMainBWindow(QtWidgets.QMainWindow): + ''' + Class for module B. Shot reconstruction. + + Attributes + ---------- + global_variables : dict + Dictionary with global variables. + directories : dict + Dictionary with directories. + tab_widgets : dict + Dictionary with tab widgets. + + ''' + def __init__(self, launcher): + ''' + Parameters + ---------- + launcher : QMainWindow + Main window of the application. + ''' super(UIMainBWindow, self).__init__() self.launcher = launcher self.setupUi() @@ -50,6 +71,14 @@ def __init__(self, launcher): self.sampling = Sampling() def closeEvent(self, event): + ''' + Close event. + + Parameters + ---------- + event : QEvent + Close event. + ''' message_box = QtWidgets.QMessageBox(self) message_box.pos() message_box.setIcon(QtWidgets.QMessageBox.Question) @@ -71,6 +100,11 @@ def closeEvent(self, event): event.ignore() def setupUi(self): + ''' + Setup UI. + + Init components, variables and connections. + ''' self.setWindowTitle("ReDs") self.setWindowIcon(QIcon("assets/icons/g868.ico")) self.setObjectName("mainWindow") @@ -712,6 +746,14 @@ def setupUi(self): self.init_visible_widgets(width=320) def init_visible_widgets(self, width=320): + ''' + Initialize the visible widgets + + Parameters + ---------- + width : int, optional + The width of the widget, by default 320 + ''' self.inputGroupBox.setMinimumWidth(width) self.inputGroupBox.setMaximumWidth(width) self.algorithmGroupBox.setMinimumWidth(width) @@ -741,13 +783,54 @@ def init_visible_widgets(self, width=320): self.jitterPushButton.setVisible(False) def init_global_variables(self): - - # variables setup - - # Tab mode ['main', 'tuning', 'comparison'] - # View mode ['normal', 'report'] - # Data mode ['complete', 'incomplete'] - + ''' + Initialize the global variables. + + These variables are used to store the data of the experiments. + + Variables + ---------- + global_varibles : dict + The global variables + # Tab mode ['main', 'tuning', 'comparison'] + # View mode ['normal', 'report'] + # Data mode ['complete', 'incomplete'] + + tab_mode : list + The tab mode according to selected tool + data_mode : list + The view mode according to kind of datasets + directories : dict + The directories of the project + state : dict + The state of the project, considering tab mode, view mode and data mode + graphics : dict + The graphics of the project + threads : list + The threads of the project for multiple experiments + workers : list + The workers of the project for multiple experiments + all_tabs : dict + The tabs of the project for generating a normal or report view + tab_widgets: dict + The tab widgets of the project + iters: int + The number of iterations for experiments + max_iter: int + The maximum number of iterations for experiments + max_iter_progress: int + The maximum number of iterations for progress bar for multiple experiments + icons_path : str + The path of the icons + param_type : str + The type of the parameter + main_params : list + The main parameters + tuning_params : list + The tuning parameters + comparison_params : list + The comparison parameters + ''' self.global_variables = dict(tab_mode='main', view_mode='normal', data_mode='complete', algorithm_name='') tab_mode = ['main', 'tuning', 'comparison'] @@ -801,6 +884,9 @@ def init_global_variables(self): [self.compParam1LineEdit4, self.compParam2LineEdit4, self.compParam3LineEdit4]] def init_actions(self): + ''' + Initialize the actions. + ''' self.onlydouble = QtGui.QDoubleValidator(decimals=10) self.onlyInt = QtGui.QIntValidator() self.experimentProgressBar.setValue(0) @@ -840,6 +926,9 @@ def init_actions(self): self.seedCheckBox.stateChanged.connect(self.activate_seed) def add_tab(self, data_name, tab_widget, graphic): + ''' + Add a tab to the tab widget. + ''' tab = QtWidgets.QWidget() tab.setObjectName(data_name) tabHLayout = QtWidgets.QHBoxLayout(tab) @@ -869,6 +958,9 @@ def add_tab(self, data_name, tab_widget, graphic): return [tab, graphic] def set_visible_normal_tabs(self, directories, data_mode, set_visible): + ''' + Set visible the normal tabs. + ''' tab_mode = self.global_variables['tab_mode'] for uploaded_directory in directories[data_mode]['uploaded']: tab_name = uploaded_directory.split('/')[-1].split('.')[0] @@ -884,6 +976,9 @@ def set_visible_normal_tabs(self, directories, data_mode, set_visible): tab_widget.setCurrentIndex(index[0]) def load_report_tabs(self): + ''' + Load the report tabs. + ''' tab_mode = self.global_variables['tab_mode'] data_mode = self.global_variables['data_mode'] is_complete = True if data_mode == 'complete' else False @@ -921,6 +1016,9 @@ def load_report_tabs(self): return def remove_report_tabs(self): + ''' + Remove the report tabs. + ''' for page, graph in self.all_tabs['report']: for tab_widget in self.tab_widgets[self.global_variables['tab_mode']]: index = tab_widget.indexOf(page) @@ -929,6 +1027,9 @@ def remove_report_tabs(self): plt.close('all') def update_tabs(self): + ''' + Update the tabs. + ''' self.remove_report_tabs() directories = self.directories[self.global_variables['tab_mode']] @@ -948,6 +1049,9 @@ def update_tabs(self): # self.set_current_index_tab_last() def set_current_index_tab_last(self): + ''' + Set the current index of the tab to the last one. + ''' self.performanceTabWidget.setCurrentIndex(self.performanceTabWidget.count() - 1) self.reportTabWidget.setCurrentIndex(self.reportTabWidget.count() - 1) self.tuningTabWidget.setCurrentIndex(self.tuningTabWidget.count() - 1) @@ -955,6 +1059,9 @@ def set_current_index_tab_last(self): self.comparisonReportTabWidget.setCurrentIndex(self.comparisonReportTabWidget.count() - 1) def update_tab_thread(self): + ''' + Update the tabs in a thread. + ''' self.thread_tab = QtCore.QThread() self.worker_tab = TabWorker() @@ -981,6 +1088,9 @@ def update_tab_thread(self): self.thread_tab.finished.connect(self.update_tab_finished) def update_tab_finished(self): + ''' + Update the tabs finished. + ''' self.mainAction.setEnabled(True) self.tuningAction.setEnabled(True) self.comparisonAction.setEnabled(True) @@ -993,6 +1103,9 @@ def update_tab_finished(self): self.resultPushButton.setEnabled(True) def update_main_visible_algorithms(self, algorithm): + ''' + Update the main visible algorithms. + ''' for i in range(3): label = self.main_params[i][0] line_edit = self.main_params[i][1] @@ -1015,11 +1128,17 @@ def update_main_visible_algorithms(self, algorithm): line_edit.setValidator(self.onlydouble) def update_tuning_visible_param(self, param): + ''' + Update the tuning visible parameters. + ''' algorithm = self.algorithmComboBox.currentText().lower() tuning_type = self.paramTuningComboBox.currentText().lower() self.update_tuning_visible_algorithms(algorithm, tuning_type) def update_tuning_visible_algorithms(self, algorithm, tuning_type): + ''' + Update the tuning visible algorithms. + ''' algorithm = str.replace(algorithm, ' ', '_') for i in range(3): @@ -1067,6 +1186,9 @@ def update_tuning_visible_algorithms(self, algorithm, tuning_type): line_edit_end.setVisible(False) def set_visible_algorithm(self, algorithm): + ''' + Set the visible algorithm. + ''' algorithm = algorithm.lower() if self.global_variables['tab_mode'] == 'main': @@ -1090,7 +1212,9 @@ def set_visible_algorithm(self, algorithm): self.update_tuning_visible_algorithms(algorithm, tuning_param) def clear_data(self): - + ''' + Clear the data in the software. + ''' if self.dataTreeWidget.findItems('', Qt.MatchContains | Qt.MatchRecursive): message_box = QtWidgets.QMessageBox(self) message_box.pos() @@ -1131,6 +1255,9 @@ def clear_data(self): plt.close('all') def update_directories(self, file_type, filenames): + ''' + Update the directories. + ''' tab_mode = self.global_variables['tab_mode'] data_mode = self.global_variables['data_mode'] @@ -1173,6 +1300,9 @@ def update_directories(self, file_type, filenames): new_filenames.append(filename) def load_files(self): + ''' + Load files in the software as filenames. + ''' kwargs = {} if 'SNAP' in os.environ: kwargs['options'] = QtWidgets.QFileDialog.DontUseNativeDialog @@ -1214,6 +1344,9 @@ def load_files(self): self.update_tab_thread() def verify_type_data(self, directories): + ''' + Verify if data is complete or incomplete. + ''' view_mode = self.global_variables['view_mode'] data_type = self.dataComboBox.currentText().lower() @@ -1261,6 +1394,9 @@ def verify_type_data(self, directories): self.data_fname[0] = [self.data_fname[0][i] for i in indices] def save_files(self): + ''' + Save files in the software with filenames. + ''' kwargs = {} if 'SNAP' in os.environ: kwargs['options'] = QFileDialog.DontUseNativeDialog @@ -1286,6 +1422,9 @@ def save_files(self): self.directories[tab_mode][data_mode]['temp_saved'] = save_name[0] def update_data_tree(self, directories): + ''' + Update data tree with the new data. + ''' self.dataTreeWidget.clear() if directories in ['', []]: @@ -1315,6 +1454,9 @@ def update_data_tree(self, directories): parent.setExpanded(True) def save_as_text_changed(self): + ''' + Update the save name when the text is changed. + ''' save_name = self.saveAsLineEdit.text() op_sys = platform.system().lower() @@ -1333,6 +1475,9 @@ def save_as_text_changed(self): 'temp_saved'] = save_name def show_about_of(self): + ''' + Show about of the software. + ''' self.about_window = QtWidgets.QWidget() self.ui_about_window = UIAboutWindow() self.ui_about_window.setupUi(self.about_window) @@ -1340,6 +1485,9 @@ def show_about_of(self): self.about_window.show() def show_main(self): + ''' + Show main window mode. + ''' self.global_variables['tab_mode'] = 'main' view_mode = self.global_variables['view_mode'] comparison = True if view_mode == 'normal' else False @@ -1355,6 +1503,9 @@ def show_main(self): self.set_result_view() def show_tuning(self): + ''' + Show tuning window mode. + ''' self.global_variables['tab_mode'] = 'tuning' view_mode = self.global_variables['view_mode'] comparison = True if view_mode == 'normal' else False @@ -1377,6 +1528,9 @@ def show_tuning(self): self.set_result_view() def show_comparison(self): + ''' + Show comparison window mode. + ''' self.global_variables['tab_mode'] = 'comparison' view_mode = self.global_variables['view_mode'] comparison = True if view_mode == 'normal' else False @@ -1392,6 +1546,9 @@ def show_comparison(self): self.set_result_view() def set_result_view(self): + ''' + Set the result view. + ''' self.update_tab_thread() tab_mode = self.global_variables['tab_mode'] data_mode = self.global_variables['data_mode'] @@ -1404,6 +1561,9 @@ def set_result_view(self): self.update_data_tree(self.directories[tab_mode][data_mode]['report']) def show_results(self): + ''' + Show results window mode. + ''' self.dataTreeWidget.clear() icon = QtGui.QIcon() @@ -1422,6 +1582,9 @@ def show_results(self): self.resultPushButton.setIcon(icon) def set_main_view(self): + ''' + Set the main view. + ''' self.set_visible_algorithm(self.algorithmComboBox.currentText().lower()) tab_mode = self.global_variables['tab_mode'] @@ -1437,6 +1600,9 @@ def set_main_view(self): self.set_result_view() def set_report_view(self): + ''' + Set the report view. + ''' self.algorithmGroupBox.setVisible(False) self.tuningGroupBox.setVisible(False) self.samplingGroupBox.setVisible(False) @@ -1449,6 +1615,9 @@ def set_report_view(self): self.set_result_view() def update_data(self, value): + ''' + Update data. + ''' if value.lower() == 'datos completos': self.samplingGroupBox.setVisible(True if self.global_variables['view_mode'] == 'normal' else False) self.global_variables['data_mode'] = 'complete' @@ -1460,37 +1629,58 @@ def update_data(self, value): self.set_result_view() def algorithm_changed(self, value): + ''' + Algorithm changed. + ''' self.set_visible_algorithm(value.lower()) def algorithm_equation_clicked(self): + ''' + Algorithm equation clicked. + ''' self.ui_equation_window = UIEquationWindow() self.ui_equation_window.setupUi(self.algorithmComboBox.currentText()) self.ui_equation_window.setWindowModality(Qt.WindowModality.ApplicationModal) self.ui_equation_window.show() def comparison_algorithm_equation_clicked(self): + ''' + Comparison algorithm equation clicked. + ''' self.ui_comparison_equation_window = UIComparisonEquationWindow() self.ui_comparison_equation_window.setupUi() self.ui_comparison_equation_window.show() def element_help_clicked(self): + ''' + Element help clicked. + ''' self.ui_element_help_window = UIElementHelpWindow() self.ui_element_help_window.setupUi() self.ui_element_help_window.setWindowModality(Qt.WindowModality.ApplicationModal) self.ui_element_help_window.show() def seed_help_clicked(self): + ''' + Seed help clicked. + ''' self.ui_seed_help_window = UISeedHelpWindow() self.ui_seed_help_window.setupUi() self.ui_seed_help_window.setWindowModality(Qt.WindowModality.ApplicationModal) self.ui_seed_help_window.show() def jitter_sampling_clicked(self): + ''' + Jitter sampling clicked. + ''' self.jitter_sampling_window = UIJitterWindow() self.jitter_sampling_window.setupUi() self.jitter_sampling_window.show() def param_tuning_changed(self, value): + ''' + Param tuning changed. + ''' self.paramValuesLabel.setVisible(True if value.lower() == 'intervalo' else False) self.paramValuesSpinBox.setVisible(True if value.lower() == 'intervalo' else False) @@ -1498,12 +1688,21 @@ def param_tuning_changed(self, value): self.update_tuning_visible_algorithms(algorithm, value.lower()) def param_changed(self, value): + ''' + Param changed. + ''' self.update_tuning_visible_param(value.lower()) def activate_seed(self, activate): + ''' + Activate seed. + ''' self.seedSpinBox.setEnabled(activate) def on_sampling_changed(self, value): + ''' + On sampling changed. + ''' sampling = value.lower() self.spacerItem4.changeSize(0, 0, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) @@ -1538,7 +1737,9 @@ def on_sampling_changed(self, value): self.spacerItem5.changeSize(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum) def verify_parameters(self, uploaded_directories): - + ''' + Verify parameters for experiments. + ''' if not uploaded_directories: return False @@ -1591,6 +1792,9 @@ def verify_parameters(self, uploaded_directories): return True def update_variables(self, data_name): + ''' + Update variables for experiments. + ''' self.experimentProgressBar.setValue(0) tab_mode = self.global_variables['tab_mode'] @@ -1606,6 +1810,9 @@ def update_variables(self, data_name): self.state[tab_mode]['progress']['fixed_params'][data_name] = {} def load_seismic_data(self, uploaded_directory): + ''' + Load seismic data for experiments. + ''' if Path(uploaded_directory).suffix == '.npy': data = np.load(uploaded_directory) else: @@ -1627,6 +1834,9 @@ def load_seismic_data(self, uploaded_directory): return data def load_parameters(self, data): + ''' + Load parameters for experiments. + ''' data_mode = self.global_variables['data_mode'] seed = None if self.seedCheckBox.checkState(): @@ -1651,6 +1861,9 @@ def load_parameters(self, data): return sampling_dict, H if data_mode == 'complete' else None def load_algorithm(self, data_name, seismic_data, H, sampling_dict, max_iter): + ''' + Load algorithm for experiments. + ''' self.algorithm_name = self.algorithmComboBox.currentText().lower() self.algorithm_name = str.replace(self.algorithm_name, ' ', '_') self.current_scale = self.scaleComboBox.currentText().lower() @@ -1684,7 +1897,9 @@ def load_algorithm(self, data_name, seismic_data, H, sampling_dict, max_iter): return ShotWorker(data_name, algorithm, max_iter, sampling_dict, performance_graphic, report_graphic) def start_experiment(self): - + ''' + Start the experiment + ''' uploaded_directories = self.directories[self.global_variables['tab_mode']][self.global_variables['data_mode']][ 'uploaded'] validate = self.verify_parameters(uploaded_directories) @@ -1741,6 +1956,9 @@ def start_experiment(self): return def report_main_progress(self, data_name, iter, res_dict, sampling_dict, graphics): + ''' + Report progress of the main experiment + ''' self.iters += 1 self.experimentProgressBar.setValue(int((self.iters / self.max_iter_progress) * 100)) @@ -1769,6 +1987,9 @@ def report_main_progress(self, data_name, iter, res_dict, sampling_dict, graphic graphics['report'].update_figure() def save_main_experiment(self, data_name, res_dict, graphics): + ''' + Save the main experiment + ''' performance_data = np.array(list(graphics['performance'].performance_data.items()), dtype=object) tab_mode = self.global_variables['tab_mode'] @@ -1786,6 +2007,9 @@ def save_main_experiment(self, data_name, res_dict, graphics): print("Results saved [Ok]") def reset_values(self): + ''' + Reset values + ''' if self.iters / self.max_iter_progress == 1.0: self.startPushButton.setEnabled(True) self.experimentProgressBar.setValue(0) @@ -1793,6 +2017,9 @@ def reset_values(self): self.threads = [] def retranslateUi(self): + ''' + Retranslate UI + ''' _translate = QtCore.QCoreApplication.translate self.setWindowTitle(_translate("mainWindow", "ReDs - Reconstruccion de Disparos | Universidad Industrial de Santander")) self.inputGroupBox.setTitle(_translate("mainWindow", "Datos sísmicos"))