Exemplo n.º 1
0
 def test_lightcurve_from_toa(self):
     lc = Lightcurve.make_lightcurve(self.times, self.dt, use_hist=True,
                                     tstart=0.5)
     lc2 = Lightcurve.make_lightcurve(self.times, self.dt, use_hist=False,
                                     tstart=0.5)
     assert np.allclose(lc.time, lc2.time)
     assert np.all(lc.counts == lc2.counts)
Exemplo n.º 2
0
 def test_lightcurve_from_toa(self):
     lc = Lightcurve.make_lightcurve(self.times, self.dt, use_hist=True,
                                     tstart=0.5)
     lc2 = Lightcurve.make_lightcurve(self.times, self.dt, use_hist=False,
                                     tstart=0.5)
     assert np.allclose(lc.time, lc2.time)
     assert np.all(lc.counts == lc2.counts)
Exemplo n.º 3
0
def test_fad_power_spectrum_equal_ev_lc(ctrate):
    dt = 0.1
    deadtime = 2.5e-3
    length = 25600
    gti = [[0, length]]
    segment_size = 256.
    ncounts = int(ctrate * length)
    ev1 = filter_for_deadtime(generate_events(length, ncounts), deadtime)
    ev2 = filter_for_deadtime(generate_events(length, ncounts), deadtime)

    lc1 = Lightcurve.make_lightcurve(ev1,
                                     dt=dt,
                                     gti=gti,
                                     tstart=0,
                                     tseg=length)
    lc2 = Lightcurve.make_lightcurve(ev2,
                                     dt=dt,
                                     gti=gti,
                                     tstart=0,
                                     tseg=length)

    ev1 = EventList(ev1, gti=gti)
    ev2 = EventList(ev2, gti=gti)

    results_out_ev = \
        FAD(ev1, ev2, segment_size, dt=dt, plot=True,
            strict=True, verbose=True,
            tolerance=0.05, norm="leahy")
    results_out_lc = \
        calculate_FAD_correction(lc1, lc2, segment_size, plot=True,
                                 strict=True, verbose=True,
                                 tolerance=0.05, norm="leahy")

    for attr in ['pds1', 'pds2', 'cs', 'ptot']:
        assert np.allclose(results_out_ev[attr], results_out_lc[attr])
Exemplo n.º 4
0
    def _make_reference_bands_from_event_data(self, data, bounds=None):
        """
        Helper method constructing reference bands for each band of interest, and constructing
        light curves from these reference bands. This operates only if the data given to
        :class:`Covariancespectrum` is event list data (i.e. photon arrival times and energies).

        Parameters
        ----------
        data : numpy.ndarray
            Array of shape ``(N, 2)``, where N is the number of photons. First column contains the
            times of arrivals, second column the corresponding photon energies.

        bounds : iterable
            The energy bounds to use for the reference band. Must be of type ``(elow, ehigh)``.

        Returns
        -------

        lc_all: list of :class:`stingray.Lightcurve` objects.
            The list of `:class:`stingray.Lightcurve` objects containing all reference
            bands, between the values given in ``bounds``.

        """

        if not bounds:
            bounds = [np.min(data[:, 1]), np.max(data[:, 1])]

        if bounds[1] <= np.min(self.band_interest[:, 0]) or \
           bounds[0] >= np.max(self.band_interest[:, 1]):
            elow = bounds[0]
            ehigh = bounds[1]

            toa = data[np.logical_and(data[:, 1] >= elow, data[:, 1] <= ehigh)]

            lc_all = Lightcurve.make_lightcurve(toa,
                                                self.dt,
                                                tstart=self.tstart,
                                                tseg=self.tseg)

        else:

            lc_all = []
            for i, b in enumerate(self.band_interest):
                elow = b[0]
                ehigh = b[1]

                emask1 = data[np.logical_and(data[:, 1] <= elow,
                                             data[:, 1] >= bounds[0])]

                emask2 = data[np.logical_and(data[:, 1] <= bounds[1],
                                             data[:, 1] >= ehigh)]

                toa = np.vstack([emask1, emask2])
                lc = Lightcurve.make_lightcurve(toa,
                                                self.dt,
                                                tstart=self.tstart,
                                                tseg=self.tseg)
                lc_all.append(lc)

        return lc_all
