def setup_class(cls): from ..simulator import Simulator cls.bin_time = 0.01 data = np.load(os.path.join(datadir, "sample_variable_lc.npy")) # No need for huge count rates flux = data / 40 times = np.arange(data.size) * cls.bin_time gti = np.asarray([[0, data.size * cls.bin_time]]) test_lc = Lightcurve(times, flux, err_dist="gauss", gti=gti, dt=cls.bin_time, skip_checks=True) cls.test_ev1, cls.test_ev2 = EventList(), EventList() cls.test_ev1.simulate_times(test_lc) cls.test_ev2.simulate_times(test_lc) N1 = cls.test_ev1.time.size N2 = cls.test_ev2.time.size cls.test_ev1.energy = np.random.uniform(0.3, 12, N1) cls.test_ev2.energy = np.random.uniform(0.3, 12, N2) mask = np.sort(np.random.randint(0, min(N1, N2) - 1, 200000)) cls.test_ev1_small = cls.test_ev1.apply_mask(mask) cls.test_ev2_small = cls.test_ev2.apply_mask(mask)
def setup_class(cls): cls.pulse_frequency = 1 / 0.101 cls.tstart = 0 cls.tend = 25.25 cls.tseg = cls.tend - cls.tstart cls.dt = 0.00606 cls.times = np.arange(cls.tstart, cls.tend, cls.dt) + cls.dt / 2 cls.counts = \ 100 + 20 * np.cos(2 * np.pi * cls.times * cls.pulse_frequency) lc = Lightcurve(cls.times, cls.counts, gti=[[cls.tstart, cls.tend]]) events = EventList() events.simulate_times(lc) events.mjdref = 57000. cls.event_times = events.time cls.dum = 'events' + HEN_FILE_EXTENSION save_events(events, cls.dum) curdir = os.path.abspath(os.path.dirname(__file__)) cls.datadir = os.path.join(curdir, 'data') fits_file = os.path.join(cls.datadir, 'monol_testA.evt') command = 'HENreadevents {0}'.format(fits_file) sp.check_call(command.split()) cls.real_event_file = os.path.join( cls.datadir, 'monol_testA_nustar_fpma_ev' + HEN_FILE_EXTENSION)
def test_load_and_save_events(self): events = EventList([0, 2, 3.], pi=[1, 2, 3], mjdref=54385.3254923845, gti = np.longdouble([[-0.5, 3.5]])) events.energy = np.array([3., 4., 5.]) save_to_intermediate_file(events, self.dum) ds = load_dataset_from_intermediate_file(self.dum) assert ds
def setup_class(cls): from ..simulator.simulator import Simulator simulator = Simulator(0.1, 10000, rms=0.4, mean=200) test_lc = simulator.simulate(1) cls.test_ev1, cls.test_ev2 = EventList(), EventList() cls.test_ev1.simulate_times(test_lc) cls.test_ev1.pha = np.random.uniform(0.3, 12, len(cls.test_ev1.time))
def test_somefunc(): lenbin = 100 T_exp = 590000 CR = 5e-3 epoch_89 = '/Users/baotong/Desktop/CDFS/txt_all_obs_0.5_8_ep3/epoch_src_test_single.txt' (TSTART, TSTOP, OBSID, exptime) = func.read_epoch(epoch_89) epoch_89 = (TSTART, TSTOP, OBSID, exptime) w = make_freq_range(dt=lenbin, epoch_file=epoch_89) # psd_model=build_psd(x=w,p=[2.3e-3, 3.4, 0., 4.3e-4],x_2=w, # p_2=[4.01e-4, 4.01e-4 / 16, 100, 2],type='bendp+lorentz') p_1 = [4.3e-4, 3.4, 0., 2e-2] p_2 = [2.67e-4, 16, 0.15, 2] psd_model = sim.build_psd(x=w, p=p_1, x_2=w, p_2=p_2, type='bendp+lorentz') frms = integrate.quad(func.bendp_lorentz, w[0], w[-1], args=(p_1, p_2))[0] frms = np.sqrt(frms) plt.loglog() plt.plot(w, psd_model) plt.xlabel('Frequency (Hz)', font2) plt.ylabel('Power', font2) plt.tick_params(labelsize=16) plt.show() lc = make_lc_from_psd(psd=psd_model, cts_rate=CR * lenbin, dt=lenbin, epoch_file=epoch_89, frms=frms) ps_org = plot_psd(lc) print('counts={0}'.format(np.sum(lc.counts))) lc_evt = Lightcurve(time=lc.time, counts=lc.counts, dt=lc.dt, gti=lc.gti) lc_evt.counts = np.random.poisson(lc_evt.counts) # ev_all = EventList() # ev_all.time = func.sim_evtlist(lc) # lc_evt = ev_all.to_lc(dt=lenbin, tstart=ev_all.time[0] - 0.5 * lenbin, # tseg=ev_all.time[-1] - ev_all.time[0]) ps_real = plot_psd(lc_evt) freq = np.arange(1 / T_exp, 0.5 / lenbin, 1 / (5 * T_exp)) freq = freq[np.where(freq > 1 / 10000.)] temp = func.get_LS(lc_evt.time, lc_evt.counts, freq=freq) # plt.subplot(121) plt.xlabel('Time', font2) plt.ylabel('Counts/bin', font2) plt.tick_params(labelsize=16) plt.plot(lc.time, lc.counts, color='red') # plt.subplot(122) plt.show() plt.plot(lc_evt.time, lc_evt.counts, color='green') print('counts={0}'.format(np.sum(lc_evt.counts))) plt.xlabel('Time', font2) plt.ylabel('Counts/bin', font2) plt.tick_params(labelsize=16) plt.show() evt = EventList() EventList.simulate_times(evt, lc=lc) print('counts={0}'.format(len(evt.time)))
def get_hist(t, len_bin): ###将输入的time信息,按照len_bin的长度输出为lc t_test = t dt = len_bin ev = EventList() ev.time = t_test lc_new = ev.to_lc(dt=dt, tstart=ev.time[0] - 0.5 * dt, tseg=ev.time[-1] - ev.time[0]) return lc_new
def test_load_and_save_events(self): events = EventList([0, 2, 3.], pi=[1, 2, 3], mjdref=54385.3254923845, gti = np.longdouble([[-0.5, 3.5]])) events.energy = np.array([3., 4., 5.]) save_events(events, self.dum) events2 = load_events(self.dum) assert np.allclose(events.time, events2.time) assert np.allclose(events.pi, events2.pi) assert np.allclose(events.mjdref, events2.mjdref) assert np.allclose(events.gti, events2.gti) assert np.allclose(events.energy, events2.energy)
def get_hist(t, len_bin,tstart=0,tstop=0): ###将输入的time信息,按照len_bin的长度输出为lc if tstart==0 and tstop==0: tstart=t[0] tstop=t[-1] tseg=tstop-tstart else:tseg=tstop-tstart t_test = t;dt=len_bin ev = EventList() ev.time = t_test lc_new = ev.to_lc(dt=dt, tstart=tstart-0.5*dt, tseg=tseg+0.5*dt) return lc_new
def setup_class(cls): cls.pulse_frequency = 1/0.101 cls.tstart = 0 cls.tend = 25.25 cls.tseg = cls.tend - cls.tstart cls.dt = 0.01212 cls.times = np.arange(cls.tstart, cls.tend, cls.dt) + cls.dt / 2 cls.counts = \ 100 + 20 * np.cos(2 * np.pi * cls.times * cls.pulse_frequency) lc = Lightcurve(cls.times, cls.counts, gti=[[cls.tstart, cls.tend]]) events = EventList() events.simulate_times(lc) cls.event_times = events.time
def setup_class(cls): cls.pulse_frequency = 1 / 0.101 cls.tstart = 0 cls.tend = 25.25 cls.tseg = cls.tend - cls.tstart cls.dt = 0.00606 cls.times = np.arange(cls.tstart, cls.tend, cls.dt) + cls.dt / 2 cls.counts = \ 100 + 20 * np.cos(2 * np.pi * cls.times * cls.pulse_frequency) lc = Lightcurve(cls.times, cls.counts, gti=[[cls.tstart, cls.tend]]) events = EventList() events.simulate_times(lc) cls.event_times = events.time
def get_lc_onesource_fixpds(k,src_index,num_trials=2): k_trial =0 FP = []; period = []; cts_num=[]; peakP=[]; power_P=[] path = '/Users/baotong/Desktop/CDFS/txt_all_obs_0.5_8_ep{0}/'.format(k) epoch_file = np.loadtxt(path + 'CDFS_epoch_ep{0}.txt'.format(k)) tstart = epoch_file[:, 0];tstop = epoch_file[:, 1] ID=epoch_file[:,2];exptime = epoch_file[:, 3] evt_file = np.loadtxt(path + '{0}.txt'.format(src_index)) bkgevt_file = np.loadtxt(path + '{0}_bkg.txt'.format(src_index)) for i in range(len(ID)): index = len(np.where(evt_file[:,2] == ID[i])[0]) index_b=len(np.where(bkgevt_file[:,2] == ID[i])[0]) cts_num.append(index-index_b/12.) dt = 100 T_exp = 11000154.981141508 freq=np.arange(1/T_exp,0.5/dt,1/(5*T_exp)) freq=freq[np.where(freq > 1 / 20000.)] if os.path.exists(path+'/simulation/{0}_LS_simP_fixpds.csv'.format(src_index)): print('caution! file exists') return None with open(path + '/simulation/{0}_LS_simP_fixpds.csv'.format(src_index), 'a+') as csvfile: header = freq header = header.astype('str') writer = csv.writer(csvfile) for i in range(len(exptime)): cts_rate = cts_num[i] / (2 * exptime[i]) * dt # 实际的cts-rate应为这个的2倍 num_bins = int(exptime[i] / dt) sim = simulator.Simulator(N=num_bins, mean=cts_rate, dt=dt) w = np.arange(1 / exptime[i], 0.5 / dt, 1 / exptime[i]) spectrum = bending_po(w, [2.3e-3, 3.4, 0.40, 4.3e-4]) # spectrum = bending_po(w, [2.3e-3, 3.4, 0.40, 4.3e-4]) + generalized_lorentzian(w, [1.0518215e-3,1.0518215e-3/16,200,2]) lc = sim.simulate(spectrum) lc.counts += cts_rate lc.counts[np.where(lc.counts < 0)] = 0 lc.time+=tstart[i] if i==0: lc_all=lc else: lc_all=lc_all.join(lc) print('run') print(lc_all.time) while k_trial<num_trials: ev_all = EventList() ev_all.time = sim_evtlist(lc_all) + tstart[0] # ev_all = ev_all.join(ev) lc_new = ev_all.to_lc(dt=dt, tstart=ev_all.time[0] - 0.5 * dt, tseg=ev_all.time[-1] - ev_all.time[0]) temp = get_LS(lc_new.time, lc_new.counts, freq=freq, trial=k_trial) writer.writerows([temp[-1]]) k_trial+=1
def get_hist_withbkg(t, t_bkg, len_bin, tstart=0, tstop=0): ###将输入的time信息,按照len_bin的长度输出为lc if tstart == 0 and tstop == 0: tstart = t[0] tstop = t[-1] tseg = tstop - tstart else: tseg = tstop - tstart t_test = t t_bkg_test = t_bkg dt = len_bin t_bkg_test = np.delete(t_bkg_test, t_bkg_test < 0) ev = EventList() ev_bkg = EventList() ev.time = t_test ev_bkg.time = t_bkg_test lc_new = ev.to_lc(dt=dt, tstart=tstart - 0.5 * dt, tseg=tseg + 0.5 * dt) lc_bkg = ev_bkg.to_lc(dt=dt, tstart=tstart - 0.5 * dt, tseg=tseg + 0.5 * dt) lc_bkg_level = np.mean(lc_bkg.counts) lc_out = lc_new lc_out.counts = lc_new.counts - lc_bkg.counts # lc_out.counts = lc_new.counts # print(lc_bkg.counts) return lc_out
def test_filter_for_deadtime_evlist(): """Test dead time filter, non-paralyzable case.""" events = np.array([1, 1.05, 1.07, 1.08, 1.1, 2, 2.2, 3, 3.1, 3.2]) events = EventList(events) events.pi=np.array([1, 2, 2, 2, 2, 1, 1, 1, 2, 1]) events.energy=np.array([1, 2, 2, 2, 2, 1, 1, 1, 2, 1]) events.mjdref = 10 filt_events = filter_for_deadtime(events, 0.11) expected = np.array([1, 2, 2.2, 3, 3.2]) assert np.allclose(filt_events.time, expected), \ "Wrong: {} vs {}".format(filt_events, expected) assert np.allclose(filt_events.pi, 1) assert np.allclose(filt_events.energy, 1)
def test_init_data_eventlist(self): el = EventList.from_lc(self.lc) mtp_el = Multitaper(data=el, dt=self.lc.dt) mtp = Multitaper(data=self.lc) assert max(mtp_el.multitaper_norm_power - mtp.multitaper_norm_power) == 0
def test_energy_spec_wrong_list_not_tuple(self): events = EventList( [0.09, 0.21, 0.23, 0.32, 0.4, 0.54], energy=[0, 0, 0, 0, 1, 1], gti=[[0, 0.65]] ) # Test using a list instead of tuple # with pytest.raises(ValueError): vespec = DummyVarEnergy(events, [0.0, 10000], [0, 1, 2, "lin"], bin_time=0.1)
def test_energy_property(self): events = EventList( [0.09, 0.21, 0.23, 0.8, 1.4, 1.9], energy=[0, 0, 0, 0, 1, 1], gti=[[0, 0.65]] ) energy_spec = [0, 1, 2] vespec = DummyVarEnergy(events, [0.0, 10000], energy_spec, [0.5, 1.1], bin_time=0.1) assert np.allclose(vespec.energy, [0.5, 1.5])
def test_ref_band_none(self): events = EventList([0.09, 0.21, 0.23, 0.32, 0.4, 0.54], energy=[0, 0, 0, 0, 1, 1], gti=[[0, 0.65]]) vespec = DummyVarEnergy(events, [0., 10000], (0, 1, 2, "lin"), bin_time=0.1) assert np.all(vespec.ref_band == np.array([[0, np.inf]]))
def setup_class(cls): from ..simulator.simulator import Simulator simulator = Simulator(0.1, 1000, rms=0.4, mean=200) test_lc = simulator.simulate(1) test_ev1, test_ev2 = EventList(), EventList() test_ev1.simulate_times(test_lc) test_ev2.simulate_times(test_lc) test_ev1.energy = np.random.uniform(0.3, 12, len(test_ev1.time)) test_ev2.energy = np.random.uniform(0.3, 12, len(test_ev2.time)) cls.rms = RmsEnergySpectrum(test_ev1, [0., 100], (0.3, 12, 5, "lin"), bin_time=0.01, segment_size=100, events2=test_ev2)
def setup_class(cls): time = np.arange(0, 1e7) counts = np.random.poisson(10, time.size) cls.lc = Lightcurve(time, counts, skip_checks=True) evtimes = np.sort(np.random.uniform(0, 1e7, 10**7)) pi = np.random.randint(0, 100, evtimes.size) energy = pi * 0.04 + 1.6 cls.ev = EventList( time=evtimes, pi=pi, energy=energy, gti=[[0, 1e7]], dt=1e-5, notes="Bu", ) cls.ev_noattrs = copy.deepcopy(cls.ev) cls.ev_noattrs.energy = None cls.ev_noattrs.pi = None cls.ev_noattrs.mjdref = 0 cls.ev_noattrs.gti = None cls.ev_noattrs.dt = 0 cls.ev_noattrs.notes = None cls.lc_path = saveData(cls.lc, persist=False) cls.ev_path = saveData(cls.ev, persist=False) cls.ev_path_noattrs = saveData(cls.ev_noattrs, persist=False)
def test_cov_invalid_evlist_warns(self): ev = EventList(time=[], energy=[], gti=self.test_ev1.gti) with pytest.warns(UserWarning) as record: rms = CovarianceSpectrum(ev, [0.0, 100], (0.3, 12, 5, "lin"), bin_time=0.01, segment_size=100) assert np.all(np.isnan(rms.spectrum)) assert np.all(np.isnan(rms.spectrum_error))
def pulsar_events_mp(length, period, ctrate, pulsed_fraction, mean_obs, bkg_ctrate, detlev, nbin=128): nustar_orb = 5808 dt = period / 20 # The total length of the time series should be the number of pointings times the time per orbit. # Add one orbit for buffer. N_orb = int(round(length / mean_obs, 0)) tot_len = (N_orb + 1) * nustar_orb # The orbital period is 5808s. Every 5808s, a continuous observation with min_obs < length < max_obs begins start_t = numpy.multiply( numpy.arange(N_orb), numpy.random.normal(loc=nustar_orb, scale=60, size=N_orb)) point_t = numpy.random.uniform(low=mean_obs - 500, high=mean_obs + 500, size=N_orb) end_t = numpy.add(start_t, point_t) times = numpy.arange(dt / 2, tot_len + dt / 2, dt) cont_lc = numpy.random.poisson( (ctrate * (1 + pulsed_fraction * numpy.cos(2 * numpy.pi / period * times)) * dt)) + numpy.random.poisson(bkg_ctrate * dt) lc = Lightcurve(time=times, counts=cont_lc, gti=numpy.column_stack((start_t, end_t)), dt=dt) exposure = numpy.sum(point_t) events = EventList() events.gti = lc.gti events.simulate_times(lc) phase = numpy.arange(0, 1, 1 / nbin) zsq = z_n(phase, n=2, norm=fold_events(events.time, 1 / period, nbin=nbin)[1]) detected = zsq > detlev return (detected, exposure)
def test_construct_lightcurves(self): events = EventList( [0.09, 0.21, 0.23, 0.32, 0.4, 0.54], energy=[0, 0, 0, 0, 1, 1], gti=[[0, 0.65]] ) vespec = DummyVarEnergy(events, [0.0, 10000], (0, 1, 2, "lin"), [0.5, 1.1], bin_time=0.1) base_lc, ref_lc = vespec._construct_lightcurves([0, 0.5], tstart=0, tstop=0.65) np.testing.assert_allclose(base_lc.counts, [1, 0, 2, 1, 0, 0]) np.testing.assert_allclose(ref_lc.counts, [0, 0, 0, 0, 1, 1])
def test_energy_spec_wrong_str(self): events = EventList([0.09, 0.21, 0.23, 0.32, 0.4, 0.54], pha=[0, 0, 0, 0, 1, 1], gti=[[0, 0.65]]) # Test using a list instead of tuple with pytest.raises(ValueError): vespec = DummyVarEnergy(events, [0., 10000], (0, 1, 2, "xxx"), bin_time=0.1)
def setup_class(cls): cls.pulse_frequency = 1 / 0.101 cls.tstart = 0 cls.tend = 25.25 cls.tseg = cls.tend - cls.tstart cls.dt = 0.00606 cls.times = np.arange(cls.tstart, cls.tend, cls.dt) + cls.dt / 2 cls.counts = \ 100 + 20 * np.cos(2 * np.pi * cls.times * cls.pulse_frequency) lc = Lightcurve(cls.times, cls.counts, gti=[[cls.tstart, cls.tend]]) events = EventList() events.simulate_times(lc) cls.event_times = events.time cls.dum_noe = 'events_noe' + HEN_FILE_EXTENSION save_events(events, cls.dum_noe) events.pi = np.random.uniform(3, 79, len(events.time)) cls.dum = 'events' + HEN_FILE_EXTENSION save_events(events, cls.dum)
def setup_class(cls): cls.times = [0.1, 2, 4, 5.5] cls.energy = [3, 5, 2, 4] cls.events = EventList(time=cls.times, energy=cls.energy, pi=cls.energy, gti=[[0, 6.]])
def sim_bunch_lc_evt(CR, dt, period, epoch_file, outpath, num_trials=100): lenbin = dt # epoch_89 = '/Users/baotong/Desktop/CDFS/txt_all_obs_0.5_8_ep3/epoch_src_89.txt' w = make_freq_range(dt=lenbin, epoch_file=epoch_file) qpo_f = 1. / period (TSTART, TSTOP, OBSID, exptime) = epoch_file if type(TSTART) == type(1.2): print('Single exposure') TSTART = [TSTART] TSTOP = [TSTOP] OBSID = [OBSID] exptime = [exptime] with open( outpath + 'CR_{0}_P_{1}_REJ1034_simpleway.txt'.format( "%.0e" % CR, str(int(period))), 'a+') as f: k_trial = 0 while k_trial < num_trials: ev_all = EventList() # lc = make_lc_from_psd(psd=psd_model, cts_rate=CR / 2 * lenbin, dt=lenbin, epoch_file=epoch_file) print('trial' + ': ' + str(k_trial)) # lc_evt = Lightcurve(time=lc.time, counts=lc.counts, dt=lc.dt, gti=lc.gti) # lc_evt.counts = np.random.poisson(lc_evt.counts) T_tot = TSTOP[-1] - TSTART[0] for i in range(len(exptime)): cts_rate = 0.5 * CR * lenbin # 实际的cts-rate应为这个的2倍 num_bins = int(exptime[i] / dt) sim = simulator.Simulator(N=num_bins, mean=cts_rate, dt=lenbin) w = np.arange(1 / exptime[i], 0.5 / lenbin, 1 / exptime[i]) psd_model = build_psd(x=w, p=[2.3e-3, 3.4, 0., 4.3e-4], x_2=w, p_2=[qpo_f, qpo_f / 16, 100, 2], type='bendp+lorentz') # psd_model = build_psd(x=w, p=[2.3e-3, 3.4, 0., 4.3e-4], # type='bendp') spectrum = psd_model lc_cut = sim.simulate(spectrum) lc_cut.counts += cts_rate lc_cut.counts[np.where(lc_cut.counts < 0)] = 0 lc_cut.counts = np.random.poisson(lc_cut.counts) # print(np.sum(lc_cut.counts)) ev = EventList() ev.time = func.sim_evtlist(lc_cut) + TSTART[i] ev_all = ev_all.join(ev) lc_long = ev_all.to_lc(dt=dt, tstart=ev_all.time[0] - 0.5 * dt, tseg=ev_all.time[-1] - ev_all.time[0]) print('counts={0}'.format(np.sum(lc_long.counts))) T_exp = lc_long.time[-1] - lc_long.time[0] freq = np.arange(1 / T_exp, 0.5 / lenbin, 1 / (5 * T_exp)) freq = freq[np.where(freq > 1 / 20000.)] # print(T_tot) # print(T_exp) temp = func.get_LS(lc_long.time, lc_long.counts, freq=freq) f.writelines((str(temp[0]) + ' ' + str(temp[1]) + ' ' + str(temp[2]) + ' ' + '\n')) k_trial += 1 f.close()
def test_lag_invalid_evlist_warns(self): ev = EventList(time=[], energy=[], gti=self.lag.events1.gti) with pytest.warns(UserWarning) as record: lag = LagEnergySpectrum(ev, [0., 0.5], (0.3, 9, 4, "lin"), [9, 12], bin_time=0.1, segment_size=30, events2=self.lag.events2) assert np.allclose(lag.spectrum, 0) assert np.allclose(lag.spectrum_error, 0)
def test_rms_invalid_evlist_warns(self): ev = EventList(time=[], energy=[], gti=self.rms.events1.gti) with pytest.warns(UserWarning) as record: rms = RmsEnergySpectrum(ev, [0., 100], (0.3, 12, 5, "lin"), bin_time=0.01, segment_size=100, events2=self.rms.events2) assert np.allclose(rms.spectrum, 0) assert np.allclose(rms.spectrum_error, 0)
def test_construct_lightcurves_no_exclude(self): events = EventList( [0.09, 0.21, 0.23, 0.32, 0.4, 0.54], energy=[0, 0, 0, 0, 1, 1], gti=[[0, 0.65]] ) vespec = DummyVarEnergy(events, [0.0, 10000], (0, 1, 2, "lin"), [0, 0.5], bin_time=0.1) base_lc, ref_lc = vespec._construct_lightcurves( [0, 0.5], tstart=0, tstop=0.65, exclude=False ) np.testing.assert_equal(base_lc.counts, ref_lc.counts)
def setup_class(self): tstart = 0.0 tend = 1.0 self.dt = np.longdouble(0.0001) times1 = np.sort(np.random.uniform(tstart, tend, 1000)) times2 = np.sort(np.random.uniform(tstart, tend, 1000)) gti = np.array([[tstart, tend]]) self.events1 = EventList(times1, gti=gti) self.events2 = EventList(times2, gti=gti) self.cs = Crossspectrum(self.events1, self.events2, dt=self.dt) self.acs = AveragedCrossspectrum(self.events1, self.events2, segment_size=1, dt=self.dt) self.lc1, self.lc2 = self.events1, self.events2
def test_works_with_events(self): lc = copy.deepcopy(self.lc) lc.counts = np.floor(lc.counts) ev = EventList.from_lc(lc) dps = DynamicalPowerspectrum(lc, segment_size=10) with pytest.raises(ValueError): # Without dt, it fails _ = DynamicalPowerspectrum(ev, segment_size=10) dps_ev = DynamicalPowerspectrum(ev, segment_size=10, dt=self.lc.dt) assert np.allclose(dps.dyn_ps, dps_ev.dyn_ps)
def setup_class(cls): tstart = 0.0 tend = 10.0 cls.dt = 0.0001 cls.segment_size = tend - tstart times = np.sort(np.random.uniform(tstart, tend, 1000)) gti = np.array([[tstart, tend]]) cls.events = EventList(times, gti=gti) cls.lc = cls.events
def setup_class(cls): from ..simulator.simulator import Simulator dt = 0.1 simulator = Simulator(dt, 1000, rms=0.4, mean=200) test_lc1 = simulator.simulate(2) test_lc2 = Lightcurve(test_lc1.time, np.array(np.roll(test_lc1.counts, 2)), err_dist=test_lc1.err_dist, dt=dt) test_ev1, test_ev2 = EventList(), EventList() test_ev1.simulate_times(test_lc1) test_ev2.simulate_times(test_lc2) test_ev1.energy = np.random.uniform(0.3, 9, len(test_ev1.time)) test_ev2.energy = np.random.uniform(9, 12, len(test_ev2.time)) cls.lag = LagEnergySpectrum(test_ev1, [0., 0.5], (0.3, 9, 4, "lin"), [9, 12], bin_time=0.1, segment_size=30, events2=test_ev2)
def test_get_eventlist_dataset_from_stingray_Eventlist(capsys): from stingray.events import EventList from astropy.io.fits import Header ev = EventList(time=[0, 1], pi=[2, 2], energy=[3., 4.], gti=np.array([[-0.5, 1.5]])) ds = get_eventlist_dataset_from_stingray_Eventlist(ev) out, err = capsys.readouterr() print("Out:", out) print("Err:", err) if err: assert "Event list has no header" in err header = Header() header["Bu"] = "Bu" ev.header = header.tostring() ds = get_eventlist_dataset_from_stingray_Eventlist(ev) assert np.allclose(ds.tables["EVENTS"].columns["TIME"].values, ev.time) if "ENERGY" in ds.tables["EVENTS"].columns: assert np.allclose(ds.tables["EVENTS"].columns["ENERGY"].values, ev.energy) assert np.allclose(ds.tables["EVENTS"].columns["PI"].values, ev.pi)