def __init__(self, parent, reference_cut_file, checked_cuts, partition_count, y_scale): """Inits widget. Args: parent: MeasurementTabWidget reference_cut_file: String representing reference cut file. checked_cuts: String list representing cut files. partition_count: Integer representing how many splits cut files are divided to. y_scale: Integer flag representing how Y axis is scaled. """ try: super().__init__() self.parent = parent self.icon_manager = parent.icon_manager self.measurement = self.parent.measurement self.reference_cut_file = reference_cut_file self.checked_cuts = checked_cuts self.partition_count = partition_count self.y_scale = y_scale # TODO: Use Null with GUI ProgresBar. if self.measurement.statusbar: self.progress_bar = QtGui.QProgressBar() self.measurement.statusbar.addWidget(self.progress_bar, 1) self.progress_bar.show() QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents) # Mac requires event processing to show progress bar and its # process. else: self.progress_bar = None self.ui = uic.loadUi(os.path.join("ui_files", "ui_element_losses.ui"), self) title = "{0} - Reference cut: {1}".format(self.ui.windowTitle(), os.path.basename(self.reference_cut_file)) self.ui.setWindowTitle(title) # Calculate elemental losses self.losses = ElementLosses( self.measurement.directory_cuts, self.measurement.directory_elemloss, self.reference_cut_file, self.checked_cuts, self.partition_count, progress_bar=self.progress_bar, ) self.split_counts = self.losses.count_element_cuts() # Check for RBS selections. rbs_list = {} for cut in self.checked_cuts: filename = os.path.basename(cut) split = filename.split(".") if is_rbs(cut): # This should work for regular cut and split. key = "{0}.{1}.{2}".format(split[1], split[2], split[3]) rbs_list[key] = get_scatter_element(cut) # Connect buttons self.ui.splitSaveButton.clicked.connect(self.__save_splits) self.matplotlib = MatplotlibElementLossesWidget( self, self.split_counts, legend=True, y_scale=y_scale, rbs_list=rbs_list ) except: import traceback msg = "Could not create Elemental Losses graph. " err_file = sys.exc_info()[2].tb_frame.f_code.co_filename str_err = ", ".join( [ sys.exc_info()[0].__name__ + ": " + traceback._some_str(sys.exc_info()[1]), err_file, str(sys.exc_info()[2].tb_lineno), ] ) msg += str_err logging.getLogger(self.measurement.measurement_name).error(msg) if hasattr(self, "matplotlib"): self.matplotlib.delete() finally: if self.progress_bar: self.measurement.statusbar.removeWidget(self.progress_bar) self.progress_bar.hide()
def __init__(self, parent, output_dir, use_cuts, elements, x_units, line_zero, line_scale, systematic_error): '''Inits widget. Args: parent: A MeasurementTabWidget. output_dir: A string representing directory in which the depth files are located. use_cuts: A string list representing Cut files. elements: A list of Element objects that are used in depth profile. x_units: Units to be used for x-axis of depth profile. line_zero: A boolean representing if vertical line is drawn at zero. line_scale: A boolean representing if horizontal line is drawn at the defined depth scale. systematic_error: A double representing systematic error. ''' try: super().__init__() self.parent = parent self.icon_manager = parent.icon_manager self.measurement = parent.measurement self.output_dir = output_dir self.elements = elements self.x_units = x_units self.__use_cuts = use_cuts; self.__line_zero = line_zero self.__line_scale = line_scale self.__systerr = systematic_error self.ui = uic.loadUi(os.path.join("ui_files", "ui_depth_profile.ui"), self) # Make the directory for depth files if not os.path.exists(self.output_dir): os.makedirs(self.output_dir) output_files = os.path.join(self.output_dir, 'depth') dp = DepthFiles(self.__use_cuts, output_files) dp.create_depth_files() # Check for RBS selections. rbs_list = {} for cut in self.__use_cuts: filename = os.path.basename(cut) split = filename.split('.') element = Element(split[1]) if is_rbs(cut): # This should work for regular cut and split. key = "{0}.{1}.{2}".format(split[1], split[2], split[3]) scatter_element = get_scatter_element(cut) rbs_list[key] = scatter_element index = 0 found_scatter = False for elm in elements: # Makeshift if elm == element: found_scatter = True break index += 1 # When loading project, the scatter element is already # replaced. This is essentially done only when creating # a new Depth Profile graph. if found_scatter: elements[index] = scatter_element self.measurement.generate_tof_in() settings = self.measurement.measurement_settings.\ get_measurement_settings() ds = settings.depth_profile_settings depth_scale_from = ds.depths_for_concentration_from depth_scale_to = ds.depths_for_concentration_to self.matplotlib = MatplotlibDepthProfileWidget(self, self.output_dir, self.elements, rbs_list, (depth_scale_from, depth_scale_to), self.x_units, True, # legend self.__line_zero, self.__line_scale, self.__systerr) except: import traceback msg = "Could not create Depth Profile graph. " err_file = sys.exc_info()[2].tb_frame.f_code.co_filename str_err = ", ".join([sys.exc_info()[0].__name__ + ": " + \ traceback._some_str(sys.exc_info()[1]), err_file, str(sys.exc_info()[2].tb_lineno)]) msg += str_err logging.getLogger(self.measurement.measurement_name).error(msg) if hasattr(self, "matplotlib"): self.matplotlib.delete()
def __init__(self, parent, use_cuts, width): '''Inits widget. Args: parent: A MeasurementTabWidget. use_cuts: A string list representing Cut files. width: A float representing Energy Spectrum histogram's bin width. ''' try: super().__init__() self.parent = parent self.icon_manager = parent.icon_manager self.measurement = self.parent.measurement self.use_cuts = use_cuts self.width = width if self.measurement.statusbar: self.progress_bar = QtGui.QProgressBar() self.measurement.statusbar.addWidget(self.progress_bar, 1) self.progress_bar.show() QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents) # Mac requires event processing to show progress bar and its # process. else: self.progress_bar = None self.ui = uic.loadUi(os.path.join("ui_files", "ui_energy_spectrum.ui"), self) title = "{0} - Bin Width: {1}".format(self.ui.windowTitle(), width) self.ui.setWindowTitle(title) # Generate new tof.in file for external programs self.measurement.generate_tof_in() # Do energy spectrum stuff on this self.energy_spectrum = EnergySpectrum(self.measurement, use_cuts, width, progress_bar=self.progress_bar) self.energy_spectrum_data = self.energy_spectrum.calculate_spectrum() # Check for RBS selections. rbs_list = {} for cut in self.use_cuts: filename = os.path.basename(cut) split = filename.split('.') if is_rbs(cut): # This should work for regular cut and split. key = "{0}.{1}.{2}".format(split[1], split[2], split[3]) rbs_list[key] = get_scatter_element(cut) # Graph in matplotlib widget and add to window self.matplotlib = MatplotlibEnergySpectrumWidget( self, self.energy_spectrum_data, rbs_list) except: import traceback msg = "Could not create Energy Spectrum graph. " err_file = sys.exc_info()[2].tb_frame.f_code.co_filename str_err = ", ".join([sys.exc_info()[0].__name__ + ": " + \ traceback._some_str(sys.exc_info()[1]), err_file, str(sys.exc_info()[2].tb_lineno)]) msg += str_err logging.getLogger(self.measurement.measurement_name).error(msg) if hasattr(self, "matplotlib"): self.matplotlib.delete() finally: if self.progress_bar: self.measurement.statusbar.removeWidget(self.progress_bar) self.progress_bar.hide()