From: W. Trevor King Date: Mon, 19 Nov 2012 06:21:36 +0000 (-0500) Subject: FFT_tools: remove redundant class names from TestCase methods X-Git-Tag: 0.5~9 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=082e5efca5e44421a9ee105338a92fc276f9d582;p=FFT-tools.git FFT_tools: remove redundant class names from TestCase methods --- diff --git a/FFT_tools.py b/FFT_tools.py index 933e064..51a2fea 100644 --- a/FFT_tools.py +++ b/FFT_tools.py @@ -383,7 +383,7 @@ class TestRFFT (_unittest.TestCase): class TestUnitaryRFFT (_unittest.TestCase): """Verify `unitary_rfft`. """ - def run_unitary_rfft_parsevals(self, xs, freq, freqs, Xs): + def run_parsevals(self, xs, freq, freqs, Xs): """Check the discretized integral form of Parseval's theorem Notes @@ -409,12 +409,12 @@ class TestUnitaryRFFT (_unittest.TestCase): raise ValueError( "Mismatch on Parseval's, {} != {}".format(lhs, rhs)) - def test_unitary_rfft_parsevals(self): + def test_parsevals(self): "Test unitary rfft on Parseval's theorem" xs = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1] dt = _numpy.pi freqs,Xs = unitary_rfft(xs, 1.0 / dt) - self.run_unitary_rfft_parsevals(xs, 1.0 / dt, freqs, Xs) + self.run_parsevals(xs, 1.0 / dt, freqs, Xs) def rect(self, t): r"""Rectangle function. @@ -434,8 +434,7 @@ class TestUnitaryRFFT (_unittest.TestCase): else: return 0 - def run_unitary_rfft_rect(self, a=1.0, time_shift=5.0, samp_freq=25.6, - samples=256): + 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)`. Notes @@ -482,12 +481,12 @@ class TestUnitaryRFFT (_unittest.TestCase): freq_axes.plot(freq_axis, expected, 'b-') freq_axes.set_title('freq series') - def test_unitary_rfft_rect(self): + def test_rect(self): "Test unitary FFTs on variously shaped rectangular functions." - self.run_unitary_rfft_rect(a=0.5) - self.run_unitary_rfft_rect(a=2.0) - self.run_unitary_rfft_rect(a=0.7, samp_freq=50, samples=512) - self.run_unitary_rfft_rect(a=3.0, samp_freq=60, samples=1024) + self.run_rect(a=0.5) + self.run_rect(a=2.0) + self.run_rect(a=0.7, samp_freq=50, samples=512) + self.run_rect(a=3.0, samp_freq=60, samples=1024) def gaussian(self, a, t): r"""Gaussian function. @@ -499,8 +498,7 @@ class TestUnitaryRFFT (_unittest.TestCase): """ return _numpy.exp(-a * t**2) - def run_unitary_rfft_gaussian(self, a=1.0, time_shift=5.0, samp_freq=25.6, - samples=256): + 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)`. Notes @@ -547,17 +545,16 @@ class TestUnitaryRFFT (_unittest.TestCase): freq_axes.plot(freq_axis, expected, 'b-') freq_axes.set_title('freq series') - def test_unitary_rfft_gaussian(self): + def test_gaussian(self): "Test unitary FFTs on variously shaped gaussian functions." - self.run_unitary_rfft_gaussian(a=0.5) - self.run_unitary_rfft_gaussian(a=2.0) - self.run_unitary_rfft_gaussian(a=0.7, samp_freq=50, samples=512) - self.run_unitary_rfft_gaussian(a=3.0, samp_freq=60, samples=1024) + self.run_gaussian(a=0.5) + self.run_gaussian(a=2.0) + self.run_gaussian(a=0.7, samp_freq=50, samples=512) + self.run_gaussian(a=3.0, samp_freq=60, samples=1024) class TestUnitaryPowerSpectrum (_unittest.TestCase): - def run_unitary_power_spectrum_sin(self, sin_freq=10, samp_freq=512, - samples=1024): + def run_sin(self, sin_freq=10, samp_freq=512, samples=1024): x = _numpy.zeros((samples,), dtype=_numpy.float) samp_freq = _numpy.float(samp_freq) for i in range(samples): @@ -612,29 +609,21 @@ class TestUnitaryPowerSpectrum (_unittest.TestCase): freq_axes.set_title( '{} samples of sin at {} Hz'.format(samples, sin_freq)) - - def test_unitary_power_spectrum_sin(self): + def test_sin(self): "Test unitary power spectrums on variously shaped sin functions" - self.run_unitary_power_spectrum_sin( - sin_freq=5, samp_freq=512, samples=1024) - self.run_unitary_power_spectrum_sin( - sin_freq=5, samp_freq=512, samples=2048) - self.run_unitary_power_spectrum_sin( - sin_freq=5, samp_freq=512, samples=4098) - self.run_unitary_power_spectrum_sin( - sin_freq=7, samp_freq=512, samples=1024) - self.run_unitary_power_spectrum_sin( - sin_freq=5, samp_freq=1024, samples=2048) + self.run_sin(sin_freq=5, samp_freq=512, samples=1024) + self.run_sin(sin_freq=5, samp_freq=512, samples=2048) + self.run_sin(sin_freq=5, samp_freq=512, samples=4098) + self.run_sin(sin_freq=7, samp_freq=512, samples=1024) + self.run_sin(sin_freq=5, samp_freq=1024, samples=2048) # finally, with some irrational numbers, to check that I'm not # getting lucky - self.run_unitary_power_spectrum_sin( + self.run_sin( sin_freq=_numpy.pi, samp_freq=100 * _numpy.exp(1), samples=1024) # test with non-integer number of periods - self.run_unitary_power_spectrum_sin( - sin_freq=5, samp_freq=512, samples=256) + self.run_sin(sin_freq=5, samp_freq=512, samples=256) - def run_unitary_power_spectrum_delta(self, amp=1, samp_freq=1, - samples=256): + def run_delta(self, amp=1, samp_freq=1, samples=256): """TODO """ x = _numpy.zeros((samples,), dtype=_numpy.float) @@ -670,30 +659,24 @@ class TestUnitaryPowerSpectrum (_unittest.TestCase): freq_axes.plot(freq_axis, expected, 'b-') freq_axes.set_title('{} samples of delta amp {}'.format(samples, amp)) - def test_unitary_power_spectrum_delta(self): + def test_delta(self): "Test unitary power spectrums on various delta functions" - self.run_unitary_power_spectrum_delta( - amp=1, samp_freq=1.0, samples=1024) - self.run_unitary_power_spectrum_delta( - amp=1, samp_freq=1.0, samples=2048) + self.run_delta(amp=1, samp_freq=1.0, samples=1024) + self.run_delta(amp=1, samp_freq=1.0, samples=2048) # expected = 2*computed - self.run_unitary_power_spectrum_delta( - amp=1, samp_freq=0.5, samples=2048) + self.run_delta(amp=1, samp_freq=0.5, samples=2048) # expected = 0.5*computed - self.run_unitary_power_spectrum_delta( - amp=1, samp_freq=2.0, samples=2048) - self.run_unitary_power_spectrum_delta( - amp=3, samp_freq=1.0, samples=1024) - self.run_unitary_power_spectrum_delta( - amp=_numpy.pi, samp_freq=_numpy.exp(1), samples=1024) + self.run_delta(amp=1, samp_freq=2.0, samples=2048) + self.run_delta(amp=3, samp_freq=1.0, samples=1024) + self.run_delta(amp=_numpy.pi, samp_freq=_numpy.exp(1), samples=1024) def gaussian(self, area, mean, std, t): "Integral over all time = area (i.e. normalized for area=1)" return area / (std * _numpy.sqrt(2.0 * _numpy.pi)) * _numpy.exp( -0.5 * ((t-mean)/std)**2) - def run_unitary_power_spectrum_gaussian(self, area=2.5, mean=5, std=1, - samp_freq=10.24 ,samples=512): + def run_gaussian(self, area=2.5, mean=5, std=1, samp_freq=10.24, + samples=512): """TODO. """ x = _numpy.zeros((samples,), dtype=_numpy.float) @@ -744,21 +727,20 @@ class TestUnitaryPowerSpectrum (_unittest.TestCase): freq_axes.plot(freq_axis, expected, 'b-') freq_axes.set_title('freq series') - def test_unitary_power_spectrum_gaussian(self): + def test_gaussian(self): "Test unitary power spectrums on various gaussian functions" for area in [1, _numpy.pi]: for std in [1, _numpy.sqrt(2)]: for samp_freq in [10.0, _numpy.exp(1)]: for samples in [1024, 2048]: - self.run_unitary_power_spectrum_gaussian( + self.run_gaussian( area=area, std=std, samp_freq=samp_freq, samples=samples) class TestUnitaryAvgPowerSpectrum (_unittest.TestCase): - def run_unitary_avg_power_spectrum_sin(self, sin_freq=10, samp_freq=512, - samples=1024, chunk_size=512, - overlap=True, window=window_hann): + def run_sin(self, sin_freq=10, samp_freq=512, samples=1024, chunk_size=512, + overlap=True, window=window_hann): """TODO """ x = _numpy.zeros((samples,), dtype=_numpy.float) @@ -797,22 +779,16 @@ class TestUnitaryAvgPowerSpectrum (_unittest.TestCase): freq_axes.set_title( '{} samples of sin at {} Hz'.format(samples, sin_freq)) - def test_unitary_avg_power_spectrum_sin(self): + def test_sin(self): "Test unitary avg power spectrums on variously shaped sin functions." - self.run_unitary_avg_power_spectrum_sin( - sin_freq=5, samp_freq=512, samples=1024) - self.run_unitary_avg_power_spectrum_sin( - sin_freq=5, samp_freq=512, samples=2048) - self.run_unitary_avg_power_spectrum_sin( - sin_freq=5, samp_freq=512, samples=4098) - self.run_unitary_avg_power_spectrum_sin( - sin_freq=17, samp_freq=512, samples=1024) - self.run_unitary_avg_power_spectrum_sin( - sin_freq=5, samp_freq=1024, samples=2048) + self.run_sin(sin_freq=5, samp_freq=512, samples=1024) + self.run_sin(sin_freq=5, samp_freq=512, samples=2048) + self.run_sin(sin_freq=5, samp_freq=512, samples=4098) + self.run_sin(sin_freq=17, samp_freq=512, samples=1024) + self.run_sin(sin_freq=5, samp_freq=1024, samples=2048) # test long wavelenth sin, so be closer to window frequency - self.run_unitary_avg_power_spectrum_sin( - sin_freq=1, samp_freq=1024, samples=2048) + self.run_sin(sin_freq=1, samp_freq=1024, samples=2048) # finally, with some irrational numbers, to check that I'm not # getting lucky - self.run_unitary_avg_power_spectrum_sin( + self.run_sin( sin_freq=_numpy.pi, samp_freq=100 * _numpy.exp(1), samples=1024)