コード例 #1
0
ファイル: grbsummary.py プロジェクト: Solaro/lalsuite
def directional_horizon(ifos, RA, dec, gps_time, horizons=None):
    """
    Return a dictionary of sensitivity numbers for each detector, based on
    a known sky location and an optional input dictionary of inspiral horizon
    distances for a reference source of the user's choice.
    If the horizons dictionary is specified, the returned values are interpreted
    as inspiral horizons in that direction.
    """
    # Convert type if necessary
    if type(gps_time)==int: gps_time=float(gps_time)

    from pylal import antenna

    # Sensitivies specifies relative SNRs of a reference signal (BNS)
    if horizons is None:
	horizons={}
	for det in ifos:
		horizons[det]=1.0
    else:
	assert len(ifos)==len(horizons)

    resps={}
    # Make a dictionary of average responses
    for det in ifos:
	resps[det]=antenna.response(gps_time,RA,dec,0,0,'radians',det)[3]*horizons[det]
    
    return resps
コード例 #2
0
def directional_horizon(ifos, RA, dec, gps_time, horizons=None):
    """
    Return a dictionary of sensitivity numbers for each detector, based on
    a known sky location and an optional input dictionary of inspiral horizon
    distances for a reference source of the user's choice.
    If the horizons dictionary is specified, the returned values are interpreted
    as inspiral horizons in that direction.
    """
    # Convert type if necessary
    if type(gps_time) == int: gps_time = float(gps_time)

    from pylal import antenna

    # Sensitivies specifies relative SNRs of a reference signal (BNS)
    if horizons is None:
        horizons = {}
        for det in ifos:
            horizons[det] = 1.0
    else:
        assert len(ifos) == len(horizons)

    resps = {}
    # Make a dictionary of average responses
    for det in ifos:
        resps[det] = antenna.response(gps_time, RA, dec, 0, 0, 'radians',
                                      det)[3] * horizons[det]

    return resps
コード例 #3
0
def make_bbh(hp, hc, fs, ra, dec, psi, det):
    """
    turns hplus and hcross into a detector output
    applies antenna response and
    and applies correct time delays to each detector
    """

    # make basic time vector
    tvec = np.arange(len(hp)) / float(fs)

    # compute antenna response and apply
    Fp, Fc, _, _ = antenna.response(0.0, ra, dec, 0, psi, 'radians', det)
    ht = hp * Fp + hc * Fc  # overwrite the timeseries vector to reuse it

    # compute time delays relative to Earth centre
    frDetector = lalsimulation.DetectorPrefixToLALDetector(det)
    tdelay = lal.TimeDelayFromEarthCenter(frDetector.location, ra, dec, 0.0)
    print '{}: computed {} Earth centre time delay = {}'.format(
        time.asctime(), det, tdelay)
    # interpolate to get time shifted signal
    ht_tck = interpolate.splrep(tvec, ht, s=0)
    hp_tck = interpolate.splrep(tvec, hp, s=0)
    hc_tck = interpolate.splrep(tvec, hc, s=0)
    tnew = tvec + tdelay
    new_ht = interpolate.splev(tnew, ht_tck, der=0, ext=1)
    new_hp = interpolate.splev(tnew, hp_tck, der=0, ext=1)
    new_hc = interpolate.splev(tnew, hc_tck, der=0, ext=1)

    return new_ht, new_hp, new_hc
