Exemplo n.º 1
0
        def getDMcurve(
                M):  # return the normalized DM curve downsampled to M points
            feature = '%s:%s' % ('DMbins', M)
            if M == 0:
                return np.array([])
            if not feature in self.extracted_feature:
                ddm = (self.dms.max() - self.dms.min()) / 2.
                loDM, hiDM = (self.bestdm - ddm, self.bestdm + ddm)
                loDM = max((0, loDM))  #make sure cut off at 0 DM
                hiDM = max((ddm, hiDM))  #make sure cut off at 0 DM
                N = 100
                interp = False
                sumprofs = self.profs.sum(0)
                if not interp:
                    profs = sumprofs
                else:
                    profs = np.zeros(np.shape(sumprofs), dtype='d')
                DMs = psr_utils.span(loDM, hiDM, N)
                chis = np.zeros(N, dtype='f')
                subdelays_bins = self.subdelays_bins.copy()
                for ii, DM in enumerate(DMs):
                    subdelays = psr_utils.delay_from_DM(DM, self.barysubfreqs)
                    hifreqdelay = subdelays[-1]
                    subdelays = subdelays - hifreqdelay
                    delaybins = subdelays * self.binspersec - subdelays_bins
                    if interp:
                        interp_factor = 16
                        for jj in range(self.nsub):
                            profs[jj] = psr_utils.interp_rotate(
                                sumprofs[jj],
                                delaybins[jj],
                                zoomfact=interp_factor)
                        # Note: Since the interpolation process slightly changes the values of the
                        # profs, we need to re-calculate the average profile value
                        avgprof = (profs / self.proflen).sum()
                    else:
                        new_subdelays_bins = np.floor(delaybins + 0.5)
                        for jj in range(self.nsub):
                            #profs[jj] = psr_utils.rotate(profs[jj], new_subdelays_bins[jj])
                            delay_bins = int(new_subdelays_bins[jj] %
                                             len(profs[jj]))
                            if not delay_bins == 0:
                                profs[jj] = np.concatenate(
                                    (profs[jj][delay_bins:],
                                     profs[jj][:delay_bins]))

                        subdelays_bins += new_subdelays_bins
                        avgprof = self.avgprof
                    sumprof = profs.sum(0)
                    chis[ii] = self.calc_redchi2(prof=sumprof, avg=avgprof)
                DMcurve = normalize(downsample(chis, M))
                self.extracted_feature[feature] = DMcurve
            return self.extracted_feature[feature]
Exemplo n.º 2
0
def get_baryv(ra, dec, mjd, T, obs="GB"):
    """
    get_baryv(ra, dec, mjd, T):
        Determine the average barycentric velocity towards 'ra', 'dec'
        during an observation from 'obs'.  The RA and DEC are in the
        standard string format (i.e. 'hh:mm:ss.ssss' and 'dd:mm:ss.ssss').
        'T' is in sec and 'mjd' is (of course) in MJD.
    """
    tts = pu.span(mjd, mjd + T / 86400.0, 100)
    nn = len(tts)
    bts = numpy.zeros(nn, dtype=numpy.float64)
    vel = numpy.zeros(nn, dtype=numpy.float64)
    presto.barycenter(tts, bts, vel, nn, ra, dec, obs, "DE200")
    return vel.mean()
Exemplo n.º 3
0
def get_baryv(ra, dec, mjd, T, obs="GB"):
    """
    get_baryv(ra, dec, mjd, T):
        Determine the average barycentric velocity towards 'ra', 'dec'
        during an observation from 'obs'.  The RA and DEC are in the
        standard string format (i.e. 'hh:mm:ss.ssss' and 'dd:mm:ss.ssss').
        'T' is in sec and 'mjd' is (of course) in MJD.
    """
    tts = pu.span(mjd, mjd+T/86400.0, 100)
    nn = len(tts)
    bts = numpy.zeros(nn, dtype=numpy.float64)
    vel = numpy.zeros(nn, dtype=numpy.float64)
    presto.barycenter(tts, bts, vel, nn, ra, dec, obs, "DE200")
    return vel.mean()
Exemplo n.º 4
0
def get_baryv(ra, dec, mjd, T, obs="PK"):
    """
   get_baryv(ra, dec, mjd, T, obs="PK"):
     Determine the average barycentric velocity towards 'ra', 'dec'
     during an observation from 'obs'.  The RA and DEC are in the
     standard string format (i.e. 'hh:mm:ss.ssss' and 'dd:mm:ss.ssss').
     'T' is in sec and 'mjd' is (of course) in MJD.  The obs variable
     is the standard two character string from TEMPO:  PK, GB, AO, GM, JB, ...
   """
    tts = psr_utils.span(mjd, mjd + T / 86400.0, 100)
    nn = len(tts)
    bts = Num.zeros(nn, 'd')
    vel = Num.zeros(nn, 'd')
    barycenter(tts, bts, vel, nn, ra, dec, obs, "DE200")
    avgvel = Num.add.reduce(vel) / nn
    return avgvel
