Пример #1
0
def estimate_rz(psr, T, show=0, device='/XWIN'):
    """
    estimate_rz(psr, T, show=0, device='/XWIN'):
        Return estimates of a pulsar's average Fourier freq ('r')
        relative to its nominal Fourier freq as well as its
        Fourier f-dot ('z') in bins, of a pulsar.
           'psr' is a psrparams structure describing the pulsar.
           'T' is the length of the observation in sec.
           'show' if true, displays plots of 'r' and 'z'.
           'device' if the device to plot to if 'show' is true.
    """
    startE = keplers_eqn(psr.orb.t, psr.orb.p, psr.orb.e, 1.0E-15)
    numorbpts = int(T / psr.orb.p + 1.0) * 1024 + 1
    dt = T / (numorbpts - 1)
    E = dorbint(startE, numorbpts, dt, psr.orb)
    z = z_from_e(E, psr, T)
    r = T / p_from_e(E, psr) - T / psr.p
    if show:
        times = np.arange(numorbpts) * dt
        Pgplot.plotxy(r, times, labx='Time', \
                      laby='Fourier Frequency (r)', device=device)
        if device == '/XWIN':
            print('Press enter to continue:')
            try:
                i = raw_input()
            except NameError:
                i = input()
        Pgplot.nextplotpage()
        Pgplot.plotxy(z,
                      times,
                      labx='Time',
                      laby='Fourier Frequency Derivative (z)',
                      device=device)
        Pgplot.closeplot()
    return r.mean(), z.mean()
Пример #2
0
 def plot_chi2_vs_sub(self, device='/xwin'):
     """
     plot_chi2_vs_sub(self, device='/xwin'):
         Plot (and return) an array showing the reduced-chi^2 versus
             the subband number.
     """
     # Sum the profiles in each subband
     profs = self.profs.sum(0)
     # Compute the averages and variances for the subbands
     avgs = profs.sum(1) / self.proflen
     vars = []
     for sub in range(self.nsub):
         var = 0.0
         if sub in self.killed_subbands:
             vars.append(var)
             continue
         for part in range(self.npart):
             if part in self.killed_intervals:
                 continue
             var += self.stats[part][sub][5]  # foldstats prof_var
         vars.append(var)
     chis = Num.zeros(self.nsub, dtype='f')
     for ii in range(self.nsub):
         chis[ii] = self.calc_redchi2(prof=profs[ii],
                                      avg=avgs[ii],
                                      var=vars[ii])
     # Now plot it
     Pgplot.plotxy(chis,
                   labx="Subband Number",
                   laby=r"Reduced-\gx\u2\d",
                   rangey=[0.0, max(chis) * 1.1],
                   device=device)
     return chis
Пример #3
0
 def plot_sumprof(self, device='/xwin'):
     """
     plot_sumprof(self, device='/xwin'):
         Plot the dedispersed and summed profile.
     """
     if 'subdelays' not in self.__dict__:
         print("Dedispersing first...")
         self.dedisperse()
     normprof = self.sumprof - min(self.sumprof)
     normprof /= max(normprof)
     Pgplot.plotxy(normprof, labx="Phase Bins", laby="Normalized Flux",
                   device=device)
Пример #4
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=r"Reduced-\gx\u2\d",
                   device=device)
     return (chis, DMs)
Пример #5
0
        shapiro_measurable(R, S, MJD):
            Return the predicted _measurable_ Shapiro delay (in us) for a
                variety of barycentric MJDs, given the R and S parameters.  
                This is eqn 28 in Freire & Wex 2010 and is only valid in 
                the low eccentricity limit.
        """
        ma, ea, ta = self.calc_anoms(MJD)
        ws = self.calc_omega(MJD)
        Phi = ma + ws
        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__':
    import presto.Pgplot as pg

    # The following reproduces the RV plot in Hulse & Taylor, 1975
    psrA = binary_psr("B1913+16.par")
    T0 = 42320.933  # From Hulse & Taylor, 1975
    times = psr_utils.span(0.0, psrA.par.PB, 1000) + T0
    rv = psrA.radial_velocity(times)
    pg.plotxy(rv, (times-T0)*24, \
        labx="Hours since Periastron", laby="Radial Velocity (km.s)")
    pg.closeplot()
Пример #6
0
    else:
        if gaussfitfile is not None:
            template = psr_utils.read_gaussfitfile(gaussfitfile, numbins)
        else:
            template = psr_utils.gaussian_profile(numbins, 0.0, gaussianwidth)
    # Normalize it
    template -= min(template)
    template /= max(template)
    # Rotate it so that it becomes a "true" template according to FFTFIT
    shift, eshift, snr, esnr, b, errb, ngood = measure_phase(
        template, template)
    template = psr_utils.fft_rotate(template, shift)

    # Determine the off-pulse bins
    if bkgd_vals is not None:
        Pgplot.plotxy(template, labx="Phase bins")
        Pgplot.plotxy(template[bkgd_vals],
                      Num.arange(numbins)[bkgd_vals],
                      line=None,
                      symbol=2,
                      color='red')
        Pgplot.closeplot()
        offpulse_inds = bkgd_vals
        onpulse_inds = set(Num.arange(numbins)) - set(bkgd_vals)
    else:
        offpulse_inds = Num.compress(template <= bkgd_cutoff,
                                     Num.arange(numbins))
        onpulse_inds = Num.compress(template > bkgd_cutoff,
                                    Num.arange(numbins))
        Pgplot.plotxy(template)
        Pgplot.plotxy([bkgd_cutoff, bkgd_cutoff], [0.0, numbins], color='red')