コード例 #4
0
ファイル: gw_template_maker.py プロジェクト: jmcginn/GenNet
def make_bbh(hp, hc, fs, ra, dec, psi, det):
    """ Turns hplus and hcross into a detector output
    applies antenna response and
    and applies correct time delays to each detector

    Parameters
    ----------
    hp:
        h-plus version of GW waveform
    hc:
        h-cross version of GW waveform
    fs:
        sampling frequency
    ra:
        right ascension
    dec:
        declination
    psi:
        polarization angle        
    det:
        detector

    Returns
    -------
    ht:
        combined h-plus and h-cross version of waveform
    hp:
        h-plus version of GW waveform 
    hc:
        h-cross version of GW waveform
    """
    # make basic time vector
    tvec = np.arange(len(hp)) / float(fs)

    # compute antenna response and apply
    Fp, Fc, _, _ = antenna.response(float(event_time), ra, dec, 0, psi,
                                    'radians', det)
    ht = hp * Fp + hc * Fc  # overwrite the timeseries vector to reuse it

    # compute time delays relative to Earth centre
    frDetector = lalsimulation.DetectorPrefixToLALDetector(det)
    tdelay = lal.TimeDelayFromEarthCenter(frDetector.location, ra, dec,
                                          float(event_time))
    if verb:
        print '{}: computed {} Earth centre time delay = {}'.format(
            time.asctime(), det, tdelay)

    # interpolate to get time shifted signal
    ht_tck = interpolate.splrep(tvec, ht, s=0)
    hp_tck = interpolate.splrep(tvec, hp, s=0)
    hc_tck = interpolate.splrep(tvec, hc, s=0)
    if gw_tmp: tnew = tvec - tdelay
    else:
        tnew = tvec - tdelay  # + (np.random.uniform(low=-0.037370920181274414,high=0.0055866241455078125))
    new_ht = interpolate.splev(tnew, ht_tck, der=0, ext=1)
    new_hp = interpolate.splev(tnew, hp_tck, der=0, ext=1)
    new_hc = interpolate.splev(tnew, hc_tck, der=0, ext=1)

    return ht, hp, hc
コード例 #5
0
def rescale_dist(
    on_ifos, dist_type, weight_dist,
    phys_dist=None, param_dist=None
    ):

    N_signals = int(1e6)
    trigTime = 0.0

    # if decisive distance is desired, get the antenna responses for each signal
    if dist_type == 'decisive_distance':
        # sky position (right ascension & declination)
        ra = 360 * numpy.random.rand(N_signals)
        dec = 180 * numpy.random.rand(N_signals) - 90
        # additional angles
        inclination = 180 * numpy.random.rand(N_signals)
        polarization = 360 * numpy.random.rand(N_signals)
   
        f_q = {} 
        for ifo in on_ifos:
            f_q[ifo] = numpy.zeros(N_signals)
            for index in range(N_signals):
                _, _, _, f_q[ifo][index] = antenna.response(
                   trigTime,
                   ra[index], dec[index],
                   inclination[index], polarization[index],
                   'degree', ifo )
    
    prob_d_d = {}
    for j in range(len(phys_dist)-1):
        # for this physical distance range, create signals that are uniform in volume
        volume = 4*numpy.pi/3 * numpy.random.uniform(
            low = phys_dist[j]**3.0,
            high = phys_dist[j+1]**3.0,
            size = N_signals)
        dist = numpy.power(volume*(3/(4*numpy.pi)), 1./3)

        # create decisive distance (if desired)
        if dist_type == 'decisive_distance':
            dist_eff = {}
            for ifo in on_ifos:
                dist_eff[ifo] = dist / f_q[ifo]
            dist_dec = numpy.sort(dist_eff.values(), 0)[1]

        # weight distance measure by chirp mass (if desired)
        if weight_dist:
            # Component masses are Gaussian distributed around the Chandrasekar mass
            mass1, mass2 = 0.13 * numpy.random.randn(2, N_signals) + 1.40
            mchirp = numpy.power(mass1+mass2, -1./5) * numpy.power(mass1*mass2, 3./5)
            if dist_type == 'decisive_distance':
                dist_chirp = chirp_dist(dist_dec, mchirp)
            if dist_type == 'distance':
                dist_chirp = chirp_dist(dist, mchirp)
            N_d, _ = numpy.histogram(dist_chirp, bins=param_dist)
        else:
            N_d, _ = numpy.histogram(dist_dec, bins=param_dist)
    
        prob_d_d[phys_dist[j+1]] = numpy.float_(N_d)/numpy.sum(N_d)

    return prob_d_d
