src/pys5p/biweight.py
def __biweight(data, spread=False):
    """
    Calculate biweight parameters for the whole dataset
    """
    # calculate median and median absolute difference
    if np.isnan(data).any():
        biweight_median = np.nanmedian(data)
        delta = data - biweight_median
        delta_median = np.nanmedian(np.abs(delta))
    else:
        biweight_median = np.median(data)
        delta = data - biweight_median
        delta_median = np.median(np.abs(delta))
    if delta_median == 0.:
        if spread:
            return (biweight_median, 0.)
        return biweight_median

    # calculate biweight median
    wmx = np.clip(1 - (delta / (6 * delta_median)) ** 2, 0, None) ** 2
    biweight_median += np.nansum(wmx * delta) / np.nansum(wmx)
    del wmx
    gc.collect()
    if not spread:
        return biweight_median

    # calculate biweight variance
    umn = np.clip((delta / (9 * delta_median)) ** 2, None, 1)
    biweight_var = np.nansum(delta ** 2 * (1 - umn) ** 4)
    del delta
    gc.collect()
    biweight_var /= np.nansum((1 - umn) * (1 - 5 * umn)) ** 2
    biweight_var *= np.sum(np.isfinite(data))

    return (biweight_median, np.sqrt(biweight_var))

    Calculate biweight parameters for the whole dataset
    
Calculate biweight parameters for the whole dataset
Calculate biweight parameters for the whole dataset
def __biweight(data, spread=False):
    if np.isnan(data).any():
        biweight_median = np.nanmedian(data)
        delta = data - biweight_median
        delta_median = np.nanmedian(np.abs(delta))
    else:
        biweight_median = np.median(data)
        delta = data - biweight_median
        delta_median = np.median(np.abs(delta))
    if delta_median == 0.:
        if spread:
            return (biweight_median, 0.)
        return biweight_median
    wmx = np.clip(1 - (delta / (6 * delta_median)) ** 2, 0, None) ** 2
    biweight_median += np.nansum(wmx * delta) / np.nansum(wmx)
    del wmx
    gc.collect()
    if not spread:
        return biweight_median
    umn = np.clip((delta / (9 * delta_median)) ** 2, None, 1)
    biweight_var = np.nansum(delta ** 2 * (1 - umn) ** 4)
    del delta
    gc.collect()
    biweight_var /= np.nansum((1 - umn) * (1 - 5 * umn)) ** 2
    biweight_var *= np.sum(np.isfinite(data))
    return (biweight_median, np.sqrt(biweight_var))
def __biweight ( data , spread = False ) : if np . isnan ( data ) . any ( ) : biweight_median = np . nanmedian ( data ) delta = data - biweight_median delta_median = np . nanmedian ( np . abs ( delta ) ) else : biweight_median = np . median ( data ) delta = data - biweight_median delta_median = np . median ( np . abs ( delta ) ) if delta_median == 0. : if spread : return ( biweight_median , 0. ) return biweight_median wmx = np . clip ( 1 - ( delta / ( 6 * delta_median ) ) ** 2 , 0 , None ) ** 2 biweight_median += np . nansum ( wmx * delta ) / np . nansum ( wmx ) del wmx gc . collect ( ) if not spread : return biweight_median umn = np . clip ( ( delta / ( 9 * delta_median ) ) ** 2 , None , 1 ) biweight_var = np . nansum ( delta ** 2 * ( 1 - umn ) ** 4 ) del delta gc . collect ( ) biweight_var /= np . nansum ( ( 1 - umn ) * ( 1 - 5 * umn ) ) ** 2 biweight_var *= np . sum ( np . isfinite ( data ) ) return ( biweight_median , np . sqrt ( biweight_var ) )
Calculate biweight parameters for the whole dataset
Calculate biweight parameters for the whole dataset
"""
    Calculate biweight parameters for the whole dataset
    """ # calculate median and median absolute difference # calculate biweight median # calculate biweight variance
data
spread