Esempio n. 1
0
 def test_flat_top_window(self):
     result = np.array([
         8.67361738e-17, -2.62000000e-01, 4.63600000e+00, -2.62000000e-01,
         8.67361738e-17
     ])
     window = utils.create_window(self.N, self.flattop_window)
     assert np.allclose(window, result)
Esempio n. 2
0
    def _get_window(self):
        """
            Returns a window function of self.window_name type
        """
        N = 2 * self.maxlag + 1
        window_even = utils.create_window(N, self.window_name)

        # 2d even window
        window2d = np.array([window_even, ] * N)

        ## One-sided window with zero padding
        window = np.zeros(N)
        window[:self.maxlag + 1] = window_even[self.maxlag:]
        window[self.maxlag:] = 0

        # 2d window function to apply to bispectrum
        row = np.concatenate(([window[0]], np.zeros(2 * self.maxlag)))
        toep_matrix = toeplitz(window, row)
        toep_matrix += np.tril(toep_matrix, -1).transpose()
        window = toep_matrix[..., ::-1] * window2d * window2d.transpose()
        return window
Esempio n. 3
0
 def test_bad_N(self):
     N_bad = 'abc'
     with pytest.raises(TypeError):
         window = utils.create_window(N_bad, self.uniform_window)
Esempio n. 4
0
 def test_bad_window_type(self):
     window_bad = 123
     with pytest.raises(TypeError):
         window = utils.create_window(self.N, window_bad)
Esempio n. 5
0
 def test_welch_window(self):
     result = np.array([0, 0.75, 1, 0.75, 0])
     window = utils.create_window(self.N, self.welch_window)
     assert np.allclose(window, result)
Esempio n. 6
0
 def test_hanning_window(self):
     result = np.array([0, 0.5, 1, 0.5, 0])
     window = utils.create_window(self.N, self.hanning_window)
     assert np.allclose(window, result)
Esempio n. 7
0
 def test_parzen_window(self):
     result = np.array([0, 0.25, 1, 0.25, 0])
     window = utils.create_window(self.N, self.parzen_window)
     assert np.allclose(window, result)
Esempio n. 8
0
 def test_N_equals_zero(self):
     N = 0
     window = utils.create_window(N)
     assert len(window) == 0
Esempio n. 9
0
 def test_triangular_window(self):
     result = np.array([0.6, 0.8, 1, 0.8, 0.6])
     window = utils.create_window(self.N, self.triangular_window)
     assert np.allclose(window, result)
Esempio n. 10
0
 def test_hanning_window(self):
     result = np.array([0, 0.5, 1, 0.5, 0])
     window = utils.create_window(self.N, self.hanning_window)
     assert np.allclose(window, result)
Esempio n. 11
0
 def test_hamming_window(self):
     result = np.array([0.08, 0.54, 1, 0.54, 0.08])
     window = utils.create_window(self.N, self.hamming_window)
     assert np.allclose(window, result)
Esempio n. 12
0
 def test_parzen_window(self):
     result = np.array([0, 0.25, 1, 0.25, 0])
     window = utils.create_window(self.N, self.parzen_window)
     assert np.allclose(window, result)
Esempio n. 13
0
 def test_uniform_window(self):
     result = np.ones(self.N)
     window = utils.create_window(self.N)
     assert np.allclose(window, result)
Esempio n. 14
0
 def test_N_equals_zero(self):
     N = 0
     window = utils.create_window(N)
     assert len(window) == 0
Esempio n. 15
0
 def test_not_available_window(self):
     window_not = 'kaiser'
     with pytest.raises(ValueError):
         window = utils.create_window(self.N, window_not)
Esempio n. 16
0
 def test_bad_window_type(self):
     window_bad = 123
     with pytest.raises(TypeError):
         window = utils.create_window(self.N, window_bad)
Esempio n. 17
0
 def test_not_available_window(self):
     window_not = 'kaiser'
     with pytest.raises(ValueError):
         window = utils.create_window(self.N, window_not)
Esempio n. 18
0
 def test_welch_window(self):
     result = np.array([0, 0.75, 1, 0.75, 0])
     window = utils.create_window(self.N, self.welch_window)
     assert np.allclose(window, result)
Esempio n. 19
0
 def test_uniform_window(self):
     result = np.ones(self.N)
     window = utils.create_window(self.N)
     assert np.allclose(window, result)
Esempio n. 20
0
 def test_blackmann_window(self):
     result = np.array([0.006879, 0.349741, 0.999999, 0.349741, 0.006879])
     window = utils.create_window(self.N, self.blackmann_window)
     assert np.allclose(window, result)
Esempio n. 21
0
 def test_hamming_window(self):
     result = np.array([0.08, 0.54, 1, 0.54, 0.08])
     window = utils.create_window(self.N, self.hamming_window)
     assert np.allclose(window, result)
Esempio n. 22
0
 def test_flat_top_window(self):
     result = np.array([8.67361738e-17, -2.62000000e-01, 4.63600000e+00, -2.62000000e-01,
                        8.67361738e-17])
     window = utils.create_window(self.N, self.flattop_window)
     assert np.allclose(window, result)
Esempio n. 23
0
 def test_triangular_window(self):
     result = np.array([0.6, 0.8, 1, 0.8, 0.6])
     window = utils.create_window(self.N, self.triangular_window)
     assert np.allclose(window, result)
Esempio n. 24
0
cadence = 12.

# Number of exposures
n_exposure = 234

# Times at which the exposures are made
times = cadence*np.arange(0, n_exposure)  # seconds

# Counts per second
signal = 300 * np.sin(2.*np.pi*times/0.5) + 1000  # counts/s

# Noisy version of the true signal
noisy = np.random.poisson(signal*exposure_time)  # counts


uniform = create_window(len(signal))
hanning = create_window(len(signal), window_type='hanning')

lc = []
for window_type in [uniform, hanning]:
    data = noisy*window_type
    lc.append(Lightcurve(times, data))

ps1 = Powerspectrum(lc[0])
ps2 = Powerspectrum(lc[1])


fig, ax1 = plt.subplots(1, 1, figsize=(9, 6), sharex=True)
ax1.plot(ps1.freq, ps1.power, lw=1, color='blue', label='no window')
ax1.plot(ps2.freq, ps2.power, lw=1, color='red', label='Hanning')
ax1.set_xlabel("Frequency (Hz)")
Esempio n. 25
0
 def test_blackmann_window(self):
     result = np.array([0.006879, 0.349741, 0.999999, 0.349741, 0.006879])
     window = utils.create_window(self.N, self.blackmann_window)
     assert np.allclose(window, result)
Esempio n. 26
0
 def test_bad_N(self):
     N_bad = 'abc'
     with pytest.raises(TypeError):
         window = utils.create_window(N_bad, self.uniform_window)