コード例 #6
0
def rescale_dist(on_ifos,
                 dist_type,
                 weight_dist,
                 phys_dist=None,
                 param_dist=None):

    N_signals = int(1e6)
    trigTime = 0.0

    # if decisive distance is desired, get the antenna responses for each signal
    if dist_type == 'decisive_distance':
        # sky position (right ascension & declination)
        ra = 360 * numpy.random.rand(N_signals)
        dec = 180 * numpy.random.rand(N_signals) - 90
        # additional angles
        inclination = 180 * numpy.random.rand(N_signals)
        polarization = 360 * numpy.random.rand(N_signals)

        f_q = {}
        for ifo in on_ifos:
            f_q[ifo] = numpy.zeros(N_signals)
            for index in range(N_signals):
                _, _, _, f_q[ifo][index] = antenna.response(
                    trigTime, ra[index], dec[index], inclination[index],
                    polarization[index], 'degree', ifo)

    prob_d_d = {}
    for j in range(len(phys_dist) - 1):
        # for this physical distance range, create signals that are uniform in volume
        volume = 4 * numpy.pi / 3 * numpy.random.uniform(
            low=phys_dist[j]**3.0, high=phys_dist[j + 1]**3.0, size=N_signals)
        dist = numpy.power(volume * (3 / (4 * numpy.pi)), 1. / 3)

        # create decisive distance (if desired)
        if dist_type == 'decisive_distance':
            dist_eff = {}
            for ifo in on_ifos:
                dist_eff[ifo] = dist / f_q[ifo]
            dist_dec = numpy.sort(dist_eff.values(), 0)[1]

        # weight distance measure by chirp mass (if desired)
        if weight_dist:
            # Component masses are Gaussian distributed around the Chandrasekar mass
            mass1, mass2 = 0.13 * numpy.random.randn(2, N_signals) + 1.40
            mchirp = numpy.power(mass1 + mass2, -1. / 5) * numpy.power(
                mass1 * mass2, 3. / 5)
            if dist_type == 'decisive_distance':
                dist_chirp = chirp_dist(dist_dec, mchirp)
            if dist_type == 'distance':
                dist_chirp = chirp_dist(dist, mchirp)
            N_d, _ = numpy.histogram(dist_chirp, bins=param_dist)
        else:
            N_d, _ = numpy.histogram(dist_dec, bins=param_dist)

        prob_d_d[phys_dist[j + 1]] = numpy.float_(N_d) / numpy.sum(N_d)

    return prob_d_d
コード例 #7
0
def get_det_response(ra, dec, trigTime):
    """Return detector response for complete set of IFOs for given sky
    location and time. Inclination and polarization are unused so are
    arbitrarily set to 0.
    """
    f_plus = {}
    f_cross = {}
    inclination = 0
    polarization = 0
    for ifo in ['G1', 'H1', 'H2', 'L1', 'T1', 'V1']:
        f_plus[ifo],f_cross[ifo],_,_ = antenna.response(trigTime, ra, dec,\
                                                        inclination,
                                                        polarization, 'degree',
                                                        ifo)
    return f_plus, f_cross
コード例 #8
0
def get_det_response(ra, dec, trigTime):
    """Return detector response for complete set of IFOs for given sky
    location and time. Inclination and polarization are unused so are
    arbitrarily set to 0.
    """
    f_plus  = {}
    f_cross = {}
    inclination   = 0
    polarization  = 0
    for ifo in ['G1','H1','H2','L1','T1','V1']:
        f_plus[ifo],f_cross[ifo],_,_ = antenna.response(trigTime, ra, dec,\
                                                        inclination,
                                                        polarization, 'degree',
                                                        ifo)
    return f_plus,f_cross
コード例 #9
0
ファイル: mdctools.py プロジェクト: princess-supernova/minke
 def _responses(self, row):
     """
     Calculate the antenna repsonses for each detector to the waveform.
     
     Parameters
     ----------
     row : int
         The row number of the waveforms to be measured
         
     Returns
     -------
     responses : list of lists
         A list containing the lists of antenna responses, with the first 
         element of each list containing the detector acronym.
     """
     output = []
     row = self.waveforms[row]
     for detector in self.detectors:
         time = row.time_geocent_gps + self._timeDelayFromGeocenter(detector, row.ra, row.dec, row.time_geocent_gps)
         time = np.float64(time)
         rs = response(time, row.ra, row.dec, 0, row.psi, 'radians', detector)
         output.append([detector, time, rs[0], rs[1]]   )
     return output
