Exemple #1
0
#! /usr/bin/env python

import RIFT.lalsimutils as lalsimutils
import RIFT.misc.ourparams as ourparams

opts, rosDebugMessagesDictionary = ourparams.ParseStandardArguments()
lalsimutils.rosDebugMessagesDictionary = rosDebugMessagesDictionary

Psig = ourparams.PopulatePrototypeSignal(opts)

timeWaveform = lalsimutils.estimateWaveformDuration(Psig)

print(float(timeWaveform))
Exemple #2
0
    filename = opts.inj
    event = opts.event_id
    xmldoc = utils.load_filename(filename,
                                 verbose=True,
                                 contenthandler=lalsimutils.cthdler)
    sim_inspiral_table = table.get_table(xmldoc,
                                         lsctables.SimInspiralTable.tableName)
    P.copy_sim_inspiral(sim_inspiral_table[int(event)])
    P.taper = lalsimutils.lsu_TAPER_START
    if opts.approx:
        P.approx = lalsim.GetApproximantFromString(str(opts.approx))
P.taper = lalsimutils.lsu_TAPER_START  # force taper
P.detector = opts.instrument
P.print_params()

T_est = lalsimutils.estimateWaveformDuration(P)
T_est = P.deltaT * lalsimutils.nextPow2(T_est / P.deltaT)
if T_est < opts.seglen:
    T_est = opts.seglen
P.deltaF = 1. / T_est
print(" Duration ", T_est)
if T_est < opts.seglen:
    print(" Buffer length too short, automating retuning forced ")

# Generate signal
hoft = lalsimutils.hoft(
    P
)  # include translation of source, but NOT interpolation onto regular time grid
# zero pad to be opts.seglen long, if necessary
if opts.seglen / hoft.deltaT > hoft.data.length:
    TDlenGoal = int(opts.seglen / hoft.deltaT)
for indx_P in np.arange(len(P_list)):
    include_item=True
    P = P_list[indx_P]
    for indx in np.arange(len(coord_names)):
        fac=1
        # sanity check restrictions, which may cause problems with the coordinate converters
        if coord_names[indx] is 'eta' and (X_out[indx_P,indx]>0.25 or out[indx_P,indx]<0.001) :
            continue
        if coord_names[indx] is 'delta_mc' and (X_out[indx_P,indx]>1 or out[indx_P,indx]<0.) :
            continue
        if coord_names[indx] in ['mc','m1','m2','mtot']:
            fac = lal.MSUN_SI
        P_list[indx_P].assign_param( coord_names[indx], X_out[indx_P,indx]*fac)

    if not(opts.enforce_duration_bound is None):
      if lalsimutils.estimateWaveformDuration(P)> opts.enforce_duration_bound:
        include_item = False
    for param in downselect_dict:
        val = P.extract_param(param)
        if param in ['mc','m1','m2','mtot']:
            val = val/ lal.MSUN_SI
        if val < downselect_dict[param][0] or val > downselect_dict[param][1]:
            include_item =False
    if include_item:
        P_out.append(P)




# Randomize parameters that have been requested to be randomized
#   - note there is NO SANITY CHECKING if you do this
Exemple #4
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
Exemple #5
0
            print( " Run ligo-proxy-init or otherwise have a method to query gracedb / use CVMFS frames as you need! ! ")
            sys.exit(1)
print(" Event ", gwid)
base_dir = os.getcwd()
if opts.use_ini:
    base_dir =''  # all directories are provided as full path names


