From 797994a11ac5ec6bee9ea01c092947d0c34115f1 Mon Sep 17 00:00:00 2001
From: Marcus Müller <marcus@hostalia.de>
Date: Fri, 24 Aug 2018 23:00:55 +0200
Subject: Replace scipy/pylab where numpy/pyplot is sufficient

This should reduce the number of times users are prompted to install
pylab || scipy when they'd actually get away with functionality fully
contained in numpy and matplotlib.

This only solves the obvious cases. There's some usage of `pylab.mlab`
that would need more than 20s of consideration.
---
 gr-filter/examples/decimate.py | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

(limited to 'gr-filter/examples/decimate.py')

diff --git a/gr-filter/examples/decimate.py b/gr-filter/examples/decimate.py
index fb37d8047e..7ebd5a28ed 100644
--- a/gr-filter/examples/decimate.py
+++ b/gr-filter/examples/decimate.py
@@ -27,6 +27,7 @@ from gnuradio import gr
 from gnuradio import blocks
 from gnuradio import filter
 import sys, time
+import numpy
 
 try:
     from gnuradio import analog
@@ -34,16 +35,10 @@ except ImportError:
     sys.stderr.write("Error: Program requires gr-analog.\n")
     sys.exit(1)
 
-try:
-    import scipy
-    from scipy import fftpack
-except ImportError:
-    sys.stderr.write("Error: Program requires scipy (see: www.scipy.org).\n")
-    sys.exit(1)
 
 try:
-    import pylab
-    from pylab import mlab
+    from matplotlib import pyplot
+    from matplotlib import pyplot as mlab
 except ImportError:
     sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n")
     sys.exit(1)
@@ -63,7 +58,7 @@ class pfb_top_block(gr.top_block):
                                               window=filter.firdes.WIN_BLACKMAN_hARRIS)
 
         # Calculate the number of taps per channel for our own information
-        tpc = scipy.ceil(float(len(self._taps)) / float(self._decim))
+        tpc = numpy.ceil(float(len(self._taps)) / float(self._decim))
         print("Number of taps:     ", len(self._taps))
         print("Number of filters:  ", self._decim)
         print("Taps per channel:   ", tpc)
@@ -106,14 +101,14 @@ def main():
     print("Run time: %f" % (tend - tstart))
 
     if 1:
-        fig1 = pylab.figure(1, figsize=(16,9))
-        fig2 = pylab.figure(2, figsize=(16,9))
+        fig1 = pyplot.figure(1, figsize=(16,9))
+        fig2 = pyplot.figure(2, figsize=(16,9))
 
         Ns = 10000
         Ne = 10000
 
         fftlen = 8192
-        winfunc = scipy.blackman
+        winfunc = numpy.blackman
         fs = tb._fs
 
         # Plot the input to the decimator
@@ -124,8 +119,8 @@ def main():
         X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs,
                           window = lambda d: d*winfunc(fftlen),
                           scale_by_freq=True)
-        X_in = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
-        f_in = scipy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size))
+        X_in = 10.0*numpy.log10(abs(numpy.fft.fftshift(X)))
+        f_in = numpy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size))
         p1_f = sp1_f.plot(f_in, X_in, "b")
         sp1_f.set_xlim([min(f_in), max(f_in)+1])
         sp1_f.set_ylim([-200.0, 50.0])
@@ -137,8 +132,8 @@ def main():
         Ts = 1.0 / fs
         Tmax = len(d)*Ts
 
-        t_in = scipy.arange(0, Tmax, Ts)
-        x_in = scipy.array(d)
+        t_in = numpy.arange(0, Tmax, Ts)
+        x_in = numpy.array(d)
         sp1_t = fig1.add_subplot(2, 1, 2)
         p1_t = sp1_t.plot(t_in, x_in.real, "b")
         p1_t = sp1_t.plot(t_in, x_in.imag, "r")
@@ -156,8 +151,8 @@ def main():
         X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs_o,
                           window = lambda d: d*winfunc(fftlen),
                           scale_by_freq=True)
-        X_o = 10.0*scipy.log10(abs(fftpack.fftshift(X)))
-        f_o = scipy.arange(-fs_o / 2.0, fs_o / 2.0, fs_o / float(X_o.size))
+        X_o = 10.0*numpy.log10(abs(numpy.fft.fftshift(X)))
+        f_o = numpy.arange(-fs_o / 2.0, fs_o / 2.0, fs_o / float(X_o.size))
         p2_f = sp2_f.plot(f_o, X_o, "b")
         sp2_f.set_xlim([min(f_o), max(f_o)+1])
         sp2_f.set_ylim([-200.0, 50.0])
@@ -170,8 +165,8 @@ def main():
         Ts_o = 1.0 / fs_o
         Tmax_o = len(d)*Ts_o
 
-        x_o = scipy.array(d)
-        t_o = scipy.arange(0, Tmax_o, Ts_o)
+        x_o = numpy.array(d)
+        t_o = numpy.arange(0, Tmax_o, Ts_o)
         sp2_t = fig2.add_subplot(2, 1, 2)
         p2_t = sp2_t.plot(t_o, x_o.real, "b-o")
         p2_t = sp2_t.plot(t_o, x_o.imag, "r-o")
@@ -180,7 +175,7 @@ def main():
         sp2_t.set_xlabel("Time (s)")
         sp2_t.set_ylabel("Amplitude")
 
-        pylab.show()
+        pyplot.show()
 
 
 if __name__ == "__main__":
-- 
cgit v1.2.3