Exemplo n.º 5
0
def get_baryv(ra, dec, mjd, T, obs="PK"):
   """
   get_baryv(ra, dec, mjd, T, obs="PK"):
     Determine the average barycentric velocity towards 'ra', 'dec'
     during an observation from 'obs'.  The RA and DEC are in the
     standard string format (i.e. 'hh:mm:ss.ssss' and 'dd:mm:ss.ssss').
     'T' is in sec and 'mjd' is (of course) in MJD.  The obs variable
     is the standard two character string from TEMPO:  PK, GB, AO, GM, JB, ...
   """
   tts = psr_utils.span(mjd, mjd+T/86400.0, 100)
   nn = len(tts)
   bts = Num.zeros(nn, 'd')
   vel = Num.zeros(nn, 'd')
   barycenter(tts, bts, vel, nn, ra, dec, obs, "DE200")
   avgvel = Num.add.reduce(vel)/nn
   return avgvel
Exemplo n.º 6
0
        def getDMcurve(M): # return the normalized DM curve downsampled to M points
            feature = '%s:%s' % ('DMbins', M)
            if M == 0:
                return np.array([])
            if not feature in self.extracted_feature:
                ddm = (self.dms.max() - self.dms.min())/2.
                loDM, hiDM = (self.bestdm - ddm , self.bestdm + ddm)
                loDM = max((0, loDM)) #make sure cut off at 0 DM
                hiDM = max((ddm, hiDM)) #make sure cut off at 0 DM
                N = 100
                interp = False
                sumprofs = self.profs.sum(0)
                if not interp:
                    profs = sumprofs
                else:
                    profs = np.zeros(np.shape(sumprofs), dtype='d')
                DMs = psr_utils.span(loDM, hiDM, N)
                chis = np.zeros(N, dtype='f')
                subdelays_bins = self.subdelays_bins.copy()
                for ii, DM in enumerate(DMs):
                    subdelays = psr_utils.delay_from_DM(DM, self.barysubfreqs)
                    hifreqdelay = subdelays[-1]
                    subdelays = subdelays - hifreqdelay
                    delaybins = subdelays*self.binspersec - subdelays_bins
                    if interp:
                        interp_factor = 16
                        for jj in range(self.nsub):
                            profs[jj] = psr_utils.interp_rotate(sumprofs[jj], delaybins[jj],
                                                                zoomfact=interp_factor)
                        # Note: Since the interpolation process slightly changes the values of the
                        # profs, we need to re-calculate the average profile value
                        avgprof = (profs/self.proflen).sum()
                    else:
                        new_subdelays_bins = np.floor(delaybins+0.5)
                        for jj in range(self.nsub):
                            #profs[jj] = psr_utils.rotate(profs[jj], new_subdelays_bins[jj])
                            delay_bins = int(new_subdelays_bins[jj] % len(profs[jj]))
                            if not delay_bins==0:
                                profs[jj] = np.concatenate((profs[jj][delay_bins:], profs[jj][:delay_bins]))

                        subdelays_bins += new_subdelays_bins
                        avgprof = self.avgprof
                    sumprof = profs.sum(0)
                    chis[ii] = self.calc_redchi2(prof=sumprof, avg=avgprof)
                DMcurve = normalize(downsample(chis, M))
                self.extracted_feature[feature] = DMcurve
            return self.extracted_feature[feature]
 def plot_chi2_vs_DM(self, loDM, hiDM, N=100, interp=0, device='/xwin'):
     """
     plot_chi2_vs_DM(self, loDM, hiDM, N=100, interp=0, device='/xwin'):
         Plot (and return) an array showing the reduced-chi^2 versus
             DM (N DMs spanning loDM-hiDM).  Use sinc_interpolation
             if 'interp' is non-zero.
     """
     # Sum the profiles in time
     sumprofs = self.profs.sum(0)
     if not interp:
         profs = sumprofs
     else:
         profs = Num.zeros(Num.shape(sumprofs), dtype='d')
     DMs = psr_utils.span(loDM, hiDM, N)
     chis = Num.zeros(N, dtype='f')
     subdelays_bins = self.subdelays_bins.copy()
     for ii, DM in enumerate(DMs):
         subdelays = psr_utils.delay_from_DM(DM, self.barysubfreqs)
         hifreqdelay = subdelays[-1]
         subdelays = subdelays - hifreqdelay
         delaybins = subdelays * self.binspersec - subdelays_bins
         if interp:
             interp_factor = 16
             for jj in range(self.nsub):
                 profs[jj] = psr_utils.interp_rotate(sumprofs[jj],
                                                     delaybins[jj],
                                                     zoomfact=interp_factor)
             # Note: Since the interpolation process slightly changes the values of the
             # profs, we need to re-calculate the average profile value
             avgprof = (profs / self.proflen).sum()
         else:
             new_subdelays_bins = Num.floor(delaybins + 0.5)
             for jj in range(self.nsub):
                 profs[jj] = psr_utils.rotate(profs[jj],
                                              int(new_subdelays_bins[jj]))
             subdelays_bins += new_subdelays_bins
             avgprof = self.avgprof
         sumprof = profs.sum(0)
         chis[ii] = self.calc_redchi2(prof=sumprof, avg=avgprof)
     # Now plot it
     Pgplot.plotxy(chis,
                   DMs,
                   labx="DM",
                   laby="Reduced-\gx\u2\d",
                   device=device)
     return (chis, DMs)