Exemplo n.º 5
0
 def test_lightcurve_from_toa_random_nums(self):
     times = np.random.uniform(0, 10, 1000)
     lc = Lightcurve.make_lightcurve(times, self.dt, use_hist=True,
                                     tstart=0.5)
     lc2 = Lightcurve.make_lightcurve(times, self.dt, use_hist=False,
                                     tstart=0.5)
     assert np.allclose(lc.time, lc2.time)
     assert np.all(lc.counts == lc2.counts)
Exemplo n.º 6
0
 def test_lightcurve_from_toa_random_nums(self):
     times = np.random.uniform(0, 10, 1000)
     lc = Lightcurve.make_lightcurve(times, self.dt, use_hist=True,
                                     tstart=0.5)
     lc2 = Lightcurve.make_lightcurve(times, self.dt, use_hist=False,
                                     tstart=0.5)
     assert np.allclose(lc.time, lc2.time)
     assert np.all(lc.counts == lc2.counts)
Exemplo n.º 7
0
    def test_lightcurve_from_toa_Time(self):
        mjdref = 56789
        mjds = Time(self.times / 86400 + mjdref, format='mjd')

        lc = Lightcurve.make_lightcurve(mjds,
                                        self.dt,
                                        mjdref=mjdref,
                                        use_hist=True,
                                        tstart=0.5)
        lc2 = Lightcurve.make_lightcurve(self.times,
                                         self.dt,
                                         use_hist=False,
                                         tstart=0.5,
                                         mjdref=mjdref)
        assert np.allclose(lc.time, lc2.time)
        assert np.allclose(lc.counts, lc2.counts)
Exemplo n.º 8
0
    def test_tseg(self):
        tstart = 0.0
        tseg = 5.0
        lc = Lightcurve.make_lightcurve(self.times, self.dt, tseg=tseg, tstart=tstart)

        assert lc.tseg == tseg
        assert lc.time[-1] - lc.time[0] == tseg - self.dt
Exemplo n.º 9
0
def generate_deadtime_lc(ev, dt, tstart=0, tseg=None, deadtime=2.5e-3):
    ev = filter_for_deadtime(ev, deadtime)
    return Lightcurve.make_lightcurve(ev,
                                      dt=dt,
                                      tstart=tstart,
                                      tseg=tseg,
                                      gti=np.array([[tstart, tseg]]))
Exemplo n.º 10
0
    def test_tseg(self):
        tstart = 0.0
        tseg = 5.0
        lc = Lightcurve.make_lightcurve(self.times, self.dt,
                                        tseg=tseg, tstart=tstart)

        assert lc.tseg == tseg
        assert lc.time[-1] - lc.time[0] == tseg - self.dt
Exemplo n.º 11
0
    def setup_class(cls):
        photon_arrivals = np.sort(np.random.uniform(0,1000, size=10000))
        cls.lc = Lightcurve.make_lightcurve(photon_arrivals, dt=1.0)
        cls.ps = Powerspectrum(cls.lc, norm="frac")
        pl = models.PowerLaw1D()
        pl.x_0.fixed = True

        cls.lpost = PSDPosterior(cls.ps.freq, cls.ps.power, pl, m=cls.ps.m)
Exemplo n.º 12
0
    def setup_class(cls):
        photon_arrivals = np.sort(np.random.uniform(0, 1000, size=10000))
        cls.lc = Lightcurve.make_lightcurve(photon_arrivals, dt=1.0)
        cls.ps = Powerspectrum(cls.lc, norm="frac")
        pl = models.PowerLaw1D()
        pl.x_0.fixed = True

        cls.lpost = PSDPosterior(cls.ps.freq, cls.ps.power, pl, m=cls.ps.m)
Exemplo n.º 13
0
 def test_nondivisble_tseg(self):
     """
     If the light curve length input is not divisible by the time
     resolution, the last (fractional) time bin will be dropped.
     """
     tstart = 0.0
     tseg = 5.5
     lc = Lightcurve.make_lightcurve(self.times, self.dt, tseg=tseg, tstart=tstart)
     assert lc.tseg == int(tseg / self.dt)
