Example #1
0
    def __init__(self, x, new_image):
        super(Plotter, self).__init__()

        self.acquirer = DataAcquirer(x, new_image, "running")
        self.acquirer.new_data_processed.connect(self.send_plot)
        # self.x = x
        # self.new_image = new_image # camera signal that triggers calculation
        # self.running = False
        # # For fps calculation. Leave out earliest 2.5 ms
        # self.one_second = datetime.timedelta(seconds=1, microseconds=-2500)

        # # Give self own event loop so that incoming signals are queued
        # self.thread = core.QThread()
        # self.moveToThread(self.thread)
        # core.QTimer.singleShot(0, self.thread.start)

        # End safely upon exit
        atexit.register(self.__del__)
Example #2
0
    def __init__(self, x, new_image):
        super(Plotter, self).__init__()

        self.acquirer = DataAcquirer(x, new_image, "running")
        self.acquirer.new_data_processed.connect(self.send_plot)
        # self.x = x
        # self.new_image = new_image # camera signal that triggers calculation
        # self.running = False
        # # For fps calculation. Leave out earliest 2.5 ms
        # self.one_second = datetime.timedelta(seconds=1, microseconds=-2500)

        # # Give self own event loop so that incoming signals are queued
        # self.thread = core.QThread()
        # self.moveToThread(self.thread)
        # core.QTimer.singleShot(0, self.thread.start)

        # End safely upon exit
        atexit.register(self.__del__)
Example #3
0
class Plotter(core.QObject):
    plot = core.pyqtSignal(object, object)
    countup = core.pyqtSignal(int)
    fps = core.pyqtSignal(int)

    def __init__(self, x, new_image):
        super(Plotter, self).__init__()

        self.acquirer = DataAcquirer(x, new_image, "running")
        self.acquirer.new_data_processed.connect(self.send_plot)
        # self.x = x
        # self.new_image = new_image # camera signal that triggers calculation
        # self.running = False
        # # For fps calculation. Leave out earliest 2.5 ms
        # self.one_second = datetime.timedelta(seconds=1, microseconds=-2500)

        # # Give self own event loop so that incoming signals are queued
        # self.thread = core.QThread()
        # self.moveToThread(self.thread)
        # core.QTimer.singleShot(0, self.thread.start)

        # End safely upon exit
        atexit.register(self.__del__)

    def change_n(self, n):
        """Stop and restart with different number of averages"""
        if self.running and n != self.n:
            # Restart with new value of n
            self.abort()
            self.acquire(n)

    def acquire(self, n):
        # Leave all array allocation beyond storage to subclasses

        # Set up counters
        # self.n = n
        # self.i = -1     # First thing it does is get incremented
        # self.start_countup = 0

        # # Set up storage
        # self.storage = np.zeros((self.n, self.x), dtype=np.int32)

        # # Set up fft arrays
        # self.ft_in = fftw.n_byte_align(np.zeros((n, self.x), dtype=np.complex128), 16)
        # self.ft_out = fftw.n_byte_align(np.zeros((n, self.x), dtype=np.complex128), 16)
        # self.ift_in = fftw.n_byte_align(np.zeros((n, self.x), dtype=np.complex128), 16)
        # self.ift_out = fftw.n_byte_align(np.zeros((n, self.x), dtype=np.complex128), 16)
        # self.high_pass = np.zeros((n, self.x), dtype=np.complex128)
        # self.high_pass[0,:] = 1
        # self.fft = fftw.FFTW(self.ft_in, self.ft_out, axes=(0,), direction='FFTW_FORWARD',
        #                     flags=('FFTW_MEASURE',), threads=1, planning_timelimit=None)
        # self.ifft = fftw.FFTW(self.ift_in, self.ift_out, axes=(0,), direction='FFTW_BACKWARD',
        #                     flags=('FFTW_MEASURE',), threads=1, planning_timelimit=None)
        # # self.fft = fftw.FFTW(self.ft_in, self.ft_out, axes=(0), direction='FFTW_FORWARD')
        # # self.ifft = fftw.FFTW(self.ift_in, self.ift_out, axes=(0), direction='FFTW_BACKWARD')

        # # Get ready to calculate fps
        # self.plot_times = []

        # Go
        # self.new_image.connect(self.send_plot)

        self.acquirer.acquire(n)
        self.running = True

    def send_plot(self, datablock):
        # Tell listeners to plot what self.calc returns
        self.plot.emit(self.x, datablock.ra_sim.average)

    # def send_plot(self, x_arr, y_arr):
    #     # Progressively increase denominator of avg until n is reached
    #     if self.start_countup < self.n:
    #         # Increment counters
    #         self.i += 1
    #         self.start_countup += 1

    #         # Tell listeners to plot what self.countup_calc returns
    #         self.plot.emit(*self.countup_calc(x_arr, y_arr))

    #         # Tell listeners how far in the start countup self is
    #         self.countup.emit(self.start_countup)
    #     # Then just use n
    #     else:
    #         # Increment rotating counter only, modulus len(storage)
    #         self.i += 1
    #         self.i %= self.n

    #         # Tell listeners to plot what self.calc returns
    #         self.plot.emit(*self.calc(x_arr, y_arr))

    #     # Send the calculated fps
    #     self.calc_fps()

    #     # Afterwards, save the new data into storage (over any old data)
    #     self.storage[self.i] = y_arr

    def countup_calc(self, x_arr, y_arr):
        """By default, just call calc"""
        return self.calc(x_arr, y_arr)

    def calc(self, x_arr, y_arr):
        """Must implement this method in subclasses."""
        # Qt complains when I use an abstract base class, so do this instead:
        raise NotImplementedError

    def calc_fps(self):
        now = datetime.datetime.now()
        one_second_ago = now - self.one_second
        self.plot_times.append(now)

        for j in xrange(len(self.plot_times)):
            # look for where one second ago starts
            if self.plot_times[j] > one_second_ago:
                # get rid of everything before that and quit
                del self.plot_times[:j]
                break
        self.fps.emit(len(self.plot_times))

    def abort(self):
        self.running = False
        self.new_image.disconnect(self.send_plot)

        del self.n, self.i, self.start_countup
        del self.storage
        del self.plot_times
        del self.ft_in, self.ft_out, self.ift_in, self.ift_out
        del self.fft, self.ifft, self.high_pass

    def __del__(self):
        if self.running:
            self.abort()
        self.thread.quit()
