Example #1
0
    def dispersion_delay(self, toas):
        """Return the dispersion delay at each toa."""
        try:
            bfreq = self.barycentric_radio_freq(toas)
        except AttributeError:
            warn("Using topocentric frequency for dedispersion!")
            bfreq = toas['freq']

        # Constant dm delay
        dmdelay = self.DM.value * DMconst / bfreq**2
        # Set toas to the right DMX peiod.
        if 'DMX_section' not in toas.keys():
            toas['DMX_section'] = np.zeros_like(toas['index'])
            epoch_ind = 1
            while epoch_ind in self.DMX_mapping:
                # Get the parameters
                r1 = getattr(self, self.DMXR1_mapping[epoch_ind]).value
                r2 = getattr(self, self.DMXR2_mapping[epoch_ind]).value
                msk = np.logical_and(toas['tdbld'] >= ut.time_to_longdouble(r1),
                                     toas['tdbld'] <= ut.time_to_longdouble(r2))
                toas['DMX_section'][msk] = epoch_ind
                epoch_ind = epoch_ind + 1

        # Get DMX delays
        DMX_group = toas.group_by('DMX_section')
        for ii, key in enumerate(DMX_group.groups.keys):
            keyval = key.as_void()[0]
            if keyval != 0:
                dmx = getattr(self, self.DMX_mapping[keyval]).value
                ind = DMX_group.groups[ii]['index']
                # Apply the DMX delays
                dmdelay[ind] += dmx * DMconst / bfreq[ind]**2

        return dmdelay
Example #2
0
def test_time_to_longdouble(format, i, f):
    t = Time(val=i, val2=f, format=format, scale="tai")
    ld = np.longdouble(i) + np.longdouble(f)
    assert_quantity_allclose(time_to_longdouble(t) * u.day,
                             ld * u.day,
                             rtol=0,
                             atol=1.0 * u.ns)
Example #3
0
def test_time_to_longdouble_close_to_time_to_mjd_string(format, i, f):
    t = Time(val=i, val2=f, format=format, scale="tai")
    assert_quantity_allclose(
        np.longdouble(time_to_mjd_string(t)) * u.day,
        time_to_longdouble(t) * u.day,
        rtol=0,
        atol=3.0 * u.ns,
    )
Example #4
0
    def d_phase_d_toa(self, toas, time_intval = 60 ,method = None,
                      num_sample = 20, order = 11):
        """Return the derivative of phase wrt TOA
            time_intval: is in seconds
            method: with finite difference and chebyshev interpolation


        """
        d_phase_d_toa = np.zeros(len(toas))

        if method is None or "FDM":
        # Using finite difference to calculate the derivitve
            dt = np.longdouble(time_intval)/np.longdouble(num_sample)
            num_sample = int(num_sample)/2*2+1

            for i,singal_toa in enumerate(toas):
                toa_utc_ld = utils.time_to_longdouble(singal_toa['mjd'])
                # Resample the toa points
                domain = (toa_utc_ld-time_intval/2.0,toa_utc_ld+time_intval/2.0)
                sample = np.linspace(domain[0],domain[1],num_sample)

                toa_list = []
                for sample_time in sample:
                    toa_list.append(toa.TOA((np.modf(sample_time)[1],
                                np.modf(sample_time)[0]),obs = singal_toa['obs'],
                                freq = singal_toa['freq']))

                sample_toalist = toa.get_TOAs_list(toa_list)
                ph = self.phase(sample_toalist.table)
                p = ph.int-ph.int.min()+ph.frac
                p = np.array(p,dtype='float64')
                # Reduce the value of samples in order to use double precision
                reduce_samepl = np.array((sample-sample.min())*86400.0,dtype = 'float64')
                dx = np.gradient(reduce_samepl)
                dp = np.gradient(p-p.mean(),dx)
                d_phase_d_toa[i] = dp[num_sample/2]

        if method is "chebyshev":
        # Using chebyshev interpolation to calculate the

            for i,singal_toa in enumerate(toas):
                # Have more sample point around toa
                toa_utc_ld = utils.time_to_longdouble(singal_toa['mjd'])
                domain = (toa_utc_ld-time_intval/2.0,toa_utc_ld+time_intval/2.0)
                sample = np.linspace(domain[0],domain[1],num_sample)

                toa_list = []
                for sample_time in sample:
                    toa_list.append(toa.TOA((np.modf(sample_time)[1],
                                np.modf(sample_time)[0]),obs = singal_toa['obs'],
                                freq = singal_toa['freq']))

                sample_toalist = toa.get_TOAs_list(toa_list)
                # Calculate phase
                ph = self.phase(sample_toalist.table)
                p = ph.int-ph.int.min()+ph.frac
                p = np.array(p,dtype='float64')
                # reduce the phase value to use double precision
                reduce_samepl = np.array((sample-sample.min())*86400.0,dtype = 'float64')
                coeff = np.polynomial.chebyshev.chebfit(reduce_samepl, p,order)
                dcoeff = np.polynomial.chebyshev.chebder(coeff)
                dy =  np.polynomial.chebyshev.chebval(reduce_samepl,dcoeff)
                d_phase_d_toa[i] = dy[num_sample/2]

        return d_phase_d_toa
