def test_rebin_with_invalid_type_attribute(self):
     new_df = 2
     aps = AveragedPowerspectrum(lc=self.lc, segment_size=1,
                                 norm='leahy')
     aps.type = 'invalid_type'
     with pytest.raises(AttributeError):
         assert aps.rebin(df=new_df)
    def test_rebin_factor(self, f):
        """
        TODO: Not sure how to write tests for the rebin method!
        """

        aps = AveragedPowerspectrum(lc=self.lc, segment_size=1,
                                    norm="Leahy")
        bin_aps = aps.rebin(f=f)
        assert np.isclose(bin_aps.freq[1]-bin_aps.freq[0], bin_aps.df,
                          atol=1e-4, rtol=1e-4)
        assert np.isclose(bin_aps.freq[0],
                          (aps.freq[0]-aps.df*0.5+bin_aps.df*0.5),
                          atol=1e-4, rtol=1e-4)
    def test_fractional_rms_in_frac_norm(self):
        time = np.arange(0, 400, 1) + 0.5

        poisson_counts = np.random.poisson(100.0,
                                           size=time.shape[0])

        lc = Lightcurve(time, counts=poisson_counts, dt=1,
                            gti=[[0, 400]])
        ps = AveragedPowerspectrum(lc=lc, norm="frac", segment_size=100)
        rms_ps, rms_err = ps.compute_rms(min_freq=ps.freq[1],
                                         max_freq=ps.freq[-1],
                                         white_noise_offset=0)
        rms_lc = np.std(lc.counts) / np.mean(lc.counts)
        assert np.isclose(rms_ps, rms_lc, atol=0.01)
 def test_init_with_nonsense_segment(self):
     segment_size = "foo"
     with pytest.raises(TypeError):
         assert AveragedPowerspectrum(self.lc, segment_size)
 def test_init_without_segment(self):
     with pytest.raises(ValueError):
         assert AveragedPowerspectrum(self.lc)
示例#6
0
 def test_rebin_with_valid_type_attribute(self):
     new_df = 2
     aps = AveragedPowerspectrum(lc=self.lc1, segment_size=1,
                                 norm='leahy')
     assert aps.rebin(df=new_df)
 def test_rebin_with_valid_type_attribute(self):
     new_df = 2
     aps = AveragedPowerspectrum(lc=self.lc1, segment_size=1, norm="leahy")
     assert aps.rebin(df=new_df)
示例#8
0
 def test_init_with_nan_segment(self):
     segment_size = np.nan
     assert AveragedPowerspectrum(self.lc, segment_size)
示例#9
0
 def test_init_with_nonsense_segment(self):
     segment_size = "foo"
     assert AveragedPowerspectrum(self.lc, segment_size)
示例#10
0
 def test_from_lc_iter_works(self):
     pds_ev = AveragedPowerspectrum.from_lc_iterable(
         self.events.to_lc_iter(self.dt, self.segment_size),
         segment_size=self.segment_size, dt=self.dt, norm="leahy",
         silent=True, gti=self.events.gti)
     assert np.allclose(self.leahy_pds.power, pds_ev.power)
 def test_rebin_with_invalid_type_attribute(self):
     new_df = 2
     aps = AveragedPowerspectrum(lc=self.lc, segment_size=1, norm='leahy')
     aps.type = 'invalid_type'
     with pytest.raises(AttributeError):
         assert aps.rebin(df=new_df)
示例#12
0
 def test_from_events_works_aps(self):
     pds_ev = AveragedPowerspectrum.from_events(
         self.events, segment_size=self.segment_size, dt=self.dt, norm="leahy", silent=True)
     assert np.allclose(self.leahy_pds.power, pds_ev.power)
示例#13
0
def createAvgPspec(lc, seg):
    AveragedPowerspectrum(lc, seg)
示例#14
0
 def test_init_with_none_segment(self, legacy):
     segment_size = None
     with pytest.raises(ValueError):
         assert AveragedPowerspectrum(self.lc, segment_size, legacy=legacy)
示例#15
0
 def test_initialize_empty(self, skip_checks):
     cs = AveragedPowerspectrum(skip_checks=skip_checks)
     assert cs.freq is None
示例#16
0
 def setup_class(cls):
     cls.cs = AveragedPowerspectrum()
     cls.cs.freq = np.arange(10)
     cls.cs.power = np.random.uniform(0, 10, 10)
     cls.cs.m = 2
     cls.cs.nphots1 = 34
 def test_init_with_nan_segment(self):
     segment_size = np.nan
     with pytest.raises(ValueError):
         assert AveragedPowerspectrum(self.lc, segment_size)
