示例#1
0
	def update_grid(self):
		#update the x axis
		x_max = 2.0
		self.plotter.set_x_grid(-x_max, x_max, common.get_clean_num(2.0*x_max/self[X_DIVS_KEY]))
		#update the y axis
		y_max = 2.0
		self.plotter.set_y_grid(-y_max, y_max, common.get_clean_num(2.0*y_max/self[Y_DIVS_KEY]))
		#update plotter
		self.plotter.update()
示例#2
0
 def update_grid(self):
     # update the x axis
     x_max = 2.0
     self.plotter.set_x_grid(-x_max, x_max, common.get_clean_num(2.0 * x_max / self[X_DIVS_KEY]))
     # update the y axis
     y_max = 2.0
     self.plotter.set_y_grid(-y_max, y_max, common.get_clean_num(2.0 * y_max / self[Y_DIVS_KEY]))
     # update plotter
     self.plotter.update()
示例#3
0
    def update_grid(self, *args):
        """
		Update the plotter grid.
		This update method is dependent on the variables below.
		Determine the x and y axis grid parameters.
		The x axis depends on sample rate, baseband freq, and x divs.
		The y axis depends on y per div, y divs, and ref level.
		"""
        #grid parameters
        sample_rate = self[SAMPLE_RATE_KEY]
        frame_rate = self[FRAME_RATE_KEY]
        if frame_rate < 1.0:
            frame_rate = 1.0
        baseband_freq = self[BASEBAND_FREQ_KEY]
        num_lines = self[NUM_LINES_KEY]
        y_divs = self[Y_DIVS_KEY]
        x_divs = self[X_DIVS_KEY]
        #determine best fitting x_per_div
        if self.real: x_width = sample_rate / 2.0
        else: x_width = sample_rate / 1.0
        x_per_div = common.get_clean_num(x_width / x_divs)
        #update the x grid
        if self.real:
            self.plotter.set_x_grid(
                baseband_freq,
                baseband_freq + sample_rate / 2.0,
                x_per_div,
                True,
            )
        else:
            self.plotter.set_x_grid(
                baseband_freq - sample_rate / 2.0,
                baseband_freq + sample_rate / 2.0,
                x_per_div,
                True,
            )
        #update x units
        self.plotter.set_x_label('Frequency', 'Hz')
        #update y grid
        duration = float(num_lines) / frame_rate
        y_per_div = common.get_clean_num(duration / y_divs)
        self.plotter.set_y_grid(0, duration, y_per_div, True)
        #update y units
        self.plotter.set_y_label('Time', 's')
        #update plotter
        self.plotter.update()
示例#4
0
	def update_grid(self, *args):
		"""
		Update the plotter grid.
		This update method is dependent on the variables below.
		Determine the x and y axis grid parameters.
		The x axis depends on sample rate, baseband freq, and x divs.
		The y axis depends on y per div, y divs, and ref level.
		"""
		#grid parameters
		sample_rate = self[SAMPLE_RATE_KEY]
		frame_rate = self[FRAME_RATE_KEY]
		if frame_rate < 1.0 :
			frame_rate = 1.0
		baseband_freq = self[BASEBAND_FREQ_KEY]
		num_lines = self[NUM_LINES_KEY]
		y_divs = self[Y_DIVS_KEY]
		x_divs = self[X_DIVS_KEY]
		#determine best fitting x_per_div
		if self.real: x_width = sample_rate/2.0
		else: x_width = sample_rate/1.0
		x_per_div = common.get_clean_num(x_width/x_divs)
		#update the x grid
		if self.real:
			self.plotter.set_x_grid(
				baseband_freq,
				baseband_freq + sample_rate/2.0,
				x_per_div, True,
			)
		else:
			self.plotter.set_x_grid(
				baseband_freq - sample_rate/2.0,
				baseband_freq + sample_rate/2.0,
				x_per_div, True,
			)
		#update x units
		self.plotter.set_x_label('Frequency', 'Hz')
		#update y grid
		duration = float(num_lines)/frame_rate
		y_per_div = common.get_clean_num(duration/y_divs)
		self.plotter.set_y_grid(0, duration, y_per_div, True)
		#update y units
		self.plotter.set_y_label('Time', 's')
		#update plotter
		self.plotter.update()