Exemplo n.º 14
0
 def test_nondivisble_tseg(self):
     """
     If the light curve length input is not divisible by the time
     resolution, the last (fractional) time bin will be dropped.
     """
     tstart = 0.0
     tseg = 5.5
     lc = Lightcurve.make_lightcurve(self.times, self.dt,
                                     tseg=tseg, tstart=tstart)
     assert lc.tseg == int(tseg/self.dt)
Exemplo n.º 15
0
    def test_bin_correctly(self):
        ncounts = np.array([2, 1, 0, 3])
        tstart = 0.0
        tseg = 4.0

        toa = np.hstack([np.random.uniform(i, i + 1, size=n) for i, n in enumerate(ncounts)])

        dt = 1.0
        lc = Lightcurve.make_lightcurve(toa, dt, tseg=tseg, tstart=tstart)

        assert np.allclose(lc.counts, ncounts)
Exemplo n.º 16
0
    def test_bin_correctly(self):
        ncounts = np.array([2, 1, 0, 3])
        tstart = 0.0
        tseg = 4.0

        toa = np.hstack([np.random.uniform(i, i+1, size=n)
                         for i, n in enumerate(ncounts)])

        dt = 1.0
        lc = Lightcurve.make_lightcurve(toa, dt, tseg=tseg, tstart=tstart)

        assert np.allclose(lc.counts, ncounts)
Exemplo n.º 17
0
    def _make_reference_bands_from_event_data(self, data, bounds=None):

        if not bounds:
            bounds = [np.min(data[:, 1]), np.max(data[:, 1])]

        print("Band interest: " + str(self.band_interest))
        print("Bounds: " + str(bounds))
        if bounds[1] <= np.min(self.band_interest[:, 0]) or \
           bounds[0] >= np.max(self.band_interest[:, 1]):
            elow = bounds[0]
            ehigh = bounds[1]

            toa = data[np.logical_and(data[:, 1] >= elow, data[:, 1] <= ehigh)]

            lc_all = Lightcurve.make_lightcurve(toa,
                                                self.dt,
                                                tstart=self.tstart,
                                                tseg=self.tseg)

        else:

            lc_all = []
            for i, b in enumerate(self.band_interest):
                elow = b[0]
                ehigh = b[1]

                emask1 = data[np.logical_and(data[:, 1] <= elow,
                                             data[:, 1] >= bounds[0])]

                emask2 = data[np.logical_and(data[:, 1] <= bounds[1],
                                             data[:, 1] >= ehigh)]

                toa = np.vstack([emask1, emask2])
                lc = Lightcurve.make_lightcurve(toa,
                                                self.dt,
                                                tstart=self.tstart,
                                                tseg=self.tseg)
                lc_all.append(lc)

        return lc_all
Exemplo n.º 18
0
    def _make_reference_bands_from_event_data(self, data, bounds=None):

        if not bounds:
            bounds = [np.min(data[:, 1]), np.max(data[:, 1])]

        if bounds[1] <= np.min(self.band_interest[:, 0]) or \
           bounds[0] >= np.max(self.band_interest[:, 1]):
            elow = bounds[0]
            ehigh = bounds[1]

            toa = data[np.logical_and(
                data[:, 1] >= elow,
                data[:, 1] <= ehigh)]

            lc_all = Lightcurve.make_lightcurve(toa, self.dt,
                                                tstart=self.tstart,
                                                tseg=self.tseg)

        else:

            lc_all = []
            for i, b in enumerate(self.band_interest):
                elow = b[0]
                ehigh = b[1]

                emask1 = data[np.logical_and(
                    data[:, 1] <= elow,
                    data[:, 1] >= bounds[0])]

                emask2 = data[np.logical_and(
                    data[:, 1] <= bounds[1],
                    data[:, 1] >= ehigh)]

                toa = np.vstack([emask1, emask2])
                lc = Lightcurve.make_lightcurve(toa, self.dt,
                                                tstart=self.tstart,
                                                tseg=self.tseg)
                lc_all.append(lc)

        return lc_all