示例#18
0
 def test_segments_with_leftover(self):
     segment_size = self.lc.tseg/2. - 1.
     ps = AveragedPowerspectrum(self.lc, segment_size)
     assert np.isclose(ps.segment_size, segment_size)
     assert ps.m == 2
 def test_rebin_log(self, df):
     # For now, just verify that it doesn't crash
     aps = AveragedPowerspectrum(lc=self.lc, segment_size=1, norm="Leahy")
     bin_aps = aps.rebin_log(df)
import numpy as np
from stingray import Lightcurve, Powerspectrum, AveragedPowerspectrum
import matplotlib.pyplot as plt
from astropy.io import ascii
p, q= np.loadtxt("lxp2level2_t1_50_3-10kev.txt", unpack=True, usecols=[0,1])
lc = Lightcurve(p,q)
avg_ps_mode = AveragedPowerspectrum(lc, 198, norm='leahy')
log_rb_ps = avg_ps_mode.rebin_log(f=0.02)
lin_rb_ps = avg_ps_mode.rebin(10, method='mean')
#plt.plot(lc.time, lc.counts, lw=1, color='blue')
plt.plot(avg_ps_mode.freq, avg_ps_mode.power, lw=1, color='black')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Power (Leahy)')
plt.show()

示例#21
0
 def check_segment_size(self, nseg):
     segment_size = self.lc.tseg/nseg
     ps = AveragedPowerspectrum(self.lc, segment_size)
     assert ps.m == nseg
示例#22
0
 def test_rebin_log(self, df):
     # For now, just verify that it doesn't crash
     aps = AveragedPowerspectrum(lc=self.lc, segment_size=1,
                                 norm="Leahy")
     bin_aps = aps.rebin_log(df)
示例#23
0
 def test_init_without_segment(self):
     assert AveragedPowerspectrum(self.lc)
示例#24
0
 def test_init(self):
     AveragedPowerspectrum(self.lc, self.segment_size, dt=self.dt)
示例#25
0
 def test_init_with_none_segment(self):
     segment_size = None
     assert AveragedPowerspectrum(self.lc, segment_size)
示例#26
0
 def test_init_with_inf_segment(self):
     segment_size = np.inf
     with pytest.raises(ValueError):
         assert AveragedPowerspectrum(self.lc, segment_size, dt=self.dt)
示例#27
0
 def test_one_segment(self):
     segment_size = self.lc.tseg
     ps = AveragedPowerspectrum(self.lc, segment_size)
     assert np.isclose(ps.segment_size, segment_size)
示例#28
0
p, q= np.loadtxt("lxp2level2_t1_50_3-10kev.txt", unpack=True, usecols=[0,1])
font_prop = font_manager.FontProperties(size=16)

f = fits.open('lxp2level2.lcurv')		#Import fits
dt = f[1].header['TIMEDEL']
toa = f[1].data['TIME']
cou = f[1].data['RATE']
expo = f[1].header['EXPOSURE']
mean = np.mean(cou)

#lc = Lightcurve(toa, cou)
lc = Lightcurve(p,q)
#plt.plot(lc.time, lc.counts, lw=0.5, color='blue')
#plt.show()

avg_ps_mode = AveragedPowerspectrum(lc, 4000, norm='leahy')		#Change the segment size based on the data bin
print("Number of segments: %d" % avg_ps_mode.m)
fig, ax = plt.subplots(1,1,figsize=(17,10))
#log_rb_ps = avg_ps_mode.rebin_log(f=0.02)
#lin_rb_ps = avg_ps_mode.rebin(0.00025, method='mean')
ax.plot(avg_ps_mode.freq, avg_ps_mode.power, lw=1, color='black')
#ax.plot(lc.time, lc.counts, lw=1, color='black')
ax.set_xlabel("Frequency (Hz)", fontproperties=font_prop)
ax.set_ylabel("Power (Leahy)", fontproperties=font_prop)
#ax.set_yscale('log')
ax.tick_params(axis='x', labelsize=9)
ax.tick_params(axis='y', labelsize=9)
ax.tick_params(which='major', width=1.5, length=7)
ax.tick_params(which='minor', width=1.5, length=4)
plt.show()