示例#5
0
	def autoscale(self, *args):
		"""
		Autoscale the fft plot to the last frame.
		Set the dynamic range and reference level.
		"""
		if not len(self.samples): return
		min_level, max_level = common.get_min_max_fft(self.samples)
		#set the range to a clean number of the dynamic range
		self[Y_PER_DIV_KEY] = common.get_clean_num(1+(max_level - min_level)/self[Y_DIVS_KEY])
		#set the reference level to a multiple of y per div
		self[REF_LEVEL_KEY] = self[Y_PER_DIV_KEY]*round(.5+max_level/self[Y_PER_DIV_KEY])
示例#6
0
	def autoscale(self, *args):
		"""
		Autoscale the waterfall plot to the last frame.
		Set the dynamic range and reference level.
		Does not affect the current data in the waterfall.
		"""
		if not len(self.samples): return
		min_level, max_level = common.get_min_max_fft(self.samples)
		#set the range and level
		self[DYNAMIC_RANGE_KEY] = common.get_clean_num(max_level - min_level)
		self[REF_LEVEL_KEY] = DYNAMIC_RANGE_STEP*round(.5+max_level/DYNAMIC_RANGE_STEP)
示例#7
0
	def autoscale(self, *args):
		"""
		Autoscale the fft plot to the last frame.
		Set the dynamic range and reference level.
		"""
		if not len(self.samples): return
		min_level, max_level = common.get_min_max_fft(self.samples)
		#set the range to a clean number of the dynamic range
		self[Y_PER_DIV_KEY] = common.get_clean_num(1+(max_level - min_level)/self[Y_DIVS_KEY])
		#set the reference level to a multiple of y per div
		self[REF_LEVEL_KEY] = self[Y_PER_DIV_KEY]*round(.5+max_level/self[Y_PER_DIV_KEY])
	def autoscale(self, *args):
		"""
		Autoscale the waterfall plot to the last frame.
		Set the dynamic range and reference level.
		Does not affect the current data in the waterfall.
		"""
		if not len(self.samples): return
		min_level, max_level = common.get_min_max_fft(self.samples)
		#set the range and level
		self[DYNAMIC_RANGE_KEY] = common.get_clean_num(max_level - min_level)
		self[REF_LEVEL_KEY] = DYNAMIC_RANGE_STEP*round(.5+max_level/DYNAMIC_RANGE_STEP)
示例#9
0
    def update_grid(self, *args):
        """
		Update the plotter grid.
		This update method is dependent on the variables below.
		Determine the x and y axis grid parameters.
		The x axis depends on sample rate, baseband freq, and x divs.
		The y axis depends on y per div, y divs, and ref level.
		"""
        for trace in TRACES:
            channel = '%s' % trace.upper()
            if self[TRACE_SHOW_KEY + trace]:
                self.plotter.set_waveform(
                    channel=channel,
                    samples=self._traces[trace],
                    color_spec=TRACES_COLOR_SPEC[trace],
                )
            else:
                self.plotter.clear_waveform(channel=channel)
        #grid parameters
        sample_rate = self[SAMPLE_RATE_KEY]
        baseband_freq = self[BASEBAND_FREQ_KEY]
        y_per_div = self[Y_PER_DIV_KEY]
        y_divs = self[Y_DIVS_KEY]
        x_divs = self[X_DIVS_KEY]
        ref_level = self[REF_LEVEL_KEY]
        #determine best fitting x_per_div
        if self.real: x_width = sample_rate / 2.0
        else: x_width = sample_rate / 1.0
        x_per_div = common.get_clean_num(x_width / x_divs)
        #update the x grid
        if self.real:
            self.plotter.set_x_grid(
                baseband_freq,
                baseband_freq + sample_rate / 2.0,
                x_per_div,
                True,
            )
        else:
            self.plotter.set_x_grid(
                baseband_freq - sample_rate / 2.0,
                baseband_freq + sample_rate / 2.0,
                x_per_div,
                True,
            )
        #update x units
        self.plotter.set_x_label('Frequency', 'Hz')
        #update y grid
        self.plotter.set_y_grid(ref_level - y_per_div * y_divs, ref_level,
                                y_per_div)
        #update y units
        self.plotter.set_y_label('Power', 'dB')
        #update plotter
        self.plotter.update()
