Exemple #1
0
 def test_LCurve_init(self):
     """Test initializaiton"""
     t = np.arange(6)
     lc = az.LCurve(t, t * 0.5, t * 0.01)
     assert (lc.nt == len(t))
     assert (lc.dt == 1.)
     assert (lc.iseven)
     lc = az.LCurve(t[[0, 2, 3, 4, 5]], t[1:], t[1:] * 0.01)
     assert (not lc.iseven)
Exemple #2
0
    def test_rebin_lc__w_gaps(self):
        # t: 0  1  2  3  4  5  6  7
        # x: 0  1  2  3  4  5  6  7
        # xe:1  2  3  4  5  6  7  8
        #  : *  -  *  -  -  -  -  *
        t = np.arange(8, dtype=np.double)
        x = np.arange(8, dtype=np.double)
        xe = np.arange(1, 9) * 1.
        ind = np.array([0, 2, 7])
        lc = az.LCurve(t[ind], x[ind], xe[ind], 1.0)

        lc1 = lc.rebin(2, min_exp=0.5, error='poiss')
        np.testing.assert_array_almost_equal(lc1.time,
                                             np.array([0.5, 2.5, 6.5]))
        np.testing.assert_array_almost_equal(lc1.rate, np.array([0., 2., 7]))
        np.testing.assert_array_almost_equal(
            lc1.rerr, (np.array([((2.**0.5) + (7**0.5)) / 2, (2.**0.5),
                                 (7**0.5)])))

        # when original lc is even #
        lc = lc.make_even()
        lc1 = lc.rebin(2, min_exp=0.0, error='poiss')
        np.testing.assert_array_almost_equal(lc1.time,
                                             np.array([0.5, 2.5, 4.5, 6.5]))
        np.testing.assert_array_almost_equal(lc1.rate,
                                             np.array([0., 2., np.nan, 7]))
Exemple #3
0
    def test_rebin_lc(self):
        t = np.arange(8, dtype=np.double)
        x = np.arange(8, dtype=np.double)
        xe = np.arange(1, 9) * 1.
        lc = az.LCurve(t, x, xe)

        lc1 = lc.rebin(2, error='poiss')
        np.testing.assert_array_almost_equal(lc1.time, np.arange(0.5, 8, 2))
        np.testing.assert_array_almost_equal(lc1.rate, np.arange(0.5, 8, 2))
        np.testing.assert_array_almost_equal(
            lc1.rerr,
            np.sqrt(np.arange(0.5, 8, 2) * 2) / 2.)
def read_pn_lc(obs, dt, enL, lcdir, data_dir, interp=False, suff='', **kwargs):
    """Read PN light curves
    
    obs: a list of observation folders
    dt: time bin
    enL: a string of space-separated bin boundaries
    lcdir: directory name indicating the bin type. e.g 8l for 8 bins in log space 
    data_dir: folder containing the obsids
    interp: if true, interpolate small gaps
    suff: extra suffix to lc name if needed. e.g. __s; default:''
    kwargs for read_pn_lcurve
    """
    do_raw = False
    #if do_raw: suff = ''

    enL = np.array(enL.split(), np.double)
    en, ene = (enL[1:] + enL[:-1]) / 2, (enL[1:] - enL[:-1]) / 2
    Lc = [[
        az.LCurve.read_pn_lcurve(
            '{}/{}/pn/lc/{}/lc_{:03g}__{}{}.fits'.format(
                data_dir, o, lcdir, dt, ie + 1, suff), **kwargs) for o in obs
    ] for ie in range(len(en))]

    if do_raw:
        rLc = [[
            az.LCurve.read_pn_lcurve(
                '{}/{}/pn/lc/{}/lc_{:03g}__{}{}.fits'.format(
                    data_dir, o, lcdir, dt, ie + 1, '__s'), **kwargs)
            for o in obs
        ] for ie in range(len(en))]
        LC = []
        for ie in range(len(Lc)):
            LC.append([])
            for io in range(len(Lc[0])):
                lc, rlc = Lc[ie][io], rLc[ie][io]
                tt = np.intersect1d(lc.time, rlc.time)
                ii = np.in1d(lc.time, tt)
                rii = np.in1d(rlc.time, tt)
                lc_new = az.LCurve(tt, rlc.rate[rii], rlc.rerr[rii], rlc.dt,
                                   lc.fexp[ii])
                LC[-1].append(lc_new)
        Lc = LC

    Lc = [[ll.make_even() for ll in l] for l in Lc]
    if interp:
        for l in Lc:
            for ll in l:
                ll.interp_small_gaps(np.int(1e3 / dt), noise='norm', seed=345)
    return Lc, en, ene