Exemplo n.º 19
0
    def _create_lc_and_lc_ref(self, energy, energy_events):
        lc = Lightcurve.make_lightcurve(
                energy_events[energy], self.dt, tstart=self.min_time,
                tseg=self.max_time - self.min_time)

        # Calculating timestamps for lc_ref
        toa_ref = []
        for key, value in energy_events.items():
            if key >= self.ref_band_interest[0] and \
                    key <= self.ref_band_interest[1]:
                if key != energy:
                    toa_ref.extend(value)

        toa_ref = np.array(sorted(toa_ref))

        lc_ref = Lightcurve.make_lightcurve(
                toa_ref, self.dt, tstart=self.min_time,
                tseg=self.max_time - self.min_time)

        assert len(lc.time) == len(lc_ref.time)

        return lc, lc_ref
Exemplo n.º 20
0
    def _create_lc_and_lc_ref(self, energy, energy_events):
        lc = Lightcurve.make_lightcurve(energy_events[energy],
                                        self.dt,
                                        tstart=self.min_time,
                                        tseg=self.max_time - self.min_time)

        # Calculating timestamps for lc_ref
        toa_ref = []
        for key, value in energy_events.items():
            if key >= self.ref_band_interest[0] and \
                    key <= self.ref_band_interest[1]:
                if key != energy:
                    toa_ref.extend(value)

        toa_ref = np.array(sorted(toa_ref))

        lc_ref = Lightcurve.make_lightcurve(toa_ref,
                                            self.dt,
                                            tstart=self.min_time,
                                            tseg=self.max_time - self.min_time)

        assert len(lc.time) == len(lc_ref.time)

        return lc, lc_ref
Exemplo n.º 21
0
    def _make_lightcurves(self, data):

        self.tstart = np.min(data[:, 0])
        self.tend = np.max(data[:, 0])

        self.tseg = self.tend - self.tstart

        lc_all = []

        for i, b in enumerate(self.band_interest):
            elow = b[0]
            ehigh = b[1]

            toa = data[np.logical_and(
                data[:, 1] >= elow,
                data[:, 1] <= ehigh)]

            lc = Lightcurve.make_lightcurve(toa, self.dt, tstart=self.tstart,
                                            tseg=self.tseg)
            lc_all.append(lc)

        return lc_all
Exemplo n.º 22
0
    def _make_lightcurves(self, data):

        self.tstart = np.min(data[:, 0])
        self.tend = np.max(data[:, 0])

        self.tseg = self.tend - self.tstart

        lc_all = []

        for i, b in enumerate(self.band_interest):
            elow = b[0]
            ehigh = b[1]

            toa = data[np.logical_and(data[:, 1] >= elow, data[:, 1] <= ehigh)]

            lc = Lightcurve.make_lightcurve(toa,
                                            self.dt,
                                            tstart=self.tstart,
                                            tseg=self.tseg)
            lc_all.append(lc)

        return lc_all
Exemplo n.º 23
0
    def _make_lightcurves(self, data):
        """
        Create light curves for all bands of interest from ``data``. Takes the information the
        ``band_interest`` attribute and event data in ``data``, and produces a list of
        :class:`stingray.Lightcurve` objects.

        Parameters
        ----------
        data : numpy.ndarray
            Array of shape ``(N, 2)``, where ``N`` is the number of photons. First column contains the
            times of arrivals, second column the corresponding photon energies.

        Returns
        -------
        lc_all : iterable of :class:`stingray.Lightcurve` objects
            A list of :class:`stingray.Lightcurve` objects of all bands of interest.
        """

        self.tstart = np.min(data[:, 0])
        self.tend = np.max(data[:, 0])

        self.tseg = self.tend - self.tstart

        lc_all = []

        for i, b in enumerate(self.band_interest):
            elow = b[0]
            ehigh = b[1]

            toa = data[np.logical_and(data[:, 1] >= elow, data[:, 1] <= ehigh)]

            lc = Lightcurve.make_lightcurve(toa,
                                            self.dt,
                                            tstart=self.tstart,
                                            tseg=self.tseg)
            lc_all.append(lc)

        return lc_all