示例#10
0
	def update_grid(self, *args):
		"""
		Update the plotter grid.
		This update method is dependent on the variables below.
		Determine the x and y axis grid parameters.
		The x axis depends on sample rate, baseband freq, and x divs.
		The y axis depends on y per div, y divs, and ref level.
		"""
		for trace in TRACES:
			channel = '%s'%trace.upper()
			if self[TRACE_SHOW_KEY+trace]:
				self.plotter.set_waveform(
					channel=channel,
					samples=self._traces[trace],
					color_spec=TRACES_COLOR_SPEC[trace],
				)
			else: self.plotter.clear_waveform(channel=channel)
		#grid parameters
		sample_rate = self[SAMPLE_RATE_KEY]
		baseband_freq = self[BASEBAND_FREQ_KEY]
		y_per_div = self[Y_PER_DIV_KEY]
		y_divs = self[Y_DIVS_KEY]
		x_divs = self[X_DIVS_KEY]
		ref_level = self[REF_LEVEL_KEY]
		#determine best fitting x_per_div
		if self.real: x_width = sample_rate/2.0
		else: x_width = sample_rate/1.0
		x_per_div = common.get_clean_num(x_width/x_divs)
		#update the x grid
		if self.real:
			self.plotter.set_x_grid(
				baseband_freq,
				baseband_freq + sample_rate/2.0,
				x_per_div, True,
			)
		else:
			self.plotter.set_x_grid(
				baseband_freq - sample_rate/2.0,
				baseband_freq + sample_rate/2.0,
				x_per_div, True,
			)
		#update x units
		self.plotter.set_x_label('Frequency', 'Hz')
		#update y grid
		self.plotter.set_y_grid(ref_level-y_per_div*y_divs, ref_level, y_per_div)
		#update y units
		self.plotter.set_y_label('Amplitude', 'dB')
		#update plotter
		self.plotter.update()
示例#11
0
	def update_grid(self):
		if not len(self.samples): return
		#calculate the maximum y value
		y_off = math.ceil(numpy.max(self.samples))
		y_off = min(max(y_off, 1.0), 100.0) #between 1% and 100%
		#update the x grid
		self.plotter.set_x_grid(
			self[MINIMUM_KEY], self[MAXIMUM_KEY],
			common.get_clean_num((self[MAXIMUM_KEY] - self[MINIMUM_KEY])/self[X_DIVS_KEY]),
		)
		self.plotter.set_x_label('Counts')
		#update the y grid
		self.plotter.set_y_grid(0, y_off, y_off/self[Y_DIVS_KEY])
		self.plotter.set_y_label('Frequency', '%')
		self.plotter.update()
示例#12
0
	def update_grid(self):
		if not len(self.samples): return
		#calculate the maximum y value
		y_off = math.ceil(numpy.max(self.samples))
		y_off = min(max(y_off, 1.0), 100.0) #between 1% and 100%
		#update the x grid
		self.plotter.set_x_grid(
			self[MINIMUM_KEY], self[MAXIMUM_KEY],
			common.get_clean_num((self[MAXIMUM_KEY] - self[MINIMUM_KEY])/self[X_DIVS_KEY]),
		)
		self.plotter.set_x_label('Counts')
		#update the y grid
		self.plotter.set_y_grid(0, y_off, y_off/self[Y_DIVS_KEY])
		self.plotter.set_y_label('Frequency', '%')
		self.plotter.update()
示例#13
0
    def autoscale(self, *args):
        """
		Autoscale the fft plot to the last frame.
		Set the dynamic range and reference level.
		"""
        if not len(self.samples):
            return
        # get the peak level (max of the samples)
        peak_level = numpy.max(self.samples)
        # get the noise floor (averge the smallest samples)
        noise_floor = numpy.average(numpy.sort(self.samples)[: len(self.samples) / 4])
        # padding
        noise_floor -= abs(noise_floor) * 0.5
        peak_level += abs(peak_level) * 0.1
        # set the reference level to a multiple of y divs
        self[REF_LEVEL_KEY] = self[Y_DIVS_KEY] * math.ceil(peak_level / self[Y_DIVS_KEY])
        # set the range to a clean number of the dynamic range
        self[Y_PER_DIV_KEY] = common.get_clean_num((peak_level - noise_floor) / self[Y_DIVS_KEY])
