예제 #1
0
    print >> sys.stdout,  "Computing match (%d/%d)"%( w+1,
            simulations.nsimulations)

    # Find best-fitting mass (in terms of match)
    print >> sys.stdout,  "Optimising for total mass for each sampled waveform..."

    # Find min/max allowable mass to which we can scale the waveform
    min_mass = config.min_chirp_mass * simulations.simulations[w]['eta']**(-3./5.)
    max_mass = config.max_chirp_mass * simulations.simulations[w]['eta']**(-3./5.)


    # Check we can generate the polarisations
    mass_guess = (max_mass - min_mass)*np.random.random() + min_mass 
    inclination_guess  = 90*np.random.random()
    try:
        hp, hc = nrbu.get_wf_pols(simulations.simulations[w]['wavefile'],
                mass_guess, inclination=inclination_guess, delta_t=config.delta_t)
    except:
        print >> sys.stderr, "Polarisation extraction failure, skipping %s"%(
                simulations.simulations[w]['wavefile'])
        continue


    for s, sampled_waveform in enumerate(reconstruction_data):


        # START XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
        # XXX: Debugging / Testing
        #
        # Here, we generate a pure-NR waveform and find the best-fitting parameters
        # (best fit-factor) to verify that we recover the correct parameters and match
        # when the model matches the data
# Estimate ffinal 
chi = pnutils.phenomb_chi(mass1, mass2,
        simulations.simulations[sim_number]['spin1z'],simulations.simulations[sim_number]['spin2z'])
ffinal = pnutils.get_final_freq(approx, mass1, mass2, 
        simulations.simulations[sim_number]['spin1z'],simulations.simulations[sim_number]['spin2z'])
#upp_bound = ffinal
#upp_bound = 1.5*ffinal
upp_bound = 0.5/delta_t

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# NUMERICAL RELATIVITY

