FFT_tools: Catch RuntimeErrors when importing matplotlib
[FFT-tools.git] / FFT_tools.py
index 95b998162df757f6009613fe838e280dc1a80f23..e6d058cc178416892a8425bcc05cc67b36d7aeb7 100644 (file)
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-"""Wrap Numpy's fft module to reduce clutter.
+"""Wrap Numpy's :py:mod:`~numpy.fft` module to reduce clutter.
 
 Provides a unitary discrete FFT and a windowed version based on
-:func:`numpy.fft.rfft`.
+:py:func:`numpy.fft.rfft`.
 
 Main entry functions:
 
-* :func:`unitary_rfft`
-* :func:`power_spectrum`
-* :func:`unitary_power_spectrum`
-* :func:`avg_power_spectrum`
-* :func:`unitary_avg_power_spectrum`
+* :py:func:`unitary_rfft`
+* :py:func:`power_spectrum`
+* :py:func:`unitary_power_spectrum`
+* :py:func:`avg_power_spectrum`
+* :py:func:`unitary_avg_power_spectrum`
 """
 
 import logging as _logging
@@ -32,12 +32,12 @@ import unittest as _unittest
 import numpy as _numpy
 try:
     import matplotlib.pyplot as _pyplot
-except ImportError as e:
+except (ImportError, RuntimeError) as e:
     _pyplot = None
     _pyplot_import_error = e
 
 
-__version__ = '0.4'
+__version__ = '0.5'
 
 
 LOG = _logging.getLogger('FFT-tools')
@@ -360,7 +360,8 @@ class TestRFFT (_unittest.TestCase):
 
     .. math:: X_k = \sum_{m=0}^{n-1} x_m \exp^{-2\pi imk/n}
 
-    .. [#dft] See the *Background information* section of :mod:`numpy.fft`.
+    .. [#dft] See the *Background information* section of
+       :py:mod:`numpy.fft`.
     """
     def run_rfft(self, xs, Xs):
         i = _numpy.complex(0, 1)
@@ -387,13 +388,13 @@ class TestRFFT (_unittest.TestCase):
                 timeSum, n, freqSum))
 
     def test_rfft(self):
-        "Test NumPy's builtin :func:`numpy.fft.rfft`"
+        "Test NumPy's builtin :py:func:`numpy.fft.rfft`"
         xs = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1]
         self.run_rfft(xs, _numpy.fft.rfft(xs))
 
 
 class TestUnitaryRFFT (_unittest.TestCase):
-    """Verify `unitary_rfft`.
+    """Verify :py:func:`unitary_rfft`.
     """
     def run_parsevals(self, xs, freq, freqs, Xs):
         """Check the discretized integral form of Parseval's theorem
@@ -437,7 +438,7 @@ class TestUnitaryRFFT (_unittest.TestCase):
             \rect(t) = \begin{cases}
                1& \text{if $|t| < 0.5$}, \\
                0& \text{if $|t| \ge 0.5$}.
-                       \end{cases}
+                             \end{cases}
         """
         if _numpy.abs(t) < 0.5:
             return 1
@@ -445,7 +446,7 @@ class TestUnitaryRFFT (_unittest.TestCase):
             return 0
 
     def run_rect(self, a=1.0, time_shift=5.0, samp_freq=25.6, samples=256):
-        r"""Test `unitary_rttf` on known function `rect(at)`.
+        r"""Test :py:func:`unitary_rfft` on known function :py:meth:`rect`.
 
         Notes
         -----
@@ -510,7 +511,7 @@ class TestUnitaryRFFT (_unittest.TestCase):
         return _numpy.exp(-a * t**2)
 
     def run_gaussian(self, a=1.0, time_shift=5.0, samp_freq=25.6, samples=256):
-        r"""Test `unitary_rttf` on known function `gaussian(a,t)`.
+        r"""Test :py:func:`unitary_rttf` on known function :py:meth:`gaussian`.
 
         Notes
         -----
@@ -518,7 +519,8 @@ class TestUnitaryRFFT (_unittest.TestCase):
 
         .. math::
 
-            \rfft(\gaussian(a,t)) = \sqrt{\pi/a} \cdot \gaussian(1/a,\pi f)
+            \rfft(\gaussian(a,t))
+              = \sqrt{\pi/a} \cdot \gaussian(1/a,\pi f)
         """
         samp_freq = _numpy.float(samp_freq)
         a = _numpy.float(a)