Exemple #5
0
    def test_interp_small_gaps_2(self):
        # t: 0  1  2  3  4  5  6  7
        # x: 0  1  2  3  4  5  6  7
        # xe:1  2  3  4  5  6  7  8
        #  : *  -  *  -  -  -  -  *
        t = np.arange(8, dtype=np.double)
        x = np.arange(8, dtype=np.double)
        xe = np.arange(1, 9) * 1.
        ind = np.array([0, 2, 7])
        lc = az.LCurve(t[ind], x[ind], xe[ind], 1.0)
        lc = lc.make_even()

        # no noise, all gaps #
        lc.interp_small_gaps(maxgap=20, noise=None)
        np.testing.assert_array_almost_equal(lc.rate, [0, 1, 2, 3, 4, 5, 6, 7])
        np.testing.assert_array_almost_equal(lc.rerr, [1, 4, 3, 4, 4, 4, 4, 8])
Exemple #6
0
    def test_make_even(self):
        t = np.arange(8) * 1.
        x = np.arange(8) * 1.
        xe = np.arange(1, 9) * 1.
        ind = np.arange(0, 8, 2)
        ind[-1] = len(t) - 1
        lc = az.LCurve(t[ind], x[ind], xe[ind], 1.0)
        assert (not lc.iseven)
        lc1 = lc.make_even()
        assert (lc1.iseven)
        np.testing.assert_array_equal(t, lc1.time)
        np.testing.assert_array_almost_equal(x[ind],
                                             lc1.rate[~np.isnan(lc1.rate)])

        # time cannot be cast to even, fail #
        lc.time[1] += 0.5
        with self.assertRaises(ValueError):
            lc.make_even()
Exemple #7
0
    def test_interp_small_gaps_5(self):
        # t: 0  1  2  3  4  5  6  7
        # x: 0  1  2  3  4  5  6  7
        # xe:1  2  3  4  5  6  7  8
        #  : *  -  *  -  -  -  -  *
        t = np.arange(8, dtype=np.double)
        x = np.arange(8, dtype=np.double)
        xe = np.arange(1, 9) * 1.
        ind = np.array([0, 2, 7])
        lc = az.LCurve(t[ind], x[ind], xe[ind], 1.0)
        lc = lc.make_even()

        # norm #
        lc.interp_small_gaps(maxgap=1, noise='norm', seed=123)
        np.random.seed(123)
        pp = np.random.randn(8)[1] * 4 + 1
        np.testing.assert_array_almost_equal(lc.rate,
                                             [0, pp, 2] + [np.nan] * 4 + [7])
        np.testing.assert_array_almost_equal(lc.rerr,
                                             [1, 4, 3] + [np.nan] * 4 + [8])
Exemple #8
0
    def test_interp_small_gaps_4(self):
        # t: 0  1  2  3  4  5  6  7
        # x: 0  1  2  3  4  5  6  7
        # xe:1  2  3  4  5  6  7  8
        #  : *  -  *  -  -  -  *  -
        # gap at the end of lc #
        t = np.arange(8, dtype=np.double)
        x = np.arange(8, dtype=np.double)
        xe = np.arange(1, 9) * 1.
        ind = np.array([0, 2, 6, 7])
        lc = az.LCurve(t[ind], x[ind], xe[ind], 1.0)
        lc.rate[-1] = np.nan
        lc.rerr[-1] = np.nan
        lc = lc.make_even()

        lc.interp_small_gaps(maxgap=1, noise=None)
        np.testing.assert_array_almost_equal(lc.rate,
                                             [0, 1, 2] + [np.nan] * 3 + [6, 6])
        np.testing.assert_array_almost_equal(lc.rerr, [1, 11 / 3, 3] +
                                             [np.nan] * 3 + [7, 11 / 3])
Exemple #9
0
    def test_interp_small_gaps_1(self):
        # t: 0  1  2  3  4  5  6  7
        # x: 0  1  2  3  4  5  6  7
        # xe:1  2  3  4  5  6  7  8
        #  : *  -  *  -  -  -  -  *
        t = np.arange(8, dtype=np.double)
        x = np.arange(8, dtype=np.double)
        xe = np.arange(1, 9) * 1.
        ind = np.array([0, 2, 7])
        lc = az.LCurve(t[ind], x[ind], xe[ind], 1.0)

        # not even #
        with self.assertRaises(ValueError):
            lc.interp_small_gaps(maxgap=1, noise=None)

        # no noise, 1 gap #
        lc = lc.make_even()
        lc.interp_small_gaps(maxgap=1, noise=None)
        np.testing.assert_array_almost_equal(lc.rate,
                                             [0, 1, 2] + [np.nan] * 4 + [7])
        np.testing.assert_array_almost_equal(lc.rerr,
                                             [1, 4, 3] + [np.nan] * 4 + [8])