lsctables.SnglInspiralTable.tableName)

# Determine central values of intrinsic parameters.
mchirp0 = lalinspiral.sbank.tau0tau3.m1m2_to_mchirp(opts.mass1, opts.mass2)
eta0 = opts.mass1 * opts.mass2 / np.square(opts.mass1 + opts.mass2)
chi0 = 0.

# Transform to chirp times.
thetas_0 = lalsimulation.SimInspiralTaylorF2RedSpinChirpTimesFromMchirpEtaChi(
    mchirp0, eta0, chi0, f_low)

# Sampled PSD.
f_high = 2048
df = 0.1
S = lal.CreateREAL8Vector(int(f_high // df))
S.data = [lalsimulation.SimNoisePSDaLIGOZeroDetHighPower(i * df)
    for i in range(len(S.data))]

# Allocate noise moments.
moments = [lal.CreateREAL8Vector(int((f_high - f_low) // df)) for _ in range(29)]

# Compute noise moments.
lalsimulation.SimInspiralTaylorF2RedSpinComputeNoiseMoments(
    *(moments + [S, f_low, df]))

# Compute Fisher information matrix. Note factor of 2:
# The function SimInspiralTaylorF2RedSpinFisherMatrixChirpTimes
# returns the Fisher matrix for an SNR of 1/sqrt(2). The factor
# of 2 makes this the Fisher matrix at unit SNR.
I = lalsimulation.SimInspiralTaylorF2RedSpinFisherMatrixChirpTimes(
    *(thetas_0 + [f_low, df] + moments)).data * 2
    df = psd_dict[det].deltaF
    print(det, " has length ", len(psd_dict[det].data.data), " with nyquist bin value ",  psd_dict[det].data.data[-1], " which had better be EXACTLY zero if we don't explicitly excise it.  Note also  second-to-last bin, etc are also low:  ", psd_dict[det].data.data[-2], psd_dict[det].data.data[-int(10/df)],psd_dict[det].data.data[-int(30/df)])
print(" ... so several bins may be anomalously small ... ")
for det in psd_dict.keys():
    pairups = np.transpose(np.array([fvals,psd_dict[det].data.data]))
    badbins = [k[0] for k in pairups if k[0]>100 and  k[1]<100*psd_dict[det].data.data[-1]]
    print(" highest reliable frequency in ", det, " seems to be ", badbins[0])

# Plot the raw  PSD
print(" === Plotting === ")
for det in detectors:
    if rosUseWindowing:
        tmp =  lalsimutils.regularize_swig_psd_series_near_nyquist(psd_dict[det], 80) # zero out 80 hz window near nyquist
        psd_dict[det] =  lalsimutils.enforce_swig_psd_fmin(tmp, 30.)
    plt.loglog(fvals, psd_dict[det].data.data,label='psd:'+det)
fn = np.frompyfunc(lambda x: lalsim.SimNoisePSDaLIGOZeroDetHighPower(x) if x>30 else 0,1,1)
#psd_guess = np.log10(np.array(fn(fvals)))
psd_guess = np.zeros(len(fvals))
psd_guess[1:-1] = np.array(map(lalsim.SimNoisePSDaLIGOZeroDetHighPower,fvals[1:-1]))
plt.loglog(fvals,psd_guess,label='analytic')
plt.legend()
#plt.xlim(1e1,1e2)
plt.show()

#
# 'Interpolate' PSD and replot  [option to use the 'regularize']
#
print(" === Interpolating and replotting === ")
psd_extend = {}
plt.clf()
for det in detectors:
Exemple #3
0
    "iLIGOSRD":
    vectorize(lambda f: lalsim.SimNoisePSDiLIGOSRD(f)),
    "aLIGONoSRMLowPower":
    vectorize(lambda f: lalsim.SimNoisePSDaLIGONoSRMLowPower(f)),
    "aLIGONoSRMHighPower":
    vectorize(lambda f: lalsim.SimNoisePSDaLIGONoSRMHighPower(f)),
    "aLIGONSNSOpt":
    vectorize(lambda f: lalsim.SimNoisePSDaLIGONSNSOpt(f)),
    "aLIGOBHBH20Deg":
    vectorize(lambda f: lalsim.SimNoisePSDaLIGOBHBH20Deg(f)),
    "aLIGOHighFrequency":
    vectorize(lambda f: lalsim.SimNoisePSDaLIGOHighFrequency(f)),
    "aLIGOZeroDetLowPower":
    vectorize(lambda f: lalsim.SimNoisePSDaLIGOZeroDetLowPower(f)),
    "aLIGOZeroDetHighPower":
    vectorize(lambda f: lalsim.SimNoisePSDaLIGOZeroDetHighPower(f)),
}

psd_cache = {}  # keyed by df, flow, f_max


def get_PSD(df, flow, f_max, noise_model):
    """
    Return the frequency vector and sampled PSD using the noise_model,
    which are vectorized wrappings of the noise models in lalsimulation.
    flow sets the first non-zero frequency.
    """
    if (df, flow, f_max) in psd_cache:
        return psd_cache[df, flow, f_max]
    f = arange(f_max / df + 1) * df
    LIGO_PSD = inf * ones_like(f)
Exemple #4
0
    def compute_angle_averaged_snr(self, flow=1000.0, fupp=8192.0, psddata=None,
            taper=False, distance=20):
        """
        Flanagan & Hughes eqn 2.30: angle-averaged SNR @ 20 Mpc
        """

        distance*=1e6*lal.PC_SI

        #times, Ixxtmp, Ixytmp, Ixztmp, Iyytmp, Iyztmp, Izztmp = \
        #        get_quadrupole_data(self.secderivs_path, self.waveform_name)

        # Pad the Is to 1 second
        Ixx = np.zeros(16384)
        Ixy = np.zeros(16384)
        Ixz = np.zeros(16384)
        Iyy = np.zeros(16384)
        Iyz = np.zeros(16384)
        Izz = np.zeros(16384)

        Ixx[len(Ixx)/2-0.5*len(self.Ixx):len(Ixx)/2+0.5*len(self.Ixx)] = self.Ixx
        Ixy[len(Ixy)/2-0.5*len(self.Ixy):len(Ixy)/2+0.5*len(self.Ixy)] = self.Ixy
        Ixz[len(Ixz)/2-0.5*len(self.Ixz):len(Ixz)/2+0.5*len(self.Ixz)] = self.Ixz
        Iyy[len(Iyy)/2-0.5*len(self.Iyy):len(Iyy)/2+0.5*len(self.Iyy)] = self.Iyy
        Iyz[len(Iyz)/2-0.5*len(self.Iyz):len(Iyz)/2+0.5*len(self.Iyz)] = self.Iyz
        Izz[len(Izz)/2-0.5*len(self.Izz):len(Izz)/2+0.5*len(self.Izz)] = self.Izz

        if taper:
            # window out inspiral
            Ixx = window_inspiral(Ixx)
            Ixy = window_inspiral(Ixy)
            Ixz = window_inspiral(Ixz)
            Iyy = window_inspiral(Iyy)
            Iyz = window_inspiral(Iyz)
            Izz = window_inspiral(Izz)

        # Now Fourier transform
        dt = 1.0/16384
        IxxTilde = np.abs(dt*np.fft.fft(Ixx))
        IyyTilde = np.abs(dt*np.fft.fft(Iyy))
        IxyTilde = np.abs(dt*np.fft.fft(Ixy))

        # Energy spectrum
        dEdf_term = IxxTilde**2 + IyyTilde**2 - IxxTilde*IyyTilde + \
                3.*IxyTilde**2

        #fac = 32.*lal.G_SI**2/(75.*lal.C_SI**8*distance**2)
        fac = 32.*lal.G_SI**2/(75.*lal.C_SI**8*distance**2)

        # Compute SNR
        freq = np.fft.fftfreq(len(Ixx), d=dt)
        dEdf_term = dEdf_term[freq>=0]
        freq = freq[freq>=0]
        df = np.diff(freq)[0]

        if psddata is None:
            # Use lalsim aLIGO psd

            psd=np.zeros(len(freq))
            for i in range(len(freq)):
                psd[i]=lalsim.SimNoisePSDaLIGOZeroDetHighPower(freq[i])

        else:
            # Use the data supplied in psddata and interpolate to the waveform
            # frequencies
            #psd = np.interp(freq, psddata[:,0], psddata[:,1])
            psd = np.interp(freq, psddata, psddata)


        idxlow = np.argmin(abs(flow-freq))
        idxupp = np.argmin(abs(fupp-freq))


        return (
                1.4*np.sqrt(fac*df*np.trapz(dEdf_term[idxlow:idxupp]/psd[idxlow:idxupp],dx=df))
                )