if opts.choose_data_LI_seglen:
    cmd_event = "gracedb_legacy download " + opts.gracedb_id + " coinc.xml"
    os.system(cmd_event)
    event_dict = retrieve_event_from_coinc("coinc.xml")
    P=lalsimutils.ChooseWaveformParams()
    P.m1 = event_dict["m1"]*lal.MSUN_SI; P.m2=event_dict["m2"]*lal.MSUN_SI; P.s1z = event_dict["s1z"]; P.s2z = event_dict["s2z"]
    P.fmin = opts.fmin  #  fmin we will use internally
    T_wave = lalsimutils.estimateWaveformDuration(P) +2  # 2 second buffer on end; note that with next power of 2, will go up to 4s
    T_wave_round = lalsimutils.nextPow2( T_wave)

    # For frequency-domain approximants, I need another factor of 2!
    # We have an extra buffer
    if lalsim.SimInspiralImplementedFDApproximants(P.approx)==1:
            print( " FD approximant, needs extra buffer for RIFT at present ")
            T_wave_round *=2 

    print( " Assigning auto-selected segment length ", T_wave_round)
    opts.data_LI_seglen  = T_wave_round

    # Problem with SEOBNRv3 starting frequencies
    mtot_msun = event_dict["m1"]+event_dict["m2"] 
    if ('SEOB' in opts.approx) and mtot_msun > 90*(20./opts.fmin):
            fmin_template = int(14*(90/mtot_msun))   # should also decrease this due to lmax!
def evaluate_overlap_on_grid(hfbase,param_names, grid):
    global downselect_dict
    # Validate grid is working: Create a loop and print for each one.
    # WARNING: Assumes grid for mass-unit variables hass mass units (!)
    P_list = []
    grid_revised = []
    for line in grid:
        Pgrid = P.manual_copy()
        Pgrid.ampO=opts.amplitude_order  # include 'full physics'
        Pgrid.phaseO = opts.phase_order

        # Set attributes that are being changed as necessary, leaving all others fixed
        for indx in np.arange(len(param_names)):
            Pgrid.assign_param(param_names[indx], line[indx])

        # Downselect
        include_item =True
        if not(opts.enforce_duration_bound is None):
            if lalsimutils.estimateWaveformDuration(Pgrid)> opts.enforce_duration_bound:
                include_item = False
        for param in downselect_dict:
            if Pgrid.extract_param(param) < downselect_dict[param][0] or Pgrid.extract_param(param) > downselect_dict[param][1]:
                include_item =False
        if include_item:
         grid_revised.append(line)
         if Pgrid.m2 <= Pgrid.m1:  # do not add grid elements with m2> m1, to avoid possible code pathologies !
            P_list.append(Pgrid)
         else:
            Pgrid.swap_components()  # IMPORTANT.  This should NOT change the physical functionality FOR THE PURPOSES OF OVERLAP (but will for PE - beware phiref, etc!)
            P_list.append(Pgrid)
        else:
#            print "skipping"
#            Pgrid.print_params()
            True
#            print " skipping "
#    print "Length check", len(P_list), len(grid)
    ###
    ### Loop over grid and make overlaps : see effective fisher code for wrappers
    ###
    #  FIXME: More robust multiprocessing implementation -- very heavy!
#    p=Pool(n_threads)
    # PROBLEM: Pool code doesn't work in new configuration.
    if len(grid_revised) ==0 :
        return [],[]
    grid_out = np.array(map(functools.partial(eval_overlap, grid_revised, P_list,IP), np.arange(len(grid_revised))))
    # Remove mass units at end
    for p in ['mc', 'm1', 'm2', 'mtot']:
        if p in param_names:
            indx = param_names.index(p)
            grid_out[:,indx] /= lal.MSUN_SI
    # remove distance units at end
    for p in ['distance', 'dist']:
        if p in param_names:
            indx = param_names.index(p)
            grid_out[:,indx] /= lal.PC_SI*1e6
    # Truncate grid so overlap with the base point is > opts.min_match. Make sure to CONSISTENTLY truncate all lists (e.g., the P_list)
    grid_out_new = []
    P_list_out_new = []
    for indx in np.arange(len(grid_out)):
        if opts.skip_overlap or grid_out[indx,-1] > opts.match_value:
            grid_out_new.append(grid_out[indx])
            P_list_out_new.append(P_list[indx])
    grid_out = np.array(grid_out_new)
    return grid_out, P_list_out_new