Example #4
0
class Plotter(core.QObject):
    plot = core.pyqtSignal(object, object)
    countup = core.pyqtSignal(int)
    fps = core.pyqtSignal(int)

    def __init__(self, x, new_image):
        super(Plotter, self).__init__()

        self.acquirer = DataAcquirer(x, new_image, "running")
        self.acquirer.new_data_processed.connect(self.send_plot)
        # self.x = x
        # self.new_image = new_image # camera signal that triggers calculation
        # self.running = False
        # # For fps calculation. Leave out earliest 2.5 ms
        # self.one_second = datetime.timedelta(seconds=1, microseconds=-2500)

        # # Give self own event loop so that incoming signals are queued
        # self.thread = core.QThread()
        # self.moveToThread(self.thread)
        # core.QTimer.singleShot(0, self.thread.start)

        # End safely upon exit
        atexit.register(self.__del__)

    def change_n(self, n):
        """Stop and restart with different number of averages"""
        if self.running and n != self.n:
            # Restart with new value of n
            self.abort()
            self.acquire(n)

    def acquire(self, n):
        # Leave all array allocation beyond storage to subclasses

        # Set up counters
        # self.n = n
        # self.i = -1     # First thing it does is get incremented
        # self.start_countup = 0

        # # Set up storage
        # self.storage = np.zeros((self.n, self.x), dtype=np.int32)

        # # Set up fft arrays
        # self.ft_in = fftw.n_byte_align(np.zeros((n, self.x), dtype=np.complex128), 16)
        # self.ft_out = fftw.n_byte_align(np.zeros((n, self.x), dtype=np.complex128), 16)
        # self.ift_in = fftw.n_byte_align(np.zeros((n, self.x), dtype=np.complex128), 16)
        # self.ift_out = fftw.n_byte_align(np.zeros((n, self.x), dtype=np.complex128), 16)
        # self.high_pass = np.zeros((n, self.x), dtype=np.complex128)
        # self.high_pass[0,:] = 1
        # self.fft = fftw.FFTW(self.ft_in, self.ft_out, axes=(0,), direction='FFTW_FORWARD',
        #                     flags=('FFTW_MEASURE',), threads=1, planning_timelimit=None)
        # self.ifft = fftw.FFTW(self.ift_in, self.ift_out, axes=(0,), direction='FFTW_BACKWARD',
        #                     flags=('FFTW_MEASURE',), threads=1, planning_timelimit=None)
        # # self.fft = fftw.FFTW(self.ft_in, self.ft_out, axes=(0), direction='FFTW_FORWARD')
        # # self.ifft = fftw.FFTW(self.ift_in, self.ift_out, axes=(0), direction='FFTW_BACKWARD')

        # # Get ready to calculate fps
        # self.plot_times = []

        # Go
        #self.new_image.connect(self.send_plot)

        self.acquirer.acquire(n)
        self.running = True

    def send_plot(self, datablock):
        # Tell listeners to plot what self.calc returns
        self.plot.emit(self.x, datablock.ra_sim.average)

    # def send_plot(self, x_arr, y_arr):
    #     # Progressively increase denominator of avg until n is reached
    #     if self.start_countup < self.n:
    #         # Increment counters
    #         self.i += 1
    #         self.start_countup += 1

    #         # Tell listeners to plot what self.countup_calc returns
    #         self.plot.emit(*self.countup_calc(x_arr, y_arr))

    #         # Tell listeners how far in the start countup self is
    #         self.countup.emit(self.start_countup)
    #     # Then just use n
    #     else:
    #         # Increment rotating counter only, modulus len(storage)
    #         self.i += 1
    #         self.i %= self.n

    #         # Tell listeners to plot what self.calc returns
    #         self.plot.emit(*self.calc(x_arr, y_arr))

    #     # Send the calculated fps
    #     self.calc_fps()

    #     # Afterwards, save the new data into storage (over any old data)
    #     self.storage[self.i] = y_arr

    def countup_calc(self, x_arr, y_arr):
        """By default, just call calc"""
        return self.calc(x_arr, y_arr)

    def calc(self, x_arr, y_arr):
        """Must implement this method in subclasses."""
        # Qt complains when I use an abstract base class, so do this instead:
        raise NotImplementedError

    def calc_fps(self):
        now = datetime.datetime.now()
        one_second_ago = now - self.one_second
        self.plot_times.append(now)

        for j in xrange(len(self.plot_times)):
            # look for where one second ago starts
            if self.plot_times[j] > one_second_ago:
                # get rid of everything before that and quit
                del self.plot_times[:j]
                break
        self.fps.emit(len(self.plot_times))

    def abort(self):
        self.running = False
        self.new_image.disconnect(self.send_plot)

        del self.n, self.i, self.start_countup
        del self.storage
        del self.plot_times
        del self.ft_in, self.ft_out, self.ift_in, self.ift_out
        del self.fft, self.ifft, self.high_pass

    def __del__(self):
        if self.running: self.abort()
        self.thread.quit()