Exemplo n.º 8
0
 def plot_chi2_vs_DM(self, loDM, hiDM, N=100, interp=0, device='/xwin'):
     """
     plot_chi2_vs_DM(self, loDM, hiDM, N=100, interp=0, device='/xwin'):
         Plot (and return) an array showing the reduced-chi^2 versus
             DM (N DMs spanning loDM-hiDM).  Use sinc_interpolation
             if 'interp' is non-zero.
     """
     # Sum the profiles in time
     sumprofs = self.profs.sum(0)
     if not interp:
         profs = sumprofs
     else:
         profs = Num.zeros(Num.shape(sumprofs), dtype='d')
     DMs = psr_utils.span(loDM, hiDM, N)
     chis = Num.zeros(N, dtype='f')
     subdelays_bins = self.subdelays_bins.copy()
     for ii, DM in enumerate(DMs):
         subdelays = psr_utils.delay_from_DM(DM, self.barysubfreqs)
         hifreqdelay = subdelays[-1]
         subdelays = subdelays - hifreqdelay
         delaybins = subdelays*self.binspersec - subdelays_bins
         if interp:
             interp_factor = 16
             for jj in range(self.nsub):
                 profs[jj] = psr_utils.interp_rotate(sumprofs[jj], delaybins[jj],
                                                     zoomfact=interp_factor)
             # Note: Since the interpolation process slightly changes the values of the
             # profs, we need to re-calculate the average profile value
             avgprof = (profs/self.proflen).sum()
         else:
             new_subdelays_bins = Num.floor(delaybins+0.5)
             for jj in range(self.nsub):
                 profs[jj] = psr_utils.rotate(profs[jj], int(new_subdelays_bins[jj]))
             subdelays_bins += new_subdelays_bins
             avgprof = self.avgprof
         sumprof = profs.sum(0)
         chis[ii] = self.calc_redchi2(prof=sumprof, avg=avgprof)
     # Now plot it
     Pgplot.plotxy(chis, DMs, labx="DM", laby="Reduced-\gx\u2\d", device=device)
     return (chis, DMs)
Exemplo n.º 9
0
    def shapiro_measurable(self, R, S, mean_anoms):
        """
        shapiro_measurable(R, S, mean_anoms):
            Return the predicted _measurable_ Shapiro delay (in us) for a
                variety of mean anomalies (in radians) given the R
                and S parameters.  This is eqn 28 in Freire & Wex
                2010 and is only valid in the low eccentricity limit.
        """
        Phi = mean_anoms + self.par.OM * DEGTORAD
        cbar = Num.sqrt(1.0 - S**2.0)
        zeta = S / (1.0 + cbar)
        h3 = R * zeta**3.0
        sPhi = Num.sin(Phi)
        delay = -2.0e6 * h3 * (
            Num.log(1.0 + zeta * zeta - 2.0 * zeta * sPhi) / zeta**3.0 +
            2.0 * sPhi / zeta**2.0 - Num.cos(2.0 * Phi) / zeta)
        return delay


if __name__ == '__main__':
    from Pgplot import *

    psrA = binary_psr("0737A_Lyne_DD.par")
    times = psr_utils.span(0.0, psrA.par.PB, 1000) + psrA.par.T0
    rv = psrA.radial_velocity(times)
    plotxy(rv, (times - psrA.par.T0) * 24,
           labx="Hours since Periastron",
           laby="Radial Velocity (km.s)")
    closeplot()
    print(psrA.calc_anoms(52345.32476876))
