Example #1
0
def from_string(psd_name, length, delta_f, low_freq_cutoff):
    """Generate a frequency series containing a LALSimulation PSD specified
    by name.

    Parameters
    ----------
    psd_name : string
        PSD name as found in LALSimulation, minus the SimNoisePSD prefix.
    length : int
        Length of the frequency series in samples.
    delta_f : float
        Frequency resolution of the frequency series.
    low_freq_cutoff : float
        Frequencies below this value are set to zero.

    Returns
    -------
    psd : FrequencySeries
        The generated frequency series.
    """

    # check if valid PSD model
    if psd_name not in get_psd_model_list():
        raise ValueError(psd_name + ' not found among analytical '
                         'PSD functions.')

    # make sure length has the right type for CreateREAL8FrequencySeries
    if not isinstance(length, numbers.Integral):
        warnings.warn('forcing length argument to int', RuntimeWarning)
    length = int(length)

    # if PSD model is in LALSimulation
    if psd_name in get_lalsim_psd_list():
        lalseries = lal.CreateREAL8FrequencySeries('', lal.LIGOTimeGPS(0), 0,
                                                   delta_f,
                                                   lal.DimensionlessUnit,
                                                   length)
        try:
            func = lalsimulation.__dict__[_name_prefix + psd_name +
                                          _name_suffix]
        except KeyError:
            func = lalsimulation.__dict__[_name_prefix + psd_name]
            func(lalseries, low_freq_cutoff)
        else:
            lalsimulation.SimNoisePSD(lalseries, 0, func)
        psd = FrequencySeries(lalseries.data.data, delta_f=delta_f)

    # if PSD model is coded in PyCBC
    else:
        func = pycbc_analytical_psds[psd_name]
        psd = func(length, delta_f, low_freq_cutoff)

    # zero-out content below low-frequency cutoff
    kmin = int(low_freq_cutoff / delta_f)
    psd.data[:kmin] = 0

    return psd
Example #2
0
 def __call__(self, f):
     fa = np.asarray(f)
     df = np.diff(fa)
     if fa.ndim == 1 and df.size > 1 and np.all(df[0] == df[1:]):
         fa = np.concatenate((fa, [fa[-1] + df[0]]))
         ret = lal.CreateREAL8FrequencySeries(
             None, 0, fa[0], df[0], lal.DimensionlessUnit, fa.size)
         lalsimulation.SimNoisePSD(ret, 0, self.__func)
         ret = ret.data.data[:-1]
     else:
         ret = self.__npyfunc(f)
     if not np.isscalar(ret):
         ret = ret.astype(float)
     return ret
Example #3
0
def generate_PSD(psd_name="aLIGOZeroDetHighPower", length=None, delta_f=None):
    psd_list = get_lalsim_psd_list()

    if psd_name in psd_list:
        # print (psd_name)
        # Function for PSD
        func = lalsim.__dict__["SimNoisePSD" + psd_name + "Ptr"]
        # Generate a lal frequency series
        PSDseries = lal.CreateREAL8FrequencySeries("", lal.LIGOTimeGPS(0), 0,
                                                   delta_f,
                                                   lal.DimensionlessUnit,
                                                   length)
        # func(PSDseries)
        lalsim.SimNoisePSD(PSDseries, 0, func)
    return PSDseries
Example #4
0
def getPSD(deltaF, npts, psd="SimNoisePSDaLIGOZeroDetHighPowerPtr"):
    """
    deltaF :: The frequency interval between data points.
    npts   :: Total number of date points
    psd    :: The noise model in lalsimulation. To get info use
              lalsim.__dict__ in interpretor and search string SimNoisePSD
    """
    lalseries = lal.CreateREAL8FrequencySeries('', lal.LIGOTimeGPS(0), 0,
                                               deltaF, lal.DimensionlessUnit,
                                               npts)
    func = lalsim.__dict__[psd]
    lalsim.SimNoisePSD(lalseries, 0, func)
    f_end = lalseries.f0 + len(lalseries.data.data) * lalseries.deltaF
    freq = np.linspace(lalseries.f0, f_end, len((lalseries.data.data)))
    output = np.vstack((freq, lalseries.data.data)).T

    return output
Example #5
0
def getPSD(deltaF, npts, psd="SimNoisePSDaLIGOZeroDetHighPowerPtr"):
    """
    This function accepts a frequency step-size and number of frequency points. 
    It then computes from there the noise PSD for ligo. The default psd is 
    SimNoisePSDaLIGOZeroDetHighPowerPtr which can be changed using the argument
    psd.

    deltaF :: The frequency interval between data points.
    npts   :: Total number of date points
    psd    :: The noise model in lalsimulation. To get info use
              lalsim.__dict__ in interpretor and search string SimNoisePSD
    """
    lalseries = lal.CreateREAL8FrequencySeries('', lal.LIGOTimeGPS(0), 0,
                                               deltaF, lal.DimensionlessUnit,
                                               npts)
    func = lalsim.__dict__[psd]
    lalsim.SimNoisePSD(lalseries, 0, func)
    f_end = lalseries.f0 + len(lalseries.data.data) * lalseries.deltaF
    freq = np.linspace(lalseries.f0, f_end, len((lalseries.data.data)))
    output = np.vstack((freq, lalseries.data.data)).T

    return output
Example #6
0
def from_string(psd_name, length, delta_f, low_freq_cutoff):
    """Generate a frequency series containing a LALSimulation PSD specified by name.

    Parameters
    ----------
    psd_name : string
        PSD name as found in LALSimulation, minus the SimNoisePSD prefix.
    length : int
        Length of the frequency series in samples.
    delta_f : float
        Frequency resolution of the frequency series.
    low_freq_cutoff : float
        Frequencies below this value are set to zero.

    Returns
    -------
    psd : FrequencySeries
        The generated frequency series.
    """
    if psd_name not in _psd_list:
        raise ValueError(psd_name +
                         ' not found among LALSimulation PSD functions.')
    kmin = int(low_freq_cutoff / delta_f)
    lalseries = lal.CreateREAL8FrequencySeries('', lal.LIGOTimeGPS(0), 0,
                                               delta_f, lal.DimensionlessUnit,
                                               length)
    try:
        func = lalsimulation.__dict__[_name_prefix + psd_name + _name_suffix]
    except KeyError:
        func = lalsimulation.__dict__[_name_prefix + psd_name]
        func(lalseries, low_freq_cutoff)
    else:
        lalsimulation.SimNoisePSD(lalseries, 0, func)
    psd = FrequencySeries(lalseries.data.data, delta_f=delta_f)
    psd.data[:kmin] = 0
    return psd