Example #1
0
        if o in ("-s", "--sefd"):
            SEFD = float(a)

    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],
Example #2
0
            if wgtexp != 0.0:
                weights **= wgtexp
                wmx, wmn = weights.max(), weights.min()
                # make the highest weight = 1, but keep min weight the same
                weights = wmn + ((weights - wmn) * (1.0 - wmn) / (wmx - wmn))
            for ii, x in enumerate(ts.table['flags']):
                x['weight'] = weights[ii]
        weights = np.asarray([x['weight'] for x in ts.table['flags']])
        print "There are %d events, with min / max weights %.3f / %.3f" % \
            (len(weights), weights.min(), weights.max())
    else:
        weights = None
        print "There are %d events, no weights are being used." % (len(weights))

    # Now load in the gaussian template and normalize it
    gtemplate = pu.read_gaussfitfile(gaussianfile, nbins)
    gtemplate /= gtemplate.sum()


    # Set the priors on the parameters in the model, before
    # instantiating the emcee_fitter
    # Currently, this adds a gaussian prior on each parameter
    # with width equal to the par file uncertainty * priorerrfact,
    # and then puts in some special cases.
    # *** This should be replaced/supplemented with a way to specify
    # more general priors on parameters that need certain bounds
    fitkeys, fitvals, fiterrs = get_fit_keyvals(modelin)

    for key, v, e in zip(fitkeys,fitvals,fiterrs):
        if key == 'SINI' or key == 'E' or key == 'ECC':
            getattr(modelin,key).prior = Prior(UniformBoundedRV(0.0,1.0))
Example #3
0
        #        is based on the _barycentric_ high frequency (if the barycentric 
        #        conversion was available).  For TOAs, we need a topocentric
        #        delay, which is based on the topocentric frequency fold_pfd.hifreq
        sumsubdelays = (psr_utils.delay_from_DM(fold_pfd.bestdm, sumsubfreqs) -
                        psr_utils.delay_from_DM(fold_pfd.bestdm, fold_pfd.hifreq))/SECPERDAY
    else:
        fold_pfd.subfreqs = Num.asarray([0.0])
        sumsubfreqs = Num.asarray([0.0])
        sumsubdelays = 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: obs = scopes[fold_pfd.telescope.split()[0]]
        except KeyError:  print "Unknown telescope!!!"

    # Read the polyco file (if required)
    if (fold.psr and fold.topo):
Example #4
0
        subdelays2 = psr_utils.delay_from_DM(fold_pfd.bestdm, sumsubfreqs) - \
                psr_utils.delay_from_DM(fold_pfd.bestdm, sumsubfreqs_hi)

    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:
Example #5
0
            outfilenm = a
        if o in ("-s", "--sefd"):
            SEFD = float(a)

    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, color='red')
        Pgplot.closeplot()
Example #6
0
    poly = Polyco(polyconame, recalc_polycos=options.recalc_polycos)
    mjds, phases, met_converter, weights = process_ft1(ft1name,
                                                       poly,
                                                       options.emin,
                                                       options.emax,
                                                       write=options.addphase)

    if not options.unbinned:
        if not HAVE_PRESTO:
            raise ImportError, 'Presto tools not found; binned fitting not available!'
        # Read template profile
        if (options.template is not None):
            template = psr_utils.read_profile(options.template, normalize=1)
        else:
            if (options.gauss is not None):
                template = psr_utils.read_gaussfitfile(options.gauss,
                                                       options.nbins)
            else:
                print >> sys.stderr, "WARNING: Using single gaussian template!"
                gaussianwidth = 0.1  # DEFAULT
                template = psr_utils.gaussian_profile(options.nbins, 0.0,
                                                      gaussianwidth)
            template = template / template.max()
    else:
        if options.gauss is not None:
            template = LCTemplate(template=options.gauss)
        elif options.template is not None:
            template = LCTemplate(template=options.template)
        elif options.edf:
            print 'EDF option selected; will use EDF for template.'
            template = None
        else:  # default is kernel density estimator
Example #7
0
                weights **= wgtexp
                wmx, wmn = weights.max(), weights.min()
                # make the highest weight = 1, but keep min weight the same
                weights = wmn + ((weights - wmn) * (1.0 - wmn) / (wmx - wmn))
            for ii, x in enumerate(ts.table['flags']):
                x['weight'] = weights[ii]
        weights = np.asarray([x['weight'] for x in ts.table['flags']])
        print "There are %d events, with min / max weights %.3f / %.3f" % \
            (len(weights), weights.min(), weights.max())
    else:
        weights = None
        print "There are %d events, no weights are being used." % (
            len(weights))

    # Now load in the gaussian template and normalize it
    gtemplate = pu.read_gaussfitfile(gaussianfile, nbins)
    gtemplate /= gtemplate.sum()

    # Set the priors on the parameters in the model, before
    # instantiating the emcee_fitter
    # Currently, this adds a gaussian prior on each parameter
    # with width equal to the par file uncertainty * priorerrfact,
    # and then puts in some special cases.
    # *** This should be replaced/supplemented with a way to specify
    # more general priors on parameters that need certain bounds
    fitkeys, fitvals, fiterrs = get_fit_keyvals(modelin)

    for key, v, e in zip(fitkeys, fitvals, fiterrs):
        if key == 'SINI' or key == 'E' or key == 'ECC':
            getattr(modelin, key).prior = Prior(UniformBoundedRV(0.0, 1.0))
        elif key == 'PX':