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)
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
def test_bad_N(self): N_bad = 'abc' with pytest.raises(TypeError): window = utils.create_window(N_bad, self.uniform_window)
def test_bad_window_type(self): window_bad = 123 with pytest.raises(TypeError): window = utils.create_window(self.N, window_bad)
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)
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)
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)
def test_N_equals_zero(self): N = 0 window = utils.create_window(N) assert len(window) == 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)
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)
def test_uniform_window(self): result = np.ones(self.N) window = utils.create_window(self.N) assert np.allclose(window, result)
def test_not_available_window(self): window_not = 'kaiser' with pytest.raises(ValueError): window = utils.create_window(self.N, window_not)
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)
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)
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)")