Exemplo n.º 1
0
    def __generate_movie__(self, data_vector, start_progress,
                           reference_filename):
        """
        core functionality to generate poincare plot movie
        """
        filter_manager = FilterManager(_shift=self.p.window_shift,
                    _excluded_annotations=self.p.excluded_annotations,
                    _filters=self.p.filters)

        segmenter = SegmenterManager.getDataVectorSegmenter(data_vector,
                                            self.p.window_size_value,
                                            self.p.window_size_unit,
                                            self.p.sample_step,
                                            self.p.window_shift,
                                            self.p.stepper_size,
                                            self.p.stepper_unit,
                                            mark_last_segment=True)
        if segmenter.stop:
            return True  # to avoid interrupt processing many data sources

        start_progress.segmenter = segmenter
        start_progress()
        progress = start_progress.progress
        if progress == False:
            return False

        interrupter = ControlInterruptHandler()
        data_segment_old = None

        self.__movie_progress__ = progress

        movie_maker = PoincarePlotMovieMaker(data_vector, self.p,
                            segment_count=segmenter.segment_count(),
                            filter_manager=filter_manager,
                            info_message_handler=self.__info_message_handler__,
                            reference_filename=reference_filename)

        for data_segment in segmenter:
            if segmenter.last_segment:
                movie_maker.add_data_vector_segment(None, last_segment=True)
                break

            if interrupter.isInterrupted():
                #mark interrupt state of interrupter to give consistent
                #behaviour to the rest of the code
                interrupter.interrupt()
                break

            if segmenter.data_changed:
                data_segment = filter_manager.run_filters(data_segment)

            #this could happened when for example annotation
            #filter is used and all data are annotated that means
            #all signal data are filtered out
            if data_segment == None or data_segment.signal == None \
                or not len(data_segment.signal) > 1:
                data_segment_old = data_segment
                continue

            #this situation could occur when there is a normal signal after
            #a long series of annotated signals
            if segmenter.data_changed:
                if len(data_segment.signal) == 1:
                    continue

            if segmenter.data_changed and \
                not data_segment.equals(data_segment_old):
                movie_maker.add_data_vector_segment(data_segment)
                progress.tick(additional_message=movie_maker.info_message)

            data_segment_old = data_segment

        progress.close()
        interrupted = interrupter.isInterrupted()
        interrupter.clean()

        if not interrupted or self.p.movie_save_partial:
            movie_maker.save_movie()
            self.__info_handler__(movie_maker.info_message)

        self.__movie_progress__ = None

        return not interrupted
Exemplo n.º 2
0
    def __generate_core__(self, data_vector, start_progress,
                          progress_handler=None):
        """
        core functionality to generate poincare plots
        """
        filter_manager = FilterManager(_shift=self.p.window_shift,
                    _excluded_annotations=self.p.excluded_annotations,
                    _filters=self.p.filters)

        #there could be the case when only statistics name are defined
        #and then we have to extract from the names corresponding classes
        statistics_classes = extended_statistics_classes(
                self.p.statistics_classes,
                self.p.statistics_names,
                self.p.summary_statistics_classes,
                self.p.summary_statistics_names)

        statisticsFactory = StatisticsFactory(
                    statistics_names=self.p.statistics_names,
                    statistics_classes=statistics_classes,
                    statistics_handlers=self.p.statistics_handlers,
                    _use_identity_line=self.p.use_identity_line,
                    use_buffer=self.p.use_buffer)
        if not statisticsFactory.has_statistics:
            return True
        summaryStatisticsFactory = SummaryStatisticsFactory(
            summary_statistics_names=self.p.summary_statistics_names,
            summary_statistics_classes=self.p.summary_statistics_classes)

        segmenter = SegmenterManager.getDataVectorSegmenter(data_vector,
                                            self.p.window_size_value,
                                            self.p.window_size_unit,
                                            self.p.sample_step,
                                            self.p.window_shift,
                                            self.p.stepper_size,
                                            self.p.stepper_unit)
        if self.p.print_first_signal:
            print('Signal data [first row]: ' + str(data_vector.signal))

        if segmenter.stop:
            return True  # to avoid interrupt processing many data sources

        start_progress.segmenter = segmenter
        start_progress()
        progress = start_progress.progress
        if progress == False:
            return False

        interrupter = ControlInterruptHandler()
        parameters = {}
        parameters_old = None
        data_segment_old = None
        self.__timing__ = None
        for data_segment in segmenter:
            if interrupter.isInterrupted():
                break
            if segmenter.data_changed:
                parameters.clear()
                parameters_old = None
                #data_segment_old = None
            else:
                parameters = parameters_old
                data_segment = data_segment_old

            if progress:
                tick = getattr(progress, 'tick')
                if tick:
                    tick()

            if segmenter.data_changed:
                data_segment = filter_manager.run_filters(data_segment)

            #this could happened when for example annotation
            #filter is used and all data are annotated that means
            #all signal data are filtered out
            if data_segment == None or data_segment.signal == None \
                or not len(data_segment.signal) > 1:
                parameters_old = parameters
                data_segment_old = data_segment
                continue

            #this situation could occur when there is a normal signal after
            #a long series of annotated signals
            if segmenter.data_changed:
                if len(data_segment.signal) == 1:
                    continue

            if segmenter.data_changed:
                #add timing info into parameters
                if self.p.timing:
                    self.__add_timing__(parameters, data_segment,
                                        data_segment_old)
                statistics = statisticsFactory.statistics(data_segment)
                parameters.update(statistics)

            if progress_handler:
                if segmenter.data_changed:
                    progress_handler.parameters = parameters
                    progress_handler.segmenter = segmenter
                    progress_handler()
                if progress_handler.interrupted:
                    #mark interrupt state of interrupter to give consistent
                    #behaviour to the rest of the code
                    interrupter.interrupt()
                    break

            summaryStatisticsFactory.update(parameters, data_segment)
            if segmenter.data_changed:
                parameters_old = parameters
                data_segment_old = data_segment

        self.p.summary_statistics = None
        if interrupter.isInterrupted() == False:
            if summaryStatisticsFactory.has_summary_statistics > 0:
                self.p.summary_statistics = summaryStatisticsFactory.summary_statistics # @IgnorePep8
                self.p.summary_statistics_order = summaryStatisticsFactory.summary_statistics_order # @IgnorePep8

        if progress:
            close = getattr(progress, 'close')
            if close:
                close()
        interrupted = interrupter.isInterrupted()
        interrupter.clean()

        return not interrupted