Ejemplo n.º 1
0
 def save_splits(self):
     '''Save element splits as new cut files.
     '''
     self.__element_losses_folder_clean_up()
     dirtyinteger = 0
     count = self.cut_splits.count()
     for key in self.cut_splits.get_keys():
         # Do not split elemental losses again.
         # TODO: Should elemental losses be possible to split again?
         if len(key.split('.')) == 3:
             continue
         main_cut = self.cut_splits.get_cut(key)
         splits = self.cut_splits.get_splits(key)
         
         split_count = len(splits)
         split_number = 0
         for split in splits:
             new_cut = CutFile(elem_loss=True,
                               split_number=split_number,
                               split_count=split_count)
             new_cut.copy_info(main_cut, split, split_count)
             new_cut.save(main_cut.element_number)
             split_number += 1
             self.progress_bar.setValue((100 / count) * dirtyinteger \
                 + (100 / count) * (split_number / split_count))
             QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
             # Mac requires event processing to show progress bar and its
             # process.
         dirtyinteger += 1
Ejemplo n.º 2
0
    def save_cuts(self):
        """Save cut files
        
        Saves data points within selections into cut files.
        """
        if self.selector.is_empty():
            return 0
        if not os.path.exists(self.directory_cuts):
            os.makedirs(self.directory_cuts)

        progress_bar = QtGui.QProgressBar()
        self.statusbar.addWidget(progress_bar, 1)
        progress_bar.show()
        QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
        # Mac requires event processing to show progress bar and its
        # process.

        starttime = time.time()

        self.__remove_old_cut_files()

        # Initializes the list size to match the number of selections.
        points_in_selection = [[] for unused_i in range(self.selector.count())]

        # Go through all points in measurement data
        data_count = len(self.data)
        for n in range(data_count):  # while n < data_count:
            if n % 5000 == 0:
                # Do not always update UI to make it faster.
                progress_bar.setValue((n / data_count) * 90)
                QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
                # Mac requires event processing to show progress bar and its
                # process.
            point = self.data[n]
            # Check if point is within selectors' limits for faster processing.
            if not self.selector.axes_limits.is_inside(point):
                continue

            dirtyinteger = 0  # Lazyway
            for selection in self.selector.selections:
                if selection.point_inside(point):
                    points_in_selection[dirtyinteger].append(point)
                dirtyinteger += 1

        # Save all found data points into appropriate element cut files
        # Firstly clear old cut files so those won't be accidentally
        # left there.

        dirtyinteger = 0  # Increases with for, for each selection
        content_length = len(points_in_selection)
        for points in points_in_selection:
            if points:  # If not empty selection -> save
                selection = self.selector.get_at(dirtyinteger)
                cut_file = CutFile(self.directory)
                cut_file.set_info(selection, points)
                cut_file.save()
            dirtyinteger += 1
            progress_bar.setValue(90 + (dirtyinteger / content_length) * 10)
            QtCore.QCoreApplication.processEvents(QtCore.QEventLoop.AllEvents)
            # Mac requires event processing to show progress bar and its
            # process.

        self.statusbar.removeWidget(progress_bar)
        progress_bar.hide()

        log_msg = "Saving finished in {0} seconds.".format(time.time() - starttime)
        logging.getLogger(self.measurement_name).info(log_msg)