# --- Generate the polarisations
hplus_NR, hcross_NR = nrbu.get_wf_pols(
       simulations.simulations[sim_number]['wavefile'], mass, inclination=inc,
       delta_t=delta_t, f_lower=30.0001, distance=distance)


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# APPROXIMANT 
hplus_approx, hcross_approx = get_td_waveform(approximant=approx,
        distance=distance,
        mass1=mass1,
        mass2=mass2,
        spin1x=0.0,
        spin2x=0.0,
        spin1y=0.0,
        spin2y=0.0,
        spin1z=simulations.simulations[sim_number]['spin1z'],
        spin2z=simulations.simulations[sim_number]['spin2z'],
예제 #3
0
def build_catalog(simulations, mtotal=100.0, nTsamples=1024, delta_t=1./1024,
        noise_file=None):

    """
    Build the data matrix.
    """


    # Preallocation
    amp_cat = np.zeros(shape=(simulations.nsimulations, nTsamples))
    phase_cat = np.zeros(shape=(simulations.nsimulations, nTsamples))

    for s, sim in enumerate(simulations.simulations):
        
        print "Adding {0} to catalog ({1} of {2})".format(sim['wavefile'], s,
                simulations.nsimulations)

        # Extract waveform
        hpRaw, hcRaw = nrbu.get_wf_pols(sim['wavefile'], mtotal=mtotal,
                inclination=0.0, delta_t=delta_t, f_lower=30, distance=100)
        #hp, hc = nrbu.get_wf_pols(sim['wavefile'], mtotal=mtotal,
        #        inclination=0.0, delta_t=delta_t, f_lower=30, distance=100)

        # zero-pad
        hp = pycbc.types.TimeSeries(np.zeros(nTsamples), delta_t=hpRaw.delta_t)
        hc = pycbc.types.TimeSeries(np.zeros(nTsamples), delta_t=hcRaw.delta_t)

        hp.data[:len(hpRaw)]=np.copy(hpRaw.data)
        hc.data[:len(hcRaw)]=np.copy(hcRaw.data)


        # Highpass
        #hp = pycbc.filter.highpass(hp, 30.0)
        #hc = pycbc.filter.highpass(hc, 30.0)


        # Whiten
        if noise_file is not None:

            Hp = hp.to_frequencyseries()
            Hc = hc.to_frequencyseries()

            noise_data = np.loadtxt(noise_file)
            noise_asd = np.exp(np.interp(Hp.sample_frequencies, noise_data[:,0],
                np.log(noise_data[:,1])))


            print 'whitening'
            Hp.data /= noise_asd
            Hc.data /= noise_asd

            hp = Hp.to_timeseries()
            hc = Hc.to_timeseries()

        hp = pycbc.types.TimeSeries(hp[:len(hpRaw)],delta_t=hp.delta_t)
        hc = pycbc.types.TimeSeries(hc[:len(hcRaw)],delta_t=hc.delta_t)

        amp = wfutils.amplitude_from_polarizations(hp, hc)
        phase = wfutils.phase_from_polarizations(hp, hc) 

        # Normalise to unit norm
        amp /= np.linalg.norm(amp)


        # --- Populate time series catalogue (align peak amp to center)
        peakidx = np.argmax(amp.data)

        # Apply some smoothing to the start / end to get rid of remaining
        # small-number junk

        ampthresh=1e-2
        
        # After ringdown:
        amptmp = np.copy(amp.data)
        amptmp[:peakidx] = 1e10
        postmerger = np.argwhere(amptmp < ampthresh*max(amp.data))[0]
        
        win = lal.CreateTukeyREAL8Window(int(len(phase)-postmerger), 0.1)
        window = 1-win.data.data
        window[0.5*len(window):]=0.0
        phase.data[postmerger:] *= window
        amp.data[postmerger:] *= window
        
        # before waveform:
        # XXX: careful with this - we just want to smooth out junk, but we
        # don't really want to artificially truncate the waveforms in-band

#       premerger = np.argwhere(amp>ampthresh*max(amp.data))[0]
#       
#       win = lal.CreateTukeyREAL8Window(int(len(phase)-premerger), 0.1)
#
#       window = win.data.data
#       window[0.5*len(window):]=1.0

        #phase.data *= window
        #amp.data *= window

#       from matplotlib import pyplot as pl
#       pl.figure()
#       pl.plot(amp)
#       pl.show()
#       sys.exit()
        
        # POPULATE
        # right
        start = 0.5*nTsamples
        end = start+len(amp.data)-peakidx
        amp_cat[s, start:end] = np.copy(amp.data[peakidx:])
        phase_cat[s, start:end] = np.copy(phase.data[peakidx:])

        # left
        start = 0.5*nTsamples-peakidx
        end = 0.5*nTsamples
        amp_cat[s, start:end] = np.copy(amp.data[:peakidx])
        phase_cat[s, start:end] = np.copy(phase.data[:peakidx])


    return (amp_cat, phase_cat)

    def main():
        print >> sys.stdout, sys.argv[0]
        print >> sys.stdout, __version__
        print >> sys.stdout, __date__
        return 0
    # Estimate ffinal
    ffinal = pnutils.get_final_freq(
        "SEOBNRv2", mass1, mass2, simulations.simulations[0]["spin1z"], simulations.simulations[0]["spin2z"]
    )

    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    # NUMERICAL RELATIVITY

    if errors_file is None:

        # --- Generate the polarisations from hdf5
        hplus_NR, hcross_NR = nrbu.get_wf_pols(
            simulations.simulations[0]["wavefile"],
            mass,
            inclination=inc,
            delta_t=delta_t,
            f_lower=30.0001 * min(masses) / mass,
            distance=distance,
        )

    else:
        # --- read the polarisations and errors from ascii

        hplus_NR = scale_NR(times_codeunits, hplus_NR_codeunits, mass, delta_t=delta_t)
        hcross_NR = scale_NR(times_codeunits, hcross_NR_codeunits, mass, delta_t=delta_t)

        # hplus_NR.data = window_wave(hplus_NR.data)
        # hcross_NR.data = window_wave(hcross_NR.data)

        dAmpbyAmp = scale_NR(times_codeunits, dAmpbyAmp_codeunits, mass, delta_t=delta_t)
        dphi = scale_NR(times_codeunits, dphi_codeunits, mass, delta_t=delta_t)
예제 #5
0
f.tight_layout()
f.savefig("%s_FF_ranking.eps"%user_tag)
f.savefig("%s_FF_ranking.png"%user_tag)

sys.exit()
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Waveform and data plots
best_simulation = simulations_goodmatch[matchsort][-1]
best_mass = median_masses[matchsort][-1]
std_mass = std_masses[matchsort][-1]
best_inclination = np.median(inclinations[matchsort][-1])

# Generate this waveform with this mass and inclianti

hplus, _ = \
        nrbu.get_wf_pols(best_simulation['wavefile'],
        best_mass, inclination=best_inclination, delta_t=config.delta_t)

# Useful time/freq samples
time_axis = np.arange(0, config.datalen, config.delta_t)
hplus.resize(len(time_axis))
freq_axis = np.arange(0.5*config.datalen/config.delta_t+1./config.datalen) * 1./config.datalen

# Interpolate the ASD to the waveform frequencies (this is convenient so that we
# end up with a PSD which overs all frequencies for use in the match calculation
# later - In practice, this will really just pad out the spectrum at low
# frequencies)
h1_asd_data = np.loadtxt(config.h1_spectral_estimate)
l1_asd_data = np.loadtxt(config.l1_spectral_estimate)

h1_asd = np.exp(np.interp(np.log(freq_axis), np.log(h1_asd_data[:,0]),
    np.log(h1_asd_data[:,1])))