コード例 #10
0
ファイル: legacy_grb.py プロジェクト: vitale82/pycbc
def write_antenna(page, args, seg_plot=None, grid=False, ipn=False):

    """
    Write antenna factors to merkup.page object page and generate John's
    detector response plot.
    """

    page.h3()
    page.add('Antenna factors and sky locations')
    page.h3.close()

    th = []
    td = []
    th2 = []
    td2 = []

    ifos = [args.ifo_tag[i:i+2] for i in range(0, len(args.ifo_tag), 2)]

    if ipn:
        antenna_ifo = {}
        ra = []
        dec = []
        # FIXME: Remove hardcoding here and show this in all cases
        search_file = open('../../../S5IPN_GRB%s_search_180deg.txt'
                           % args.grb_name)
        for line in search_file:
            ra.append(line.split()[0])
            dec.append(line.split()[1])
        for ifo in ifos:
            antenna_ifo[ifo] = []
            for k, l in zip(ra, dec):
                _, _, _, f_q = antenna.response(args.start_time, float(k),
                                                float(l), 0.0, 0.0, 'degree',
                                                ifo)
                antenna_ifo[ifo].append(round(f_q,3))
        dectKeys = antenna_ifo.keys()
        newList=[]

        for elements in range(len(antenna_ifo.values()[0])):
            newDict={}
            for detectors in range(len(antenna_ifo.keys())):
                newDict[dectKeys[detectors]] = antenna_ifo[\
                                               dectKeys[detectors]][elements]
            for key in newDict.keys():
                th.append(key)
            td.append(newDict.values())        
        page = write_table(page, list(set(th)), td)
    for ifo in ifos:
        _, _, _, f_q = antenna.response(args.start_time, args.ra, args.dec,
                                        0.0, 0.0, 'degree',ifo)
        th.append(ifo)
        td.append(round(f_q, 3))

    #FIXME: Work out a way to make these external calls safely
    #cmmnd = 'projectedDetectorTensor --gps-sec %d --ra-deg %f --dec-deg %f' \
    #         % (args.start_time,args.ra, args.dec)
    #for ifo in ifos:
    #    if ifo == 'H1':
    #        cmmnd += ' --display-lho'
    #    elif ifo == 'L1':
    #        cmmnd += ' --display-llo'
    #    elif ifo == 'V1':
    #        cmmnd += ' --display-virgo'
    #status = make_external_call(cmmnd)

    page = write_table(page, th, td)

#    plot = markup.page()
#    p = "projtens.png"
#    plot.a(href=p, title="Detector response and polarization")
#    plot.img(src=p)
#    plot.a.close()
#    th2 = ['Response Diagram']
#    td2 = [plot() ]

        # FIXME: Add these in!!
#    plot = markup.page()
#    p = "ALL_TIMES/plots_clustered/GRB%s_search.png"\
#        % args.grb_name
#    plot.a(href=p, title="Error Box Search")
#    plot.img(src=p)
#    plot.a.close()
#    th2.append('Error Box Search')
#    td2.append(plot())

#    plot = markup.page()
#    p = "ALL_TIMES/plots_clustered/GRB%s_simulations.png"\
#        % args.grb_name
#    plot.a(href=p, title="Error Box Simulations")
#    plot.img(src=p)
#    plot.a.close()
#    th2.append('Error Box Simulations')
#    td2.append(plot())

    if seg_plot is not None:
        plot = markup.page()
        p = os.path.basename(seg_plot)
        plot.a(href=p, title="Science Segments")
        plot.img(src=p)
        plot.a.close()
        th2.append('Science Segments')
        td2.append(plot())

    plot = markup.page()
    p = "ALL_TIMES/plots_clustered/GRB%s_sky_grid.png"\
            % args.grb_name
    plot.a(href=p, title="Sky Grid")
    plot.img(src=p)
    plot.a.close()
    th2.append('Sky Grid')
    td2.append(plot())

