Example #1
0
def init_os_common(dataset, h5file, psrlist, nf, noisedir=None, noVaryNoise=False,
            incJitterEquad=True, incEquad=True, outputfile=None):

    model = PALmodels.PTAmodels(h5file, pulsars=psrlist)

    # make model dictionary, can play with number of frequencies here
    # Note: Tmax=0 means it will use the largest time span in the array to set the frequency bin size
    fullmodel = model.makeModelDict(incRedNoise=True, incEquad=incEquad, incJitterEquad=incJitterEquad,
                                    likfunc='mark9', incGWB=True, incEphemMixture=False, nfreqs=nf, Tmax=0)

    # loop through pulsars and fix white noise parameters to values in file
    if noisedir is not None:
        for ct, p in enumerate(model.psr):
            d = np.genfromtxt(noisedir + p.name + '_noise.txt', dtype='S42')
            pars = d[:,0]
            vals = np.array([float(d[ii,2]) for ii in range(d.shape[0])])
            sigs = [psig for psig in fullmodel['signals'] if psig['pulsarind'] == ct]
            sigs = PALutils.fixNoiseValues(sigs, vals, pars, bvary=False, verbose=False)
            
            # turn back on red-noise parameters (will use later when drawing from posteriors)
            for sig in fullmodel['signals']:
                if sig['corr'] == 'single' and sig['stype'] == 'powerlaw':
                    sig['bvary'][1] = True
                    sig['bvary'][0] = True

    if noVaryNoise:
        nflags = ['efac', 'equad', 'jitter', 'jitter_equad']
        for sig in fullmodel['signals']:
            if sig['stype'] in nflags:
                sig['bvary'][0] = False

    # intialize mdoel
    model.initModel(fullmodel, memsave=True, write='no')
    
    # start parameters off at initial values (i.e the fixed values red in above)
    p0 = model.initParameters(fixpstart=True)
    
    # essentially turn off GWB component (again we will do something different when drawing from full PTA posterior)
    p0[-2] = -19
    
    # call once to fix white noise
    xi, rho, sig, Opt, Sig = model.opt_stat_mark9(p0)

    if outputfile is not None:
        f = open(outputfile, 'w')
        f.write('Opt  {0}\n'.format(Opt))
        f.write('Sig  {0}\n'.format(Sig))
        f.write('SNR  {0}\n'.format(Opt/Sig))
        f.close()

    return model
Example #2
0
    def __init__(self,
                 chaindir,
                 h5file=None,
                 jsonfile=None,
                 outdir='noise_output',
                 save=True,
                 nreal=1000):

        ret = get_mcmc_files(chaindir)
        self.chain, self.pars, self.logp = ret[0], ret[1], ret[2]
        if len(ret) == 4:
            self.indicator = ret[3]
        else:
            self.indicator = None

        self.ndim = len(self.pars)

        if not os.path.exists(outdir):
            try:
                os.makedirs(outdir)
            except OSError:
                pass

        self.jsonfile = jsonfile
        self.h5file = h5file
        if self.jsonfile is None:
            self.model = None
        else:
            # open JSON file
            with open(self.jsonfile) as f:
                pmodel = OrderedDict(json.load(f))
            pmodel['likfunc'] = 'mark6'
            # load model
            pulsars = list(map(str, pmodel['pulsarnames']))
            self.model = PALmodels.PTAmodels(self.h5file, pulsars=pulsars)
            self.model.initModel(pmodel, memsave=True, verbose=True)
            p0 = self.model.initParameters()
            self.model.mark6LogLikelihood(p0,
                                          incCorrelations=False,
                                          incJitter=True,
                                          varyNoise=True)

        self.outdir = outdir
        self.save = save
Example #3
0
if args.Tmax == 1:
    args.Tmax = None

if not os.path.exists(args.outDir):
    try:
        os.makedirs(args.outDir)
    except OSError:
        pass


# open file
incGWB = args.incGWB
if args.pname[0] != 'all':
    model = PALmodels.PTAmodels(args.h5file, pulsars=args.pname,
                                start_time=args.start_time,
                                end_time=args.end_time)
elif args.pname[0] == 'all':
    print('Using all pulsars')
    pulsars = 'all'
    model = PALmodels.PTAmodels(args.h5file, pulsars=pulsars,
                                start_time=args.start_time,
                                end_time=args.end_time)


# model options
separateEfacs = args.separateEfacs == 'backend'
separateEfacsByFreq = args.separateEfacs == 'frequencies'

separateEquads = args.separateEquads == 'backend'
separateEquadsByFreq = args.separateEquads == 'frequencies'
Example #4
0
            C += np.ones((len(l), len(l))) * ecorr[l[0]]

        avr = 1 / np.dot(M, np.dot(np.linalg.inv(C), M))
        aveerr[i] = np.sqrt(avr)
        averes[i] = avr * np.dot(M, np.dot(np.linalg.inv(C), res[l]))

    if flags is not None:
        return avetoas, averes, aveerr, aveflags
    else:
        return avetoas, aveerr, averes


h5file = './sns.h5'
pulsar = ['J1713+0747']

model = PALmodels.PTAmodels(h5file, pulsars=pulsar)
fullmodel = model.makeModelDict(incRedNoise=True,
                                noiseModel='powerlaw',
                                separateEfacsByFreq=True,
                                separateEquadsByFreq=True,
                                separateJitterEquadByFreq=True,
                                incEquad=True,
                                incJitterEquad=False,
                                likfunc='mark6')

for sig in fullmodel['signals']:
    if sig['stype'] == 'efac':
        #print sig['flagvalue']
        #if np.any([e in sig['flagvalue'] for e in ['M4', 'M3', 'ABPP']]):
        #if True:
        sig['bvary'] = [False]
Example #5
0
if not os.path.exists(chaindir):
    try:
        os.makedirs(chaindir)
    except OSError:
        pass

print "setting up run for PSR: " + this_PSR
#####
##  Initialize Model that will include a search for:
##    Basic Noise   -- red noise (pow) + DM var (pow) + efac (default) + equad + ecorr (jitter)
##    Band Noise    --  + band noise (pow); need to determine band-binning
##    System Noise  --  + sys noise (pow); too many params, use subset of systems (most important only)
##    NonStationary --  + wavelet/shapelet; non-stationary features in red/DM noise
##    periodic DM   --  + DM Amp and spec index as sinusoid
#####
model = PALmodels.PTAmodels(h5filename, pulsars=this_PSR)

basicModel = model.makeModelDict(incRedNoise=True,
                                 noiseModel='powerlaw',
                                 nfreqs=20,
                                 incDM=True,
                                 dmModel='powerlaw',
                                 ndmfreqs=20,
                                 incEquad=True,
                                 incJitterEquad=jitter,
                                 likfunc='mark9')

model.initModel(basicModel, memsave=True, fromFile=False,
                verbose=True)  # trying verbose=True to see output on cluster
params = model.get_varying_parameters()  # names of params for triplot labels
print 'Run Params:'