diff options
Diffstat (limited to 'gr-utils/python/utils')
-rwxr-xr-x | gr-utils/python/utils/gr_modtool | 4 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_char | 6 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_const | 21 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_float | 6 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_int | 4 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_iq | 19 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_qt | 26 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_short | 6 | ||||
-rw-r--r-- | gr-utils/python/utils/gr_read_file_metadata | 8 | ||||
-rw-r--r-- | gr-utils/python/utils/plot_data.py | 22 | ||||
-rw-r--r--[-rwxr-xr-x] | gr-utils/python/utils/plot_fft_base.py | 35 | ||||
-rw-r--r--[-rwxr-xr-x] | gr-utils/python/utils/plot_psd_base.py | 35 | ||||
-rw-r--r-- | gr-utils/python/utils/pyqt_filter.py | 1 | ||||
-rw-r--r-- | gr-utils/python/utils/pyqt_plot.py | 1 |
14 files changed, 105 insertions, 89 deletions
diff --git a/gr-utils/python/utils/gr_modtool b/gr-utils/python/utils/gr_modtool index 7d035a6590..f959c91f66 100755 --- a/gr-utils/python/utils/gr_modtool +++ b/gr-utils/python/utils/gr_modtool @@ -21,6 +21,8 @@ # """ A tool for editing GNU Radio out-of-tree modules. """ +from __future__ import print_function + from gnuradio.modtool import * @@ -46,7 +48,7 @@ def main(): try: args.module().run(args) except ModToolException as err: - print >> sys.stderr, err + print(err, file=sys.stderr) exit(1) if __name__ == '__main__': diff --git a/gr-utils/python/utils/gr_plot_char b/gr-utils/python/utils/gr_plot_char index ee644557bb..3199919fa9 100755 --- a/gr-utils/python/utils/gr_plot_char +++ b/gr-utils/python/utils/gr_plot_char @@ -20,11 +20,13 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function + try: import scipy except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) from argparse import ArgumentParser from gnuradio.plot_data import plot_data diff --git a/gr-utils/python/utils/gr_plot_const b/gr-utils/python/utils/gr_plot_const index 653a2539b4..2ec54c3585 100755 --- a/gr-utils/python/utils/gr_plot_const +++ b/gr-utils/python/utils/gr_plot_const @@ -20,18 +20,20 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function + try: import scipy except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) try: from pylab import * from matplotlib.font_manager import fontManager, FontProperties except ImportError: - print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" - raise SystemExit, 1 + print("Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)") + raise SystemExit(1) from argparse import ArgumentParser @@ -83,7 +85,7 @@ class draw_constellation: try: iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) except MemoryError: - print "End of File" + print("End of File") else: # retesting length here as newer version of scipy does not throw a MemoryError, just # returns a zero-length array @@ -94,7 +96,7 @@ class draw_constellation: self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.reals))]) return True else: - print "End of File" + print("End of File") return False def make_plots(self): @@ -215,9 +217,9 @@ class draw_constellation: def find(item_in, list_search): try: - return list_search.index(item_in) != None + return list_search.index(item_in) != None except ValueError: - return False + return False def main(): @@ -241,6 +243,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - - - diff --git a/gr-utils/python/utils/gr_plot_float b/gr-utils/python/utils/gr_plot_float index faf8106d70..4fd86549e2 100755 --- a/gr-utils/python/utils/gr_plot_float +++ b/gr-utils/python/utils/gr_plot_float @@ -20,11 +20,13 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function + try: import scipy except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) from argparse import ArgumentParser from gnuradio.plot_data import plot_data diff --git a/gr-utils/python/utils/gr_plot_int b/gr-utils/python/utils/gr_plot_int index c687f13b17..b4051fa15f 100755 --- a/gr-utils/python/utils/gr_plot_int +++ b/gr-utils/python/utils/gr_plot_int @@ -23,8 +23,8 @@ try: import scipy except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) from argparse import ArgumentParser from gnuradio.plot_data import plot_data diff --git a/gr-utils/python/utils/gr_plot_iq b/gr-utils/python/utils/gr_plot_iq index 7409b73909..f27f75d412 100755 --- a/gr-utils/python/utils/gr_plot_iq +++ b/gr-utils/python/utils/gr_plot_iq @@ -20,17 +20,19 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function + try: import scipy except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) try: from pylab import * except ImportError: - print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" - raise SystemExit, 1 + print("Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)") + raise SystemExit(1) from argparse import ArgumentParser @@ -81,7 +83,7 @@ class draw_iq: try: self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) except MemoryError: - print "End of File" + print("End of File") else: self.reals = scipy.array([r.real for r in self.iq]) self.imags = scipy.array([i.imag for i in self.iq]) @@ -144,9 +146,9 @@ class draw_iq: def find(item_in, list_search): try: - return list_search.index(item_in) != None + return list_search.index(item_in) != None except ValueError: - return False + return False def main(): description = "Takes a GNU Radio complex binary file and displays the I&Q data versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." @@ -170,6 +172,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - - - diff --git a/gr-utils/python/utils/gr_plot_qt b/gr-utils/python/utils/gr_plot_qt index 9205d23a7e..854ecc53b8 100755 --- a/gr-utils/python/utils/gr_plot_qt +++ b/gr-utils/python/utils/gr_plot_qt @@ -4,34 +4,34 @@ try: import scipy from scipy import fftpack except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) try: from matplotlib import mlab except ImportError: - print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net)" - raise SystemExit, 1 + print("Please install Matplotlib to run this script (http://matplotlib.sourceforge.net)") + raise SystemExit(1) try: from PyQt4 import Qt, QtCore, QtGui except ImportError: - print "Please install PyQt4 to run this script (http://www.riverbankcomputing.co.uk/software/pyqt/download)" - raise SystemExit, 1 + print("Please install PyQt4 to run this script (http://www.riverbankcomputing.co.uk/software/pyqt/download)") + raise SystemExit(1) try: import PyQt4.Qwt5 as Qwt except ImportError: - print "Please install PyQwt5 to run this script (http://pyqwt.sourceforge.net/)" - raise SystemExit, 1 + print("Please install PyQwt5 to run this script (http://pyqwt.sourceforge.net/)") + raise SystemExit(1) try: # FIXME: re-enable this before committing #from gnuradio.pyqt_plot import Ui_MainWindow from gnuradio.pyqt_plot import Ui_MainWindow except ImportError: - print "Could not import from pyqt_plot. Please build with \"pyuic4 pyqt_plot.ui -o pyqt_plot.py\"" - raise SystemExit, 1 + print("Could not import from pyqt_plot. Please build with \"pyuic4 pyqt_plot.ui -o pyqt_plot.py\"") + raise SystemExit(1) import sys, os from optparse import OptionParser @@ -284,7 +284,7 @@ class gr_plot_qt(QtGui.QMainWindow): def open_file(self): filename = Qt.QFileDialog.getOpenFileName(self, "Open", ".") if(filename != ""): - #print filename + #print(filename) self.initialize(filename) def reload_file(self): @@ -320,7 +320,7 @@ class gr_plot_qt(QtGui.QMainWindow): def init_data_input(self): self.hfile.seek(0, os.SEEK_END) self.signal_size = self.hfile.tell()/self.sizeof_data - #print "Sizeof File: ", self.signal_size + #print("Sizeof File: ", self.signal_size) self.hfile.seek(0, os.SEEK_SET) def get_data(self, start, end): @@ -338,7 +338,7 @@ class gr_plot_qt(QtGui.QMainWindow): tstep = 1.0 / self.sample_rate self.iq = iq - self.time = [tstep*(self.position + i) for i in xrange(len(self.iq))] + self.time = [tstep*(self.position + i) for i in range(len(self.iq))] self.set_file_pos_box(start, end) except MemoryError: diff --git a/gr-utils/python/utils/gr_plot_short b/gr-utils/python/utils/gr_plot_short index f900af1bac..d367ea381f 100755 --- a/gr-utils/python/utils/gr_plot_short +++ b/gr-utils/python/utils/gr_plot_short @@ -20,11 +20,13 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function + try: import scipy except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) from argparse import ArgumentParser from gnuradio.plot_data import plot_data diff --git a/gr-utils/python/utils/gr_read_file_metadata b/gr-utils/python/utils/gr_read_file_metadata index a05e7ad2c7..1a94560ad2 100644 --- a/gr-utils/python/utils/gr_read_file_metadata +++ b/gr-utils/python/utils/gr_read_file_metadata @@ -20,6 +20,8 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function + import sys from argparse import ArgumentParser @@ -45,7 +47,7 @@ def main(filename, detached=False): sys.stderr.write("Could not deserialize header: invalid or corrupt data file.\n") sys.exit(1) - print "HEADER {0}".format(nheaders) + print("HEADER {0}".format(nheaders)) info = parse_file_metadata.parse_header(header, True) if(info["extra_len"] > 0): @@ -59,7 +61,7 @@ def main(filename, detached=False): sys.stderr.write("Could not deserialize extras: invalid or corrupt data file.\n") sys.exit(1) - print "\nExtra Header:" + print("\nExtra Header:") extra_info = parse_file_metadata.parse_extra_dict(extra, info, True) nheaders += 1 @@ -67,7 +69,7 @@ def main(filename, detached=False): if(not detached): nread += info['nbytes'] handle.seek(nread, 0) - print "\n\n" + print("\n\n") if __name__ == "__main__": diff --git a/gr-utils/python/utils/plot_data.py b/gr-utils/python/utils/plot_data.py index 7d80c714fe..a054147114 100644 --- a/gr-utils/python/utils/plot_data.py +++ b/gr-utils/python/utils/plot_data.py @@ -22,20 +22,24 @@ Utility to help plotting data from files. """ +from __future__ import print_function +from __future__ import division +from __future__ import unicode_literals + try: import scipy except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) try: from pylab import * except ImportError: - print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" - raise SystemExit, 1 + print("Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)") + raise SystemExit(1) -class plot_data: +class plot_data(object): def __init__(self, datatype, filenames, options): self.hfile = list() self.legend_text = list() @@ -86,10 +90,10 @@ class plot_data: try: f = scipy.fromfile(hfile, dtype=self.datatype, count=self.block_length) except MemoryError: - print "End of File" + print("End of File") else: self.f = scipy.array(f) - self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.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]) @@ -162,6 +166,6 @@ class plot_data: def find(item_in, list_search): try: - return list_search.index(item_in) != None + return list_search.index(item_in) != None except ValueError: - return False + return False diff --git a/gr-utils/python/utils/plot_fft_base.py b/gr-utils/python/utils/plot_fft_base.py index c99462147d..5040aefa87 100755..100644 --- a/gr-utils/python/utils/plot_fft_base.py +++ b/gr-utils/python/utils/plot_fft_base.py @@ -20,22 +20,26 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import division +from __future__ import unicode_literals + try: import scipy from scipy import fftpack except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) try: from pylab import * except ImportError: - print "Please install Python Matplotlib (http://matplotlib.sourceforge.net/) and Python TkInter https://wiki.python.org/moin/TkInter to run this script" - raise SystemExit, 1 + print("Please install Python Matplotlib (http://matplotlib.sourceforge.net/) and Python TkInter https://wiki.python.org/moin/TkInter to run this script") + raise SystemExit(1) from argparse import ArgumentParser -class plot_fft_base: +class plot_fft_base(object): def __init__(self, datatype, filename, options): self.hfile = open(filename, "r") self.block_length = options.block @@ -79,33 +83,33 @@ class plot_fft_base: show() def get_data(self): - self.position = self.hfile.tell()/self.sizeof_data + self.position = self.hfile.tell() / self.sizeof_data self.text_file_pos.set_text("File Position: %d" % (self.position)) try: self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) except MemoryError: - print "End of File" + print("End of File") else: self.iq_fft = self.dofft(self.iq) tstep = 1.0 / self.sample_rate - #self.time = scipy.array([tstep*(self.position + i) for i in xrange(len(self.iq))]) - self.time = scipy.array([tstep*(i) for i in xrange(len(self.iq))]) + #self.time = scipy.array([tstep*(self.position + i) for i in range(len(self.iq))]) + self.time = scipy.array([tstep*(i) for i in range(len(self.iq))]) self.freq = self.calc_freq(self.time, self.sample_rate) def dofft(self, iq): N = len(iq) iq_fft = scipy.fftpack.fftshift(scipy.fft(iq)) # fft and shift axis - iq_fft = 20*scipy.log10(abs((iq_fft+1e-15)/N)) # convert to decibels, adjust power + iq_fft = 20*scipy.log10(abs((iq_fft+1e-15) / N)) # convert to decibels, adjust power # adding 1e-15 (-300 dB) to protect against value errors if an item in iq_fft is 0 return iq_fft def calc_freq(self, time, sample_rate): N = len(time) - Fs = 1.0 / (time.max() - time.min()) + Fs = 1.0 / (time.max( - time.min())) Fn = 0.5 * sample_rate - freq = scipy.array([-Fn + i*Fs for i in xrange(N)]) + freq = scipy.array([-Fn + i*Fs for i in range(N)]) return freq def make_plots(self): @@ -228,9 +232,9 @@ class plot_fft_base: def find(item_in, list_search): try: - return list_search.index(item_in) != None + return list_search.index(item_in) != None except ValueError: - return False + return False def main(): parser = plot_fft_base.setup_options() @@ -243,6 +247,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - - - diff --git a/gr-utils/python/utils/plot_psd_base.py b/gr-utils/python/utils/plot_psd_base.py index 2611ed4be2..0a0f3cab34 100755..100644 --- a/gr-utils/python/utils/plot_psd_base.py +++ b/gr-utils/python/utils/plot_psd_base.py @@ -20,24 +20,28 @@ # Boston, MA 02110-1301, USA. # +from __future__ import print_function +from __future__ import division +from __future__ import unicode_literals + try: import scipy from scipy import fftpack except ImportError: - print "Please install SciPy to run this script (http://www.scipy.org/)" - raise SystemExit, 1 + print("Please install SciPy to run this script (http://www.scipy.org/)") + raise SystemExit(1) try: from pylab import * except ImportError: - print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" - raise SystemExit, 1 + print("Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)") + raise SystemExit(1) from argparse import ArgumentParser from scipy import log10 from gnuradio.eng_arg import eng_float, intx -class plot_psd_base: +class plot_psd_base(object): def __init__(self, datatype, filename, options): self.hfile = open(filename, "r") self.block_length = options.block @@ -87,30 +91,30 @@ class plot_psd_base: show() def get_data(self): - self.position = self.hfile.tell()/self.sizeof_data + self.position = self.hfile.tell() / self.sizeof_data self.text_file_pos.set_text("File Position: %d" % self.position) try: self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) except MemoryError: - print "End of File" + print("End of File") return False else: # retesting length here as newer version of scipy does not throw a MemoryError, just # returns a zero-length array if(len(self.iq) > 0): tstep = 1.0 / self.sample_rate - #self.time = scipy.array([tstep*(self.position + i) for i in xrange(len(self.iq))]) - self.time = scipy.array([tstep*(i) for i in xrange(len(self.iq))]) + #self.time = scipy.array([tstep*(self.position + i) for i in range(len(self.iq))]) + self.time = scipy.array([tstep*(i) for i in range(len(self.iq))]) self.iq_psd, self.freq = self.dopsd(self.iq) return True else: - print "End of File" + print("End of File") return False def dopsd(self, iq): ''' Need to do this here and plot later so we can do the fftshift ''' - overlap = self.psdfftsize/4 + overlap = self.psdfftsize / 4 winfunc = scipy.blackman psd,freq = mlab.psd(iq, self.psdfftsize, self.sample_rate, window = lambda d: d*winfunc(self.psdfftsize), @@ -174,7 +178,7 @@ class plot_psd_base: self.sp_psd.set_xlim([f.min(), f.max()]) def draw_spec(self, t, s): - overlap = self.specfftsize/4 + overlap = self.specfftsize / 4 winfunc = scipy.blackman self.sp_spec.clear() self.sp_spec.specgram(s, self.specfftsize, self.sample_rate, @@ -270,9 +274,9 @@ class plot_psd_base: def find(item_in, list_search): try: - return list_search.index(item_in) != None + return list_search.index(item_in) != None except ValueError: - return False + return False def main(): parser = plot_psd_base.setup_options() @@ -285,6 +289,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - - - diff --git a/gr-utils/python/utils/pyqt_filter.py b/gr-utils/python/utils/pyqt_filter.py index 0c781f2347..fac17644d3 100644 --- a/gr-utils/python/utils/pyqt_filter.py +++ b/gr-utils/python/utils/pyqt_filter.py @@ -7,6 +7,7 @@ # # WARNING! All changes made in this file will be lost! +from __future__ import unicode_literals from PyQt4 import QtCore, QtGui class Ui_MainWindow(object): diff --git a/gr-utils/python/utils/pyqt_plot.py b/gr-utils/python/utils/pyqt_plot.py index 5650135abf..80711b4e88 100644 --- a/gr-utils/python/utils/pyqt_plot.py +++ b/gr-utils/python/utils/pyqt_plot.py @@ -7,6 +7,7 @@ # # WARNING! All changes made in this file will be lost! +from __future__ import unicode_literals from PyQt4 import QtCore, QtGui class Ui_MainWindow(object): |