def median(timeseries, segmentlength, **kwargs):
    """Calculate a PSD using Welch's method with a median average
    """
    if scipy_version <= '1.1.9999':
        raise ValueError(
            "median average PSD estimation requires scipy >= 1.2.0",
        )
    kwargs.setdefault('average', 'median')
    return welch(timeseries, segmentlength, **kwargs)
Calculate a PSD using Welch's method with a median average