Exemplo n.º 24
0
    def _make_lightcurves(self, data):
        """
        Create light curves for all bands of interest from ``data``. Takes the information the
        ``band_interest`` attribute and event data in ``data``, and produces a list of
        :class:`stingray.Lightcurve` objects.

        Parameters
        ----------
        data : numpy.ndarray
            Array of shape ``(N, 2)``, where ``N`` is the number of photons. First column contains the
            times of arrivals, second column the corresponding photon energies.

        Returns
        -------
        lc_all : iterable of :class:`stingray.Lightcurve` objects
            A list of :class:`stingray.Lightcurve` objects of all bands of interest.
        """

        self.tstart = np.min(data[:, 0])
        self.tend = np.max(data[:, 0])

        self.tseg = self.tend - self.tstart

        lc_all = []

        for i, b in enumerate(self.band_interest):
            elow = b[0]
            ehigh = b[1]

            toa = data[np.logical_and(
                data[:, 1] >= elow,
                data[:, 1] <= ehigh)]

            lc = Lightcurve.make_lightcurve(toa, self.dt, tstart=self.tstart,
                                            tseg=self.tseg)
            lc_all.append(lc)

        return lc_all
Exemplo n.º 25
0
def makeLCFunc(times):
    Lightcurve.make_lightcurve(times, dt=1.0)
Exemplo n.º 26
0
 def test_correct_timeresolution(self):
     lc = Lightcurve.make_lightcurve(self.times, self.dt)
     assert np.isclose(lc.dt, self.dt)
Exemplo n.º 27
0
 def test_tstart(self):
     tstart = 0.0
     lc = Lightcurve.make_lightcurve(self.times, self.dt, tstart=0.0)
     assert lc.tstart == tstart
     assert lc.time[0] == tstart + 0.5 * self.dt
Exemplo n.º 28
0
 def test_lightcurve_from_toa(self):
     lc = Lightcurve.make_lightcurve(self.times, self.dt)
Exemplo n.º 29
0
 def test_lightcurve_from_toa(self):
     lc = Lightcurve.make_lightcurve(self.times, self.dt)
Exemplo n.º 30
0
    def _make_reference_bands_from_event_data(self, data, bounds=None):
        """
        Helper method constructing reference bands for each band of interest, and constructing
        light curves from these reference bands. This operates only if the data given to
        :class:`Covariancespectrum` is event list data (i.e. photon arrival times and energies).

        Parameters
        ----------
        data : numpy.ndarray
            Array of shape ``(N, 2)``, where N is the number of photons. First column contains the
            times of arrivals, second column the corresponding photon energies.

        bounds : iterable
            The energy bounds to use for the reference band. Must be of type ``(elow, ehigh)``.

        Returns
        -------

        lc_all: list of :class:`stingray.Lightcurve` objects.
            The list of `:class:`stingray.Lightcurve` objects containing all reference
            bands, between the values given in ``bounds``.

        """

        if not bounds:
            bounds = [np.min(data[:, 1]), np.max(data[:, 1])]

        if bounds[1] <= np.min(self.band_interest[:, 0]) or \
           bounds[0] >= np.max(self.band_interest[:, 1]):
            elow = bounds[0]
            ehigh = bounds[1]

            toa = data[np.logical_and(
                data[:, 1] >= elow,
                data[:, 1] <= ehigh)]

            lc_all = Lightcurve.make_lightcurve(toa, self.dt,
                                                tstart=self.tstart,
                                                tseg=self.tseg)

        else:

            lc_all = []
            for i, b in enumerate(self.band_interest):
                elow = b[0]
                ehigh = b[1]

                emask1 = data[np.logical_and(
                    data[:, 1] <= elow,
                    data[:, 1] >= bounds[0])]

                emask2 = data[np.logical_and(
                    data[:, 1] <= bounds[1],
                    data[:, 1] >= ehigh)]

                toa = np.vstack([emask1, emask2])
                lc = Lightcurve.make_lightcurve(toa, self.dt,
                                                tstart=self.tstart,
                                                tseg=self.tseg)
                lc_all.append(lc)

        return lc_all
Exemplo n.º 31
0
 def test_tstart(self):
     tstart = 0.0
     lc = Lightcurve.make_lightcurve(self.times, self.dt, tstart=0.0)
     assert lc.tstart == tstart
     assert lc.time[0] == tstart + 0.5*self.dt
Exemplo n.º 32
0
 def test_correct_timeresolution(self):
     lc = Lightcurve.make_lightcurve(self.times, self.dt)
     assert np.isclose(lc.dt, self.dt)