示例#14
0
    def update_grid(self, *args):
        """
		Update the plotter grid.
		This update method is dependent on the variables below.
		Determine the x and y axis grid parameters.
		The x axis depends on sample rate, baseband freq, and x divs.
		The y axis depends on y per div, y divs, and ref level.
		"""
        # grid parameters
        sample_rate = self[SAMPLE_RATE_KEY]
        baseband_freq = self[BASEBAND_FREQ_KEY]
        y_per_div = self[Y_PER_DIV_KEY]
        y_divs = self[Y_DIVS_KEY]
        x_divs = self[X_DIVS_KEY]
        ref_level = self[REF_LEVEL_KEY]
        # determine best fitting x_per_div
        if self.real:
            x_width = sample_rate / 2.0
        else:
            x_width = sample_rate / 1.0
        x_per_div = common.get_clean_num(x_width / x_divs)
        # update the x grid
        if self.real:
            self.plotter.set_x_grid(baseband_freq, baseband_freq + sample_rate / 2.0, x_per_div, True)
        else:
            self.plotter.set_x_grid(
                baseband_freq - sample_rate / 2.0, baseband_freq + sample_rate / 2.0, x_per_div, True
            )
            # update x units
        self.plotter.set_x_label("Frequency", "Hz")
        # update y grid
        self.plotter.set_y_grid(ref_level - y_per_div * y_divs, ref_level, y_per_div)
        # update y units
        self.plotter.set_y_label("Amplitude", "dB")
        # update plotter
        self.plotter.update()