#    plot = markup.page()
#    p = "GRB%s_inspiral_horizon_distance.png"\
#            % args.grb_name
#    plot.a(href=p, title="Inspiral Horizon Distance")
#    plot.img(src=p)
#    plot.a.close()
#    th2.append('Inspiral Horizon Distance')
#    td2.append(plot())

    page = write_table(page, th2, td2)

    return page
コード例 #11
0
ファイル: noisy_signal.py プロジェクト: astroclark/talks
# Generate a post-merger signal
#
epoch = h1data[1]+250
trigtime = epoch+0.5
distance = 5

# Sky angles
inj_ra  = -1.0*np.pi + 2.0*np.pi*np.random.random()
inj_dec = -0.5*np.pi + np.arccos(-1.0 + 2.0*np.random.random())
inj_pol = 2.0*np.pi*np.random.random()
inj_inc = 0.5*(-1.0*np.pi + 2.0*np.pi*np.random.random())
inj_phase = 2.0*np.pi*random.random()

# Antenna response
det1_fp, det1_fc, det1_fav, det1_qval = antenna.response(
        epoch, inj_ra, inj_dec, inj_inc, inj_pol, 
        'radians', 'H1')

injoverhead=True
if injoverhead:
    # set the injection distance to that which yields an effective distance
    # equal to the targeted fixed-dist
    inj_distance = det1_qval*distance
else:
    inj_distance = np.copy(distance)

ext_params = pmns_simsig.ExtParams(distance=inj_distance, ra=inj_ra,
        dec=inj_dec, polarization=inj_pol, inclination=inj_inc, phase=inj_phase,
        geocent_peak_time=trigtime)

waveform = pmns_utils.Waveform('nl3_135135_lessvisc')
コード例 #12
0
def write_antenna(page, args, seg_plot=None, grid=False, ipn=False):
    """
    Write antenna factors to merkup.page object page and generate John's
    detector response plot.
    """
    from pylal import antenna

    page.h3()
    page.add('Antenna factors and sky locations')
    page.h3.close()

    th = []
    td = []
    th2 = []
    td2 = []

    ifos = [args.ifo_tag[i:i + 2] for i in range(0, len(args.ifo_tag), 2)]

    if ipn:
        antenna_ifo = {}
        ra = []
        dec = []
        # FIXME: Remove hardcoding here and show this in all cases
        search_file = open('../../../S5IPN_GRB%s_search_180deg.txt' %
                           args.grb_name)
        for line in search_file:
            ra.append(line.split()[0])
            dec.append(line.split()[1])
        for ifo in ifos:
            antenna_ifo[ifo] = []
            for k, l in zip(ra, dec):
                _, _, _, f_q = antenna.response(args.start_time, float(k),
                                                float(l), 0.0, 0.0, 'degree',
                                                ifo)
                antenna_ifo[ifo].append(round(f_q, 3))
        dectKeys = antenna_ifo.keys()

        for elements in range(len(antenna_ifo.values()[0])):
            newDict = {}
            for detectors in range(len(antenna_ifo.keys())):
                newDict[dectKeys[detectors]] = antenna_ifo[\
                                               dectKeys[detectors]][elements]
            for key in newDict.keys():
                th.append(key)
            td.append(newDict.values())
        page = write_table(page, list(set(th)), td)
    for ifo in ifos:
        _, _, _, f_q = antenna.response(args.start_time, args.ra, args.dec,
                                        0.0, 0.0, 'degree', ifo)
        th.append(ifo)
        td.append(round(f_q, 3))

    #FIXME: Work out a way to make these external calls safely
    #cmmnd = 'projectedDetectorTensor --gps-sec %d --ra-deg %f --dec-deg %f' \
    #         % (args.start_time,args.ra, args.dec)
    #for ifo in ifos:
    #    if ifo == 'H1':
    #        cmmnd += ' --display-lho'
    #    elif ifo == 'L1':
    #        cmmnd += ' --display-llo'
    #    elif ifo == 'V1':
    #        cmmnd += ' --display-virgo'
    #status = make_external_call(cmmnd)

    page = write_table(page, th, td)

    #    plot = markup.page()
    #    p = "projtens.png"
    #    plot.a(href=p, title="Detector response and polarization")
    #    plot.img(src=p)
    #    plot.a.close()
    #    th2 = ['Response Diagram']
    #    td2 = [plot() ]

    # FIXME: Add these in!!
    #    plot = markup.page()
    #    p = "ALL_TIMES/plots_clustered/GRB%s_search.png"\
    #        % args.grb_name
    #    plot.a(href=p, title="Error Box Search")
    #    plot.img(src=p)
    #    plot.a.close()
    #    th2.append('Error Box Search')
    #    td2.append(plot())

    #    plot = markup.page()
    #    p = "ALL_TIMES/plots_clustered/GRB%s_simulations.png"\
    #        % args.grb_name
    #    plot.a(href=p, title="Error Box Simulations")
    #    plot.img(src=p)
    #    plot.a.close()
    #    th2.append('Error Box Simulations')
    #    td2.append(plot())

    if seg_plot is not None:
        plot = markup.page()
        p = os.path.basename(seg_plot)
        plot.a(href=p, title="Science Segments")
        plot.img(src=p)
        plot.a.close()
        th2.append('Science Segments')
        td2.append(plot())

    plot = markup.page()
    p = "ALL_TIMES/plots_clustered/GRB%s_sky_grid.png"\
            % args.grb_name
    plot.a(href=p, title="Sky Grid")
    plot.img(src=p)
    plot.a.close()
    th2.append('Sky Grid')
    td2.append(plot())

    #    plot = markup.page()
    #    p = "GRB%s_inspiral_horizon_distance.png"\
    #            % args.grb_name
    #    plot.a(href=p, title="Inspiral Horizon Distance")
    #    plot.img(src=p)
    #    plot.a.close()
    #    th2.append('Inspiral Horizon Distance')
    #    td2.append(plot())

    page = write_table(page, th2, td2)

    return page
