示例#1
0
#! /usr/bin/env python
#
# USAGE
#  python util_TestXMLParameterStorage.py ; ligolw_print -t sim_inspiral -c alpha5 output.xml.gz
import RIFT.lalsimutils as lalsimutils
import numpy as np
import lal

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--output-file", default="output")
opts = parser.parse_args()

P_list_in = []
for i in np.arange(5):
    P_list_in.append(lalsimutils.ChooseWaveformParams(m1=lal.MSUN_SI *
                                                      (i + 1)))
    P_list_in[-1].lambda1 = 3 * i + 1
    P_list_in[-1].lambda2 = 3 * i + 2
    P_list_in[-1].approx = 3 * i + 2
    P_list_in[-1].print_params()

lalsimutils.ChooseWaveformParams_array_to_xml(P_list_in,
                                              fname=opts.output_file)

print(" ------ ")
P_list_out = lalsimutils.xml_to_ChooseWaveformParams_array(opts.output_file +
                                                           ".xml.gz")

for P in P_list_out:
    P.print_params()
示例#2
0
def PopulatePrototypeSignal(opts):
    approxSignal = lalsim.GetApproximantFromString(opts.approx)
    approxTemplate = approxSignal
    ampO = opts.amporder  # sets which modes to include in the physical signal
    Lmax = opts.Lmax  # sets which modes to include
    fref = opts.fref
    fminWavesSignal = opts.fmin_Template  # too long can be a memory and time hog, particularly at 16 kHz
    fminSNR = opts.fmin_SNR
    fSample = opts.srate

    Psig = None

    # Read in *coincidence* XML (overridden by injection, if present)
    if opts.coinc:
        xmldoc = utils.load_filename(opts.coinc)
        coinc_table = table.get_table(xmldoc,
                                      lsctables.CoincInspiralTable.tableName)
        assert len(coinc_table) == 1
        coinc_row = coinc_table[0]
        # Populate the SNR sequence and mass sequence
        sngl_inspiral_table = table.get_table(
            xmldoc, lsctables.SnglInspiralTable.tableName)
        m1, m2 = None, None
        for sngl_row in sngl_inspiral_table:
            # NOTE: gstlal is exact match, but other pipelines may not be
            assert m1 is None or (sngl_row.mass1 == m1
                                  and sngl_row.mass2 == m2)
            m1, m2 = sngl_row.mass1, sngl_row.mass2
        m1 = m1 * lal.MSUN_SI
        m2 = m2 * lal.MSUN_SI
        # Create a 'best recovered signal'
        Psig = lalsimutils.ChooseWaveformParams(
            m1=m1,
            m2=m2,
            approx=approxSignal,
            fmin=fminWavesSignal,
            dist=factored_likelihood.distMpcRef * 1e6 *
            lal.PC_SI,  # default distance
            fref=fref,
            ampO=ampO
        )  # FIXME: Parameter mapping from trigger space to search space

    # Read in *injection* XML
    if opts.inj:
        Psig = lalsimutils.xml_to_ChooseWaveformParams_array(str(opts.inj))[
            opts.event_id]  # Load in the physical parameters of the injection.
        Psig.deltaT = 1. / fSample  # needed if we will generate fake data from the injection xml *by this program, internally*
        timeWaveform = lalsimutils.estimateWaveformDuration(Psig)
        Psig.deltaF = 1. / lalsimutils.nextPow2(
            opts.seglen
        )  # Frequency binning needs to account for target segment length

    if not Psig and opts.channel_name:  # If data loaded but no signal generated
        if (not opts.template_mass1) or (not opts.template_mass2) or (
                not opts.force_gps_time):
            print(
                " CANCEL: Specifying parameters via m1, m2, and time on the command line "
            )
        Psig = lalsimutils.ChooseWaveformParams(
            approx=approxSignal,
            fmin=fminWavesSignal,
            dist=factored_likelihood.distMpcRef * 1e6 *
            lal.PC_SI,  # default distance
            fref=fref)
        Psig.m1 = lal.MSUN_SI * opts.template_mass1
        Psig.m2 = lal.MSUN_SI * opts.template_mass2
        Psig.tref = lal.LIGOTimeGPS(
            0.000000000)  # Initialize as GPSTime object
        Psig.tref += opts.force_gps_time  # Pass value of float into it

    if not (Psig):
        m1 = 4 * lal.MSUN_SI
        m2 = 3 * lal.MSUN_SI
        Psig = lalsimutils.ChooseWaveformParams(m1=m1,
                                                m2=m2,
                                                fmin=fminWavesSignal,
                                                fref=fref,
                                                approx=approxSignal,
                                                ampO=ampO)
    # Use forced parameters, if provided
    if opts.template_mass1:
        Psig.m1 = opts.template_mass1 * lal.LAL_MSUN_SI
    if opts.template_mass2:
        Psig.m2 = opts.template_mass2 * lal.LAL_MSUN_SI

    return Psig
示例#3
0
            npts_out = np.sum(indx_ok)
            new_samples = np.recarray((npts_out, ), dtype=samples.dtype)
            for name in samples.dtype.names:
                new_samples[name] = samples[name][indx_ok]
            samples = new_samples

        # Save samples
        posterior_list.append(samples)

        # Continue ... rest not used at present
        continue

        # Populate a P_list with the samples, so I can perform efficient conversion for plots
        # note only the DETECTOR frame properties are stored here
        P_list = []
        P = lalsimutils.ChooseWaveformParams()
        for indx in np.arange(len(samples["m1"])):
            P.m1 = samples["m1"][indx] * lal.MSUN_SI
            P.m2 = samples["m2"][indx] * lal.MSUN_SI
            P.s1x = samples["a1x"][indx]
            P.s1y = samples["a1y"][indx]
            P.s1z = samples["a1z"][indx]
            P.s2x = samples["a2x"][indx]
            P.s2y = samples["a2y"][indx]
            P.s2z = samples["a2z"][indx]
            if "lnL" in samples.keys():
                P.lnL = samples["lnL"][indx]  # creates a new field !
            else:
                P.lnL = -1
            # Populate other parameters as needed ...
            P_list.append(P)
示例#4
0
    eff_fisher_psd = getattr(lalsim, opts.fisher_psd)   # --fisher-psd SimNoisePSDaLIGOZeroDetHighPower   now
    analyticPSD_Q=True
else:
    print(" Importing PSD file ", opts.psd_file)
    eff_fisher_psd = lalsimutils.load_resample_and_clean_psd(opts.psd_file, 'H1', 1./opts.seglen)
    analyticPSD_Q = False


print(" Loading samples ")
samples_in = np.genfromtxt(opts.fname_lalinference,names=True)
print(" Done loading samples ")
deltaT = 1./4096
T_window =int(opts.seglen)

# Create overlap 
P=lalsimutils.ChooseWaveformParams()
P.deltaT = deltaT
P.deltaF = 1./T_window
P.fmin = samples_in["flow"][0]
P.approx=lalsim.SpinTaylorT2
P.print_params()
print(lalsimutils.estimateDeltaF(P), P.deltaF)
if P.deltaF > lalsimutils.estimateDeltaF(P):
    sys.exit(0)
hfBase = lalsimutils.complex_hoff(P) # Does not matter what this is.
print(" Done generating waveform")
IP = lalsimutils.CreateCompatibleComplexOverlap(hfBase,analyticPSD_Q=analyticPSD_Q,psd=eff_fisher_psd,fMax=opts.fmax,interpolate_max=True)
print(" Done populating inner product")


# Similar code: convert_output_format_inference2ile