Exemplo n.º 1
0
def fakeGWsources(args):
    # Set up the output file.
    header = toasim.header()
    header.parfile_name = args.par
    header.timfile_name = args.tim

    # Read the .par and .tim file
    toas, par = header.readParTim()

    header.nrealisations = 1
    header.ntoa = len(toas)

    # Just a debug print the content
    print toas[0]
    print par['coord']

    # Where is the source?
    source_pos = coord.SkyCoord(args.source_ra,
                                args.source_dec,
                                unit=(u.hourangle, u.degree))
    print source_pos

    # Extract the GW signal parameters from the program arguments
    gwfreq = float(args.frequency) * u.hertz
    gwamp = float(args.amp)  # in what units?
    epoch = np.longdouble(args.epoch) * u.day

    offsets = list()  # This will be the perturbations from the GW signal

    polterm = 1  # The polariation term, how to set?
    posterm = 1  # The position term, how to set?

    # Loop through all the ToAs and compute the GW signal at that time.
    for toa in toas:
        time = (toa.toa - epoch).to(u.second)
        perturbation = gwamp * np.cos((time * gwfreq).decompose() * 2 * np.pi *
                                      u.radian) * polterm * posterm
        offsets.append(perturbation)  # CHECK units
        print perturbation  # Print this out to check

    # Output the simulation
    realisation = toasim.correction(header, offsets, 0, 0, 0, "")
    with open(header.timfile_name + ".addGWSingle", "w") as f:
        header.write(f)
        realisation.write(f)
Exemplo n.º 2
0
def fakeGWsources(args):
    # Set up the output file.
    header = toasim.header()
    header.parfile_name=args.par
    header.timfile_name=args.tim

    # Read the .par and .tim file
    toas,par = header.readParTim()

    header.nrealisations=1
    header.ntoa = len(toas)


    # Just a debug print the content
    print toas[0]
    print par['coord']

    # Where is the source?
    source_pos = coord.SkyCoord(args.source_ra,args.source_dec,unit=(u.hourangle,u.degree))
    print source_pos

    # Extract the GW signal parameters from the program arguments
    gwfreq = float(args.frequency)*u.hertz
    gwamp = float(args.amp) # in what units?
    epoch = np.longdouble(args.epoch)*u.day

    offsets = list() # This will be the perturbations from the GW signal

    polterm = 1 # The polariation term, how to set?
    posterm = 1 # The position term, how to set?

    # Loop through all the ToAs and compute the GW signal at that time.
    for toa in toas:
        time = (toa.toa - epoch).to(u.second)
        perturbation = gwamp * np.cos((time * gwfreq).decompose()*2*np.pi*u.radian) * polterm * posterm
        offsets.append(perturbation) # CHECK units
        print perturbation # Print this out to check

    # Output the simulation
    realisation = toasim.correction(header, offsets,0,0,0,"")
    with open(header.timfile_name+".addGWSingle","w") as f:
        header.write(f)
        realisation.write(f)
Exemplo n.º 3
0
#!/usr/bin/python
import toasim
import sys, random, math

header = toasim.header()

header.parfile_name = sys.argv[1]
header.timfile_name = sys.argv[2]

par = open(sys.argv[1])
tim = open(sys.argv[2])

header.orig_parfile = par.read()
header.idealised_toas = tim.read()

reals = list()

range = 1e-4

i = 0
while i < len(sys.argv):
    if sys.argv[i] == "--seed":
        i += 1
        seed = int(sys.argv[i])
        random.seed(seed)
        continue
    if sys.argv[i] == "--range":
        i += 1
        range = float(sys.argv[i])
        continue
Exemplo n.º 4
0
#!/usr/bin/python
import toasim
import sys,random,math


nreal=1
header = toasim.header()

header.parfile_name=sys.argv[1]
header.timfile_name=sys.argv[2]

par=open(sys.argv[1])
tim=open(sys.argv[2])

header.orig_parfile=par.read()
header.idealised_toas=tim.read()

reals=list()

range=1e-4

i=0
while i < len(sys.argv):
    if sys.argv[i] == "--nreal":
        i+=1
        nreal=int(sys.argv[i])
        continue
    if sys.argv[i] == "--seed":
        i+=1
        seed = int(sys.argv[i])
        random.seed(seed)
