def test_intensity_varying_channels(self): """ Tests lags for multiple energy channels with each channel having same position and varying intensity. """ lc = sampledata.sample_data() s = lc.counts h = [] h.append(self.simulator.simple_ir(start=4, width=1, intensity=10)) h.append(self.simulator.simple_ir(start=4, width=1, intensity=20)) delay = int(5 / lc.dt) outputs = [] for i in h: lc2 = self.simulator.simulate(s, i) lc2 = lc2.shift(-lc2.time[0] + lc.time[0]) outputs.append(lc2) cross = [Crossspectrum(lc, lc2).rebin(0.0075) for lc2 in outputs] lags = [np.angle(c.power) / (2 * np.pi * c.freq) for c in cross] v_cutoff = 1.0 / (2.0 * 5) h_cutoffs = [ lag[int((v_cutoff - 0.0075) * 1 / 0.0075)] for lag in lags ] assert np.abs(5 - h_cutoffs[0]) < np.sqrt(5) assert np.abs(5 - h_cutoffs[1]) < np.sqrt(5)
def test_actual_event_create(self): """ Simulate an event list from actual light curve. """ lc = sample_data() new_lc = lc[0:100] events.gen_events_from_lc(new_lc.time, new_lc.counts)
def test_event_create_with_spline(self): """ Simulate an event list from actual light curve with use_spline = True. """ lc = sample_data() new_lc = lc[0:100] events.gen_events_from_lc(new_lc.time, new_lc.counts, use_spline=True)
def test_intensity_varying_channels(self): """ Tests lags for multiple energy channels with each channel having same position and varying intensity. """ lc = sampledata.sample_data() s = lc.counts h = [] h.append(self.simulator.simple_ir(start=4, width=1, intensity=10)) h.append(self.simulator.simple_ir(start=4, width=1, intensity=20)) delay = int(5/lc.dt) outputs = [] for i in h: lc2 = self.simulator.simulate(s, i) lc2 = lc2.shift(-lc2.time[0] + lc.time[0]) outputs.append(lc2) cross = [Crossspectrum(lc, lc2).rebin(0.0075) for lc2 in outputs] lags = [np.angle(c.power) / (2 * np.pi * c.freq) for c in cross] v_cutoff = 1.0/(2.0*5) h_cutoffs = [lag[int((v_cutoff-0.0075)*1/0.0075)] for lag in lags] assert np.abs(5-h_cutoffs[0]) < np.sqrt(5) assert np.abs(5-h_cutoffs[1]) < np.sqrt(5)
def test_simulate_simple_impulse(self): """ Simulate light curve from simple impulse response. """ lc = sampledata.sample_data() s = lc.counts h = self.simulator.simple_ir(10, 1, 1) output = self.simulator.simulate(s, h)
def test_simulate_simple_impulse_odd(self): """ Simulate light curve from simple impulse response. """ lc = sampledata.sample_data() s = lc.counts h = self.simulator_odd.simple_ir(10, 1, 1) output = self.simulator_odd.simulate(s, h)
def test_simulate_relativistic_impulse(self): """ Simulate light curve from relativistic impulse response. """ lc = sampledata.sample_data() s = lc.counts h = self.simulator.relativistic_ir() output = self.simulator.simulate(s, h)
def test_filtered_simulate_odd(self): """ Simulate light curve using 'filtered' mode. """ lc = sampledata.sample_data() s = lc.counts h = self.simulator_odd.simple_ir() output = self.simulator_odd.simulate(s, h, 'filtered')
def test_filtered_simulate(self): """ Simulate light curve using 'filtered' mode. """ lc = sampledata.sample_data() s = lc.counts h = self.simulator.simple_ir() output = self.simulator.simulate(s, h, 'filtered')
def test_from_stingray(): """Test the `LightCurve.from_stingray()` method.""" try: from stingray import sampledata sr = sampledata.sample_data() lc = LightCurve.from_stingray(sr) assert_allclose(sr.time, lc.time) assert_allclose(sr.counts, lc.flux) assert_allclose(sr.counts_err, lc.flux_err) except ImportError: pass # stingray is not a required dependency
def test_relativistic_lag_spectrum(self): """ Simulate light curve from relativistic impulse response and compute lag spectrum. """ lc = sampledata.sample_data() h = self.simulator.relativistic_ir(t1=3, t2=4, t3=10) delay = int(4/lc.dt) lag = self.calculate_lag(lc, h, delay) v_cutoff = 1.0/(2*4) h_cutoff = lag[int((v_cutoff-0.0075)*1/0.0075)] assert np.abs(4-h_cutoff) < np.sqrt(4)
def test_simple_lag_spectrum(self): """ Simulate light curve from simple impulse response and compute lag spectrum. """ lc = sampledata.sample_data() h = self.simulator.simple_ir(start=14, width=1) delay = int(15/lc.dt) lag = self.calculate_lag(lc, h, delay) v_cutoff = 1.0/(2*15.0) h_cutoff = lag[int((v_cutoff-0.0075)*1/0.0075)] assert np.abs(15-h_cutoff) < np.sqrt(15)
def test_relativistic_lag_spectrum(self): """ Simulate light curve from relativistic impulse response and compute lag spectrum. """ lc = sampledata.sample_data() h = self.simulator.relativistic_ir(t1=3, t2=4, t3=10) delay = int(4 / lc.dt) lag = self.calculate_lag(lc, h, delay) v_cutoff = 1.0 / (2 * 4) h_cutoff = lag[int((v_cutoff - 0.0075) * 1 / 0.0075)] assert np.abs(4 - h_cutoff) < np.sqrt(4)
def test_simple_lag_spectrum(self): """ Simulate light curve from simple impulse response and compute lag spectrum. """ lc = sampledata.sample_data() h = self.simulator.simple_ir(start=14, width=1) delay = int(15 / lc.dt) lag = self.calculate_lag(lc, h, delay) v_cutoff = 1.0 / (2 * 15.0) h_cutoff = lag[int((v_cutoff - 0.0075) * 1 / 0.0075)] assert np.abs(15 - h_cutoff) < np.sqrt(15)
def test_actual_recover_lcurve(self): """ Recover a lightcurve from an actual event list. """ lc = sample_data() new_lc = lc[0:100] ev_list = events.gen_events_from_lc(new_lc.time, new_lc.counts) bin_length = new_lc.time[1] - new_lc.time[0] new_times, new_counts = events.gen_lc_from_events(ev_list, bin_length, start_time = new_lc.time[0] - bin_length/2, stop_time = new_lc.time[-1] + bin_length/2) #TODO: Sigma needs to be 4 in order to pass test. Should it be 3? assert np.all(np.abs(new_counts - new_lc.counts) < 4 * np.sqrt(new_lc.counts)) np.testing.assert_almost_equal(new_times, new_lc.time)
def test_simple_lag_spectrum(self): """ Simulate light curve from simple impulse response and compute lag spectrum. """ lc = sampledata.sample_data() h = self.simulator.simple_ir(start=14, width=1) delay = int(15 / lc.dt) lag = self.calculate_lag(lc, h, delay) bins = np.arange(lag.size) v_cutoff = 1.0 / (2 * 15.0) dist = (v_cutoff - 0.0075) / 0.0075 spec_fun = interp1d(bins, lag) h_cutoff = spec_fun(dist) assert np.abs(15 - h_cutoff) < np.sqrt(15)
def test_position_varying_channels(self): """ Tests lags for multiple energy channels with each channel having same intensity and varying position. """ lc = sampledata.sample_data() s = lc.counts h = [] h.append(self.simulator.simple_ir(start=4, width=1)) h.append(self.simulator.simple_ir(start=9, width=1)) delays = [int(5/lc.dt), int(10/lc.dt)] outputs = [self.simulator.simulate(s, i) for i in h] cross = [Crossspectrum(lc, lc2).rebin(0.0075) for lc2 in outputs] lags = [np.angle(c.power)/ (2 * np.pi * c.freq) for c in cross] v_cutoffs = [1.0/(2.0*5), 1.0/(2.0*10)] h_cutoffs = [lag[int((v-0.0075)*1/0.0075)] for lag, v in zip(lags, v_cutoffs)] assert np.abs(5-h_cutoffs[0]) < np.sqrt(5) assert np.abs(10-h_cutoffs[1]) < np.sqrt(10)
def test_simulate_simple_impulse(self): """ Simulate light curve from simple impulse response. """ lc = sampledata.sample_data() s = lc.counts