Example #5
0
def test_time_to_longdouble_no_longer_than_time_to_mjd_string(i, f):
    t = Time(val=i, val2=f, format="mjd", scale="tai")
    assert len(time_to_mjd_string(t)) >= len(str(time_to_longdouble(t)))
Example #6
0
    def d_phase_d_toa(self,
                      toas,
                      time_intval=60,
                      method=None,
                      num_sample=20,
                      order=11):
        """Return the derivative of phase wrt TOA
            time_intval: is in seconds
            method: with finite difference and chebyshev interpolation


        """
        d_phase_d_toa = np.zeros(len(toas))

        if method is None or "FDM":
            # Using finite difference to calculate the derivitve
            dt = np.longdouble(time_intval) / np.longdouble(num_sample)
            num_sample = int(num_sample) / 2 * 2 + 1

            for i, singal_toa in enumerate(toas):
                toa_utc_ld = utils.time_to_longdouble(singal_toa['mjd'])
                # Resample the toa points
                domain = (toa_utc_ld - time_intval / 2.0,
                          toa_utc_ld + time_intval / 2.0)
                sample = np.linspace(domain[0], domain[1], num_sample)

                toa_list = []
                for sample_time in sample:
                    toa_list.append(
                        toa.TOA(
                            (np.modf(sample_time)[1], np.modf(sample_time)[0]),
                            obs=singal_toa['obs'],
                            freq=singal_toa['freq']))

                sample_toalist = toa.get_TOAs_list(toa_list)
                ph = self.phase(sample_toalist.table)
                p = ph.int - ph.int.min() + ph.frac
                p = np.array(p, dtype='float64')
                # Reduce the value of samples in order to use double precision
                reduce_samepl = np.array((sample - sample.min()) * 86400.0,
                                         dtype='float64')
                dx = np.gradient(reduce_samepl)
                dp = np.gradient(p - p.mean(), dx)
                d_phase_d_toa[i] = dp[num_sample / 2]

        if method is "chebyshev":
            # Using chebyshev interpolation to calculate the

            for i, singal_toa in enumerate(toas):
                # Have more sample point around toa
                toa_utc_ld = utils.time_to_longdouble(singal_toa['mjd'])
                domain = (toa_utc_ld - time_intval / 2.0,
                          toa_utc_ld + time_intval / 2.0)
                sample = np.linspace(domain[0], domain[1], num_sample)

                toa_list = []
                for sample_time in sample:
                    toa_list.append(
                        toa.TOA(
                            (np.modf(sample_time)[1], np.modf(sample_time)[0]),
                            obs=singal_toa['obs'],
                            freq=singal_toa['freq']))

                sample_toalist = toa.get_TOAs_list(toa_list)
                # Calculate phase
                ph = self.phase(sample_toalist.table)
                p = ph.int - ph.int.min() + ph.frac
                p = np.array(p, dtype='float64')
                # reduce the phase value to use double precision
                reduce_samepl = np.array((sample - sample.min()) * 86400.0,
                                         dtype='float64')
                coeff = np.polynomial.chebyshev.chebfit(
                    reduce_samepl, p, order)
                dcoeff = np.polynomial.chebyshev.chebder(coeff)
                dy = np.polynomial.chebyshev.chebval(reduce_samepl, dcoeff)
                d_phase_d_toa[i] = dy[num_sample / 2]

        return d_phase_d_toa