How to use the gwpy.utils.lal.find_typed_function function in gwpy

To help you get started, we’ve selected a few gwpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gwpy / gwpy / gwpy / signal / fft / lal.py View on Github external
if size != required:
        warnings.warn("Data array is the wrong size for the correct number "
                      "of averages given the input parameters. The trailing "
                      "%d samples will not be used in this calculation."
                      % (size - required))
        timeseries = timeseries[:required]

    # generate output spectrum
    create = find_typed_function(timeseries.dtype, 'Create', 'FrequencySeries')
    lalfs = create(timeseries.name, lal.LIGOTimeGPS(timeseries.epoch.gps), 0,
                   1 / segmentlength, lal.StrainUnit,
                   int(segmentlength // 2 + 1))

    # find LAL method (e.g. median-mean -> lal.REAL8AverageSpectrumMedianMean)
    methodname = ''.join(map(str.title, re.split('[-_]', method)))
    spec_func = find_typed_function(timeseries.dtype, '',
                                    'AverageSpectrum{}'.format(methodname))

    # calculate spectrum
    spec_func(lalfs, timeseries.to_lal(), segmentlength, stride, window, plan)

    # format and return
    spec = FrequencySeries.from_lal(lalfs)
    spec.name = timeseries.name
    spec.channel = timeseries.channel
    spec.override_unit(scale_timeseries_unit(
        timeseries.unit, scaling='density'))
    return spec
github gwpy / gwpy / gwpy / signal / fft / lal.py View on Github external
if method == 'median-mean' and numsegs % 2:
        numsegs -= 1
        if not numsegs:
            raise ValueError("Cannot calculate median-mean spectrum with "
                             "this small a TimeSeries.")

    required = int((numsegs - 1) * stride + segmentlength)
    if size != required:
        warnings.warn("Data array is the wrong size for the correct number "
                      "of averages given the input parameters. The trailing "
                      "%d samples will not be used in this calculation."
                      % (size - required))
        timeseries = timeseries[:required]

    # generate output spectrum
    create = find_typed_function(timeseries.dtype, 'Create', 'FrequencySeries')
    lalfs = create(timeseries.name, lal.LIGOTimeGPS(timeseries.epoch.gps), 0,
                   1 / segmentlength, lal.StrainUnit,
                   int(segmentlength // 2 + 1))

    # find LAL method (e.g. median-mean -> lal.REAL8AverageSpectrumMedianMean)
    methodname = ''.join(map(str.title, re.split('[-_]', method)))
    spec_func = find_typed_function(timeseries.dtype, '',
                                    'AverageSpectrum{}'.format(methodname))

    # calculate spectrum
    spec_func(lalfs, timeseries.to_lal(), segmentlength, stride, window, plan)

    # format and return
    spec = FrequencySeries.from_lal(lalfs)
    spec.name = timeseries.name
    spec.channel = timeseries.channel
github gwpy / gwpy / gwpy / frequencyseries / core.py View on Github external
"""
        import lal
        from ..utils.lal import (find_typed_function, to_lal_unit)

        # map unit
        try:
            unit = to_lal_unit(self.unit)
        except ValueError as e:
            warnings.warn("%s, defaulting to lal.DimensionlessUnit" % str(e))
            unit = lal.DimensionlessUnit

        # convert epoch
        epoch = lal.LIGOTimeGPS(0 if self.epoch is None else self.epoch.gps)

        # create FrequencySeries
        create = find_typed_function(self.dtype, 'Create', 'FrequencySeries')
        lalfs = create(self.name, epoch, self.f0.value, self.df.value,
                       unit, self.shape[0])
        lalfs.data.data = self.value

        return lalfs
github gwpy / gwpy / gwpy / signal / fft / lal.py View on Github external
laltype = to_lal_type_str(dtype)
    key = (length, str(window), laltype)

    # find existing window
    try:
        return LAL_WINDOWS[key]
    # or create one
    except KeyError:
        # parse window as name and arguments, e.g. ('kaiser', 24)
        if isinstance(window, (list, tuple)):
            window, beta = window
        else:
            beta = 0
        window = canonical_name(window)
        # create window
        create = find_typed_function(dtype, 'CreateNamed', 'Window')
        LAL_WINDOWS[key] = create(window, beta, length)
        return LAL_WINDOWS[key]
github gwpy / gwpy / gwpy / signal / fft / lal.py View on Github external
def window_from_array(array):
    """Convert a `numpy.ndarray` into a LAL `Window` object
    """
    import lal
    from ...utils.lal import (find_typed_function)

    dtype = array.dtype

    # create sequence
    seq = find_typed_function(dtype, 'Create', 'Sequence')(array.size)
    seq.data = array

    # create window from sequence
    return find_typed_function(dtype, 'Create', 'WindowFromSequence')(seq)
github gwpy / gwpy / gwpy / signal / fft / lal.py View on Github external
def window_from_array(array):
    """Convert a `numpy.ndarray` into a LAL `Window` object
    """
    import lal
    from ...utils.lal import (find_typed_function)

    dtype = array.dtype

    # create sequence
    seq = find_typed_function(dtype, 'Create', 'Sequence')(array.size)
    seq.data = array

    # create window from sequence
    return find_typed_function(dtype, 'Create', 'WindowFromSequence')(seq)