def _lal_spectrum(timeseries, segmentlength, noverlap=None, method='<STR_LIT>',<EOL>window=None, plan=None):
import lal<EOL>from ...utils.lal import find_typed_function<EOL>if noverlap is None:<EOL><INDENT>noverlap = int(segmentlength // <NUM_LIT:2>)<EOL><DEDENT>stride = segmentlength - noverlap<EOL>if window is None:<EOL><INDENT>window = generate_window(segmentlength, dtype=timeseries.dtype)<EOL><DEDENT>if plan is None:<EOL><INDENT>plan = generate_fft_plan(segmentlength, dtype=timeseries.dtype)<EOL><DEDENT>method = method.lower()<EOL>size = timeseries.size<EOL>numsegs = <NUM_LIT:1> + int((size - segmentlength) / stride)<EOL>if method == '<STR_LIT>' and numsegs % <NUM_LIT:2>:<EOL><INDENT>numsegs -= <NUM_LIT:1><EOL>if not numsegs:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT><DEDENT>required = int((numsegs - <NUM_LIT:1>) * stride + segmentlength)<EOL>if size != required:<EOL><INDENT>warnings.warn("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (size - required))<EOL>timeseries = timeseries[:required]<EOL><DEDENT>create = find_typed_function(timeseries.dtype, '<STR_LIT>', '<STR_LIT>')<EOL>lalfs = create(timeseries.name, lal.LIGOTimeGPS(timeseries.epoch.gps), <NUM_LIT:0>,<EOL><NUM_LIT:1> / segmentlength, lal.StrainUnit,<EOL>int(segmentlength // <NUM_LIT:2> + <NUM_LIT:1>))<EOL>methodname = '<STR_LIT>'.join(map(str.title, re.split('<STR_LIT>', method)))<EOL>spec_func = find_typed_function(timeseries.dtype, '<STR_LIT>',<EOL>'<STR_LIT>'.format(methodname))<EOL>spec_func(lalfs, timeseries.to_lal(), segmentlength, stride, window, plan)<EOL>spec = FrequencySeries.from_lal(lalfs)<EOL>spec.name = timeseries.name<EOL>spec.channel = timeseries.channel<EOL>spec.override_unit(scale_timeseries_unit(<EOL>timeseries.unit, scaling='<STR_LIT>'))<EOL>return spec<EOL>
Generate a PSD `FrequencySeries` using |lal|_

    Parameters
    ----------
    timeseries : `~gwpy.timeseries.TimeSeries`
        input `TimeSeries` data.

    segmentlength : `int`
        number of samples in single average.

    method : `str`
        average PSD method

    noverlap : `int`
        number of samples to overlap between segments, defaults to 50%.

    window : `lal.REAL8Window`, optional
        window to apply to timeseries prior to FFT

    plan : `lal.REAL8FFTPlan`, optional
        LAL FFT plan to use when generating average spectrum

    Returns
    -------
    spectrum : `~gwpy.frequencyseries.FrequencySeries`
        average power `FrequencySeries`