Exemple #1
0
 def plot_gaussians(self, params):
     plt.subplot(211)
     plt.cla()
     # Re-plot the original profile
     plt.plot(self.phases, self.profile, c='black', lw=3, alpha=0.3)
     plt.xlabel('Pulse Phase')
     plt.ylabel('Pulse Amplitude')
     DC = params[0]
     # Plot the individual gaussians
     for ii in range(self.numgaussians):
         phase, FWHM, amp = params[1+ii*3:4+ii*3]
         plt.plot(self.phases, DC + amp*gaussian_profile(self.proflen, phase, FWHM))
Exemple #2
0
def gen_gaussians(params, N):
    """
    gen_gaussians(params, N):
        Return a model of a DC-component + M gaussians
            params is a sequence of 1+M*3 values
                the first value is the DC component.  Each remaining
                group of three represents the gaussians phase (0-1),
                FWHM (0-1), and amplitude (>0.0).
            N is the number of points in the model.
    """
    numgaussians = (len(params)-1) // 3
    model = Num.zeros(N, dtype='d') + params[0]
    for ii in range(numgaussians):
        phase, FWHM, amp = params[1+ii*3:4+ii*3]
        model += amp * gaussian_profile(N, phase, FWHM)
    return model
Exemple #3
0
    else:
        fold_pfd.subfreqs = Num.asarray([0.0])
        sumsubfreqs = Num.asarray([0.0])
        sumsubdelays = Num.asarray([0.0])
        subdelays2 = Num.asarray([0.0])
        sumsubdelays_phs = Num.asarray([0.0])

    # Read the template profile
    if templatefilenm is not None:
        template = psr_utils.read_profile(templatefilenm, normalize=1)
    else:
        if (gaussfitfile):
            template = psr_utils.read_gaussfitfile(gaussfitfile, fold_pfd.proflen)
        else:
            template = psr_utils.gaussian_profile(fold_pfd.proflen, 0.0, gaussianwidth)
        template = template / max(template)
    #from Pgplot import *
    #plotxy(template)
    #closeplot()
    # Determine the Telescope used
    if (not fold.topo):
        obs = '@'  # Solarsystem Barycenter
    else:
        try: 
            if t2format:
                obs = scopes2[fold_pfd.telescope.split()[0]]
            else:
                obs = scopes[fold_pfd.telescope.split()[0]]
        except KeyError:  sys.stderr.write("Unknown telescope!!! : " + fold_pfd.telescope)
Exemple #4
0
    print("Creating a summed profile of length %d bins using DM = %f" %
          (numbins, DM))

    # Read the template profile or create an appropriate Gaussian
    if templatefilenm is not None:
        template = psr_utils.read_profile(templatefilenm)
        # Resample the template profile to have the correct number of bins (if required)
        if not len(template) == numbins:
            oldlen = len(template)
            template = sinc_interp.periodic_interp(template, numbins)[::oldlen]
    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,
Exemple #5
0
from __future__ import print_function
#>>> print fftfit.__doc__
#This module 'fftfit' is auto-generated with f2py (version:2.13.175-1250).
#Functions:
#  zbrent = zbrent(x1,x2,f1,f2,tol,tmp,pha,nsum)
#  dchisqr = dchisqr(tau,tmp,r,nsum)
#  cprof(y,c,amp,pha,nmax=len(y),nh=(len(c)-1))
#  fccf(amp,pha,shift)
#  ffft(d,npts,isign,ireal)
#  fftfit(prof,s,phi,nmax,shift,eshift,snr,esnr,b,errb,ngood)

import numpy as num
from presto.psr_utils import gaussian_profile, TWOPI
from presto.fftfit import cprof, fftfit

template = gaussian_profile(64, 0.5, 0.1)
c, amp, pha = cprof(template)
#pha.savespace()
pha1 = pha[0]
pha = num.fmod(pha - num.arange(1, len(pha) + 1) * pha1, TWOPI)
for phs in [0.1, 0.3, 0.7]:
    prof = gaussian_profile(64, phs, 0.1) + num.random.standard_normal(64)
    shift, eshift, snr, esnr, b, errb, ngood = fftfit(prof, amp, pha)
    print("True phs = %f, measured phs = %f +/- %f" %
          (phs, shift / len(prof), eshift / len(prof)))