Exemplo n.º 10
0
        """
        shapiro_measurable(R, S, mean_anoms):
            Return the predicted _measurable_ Shapiro delay (in us) for a
                variety of mean anomalies (in radians) given the R
                and S parameters.  This is eqn 28 in Freire & Wex
                2010 and is only valid in the low eccentricity limit.
        """
        Phi = mean_anoms + self.par.OM * DEGTORAD
        cbar = Num.sqrt(1.0 - S**2.0)
        zeta = S / (1.0 + cbar)
        h3 = R * zeta**3.0
        sPhi = Num.sin(Phi)
        delay = -2.0e6 * h3 * (
            Num.log(1.0 + zeta*zeta - 2.0 * zeta * sPhi) / zeta**3.0 +
            2.0 * sPhi / zeta**2.0 -
            Num.cos(2.0 * Phi) / zeta)
        return delay


if __name__=='__main__':
    from Pgplot import *
    
    psrA = binary_psr("0737A_Lyne_DD.par")
    times = psr_utils.span(0.0, psrA.par.PB, 1000) + psrA.par.T0
    rv = psrA.radial_velocity(times)
    plotxy(rv, (times-psrA.par.T0)*24,
           labx="Hours since Periastron", laby="Radial Velocity (km.s)")
    closeplot()
    print psrA.calc_anoms(52345.32476876)
    
Exemplo n.º 11
0
def calc_features_from_pfd(pfd_filepath):

    pfd_data = prepfold.pfd(str(pfd_filepath))

    if pfd_filepath.parent.name == 'positive':
        label = 1
    elif pfd_filepath.parent.name == 'negative':
        label = 0
    else:
        label = -1
        # raise RuntimeError('unable to decide the label of pfd file: {}'.format(
        #     str(pfd_filepath)))

    pfd_data.dedisperse()

    #### As done in: prepfold.pfd.plot_sumprofs
    profile = pfd_data.sumprof
    profile = normalise_1d(profile)
    ####

    profile_mean = np.mean(profile)
    profile_std_dev = np.std(profile)
    profile_skewness = scipy.stats.skew(profile)
    profile_excess_kurtosis = scipy.stats.kurtosis(profile)

    profiles_sum_axis0 = pfd_data.profs.sum(0)

    #### As done in: prepfold.pfd.plot_chi2_vs_DM
    loDM = 0
    hiDM = pfd_data.numdms
    N = pfd_data.numdms
    profs = profiles_sum_axis0.copy()  # = pfd_data.profs.sum(0)
    DMs = psr_utils.span(loDM, hiDM, N)
    chis = np.zeros(N, dtype='f')
    subdelays_bins = pfd_data.subdelays_bins.copy()
    for ii, DM in enumerate(DMs):
        subdelays = psr_utils.delay_from_DM(DM, pfd_data.barysubfreqs)
        hifreqdelay = subdelays[-1]
        subdelays = subdelays - hifreqdelay
        delaybins = subdelays * pfd_data.binspersec - subdelays_bins
        new_subdelays_bins = np.floor(delaybins + 0.5)
        for jj in range(pfd_data.nsub):
            profs[jj] = psr_utils.rotate(profs[jj],
                                         int(new_subdelays_bins[jj]))
        subdelays_bins += new_subdelays_bins
        sumprof = profs.sum(0)
        chis[ii] = pfd_data.calc_redchi2(prof=sumprof, avg=pfd_data.avgprof)
    ####

    best_dm = pfd_data.bestdm

    # crop_radius = 100
    # best_dm_index = np.searchsorted(DMs, best_dm)  # Not accurate, but close.
    # bloated_chis = np.insert(chis, N, np.full(crop_radius, chis[-1]))
    # bloated_chis = np.insert(bloated_chis, 0, np.full(crop_radius, chis[0]))
    # cropped_chis = bloated_chis[ best_dm_index : best_dm_index+2*crop_radius ]
    # chis = cropped_chis

    chis_mean = np.mean(chis)
    chis_std_dev = np.std(chis)
    chis_skewness = scipy.stats.skew(chis)
    chis_excess_kurtosis = scipy.stats.kurtosis(chis)

    #### As done in: prepfold.pfd.plot_intervals
    intervals = pfd_data.profs.sum(1)
    intervals = normalise_2d_rowwise(intervals)
    ####

    #### As done in: prepfold.pfd.plot_subbands
    subbands = profiles_sum_axis0.copy()  # = pfd_data.profs.sum(0)
    subbands = normalise_2d_rowwise(subbands)
    ####

    return (label, profile_mean, profile_std_dev, profile_skewness,
            profile_excess_kurtosis, chis_mean, chis_std_dev, chis_skewness,
            chis_excess_kurtosis, best_dm, profile, intervals, subbands, chis)