Exemplo n.º 5
0
    def main(self,argv):
        parser = argparse.ArgumentParser(description='Detect the GWB.')
        parser.add_argument('-A','--gwamp',type=float,default=1e-15)
        parser.add_argument('-a','--angles',required=True)
        parser.add_argument('-p','--psrlist',default=None)
        parser.add_argument('--par',default=".par")
        parser.add_argument('--tim',default=".tim")
        parser.add_argument('-n','--npts',type=int,default=1024)
        parser.add_argument('-N','--nreal',type=int,default=1000)
        parser.add_argument('-U','--uncorr',default=False, action='store_true')
        parser.add_argument('-D','--dipole',default=False, action='store_true')
        parser.add_argument('-I','--interp',default='linear')
        

        
        args=parser.parse_args(argv)

        psrs=list()
        pairs=list()
        angles=dict()
        DO_GW_CORR = True
        DO_DIPOLE_CORR = False
        if args.uncorr:
            DO_GW_CORR = False
            print "WARNING: GW correlation is DISABLED."
        if args.dipole:
            DO_GW_CORR = False
            DO_DIPOLE_CORR = True
            print "WARNING: GW correlation is DISABLED."
            print "WARNING: DIPOLE correlation is ENABLED."
        
        Agwb = args.gwamp

        fixedpsrlist=False
        if args.psrlist!=None:
            fixedpsrlist=True
            with open(args.psrlist) as f:
                for line in f:
                    elems=line.split()
                    psrs.append(elems[0])
            
        
        with open(args.angles) as f:
            for line in f:
                elems = line.split()
                p1=elems[0]
                p2=elems[1]
                a=float(elems[2])
                if fixedpsrlist:
                    if p1 not in psrs or p2 not in psrs:
                        continue
                else:
                    if p1 not in psrs:
                        psrs.append(p1)
                    if p2 not in psrs:
                        psrs.append(p2)
                if p1 not in angles:
                    angles[p1]=dict()
                if p2 not in angles:
                    angles[p2]=dict()
                
                angles[p1][p2]=a
                angles[p1][p1]=0
                angles[p2][p1]=a
                angles[p2][p2]=0
                pairs.append((p1,p2))
                
        Npsr=len(psrs)
        Npair=len(pairs)
        if (Npsr*(Npsr-1))/2 != Npair:
            print "ERROR: Number of pairs is not N(N-1)/2"
            sys.exit(1)
            
        startMjd=1e99
        endMjd=0
        psrnfo=dict()
        for p in psrs:
            psrnfo[p] = psrinfo(p,"%s%s"%(p,args.tim))
            startMjd = min(psrnfo[p].start(),startMjd)
            endMjd = max(psrnfo[p].finish(),endMjd)
        
        # Extend the window by one day to ensure validity
        startMjd-=0.5
        endMjd+=0.5
        
        npts1=args.npts
        tspan=endMjd - startMjd
        nreal=args.nreal
        nptsA = npts1*nreal
        
        gridMjds = linspace(startMjd,endMjd,npts1)
        dt = gridMjds[1]-gridMjds[0]
        print "dt =",dt
        print "nreal = ",nreal
        print "npts = ",npts1
        print "tspan = ",tspan
        print "start = ",startMjd
        print "end = ",endMjd
        
        rawData = zeros((Npsr,nptsA))
        
        
        pool = Pool(4)
        procs = list()
        for p in psrs:
            procs.append(pool.apply_async(ifunc_simulator.make_red_noise,args=[npts1,nreal,-13.0/3.0,dt/365.25,Agwb,True,0.001]))
        
        i=0
        for result in procs:
            rawData[i] += result.get()
            i+=1
        if DO_GW_CORR:
            C = ifunc_simulator.make_GW_covar(angles,psrs)
            L = linalg.cholesky(C)
            timeseries = dot(L,rawData)
        elif DO_DIPOLE_CORR:
            C = ifunc_simulator.make_DIPOLE_covar(angles,psrs)
            L = linalg.cholesky(C)
            timeseries = dot(L,rawData)
        else:
            timeseries=rawData
        
        
        i=0
        for psr in psrs:
            print "Write","%s%s.addGWB"%(psr,args.tim)
            with open("%s%s.addGWB"%(psr,args.tim),"w") as f:
                toasim_header = toasim.header()
                toasim_header.ntoa=len(psrnfo[psr].T)
                toasim_header.nrealisations=nreal
                toasim_header.description="Gravitational Wave background"
                toasim_header.short_desc="GWB"
                toasim_header.timfile_name="%s%s"%(psr,args.tim)
                if not DO_GW_CORR:
                    toasim_header.short_desc="GWB-uncor"
                toasim_header.rparam_len=0
                toasim_header.rparam_desc=""
                toasim_header.write(f)
                real=0
                while real < nreal:
                    print "%04d\r"%real,
                    sys.stdout.flush()

                    nn = real*npts1
                    gw = interpolate.interp1d(gridMjds,timeseries[i][nn:nn+npts1],kind=args.interp)
                    offsets=list()
                    for t in psrnfo[psr].T:
                        offsets.append(gw(t))
                    offsets=array(offsets)
                    poly = poly1d(polyfit(psrnfo[psr].T,offsets,3))
                    offsets-=poly(psrnfo[psr].T)

                    toasim_corr = toasim.correction(toasim_header,offsets,0,0,0,"")
                    toasim_corr.write(f)
                    real+=1
                print "%04d"%real
            i+=1