diff options
author | Tom Rondeau | 2011-01-15 17:48:02 -0500 |
---|---|---|
committer | Tom Rondeau | 2011-01-15 17:48:02 -0500 |
commit | 4f4268311488f88c2f20f31ba9d4615b522b946a (patch) | |
tree | 5c345c87e8566b745e692c3c12894b2adc812a30 /gr-utils/src | |
parent | 7b5095514204a524afbf6fd97bb70511519e5b35 (diff) | |
download | gnuradio-4f4268311488f88c2f20f31ba9d4615b522b946a.tar.gz gnuradio-4f4268311488f88c2f20f31ba9d4615b522b946a.tar.bz2 gnuradio-4f4268311488f88c2f20f31ba9d4615b522b946a.zip |
Fixing up other plotting tools for data read errors.
Diffstat (limited to 'gr-utils/src')
-rwxr-xr-x | gr-utils/src/python/gr_plot_const.py | 26 | ||||
-rwxr-xr-x | gr-utils/src/python/gr_plot_fft.py | 28 | ||||
-rwxr-xr-x | gr-utils/src/python/gr_plot_iq.py | 25 | ||||
-rwxr-xr-x | gr-utils/src/python/gr_plot_psd.py | 2 | ||||
-rw-r--r-- | gr-utils/src/python/plot_data.py | 20 |
5 files changed, 51 insertions, 50 deletions
diff --git a/gr-utils/src/python/gr_plot_const.py b/gr-utils/src/python/gr_plot_const.py index ec2272c74..9e4920776 100755 --- a/gr-utils/src/python/gr_plot_const.py +++ b/gr-utils/src/python/gr_plot_const.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -80,15 +80,15 @@ class draw_constellation: def get_data(self): self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data)) - iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(iq) - if(len(iq) == 0): + try: + iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: - self.reals = [r.real for r in iq] - self.imags = [i.imag for i in iq] + self.reals = scipy.array([r.real for r in iq]) + self.imags = scipy.array([i.imag for i in iq]) - self.time = [i*(1/self.sample_rate) for i in range(len(self.reals))] + self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.reals))]) def make_plots(self): # if specified on the command-line, set file pointer @@ -117,9 +117,9 @@ class draw_constellation: self.plot_const += self.sp_const.plot([self.reals[self.indx],], [self.imags[self.indx],], 'mo', ms=12) # Adjust axis - self.sp_iq.axis([min(self.time), max(self.time), - 1.5*min([min(self.reals), min(self.imags)]), - 1.5*max([max(self.reals), max(self.imags)])]) + self.sp_iq.axis([self.time.min(), self.time.max(), + 1.5*min([self.reals.min(), self.imags.min()]), + 1.5*max([self.reals.max(), self.imags.max()])]) self.sp_const.axis([-2, 2, -2, 2]) draw() @@ -127,9 +127,9 @@ class draw_constellation: def update_plots(self): self.plot_iq[0].set_data([self.time, self.reals]) self.plot_iq[1].set_data([self.time, self.imags]) - self.sp_iq.axis([min(self.time), max(self.time), - 1.5*min([min(self.reals), min(self.imags)]), - 1.5*max([max(self.reals), max(self.imags)])]) + self.sp_iq.axis([self.time.min(), self.time.max(), + 1.5*min([self.reals.min(), self.imags.min()]), + 1.5*max([self.reals.max(), self.imags.max()])]) self.plot_const[0].set_data([self.reals, self.imags]) self.sp_const.axis([-2, 2, -2, 2]) diff --git a/gr-utils/src/python/gr_plot_fft.py b/gr-utils/src/python/gr_plot_fft.py index a9c1417f9..bb21f3dcd 100755 --- a/gr-utils/src/python/gr_plot_fft.py +++ b/gr-utils/src/python/gr_plot_fft.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -81,15 +81,15 @@ class gr_plot_fft: def get_data(self): self.position = self.hfile.tell()/self.sizeof_data self.text_file_pos.set_text("File Position: %d" % (self.position)) - self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(self.iq) - if(len(self.iq) == 0): + try: + self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: self.iq_fft = self.dofft(self.iq) tstep = 1.0 / self.sample_rate - self.time = [tstep*(self.position + i) for i in xrange(len(self.iq))] + self.time = scipy.array([tstep*(self.position + i) for i in xrange(len(self.iq))]) self.freq = self.calc_freq(self.time, self.sample_rate) @@ -102,9 +102,9 @@ class gr_plot_fft: def calc_freq(self, time, sample_rate): N = len(time) - Fs = 1.0 / (max(time) - min(time)) + Fs = 1.0 / (time.max() - time.min()) Fn = 0.5 * sample_rate - freq = [-Fn + i*Fs for i in xrange(N)] + freq = scipy.array([-Fn + i*Fs for i in xrange(N)]) return freq def make_plots(self): @@ -139,14 +139,14 @@ class gr_plot_fft: imags = self.iq.imag self.plot_iq[0].set_data([self.time, reals]) self.plot_iq[1].set_data([self.time, imags]) - self.sp_iq.set_xlim(min(self.time), max(self.time)) - self.sp_iq.set_ylim([1.5*min([min(reals), min(imags)]), - 1.5*max([max(reals), max(imags)])]) + self.sp_iq.set_xlim(self.time.min(), self.time.max()) + self.sp_iq.set_ylim([1.5*min([reals.min(), imags.min()]), + 1.5*max([reals.max(), imags.max()])]) def draw_fft(self): self.plot_fft[0].set_data([self.freq, self.iq_fft]) - self.sp_fft.set_xlim(min(self.freq), max(self.freq)) - self.sp_fft.set_ylim([min(self.iq_fft)-10, max(self.iq_fft)+10]) + self.sp_fft.set_xlim(self.freq.min(), self.freq.max()) + self.sp_fft.set_ylim([self.iq_fft.min()-10, self.iq_fft.max()+10]) def update_plots(self): self.draw_time() @@ -170,8 +170,8 @@ class gr_plot_fft: freq = self.calc_freq(time, self.sample_rate) self.plot_fft[0].set_data(freq, iq_fft) - self.sp_fft.axis([min(freq), max(freq), - min(iq_fft)-10, max(iq_fft)+10]) + self.sp_fft.axis([freq.min(), freq.max(), + iq_fft.min()-10, iq_fftmax()+10]) draw() diff --git a/gr-utils/src/python/gr_plot_iq.py b/gr-utils/src/python/gr_plot_iq.py index 371ce3b79..316e60a75 100755 --- a/gr-utils/src/python/gr_plot_iq.py +++ b/gr-utils/src/python/gr_plot_iq.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -78,14 +78,14 @@ class draw_iq: def get_data(self): self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data)) - self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(self.iq) - if(len(self.iq) == 0): + try: + self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: - self.reals = [r.real for r in self.iq] - self.imags = [i.imag for i in self.iq] - self.time = [i*(1/self.sample_rate) for i in range(len(self.reals))] + self.reals = scipy.array([r.real for r in self.iq]) + self.imags = scipy.array([i.imag for i in self.iq]) + self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.reals))]) def make_plots(self): # if specified on the command-line, set file pointer @@ -99,16 +99,17 @@ class draw_iq: self.sp_iq.set_xlabel("Time (s)", fontsize=self.label_font_size, fontweight="bold") self.sp_iq.set_ylabel("Amplitude (V)", fontsize=self.label_font_size, fontweight="bold") self.plot_iq = plot(self.time, self.reals, 'bo-', self.time, self.imags, 'ro-') - self.sp_iq.set_ylim([1.5*min([min(self.reals), min(self.imags)]), - 1.5*max([max(self.reals), max(self.imags)])]) - + self.sp_iq.set_ylim([1.5*min([self.reals.min(), self.imags.min()]), + 1.5*max([self.reals.max(), self.imags.max()])]) + self.sp_iq.set_xlim(self.time.min(), self.time.max()) draw() def update_plots(self): self.plot_iq[0].set_data([self.time, self.reals]) self.plot_iq[1].set_data([self.time, self.imags]) - self.sp_iq.set_ylim([1.5*min([min(self.reals), min(self.imags)]), - 1.5*max([max(self.reals), max(self.imags)])]) + self.sp_iq.set_ylim([1.5*min([self.reals.min(), self.imags.min()]), + 1.5*max([self.reals.max(), self.imags.max()])]) + self.sp_iq.set_xlim(self.time.min(), self.time.max()) draw() def click(self, event): diff --git a/gr-utils/src/python/gr_plot_psd.py b/gr-utils/src/python/gr_plot_psd.py index 1b653d61a..d5bfca389 100755 --- a/gr-utils/src/python/gr_plot_psd.py +++ b/gr-utils/src/python/gr_plot_psd.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # diff --git a/gr-utils/src/python/plot_data.py b/gr-utils/src/python/plot_data.py index 08cdd6030..15012e589 100644 --- a/gr-utils/src/python/plot_data.py +++ b/gr-utils/src/python/plot_data.py @@ -1,5 +1,5 @@ # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -81,13 +81,13 @@ class plot_data: def get_data(self, hfile): self.text_file_pos.set_text("File Position: %d" % (hfile.tell()//self.sizeof_data)) - f = scipy.fromfile(hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(self.f) - if(len(f) == 0): + try: + f = scipy.fromfile(hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: - self.f = f - self.time = [i*(1/self.sample_rate) for i in range(len(self.f))] + self.f = scipy.array(f) + self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.f))]) def make_plots(self): self.sp_f = self.fig.add_subplot(2,1,1, position=[0.075, 0.2, 0.875, 0.6]) @@ -107,8 +107,8 @@ class plot_data: # Subplot for real and imaginary parts of signal self.plot_f += plot(self.time, self.f, 'o-') - maxval = max(maxval, max(self.f)) - minval = min(minval, min(self.f)) + maxval = max(maxval, self.f.max()) + minval = min(minval, self.f.min()) self.sp_f.set_ylim([1.5*minval, 1.5*maxval]) @@ -122,8 +122,8 @@ class plot_data: for hf,p in zip(self.hfile,self.plot_f): self.get_data(hf) p.set_data([self.time, self.f]) - maxval = max(maxval, max(self.f)) - minval = min(minval, min(self.f)) + maxval = max(maxval, self.f.max()) + minval = min(minval, self.f.min()) self.sp_f.set_ylim([1.5*minval, 1.5*maxval]) |