diff options
author | Jiří Pinkava <j-pi@seznam.cz> | 2016-06-26 13:04:39 +0200 |
---|---|---|
committer | Jiří Pinkava <j-pi@seznam.cz> | 2016-08-06 21:51:37 +0200 |
commit | 4d2809c9a46ec5676f2a08457609f559d910785f (patch) | |
tree | 3e19981d3e89729a61cc415b3a269c9eb209fd7d /gr-utils/python | |
parent | 675afc063c9ca5ccec3ede43d87aac83c1928182 (diff) |
filter: replace OptionParser by ArgumentParser for gr-utils and gr-qtgui
Diffstat (limited to 'gr-utils/python')
-rw-r--r-- | gr-utils/python/utils/gr_plot_fft | 8 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_fft_c | 11 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_fft_f | 12 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_float | 27 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_int | 27 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_iq | 31 | ||||
-rw-r--r-- | gr-utils/python/utils/gr_plot_psd | 8 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_psd_c | 13 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_psd_f | 13 | ||||
-rwxr-xr-x | gr-utils/python/utils/gr_plot_short | 27 | ||||
-rwxr-xr-x | gr-utils/python/utils/plot_fft_base.py | 33 | ||||
-rwxr-xr-x | gr-utils/python/utils/plot_psd_base.py | 48 |
12 files changed, 111 insertions, 147 deletions
diff --git a/gr-utils/python/utils/gr_plot_fft b/gr-utils/python/utils/gr_plot_fft index 4343481645..59fc88b994 100644 --- a/gr-utils/python/utils/gr_plot_fft +++ b/gr-utils/python/utils/gr_plot_fft @@ -27,13 +27,9 @@ from gnuradio.plot_fft_base import plot_fft_base def main(): parser = plot_fft_base.setup_options() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_fft_base(options.data_type, filename, options) + dc = plot_fft_base(args.data_type, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_fft_c b/gr-utils/python/utils/gr_plot_fft_c index 43e808d95a..48d3218586 100755 --- a/gr-utils/python/utils/gr_plot_fft_c +++ b/gr-utils/python/utils/gr_plot_fft_c @@ -26,15 +26,12 @@ from gnuradio.plot_fft_base import plot_fft_base def main(): parser = plot_fft_base.setup_options() - parser.remove_option("--data-type") + parser.add_argument("-d", "--data-type", default="complex64", + choices=("complex64", )) - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_fft_base("complex64", filename, options) + dc = plot_fft_base("complex64", args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_fft_f b/gr-utils/python/utils/gr_plot_fft_f index dee9b17dea..d1791419bb 100755 --- a/gr-utils/python/utils/gr_plot_fft_f +++ b/gr-utils/python/utils/gr_plot_fft_f @@ -26,15 +26,11 @@ from gnuradio.plot_fft_base import plot_fft_base def main(): parser = plot_fft_base.setup_options() - parser.remove_option("--data-type") + parser.add_argument("-d", "--data-type", default="float32", + choices=("float32", )) + args = parser.parse_args() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] - - dc = plot_fft_base("float32", filename, options) + dc = plot_fft_base("float32", args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_float b/gr-utils/python/utils/gr_plot_float index 22806e48ae..faf8106d70 100755 --- a/gr-utils/python/utils/gr_plot_float +++ b/gr-utils/python/utils/gr_plot_float @@ -26,29 +26,26 @@ except ImportError: print "Please install SciPy to run this script (http://www.scipy.org/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_data import plot_data def main(): - usage="%prog: [options] input_filenames" description = "Takes a GNU Radio floating point binary file and displays the samples 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." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", nargs='+', + help="Input file with samples") - (options, args) = parser.parse_args () - if len(args) < 1: - parser.print_help() - raise SystemExit, 1 - filenames = args + args = parser.parse_args() datatype=scipy.float32 - dc = plot_data(datatype, filenames, options) + dc = plot_data(datatype, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_int b/gr-utils/python/utils/gr_plot_int index 355ddf0189..c687f13b17 100755 --- a/gr-utils/python/utils/gr_plot_int +++ b/gr-utils/python/utils/gr_plot_int @@ -26,29 +26,26 @@ except ImportError: print "Please install SciPy to run this script (http://www.scipy.org/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_data import plot_data def main(): - usage="%prog: [options] input_filenames" description = "Takes a GNU Radio integer binary file and displays the samples 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." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", nargs='+', + help="Input file"); - (options, args) = parser.parse_args () - if len(args) < 1: - parser.print_help() - raise SystemExit, 1 - filenames = args + args = parser.parse_args() datatype=scipy.int32 - dc = plot_data(datatype, filenames, options) + dc = plot_data(datatype, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_iq b/gr-utils/python/utils/gr_plot_iq index bf8077b6b4..7409b73909 100755 --- a/gr-utils/python/utils/gr_plot_iq +++ b/gr-utils/python/utils/gr_plot_iq @@ -32,7 +32,7 @@ except ImportError: print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser class draw_iq: def __init__(self, filename, options): @@ -149,24 +149,21 @@ def find(item_in, list_search): return False def main(): - usage="%prog: [options] input_filename" 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." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") - - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] - - dc = draw_iq(filename, options) + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", + help="Input file with complex samples") + + args = parser.parse_args() + + dc = draw_iq(args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_psd b/gr-utils/python/utils/gr_plot_psd index 059ca6b645..b052cbfdd7 100644 --- a/gr-utils/python/utils/gr_plot_psd +++ b/gr-utils/python/utils/gr_plot_psd @@ -27,13 +27,9 @@ from gnuradio.plot_psd_base import plot_psd_base def main(): parser = plot_psd_base.setup_options() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_psd_base(options.data_type, filename, options) + dc = plot_psd_base(args.data_type, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_psd_c b/gr-utils/python/utils/gr_plot_psd_c index fff2bff0f2..352a838138 100755 --- a/gr-utils/python/utils/gr_plot_psd_c +++ b/gr-utils/python/utils/gr_plot_psd_c @@ -20,22 +20,19 @@ # Boston, MA 02110-1301, USA. # -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_psd_base import plot_psd_base # This is a wrapper program for plot_psd_base specifically for complex data def main(): parser = plot_psd_base.setup_options() - parser.remove_option("--data-type") + parser.add_argument("-d", "--data-type", default="complex64", + choices=("complex64", )) - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_psd_base("complex64", filename, options) + dc = plot_psd_base("complex64", args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_psd_f b/gr-utils/python/utils/gr_plot_psd_f index ec67994797..ab860e3fb8 100755 --- a/gr-utils/python/utils/gr_plot_psd_f +++ b/gr-utils/python/utils/gr_plot_psd_f @@ -20,22 +20,19 @@ # Boston, MA 02110-1301, USA. # -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_psd_base import plot_psd_base # This is a wrapper program for gr_plot_psd specifically for floating point data def main(): parser = plot_psd_base.setup_options() - parser.remove_option("--data-type") + parser.add_argument("-d", "--data-type", default="complex64", + choices=("float32", )) - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_psd_base("float32", filename, options) + dc = plot_psd_base("float32", args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/gr_plot_short b/gr-utils/python/utils/gr_plot_short index 702a2a94a6..f900af1bac 100755 --- a/gr-utils/python/utils/gr_plot_short +++ b/gr-utils/python/utils/gr_plot_short @@ -26,29 +26,26 @@ except ImportError: print "Please install SciPy to run this script (http://www.scipy.org/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from gnuradio.plot_data import plot_data def main(): - usage="%prog: [options] input_filenames" description = "Takes a GNU Radio short integer binary file and displays the samples 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." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("files", metavar="FILE", nargs="+", + help="Input file with data (int16_t)") - (options, args) = parser.parse_args () - if len(args) < 1: - parser.print_help() - raise SystemExit, 1 - filenames = args + args = parser.parse_args() datatype=scipy.int16 - dc = plot_data(datatype, filenames, options) + dc = plot_data(datatype, args.files, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/plot_fft_base.py b/gr-utils/python/utils/plot_fft_base.py index c4bc484d97..c99462147d 100755 --- a/gr-utils/python/utils/plot_fft_base.py +++ b/gr-utils/python/utils/plot_fft_base.py @@ -33,7 +33,7 @@ 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 -from optparse import OptionParser +from argparse import ArgumentParser class plot_fft_base: def __init__(self, datatype, filename, options): @@ -209,18 +209,21 @@ class plot_fft_base: @staticmethod def setup_options(): - usage="%prog: [options] input_filename" description = "Takes a GNU Radio complex binary file and displays the I&Q data versus time as well as the frequency domain (FFT) plot. The y-axis values are plotted assuming volts as the amplitude of the I&Q streams and converted into dBm in the frequency domain (the 1/N power adjustment out of the FFT is performed internally). The script plots a certain block of data at a time, specified on the command line as -B or --block. This value defaults to 1000. The start position in the file can be set by specifying -s or --start and defaults to 0 (the start of 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 and frequency axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." - parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) - parser.add_option("-d", "--data-type", type="string", default="complex64", - help="Specify the data type (complex64, float32, (u)int32, (u)int16, (u)int8) [default=%default]") - parser.add_option("-B", "--block", type="int", default=1000, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="float", default=1.0, - help="Set the sampler rate of the data [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-d", "--data-type", default="complex64", + choices=("complex64", "float32", "uint32", "int32", "uint16", + "int16", "uint8", "int8"), + help="Specify the data type [default=%(default)r]") + parser.add_argument("-B", "--block", type=int, default=1000, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("file", metavar="FILE", + help="Input file with samples") return parser def find(item_in, list_search): @@ -231,13 +234,9 @@ def find(item_in, list_search): def main(): parser = plot_fft_base.setup_options() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_fft_base(options.data_type, filename, options) + dc = plot_fft_base(args.data_type, args.file, args) if __name__ == "__main__": try: diff --git a/gr-utils/python/utils/plot_psd_base.py b/gr-utils/python/utils/plot_psd_base.py index fe3c9e12b7..2611ed4be2 100755 --- a/gr-utils/python/utils/plot_psd_base.py +++ b/gr-utils/python/utils/plot_psd_base.py @@ -33,9 +33,9 @@ except ImportError: print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)" raise SystemExit, 1 -from optparse import OptionParser +from argparse import ArgumentParser from scipy import log10 -from gnuradio.eng_option import eng_option +from gnuradio.eng_arg import eng_float, intx class plot_psd_base: def __init__(self, datatype, filename, options): @@ -244,25 +244,27 @@ class plot_psd_base: @staticmethod def setup_options(): - usage="%prog: [options] input_filename" description = "Takes a GNU Radio binary file (with specified data type using --data-type) and displays the I&Q data versus time as well as the power spectral density (PSD) plot. The y-axis values are plotted assuming volts as the amplitude of the I&Q streams and converted into dBm in the frequency domain (the 1/N power adjustment out of the FFT is performed internally). The script plots a certain block of data at a time, specified on the command line as -B or --block. The start position in the file can be set by specifying -s or --start and defaults to 0 (the start of 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 and frequency axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples. Finally, the size of the FFT to use for the PSD and spectrogram plots can be set independently with --psd-size and --spec-size, respectively. The spectrogram plot does not display by default and is turned on with -S or --enable-spec." - parser = OptionParser(option_class=eng_option, conflict_handler="resolve", - usage=usage, description=description) - parser.add_option("-d", "--data-type", type="string", default="complex64", - help="Specify the data type (complex64, float32, (u)int32, (u)int16, (u)int8) [default=%default]") - parser.add_option("-B", "--block", type="int", default=8192, - help="Specify the block size [default=%default]") - parser.add_option("-s", "--start", type="int", default=0, - help="Specify where to start in the file [default=%default]") - parser.add_option("-R", "--sample-rate", type="eng_float", default=1.0, - help="Set the sampler rate of the data [default=%default]") - parser.add_option("", "--psd-size", type="int", default=1024, - help="Set the size of the PSD FFT [default=%default]") - parser.add_option("", "--spec-size", type="int", default=256, - help="Set the size of the spectrogram FFT [default=%default]") - parser.add_option("-S", "--enable-spec", action="store_true", default=False, - help="Turn on plotting the spectrogram [default=%default]") + parser = ArgumentParser(conflict_handler="resolve", description=description) + parser.add_argument("-d", "--data-type", default="complex64", + choices=("complex64", "float32", "int32", "uint32", "int16", + "uint16", "int8", "uint8" ), + help="Specify the data type [default=%(default)r]") + parser.add_argument("-B", "--block", type=int, default=8192, + help="Specify the block size [default=%(default)r]") + parser.add_argument("-s", "--start", type=int, default=0, + help="Specify where to start in the file [default=%(default)r]") + parser.add_argument("-R", "--sample-rate", type=eng_float, default=1.0, + help="Set the sampler rate of the data [default=%(default)r]") + parser.add_argument("--psd-size", type=int, default=1024, + help="Set the size of the PSD FFT [default=%(default)r]") + parser.add_argument("--spec-size", type=int, default=256, + help="Set the size of the spectrogram FFT [default=%(default)r]") + parser.add_argument("-S", "--enable-spec", action="store_true", + help="Turn on plotting the spectrogram [default=%(default)r]") + parser.add_argument("file", metavar="FILE", + help="Input file with samples") return parser @@ -274,13 +276,9 @@ def find(item_in, list_search): def main(): parser = plot_psd_base.setup_options() - (options, args) = parser.parse_args () - if len(args) != 1: - parser.print_help() - raise SystemExit, 1 - filename = args[0] + args = parser.parse_args() - dc = plot_psd_base(options.data_type, filename, options) + dc = plot_psd_base(args.data_type, args.file, args) if __name__ == "__main__": try: |