示例#15
0
    def handle_samples(self):
        """
		Handle the cached samples from the scope input.
		Perform ac coupling, triggering, and auto ranging.
		"""
        if not self.sampleses: return
        sampleses = self.sampleses
        if self[XY_MODE_KEY]:
            self[DECIMATION_KEY] = 1
            x_samples = sampleses[self[X_CHANNEL_KEY]]
            y_samples = sampleses[self[Y_CHANNEL_KEY]]
            #autorange
            if self[AUTORANGE_KEY] and time.time(
            ) - self.autorange_ts > AUTORANGE_UPDATE_RATE:
                x_min, x_max = common.get_min_max(x_samples)
                y_min, y_max = common.get_min_max(y_samples)
                #adjust the x per div
                x_per_div = common.get_clean_num(
                    (x_max - x_min) / self[X_DIVS_KEY])
                if x_per_div != self[X_PER_DIV_KEY]:
                    self[X_PER_DIV_KEY] = x_per_div
                    return
                #adjust the x offset
                x_off = x_per_div * round((x_max + x_min) / 2 / x_per_div)
                if x_off != self[X_OFF_KEY]:
                    self[X_OFF_KEY] = x_off
                    return
                #adjust the y per div
                y_per_div = common.get_clean_num(
                    (y_max - y_min) / self[Y_DIVS_KEY])
                if y_per_div != self[Y_PER_DIV_KEY]:
                    self[Y_PER_DIV_KEY] = y_per_div
                    return
                #adjust the y offset
                y_off = y_per_div * round((y_max + y_min) / 2 / y_per_div)
                if y_off != self[Y_OFF_KEY]:
                    self[Y_OFF_KEY] = y_off
                    return
                self.autorange_ts = time.time()
            #plot xy channel
            self.plotter.set_waveform(
                channel='XY',
                samples=(x_samples, y_samples),
                color_spec=CHANNEL_COLOR_SPECS[0],
                marker=self[XY_MARKER_KEY],
            )
            #turn off each waveform
            for i, samples in enumerate(sampleses):
                self.plotter.clear_waveform(channel='Ch%d' % (i + 1))
        else:
            #autorange
            if self[AUTORANGE_KEY] and time.time(
            ) - self.autorange_ts > AUTORANGE_UPDATE_RATE:
                bounds = [common.get_min_max(samples) for samples in sampleses]
                y_min = numpy.min([bound[0] for bound in bounds])
                y_max = numpy.max([bound[1] for bound in bounds])
                #adjust the y per div
                y_per_div = common.get_clean_num(
                    (y_max - y_min) / self[Y_DIVS_KEY])
                if y_per_div != self[Y_PER_DIV_KEY]:
                    self[Y_PER_DIV_KEY] = y_per_div
                    return
                #adjust the y offset
                y_off = y_per_div * round((y_max + y_min) / 2 / y_per_div)
                if y_off != self[Y_OFF_KEY]:
                    self[Y_OFF_KEY] = y_off
                    return
                self.autorange_ts = time.time()
            #number of samples to scale to the screen
            actual_rate = self.get_actual_rate()
            time_span = self[T_PER_DIV_KEY] * self[T_DIVS_KEY]
            num_samps = int(round(time_span * actual_rate))
            #handle the time offset
            t_off = self[T_FRAC_OFF_KEY] * (len(sampleses[0]) / actual_rate -
                                            time_span)
            if t_off != self[T_OFF_KEY]:
                self[T_OFF_KEY] = t_off
                return
            samps_off = int(round(actual_rate * self[T_OFF_KEY]))
            #adjust the decim so that we use about half the samps
            self[DECIMATION_KEY] = int(
                round(time_span * self[SAMPLE_RATE_KEY] /
                      (0.5 * len(sampleses[0]))))
            #num samps too small, auto increment the time
            if num_samps < 2:
                self[T_PER_DIV_KEY] = common.get_clean_incr(
                    self[T_PER_DIV_KEY])
                #num samps in bounds, plot each waveform
            elif num_samps <= len(sampleses[0]):
                for i, samples in enumerate(sampleses):
                    #plot samples
                    self.plotter.set_waveform(
                        channel='Ch%d' % (i + 1),
                        samples=samples[samps_off:num_samps + samps_off],
                        color_spec=CHANNEL_COLOR_SPECS[i],
                        marker=self[common.index_key(MARKER_KEY, i)],
                        trig_off=self.trigger_offset,
                    )
            #turn XY channel off
            self.plotter.clear_waveform(channel='XY')
        #keep trigger level within range
        if self[TRIGGER_LEVEL_KEY] > self.get_y_max():
            self[TRIGGER_LEVEL_KEY] = self.get_y_max()
            return
        if self[TRIGGER_LEVEL_KEY] < self.get_y_min():
            self[TRIGGER_LEVEL_KEY] = self.get_y_min()
            return
        #disable the trigger channel
        if not self[TRIGGER_SHOW_KEY] or self[XY_MODE_KEY] or self[
                TRIGGER_MODE_KEY] == gr.gr_TRIG_MODE_FREE:
            self.plotter.clear_waveform(channel='Trig')
        else:  #show trigger channel
            trigger_level = self[TRIGGER_LEVEL_KEY]
            trigger_point = (len(self.sampleses[0]) -
                             1) / self.get_actual_rate() / 2.0
            self.plotter.set_waveform(
                channel='Trig',
                samples=([
                    self.get_t_min(), trigger_point, trigger_point,
                    trigger_point, trigger_point,
                    self.get_t_max()
                ], [
                    trigger_level, trigger_level,
                    self.get_y_max(),
                    self.get_y_min(), trigger_level, trigger_level
                ]),
                color_spec=TRIGGER_COLOR_SPEC,
            )
        #update the plotter
        self.plotter.update()
