Пример #1
0
def LoadSpokeXML(fname):
    # load the xml file
    P_list = lalsimutils.xml_to_ChooseWaveformParams_array(fname)

    # group by spokes
    sdHere = {}
    for P in P_list:
        #        spoke_id = str( [round(elem, 3) for elem in ChooseWaveformParams_to_spoke_label(P)])
        spoke_id = str(ChooseWaveformParams_to_spoke_label(P))
        if sdHere.has_key(spoke_id):
            sdHere[spoke_id].append(P)
        else:
            sdHere[spoke_id] = [P]
    # return
    return sdHere
    dlist_ranges = []
if len(dlist) != len(dlist_ranges):
    print(" downselect parameters inconsistent", dlist, dlist_ranges)
for indx in np.arange(len(dlist_ranges)):
    downselect_dict[dlist[indx]] = dlist_ranges[indx]

if otps.verbose:
    print(downselect_dict)

# downselection procedure: fix units so I can downselect on mass parameters
for p in ['mc', 'm1', 'm2', 'mtot']:
    if p in downselect_dict.keys():
        downselect_dict[p] = np.array(downselect_dict[p], dtype=np.float64)
        downselect_dict[p] *= lal.MSUN_SI  # add back units

P_list_in = lalsimutils.xml_to_ChooseWaveformParams_array(opts.fname)
P_inj = lalsimutils.xml_to_ChooseWaveformParams_array(opts.fname)[opts.event]
param_ref_vals = {}
for param in downselect_dict.keys():
    param_ref_vals[param] = P_inj.extract_param(param)

P_list = []
for P in P_list_in:
    include_item = True
    for param in downselect_dict.keys():
        param_here = P.extract_param(param)
        if not (param_here > downselect_dict[param][0]
                and param_here < downselect_dict[param][1]):
            include_item = False
            continue
    if include_item:
        IP_list[ifo] = lalsimutils.ComplexIP(fNyq=fNyq,
                                             deltaF=df,
                                             analyticPSD_Q=analyticPSD_Q,
                                             psd=psd_dict[ifo],
                                             fMax=opts.fmax,
                                             fLow=fmin)

###
### Load injection XML
###

if opts.inj is None:
    print(" --inj required")
    sys.exit(0)
print(" Reading injection file 1 for comparison ", opts.inj)
P1_list = lalsimutils.xml_to_ChooseWaveformParams_array(opts.inj)
nlines1 = len(P1_list)
print(" Read  ", nlines1, " injections")

if nlines1 < 1:
    print(" No data in ", opts.inj)

tref = float((P1_list[0]).tref)  # default
if not (opts.tref is None):
    tref = opts.tref

if opts.inj2 is None:
    print(" --inj2 required")
    sys.exit(0)
print(" Reading injection file 1 for comparison ", opts.inj2)
P2_list = lalsimutils.xml_to_ChooseWaveformParams_array(opts.inj2)
Пример #4
0
    def likelihood_function(x, y, z, a, b, c, d, e, f, g):
        if isinstance(x, float):
            return np.exp(my_fit([x, y, z, a, b, c, d, e, f, g]))
        else:
            return np.exp(
                my_fit(
                    convert_coords(np.array([x, y, z, a, b, c, d, e, f,
                                             g]).T)))


# PROCEDURE
#   - Identify grid of desired parameters (e.g., ascii table)
#   - Create

# Base
P_base = lalsimutils.xml_to_ChooseWaveformParams_array(opts.fname_xml_base)[0]

# Grid
samples_rec = np.genfromtxt(opts.fname_parameter_grid, names=True)
params_rec = samples_rec.dtype.names

# Conversion
P_list = []
grid_list = []
lnL_list = []
for indx in np.arange(len(samples_rec[params_rec[0]])):
    P = P_base.manual_copy()
    for param in params_rec:
        val = samples_rec[param][indx]
        fac = 1
        if param in ['mc', 'm1', 'm2', 'mtot']:
Пример #5
0
parser = optparse.OptionParser()
parser.add_option("--output-file",
                  default="merged_output",
                  help="Filename, note xml.gz is appened automatically")
parser.add_option("--compare-parameter", action='append')
parser.add_option(
    "--force-approximant", default=None
)  # because there is a weird bug that sometimes hits me with type conversion
parser.add_option("--verbose")
opts, args = parser.parse_args()

# Loop over arguments, joining
P_list = []
for fname in args:
    print(" File name : ", fname)
    P_list_here = lalsimutils.xml_to_ChooseWaveformParams_array(fname)
    print(" Read n= ", len(P_list_here))
    for P in P_list_here:
        P.tref = 0.0  # insure it is ok  -- there have been problems with malformed times. DANGEROUS if used for another purpose than mine!
    print(" Revised length before cutting: N = ", len(P_list_here))
    if opts.force_approximant:
        approx = lalsim.GetApproximantFromString(opts.force_approximant)
        print(" Forcing approx = ", approx, " AKA ",
              lalsim.GetStringFromApproximant(approx), " from ",
              opts.force_approximant)
        for P in P_list_here:
            P.approx = approx
    P_list = P_list + P_list_here

if opts.verbose:
    for P in P_list:
Пример #6
0
#! /usr/bin/env python
import numpy as np
import RIFT.lalsimutils as lalsimutils

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--fname",
                    help="filename of *.dat file [standard ILE output]")
parser.add_argument("--fname-reference", help="xml also")
parser.add_argument("--parameter",
                    action='append',
                    help="list of parameter names")
opts = parser.parse_args()

P_list = lalsimutils.xml_to_ChooseWaveformParams_array(opts.fname)
P_ref_list = lalsimutils.xml_to_ChooseWaveformParams_array(
    opts.fname_reference)

# Find the mean value of the reference point
parameters_to_center = [
    'mc', 'eta'
]  # could also add 'chieff_aligned', in cases with significant spin
if opts.parameter:
    parameters_to_center = opts.parameter
dat = np.zeros((len(P_list), len(parameters_to_center)))
for indx in np.arange(len(P_list)):
    for pIndex in np.arange(len(parameters_to_center)):
        param = parameters_to_center[pIndex]
        val = P_list[indx].extract_param(param)
        dat[indx, pIndex] = val