コード例 #13
0
        distance=opts.fixed_distance
    else:
        # Read from config file
        if cp.get('injections', 'dist-distr')=='fixed':
            distance = cp.getfloat('injections', 'fixed-dist')

    # Sky angles
    inj_ra  = -1.0*np.pi + 2.0*np.pi*np.random.random()
    inj_dec = -0.5*np.pi + np.arccos(-1.0 + 2.0*np.random.random())
    inj_pol = 2.0*np.pi*np.random.random()
    inj_inc = 0.5*(-1.0*np.pi + 2.0*np.pi*np.random.random())
    inj_phase = 2.0*np.pi*random.random()

    # Antenna response
    det1_fp, det1_fc, det1_fav, det1_qval = antenna.response(
            epoch, inj_ra, inj_dec, inj_inc, inj_pol, 
            'radians', cp.get('analysis', 'ifo1'))

    if cp.getboolean('injections', 'inj-overhead'):
        # set the injection distance to that which yields an effective distance
        # equal to the targeted fixed-dist
        inj_distance = det1_qval*distance
    else:
        inj_distance = np.copy(distance)

    # --- End injection params

    # -----------------------------------------------
    # --- Project waveform onto these extrinsic params
    # Extrinsic parameters
    ext_params = simsig.ExtParams(distance=inj_distance, ra=inj_ra, dec=inj_dec,
コード例 #14
0
ファイル: generate_xml_tables.py プロジェクト: ecm0/simcbc
 def antenna_pattern(self, time_at_coalescence, RA, dec, iota, psi):
     """ Compute antenna response
     """
     fplus, fcross, _, _ = antenna.response(time_at_coalescence, RA, dec,
                                            iota, psi, 'degree', self.name)
     return fplus, fcross
コード例 #15
0
ファイル: generate_xml_tables.py プロジェクト: ecm0/simcbc
 def antenna_pattern(self, time_at_coalescence, RA, dec, iota, psi):
     """ Compute antenna response
     """
     fplus,fcross,_,_ = antenna.response(time_at_coalescence,
                                 RA, dec, iota, psi, 'degree', self.name)
     return fplus, fcross