示例#16
0
	def handle_samples(self):
		"""
		Handle the cached samples from the scope input.
		Perform ac coupling, triggering, and auto ranging.
		"""
		if not self.sampleses: return
		sampleses = self.sampleses
		if self[XY_MODE_KEY]:
			self[DECIMATION_KEY] = 1
			x_samples = sampleses[self[X_CHANNEL_KEY]]
			y_samples = sampleses[self[Y_CHANNEL_KEY]]
			#autorange
			if self[AUTORANGE_KEY] and time.time() - self.autorange_ts > AUTORANGE_UPDATE_RATE:
				x_min, x_max = common.get_min_max(x_samples)
				y_min, y_max = common.get_min_max(y_samples)
				#adjust the x per div
				x_per_div = common.get_clean_num((x_max-x_min)/self[X_DIVS_KEY])
				if x_per_div != self[X_PER_DIV_KEY]: self[X_PER_DIV_KEY] = x_per_div; return
				#adjust the x offset
				x_off = x_per_div*round((x_max+x_min)/2/x_per_div)
				if x_off != self[X_OFF_KEY]: self[X_OFF_KEY] = x_off; return
				#adjust the y per div
				y_per_div = common.get_clean_num((y_max-y_min)/self[Y_DIVS_KEY])
				if y_per_div != self[Y_PER_DIV_KEY]: self[Y_PER_DIV_KEY] = y_per_div; return
				#adjust the y offset
				y_off = y_per_div*round((y_max+y_min)/2/y_per_div)
				if y_off != self[Y_OFF_KEY]: self[Y_OFF_KEY] = y_off; return
				self.autorange_ts = time.time()
			#plot xy channel
			self.plotter.set_waveform(
				channel='XY',
				samples=(x_samples, y_samples),
				color_spec=CHANNEL_COLOR_SPECS[0],
				marker=self[XY_MARKER_KEY],
			)
			#turn off each waveform
			for i, samples in enumerate(sampleses):
				self.plotter.clear_waveform(channel='Ch%d'%(i+1))
		else:
			#autorange
			if self[AUTORANGE_KEY] and time.time() - self.autorange_ts > AUTORANGE_UPDATE_RATE:
				bounds = [common.get_min_max(samples) for samples in sampleses]
				y_min = numpy.min([bound[0] for bound in bounds])
				y_max = numpy.max([bound[1] for bound in bounds])
				#adjust the y per div
				y_per_div = common.get_clean_num((y_max-y_min)/self[Y_DIVS_KEY])
				if y_per_div != self[Y_PER_DIV_KEY]: self[Y_PER_DIV_KEY] = y_per_div; return
				#adjust the y offset
				y_off = y_per_div*round((y_max+y_min)/2/y_per_div)
				if y_off != self[Y_OFF_KEY]: self[Y_OFF_KEY] = y_off; return
				self.autorange_ts = time.time()
			#number of samples to scale to the screen
			actual_rate = self.get_actual_rate()
			time_span = self[T_PER_DIV_KEY]*self[T_DIVS_KEY]
			num_samps = int(round(time_span*actual_rate))
			#handle the time offset
			t_off = self[T_FRAC_OFF_KEY]*(len(sampleses[0])/actual_rate - time_span)
			if t_off != self[T_OFF_KEY]: self[T_OFF_KEY] = t_off; return
			samps_off = int(round(actual_rate*self[T_OFF_KEY]))
			#adjust the decim so that we use about half the samps
			self[DECIMATION_KEY] = int(round(
					time_span*self[SAMPLE_RATE_KEY]/(0.5*len(sampleses[0]))
				)
			)
			#num samps too small, auto increment the time
			if num_samps < 2: self[T_PER_DIV_KEY] = common.get_clean_incr(self[T_PER_DIV_KEY])
			#num samps in bounds, plot each waveform
			elif num_samps <= len(sampleses[0]):
				for i, samples in enumerate(sampleses):
					#plot samples
					self.plotter.set_waveform(
						channel='Ch%d'%(i+1),
						samples=samples[samps_off:num_samps+samps_off],
						color_spec=CHANNEL_COLOR_SPECS[i],
						marker=self[common.index_key(MARKER_KEY, i)],
						trig_off=self.trigger_offset,
					)
			#turn XY channel off
			self.plotter.clear_waveform(channel='XY')
		#keep trigger level within range
		if self[TRIGGER_LEVEL_KEY] > self.get_y_max():
			self[TRIGGER_LEVEL_KEY] = self.get_y_max(); return
		if self[TRIGGER_LEVEL_KEY] < self.get_y_min():
			self[TRIGGER_LEVEL_KEY] = self.get_y_min(); return
		#disable the trigger channel
		if not self[TRIGGER_SHOW_KEY] or self[XY_MODE_KEY] or self[TRIGGER_MODE_KEY] == wxgui.TRIG_MODE_FREE:
			self.plotter.clear_waveform(channel='Trig')
		else: #show trigger channel
			trigger_level = self[TRIGGER_LEVEL_KEY]
			trigger_point = (len(self.sampleses[0])-1)/self.get_actual_rate()/2.0
			self.plotter.set_waveform(
				channel='Trig',
				samples=(
					[self.get_t_min(), trigger_point, trigger_point, trigger_point, trigger_point, self.get_t_max()],
					[trigger_level, trigger_level, self.get_y_max(), self.get_y_min(), trigger_level, trigger_level]
				),
				color_spec=TRIGGER_COLOR_SPEC,
			)
		#update the plotter
		self.plotter.update()