# Path: src/pys5p/biweight.py
# def biweight(data, axis=None, spread=False):
#     """
#     Calculate Tukey's biweight.
#     Implementation based on Eqn. 7.6 and 7.7 in the SWIR OCAL ATBD.
# 
#     Parameters
#     ----------
#     data   :   array_like
#        input array
#     axis   :   int, optional
#        axis along which the biweight medians are computed.
#         - Note that axis will be ignored when data is a 1-D array.
#     spread :   bool, optional
#        if True, then return also the biweight spread.
# 
#     Returns
#     -------
#     out    :   ndarray or tuple
#        biweight median and biweight spread if parameter "spread" is True
#     """
#     if axis is None or data.ndim == 1:
#         mask = np.isfinite(data)
#         if np.all(~mask):
#             if spread:
#                 return (np.nan, 0.)
#             return np.nan
#         return __biweight(data, spread)
# 
#     # only a single axis!
#     if not isinstance(axis, int):
#         raise TypeError('axis not an integer')
#     if not 0 <= axis < data.ndim:
#         raise ValueError('axis out-of-range')
# 
#     with warnings.catch_warnings():
#         warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
#         return __biweight_axis(data, axis, spread)


from collections import namedtuple
from copy import deepcopy
from pathlib import PurePath
from h5py import Dataset
from .biweight import biweight
import numpy as np
        """
        Returns biweight median of the data in the S5Pmsm

        Parameters
        ----------
        data_sel  :  numpy slice
           A numpy slice generated for example numpy.s_. Can be used to skip
           the first and/or last frame
        axis  : int, optional
           Axis or axes along which the medians are computed. Default is 0.
        keepdims  : bool, optional
           If this is set to True, the axes which are reduced are left in the
           result as dimensions with size one. With this option, the result
           will broadcast correctly against the original arr.

        Returns
        -------
        S5Pmsm object with its data (value & error) replaced by its biweight
        medians along one axis. The coordinates are adjusted, accordingly.
        """
        if data_sel is None:
            if self.error is not None:
                self.value = biweight(self.value, axis=axis)
                self.error = biweight(self.error, axis=axis)
            else:
                (self.value, self.error) = biweight(self.value,
                                                    axis=axis, spread=True)
        else:
            if self.error is not None:
                self.value = biweight(self.value[data_sel], axis=axis)

# Path: src/pys5p/biweight.py
# def biweight(data, axis=None, spread=False):
#     """
#     Calculate Tukey's biweight.
#     Implementation based on Eqn. 7.6 and 7.7 in the SWIR OCAL ATBD.
# 
#     Parameters
#     ----------
#     data   :   array_like
#        input array
#     axis   :   int, optional
#        axis along which the biweight medians are computed.
#         - Note that axis will be ignored when data is a 1-D array.
#     spread :   bool, optional
#        if True, then return also the biweight spread.
# 
#     Returns
#     -------
#     out    :   ndarray or tuple
#        biweight median and biweight spread if parameter "spread" is True
#     """
#     if axis is None or data.ndim == 1:
#         mask = np.isfinite(data)
#         if np.all(~mask):
#             if spread:
#                 return (np.nan, 0.)
#             return np.nan
#         return __biweight(data, spread)
# 
#     # only a single axis!
#     if not isinstance(axis, int):
#         raise TypeError('axis not an integer')
#     if not 0 <= axis < data.ndim:
#         raise ValueError('axis out-of-range')
# 
#     with warnings.catch_warnings():
#         warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')
#         return __biweight_axis(data, axis, spread)


# Path: src/pys5p/s5p_msm.py
from collections import namedtuple
from copy import deepcopy
from pathlib import PurePath
from h5py import Dataset
from .biweight import biweight
import numpy as np

        """
        Returns biweight median of the data in the S5Pmsm

        Parameters
        ----------
        data_sel  :  numpy slice
           A numpy slice generated for example numpy.s_. Can be used to skip
           the first and/or last frame
        axis  : int, optional
           Axis or axes along which the medians are computed. Default is 0.
        keepdims  : bool, optional
           If this is set to True, the axes which are reduced are left in the
           result as dimensions with size one. With this option, the result
           will broadcast correctly against the original arr.

        Returns
        -------
        S5Pmsm object with its data (value & error) replaced by its biweight
        medians along one axis. The coordinates are adjusted, accordingly.
        """
        if data_sel is None:
            if self.error is not None:
                self.value = biweight(self.value, axis=axis)
                self.error = biweight(self.error, axis=axis)
            else:
                (self.value, self.error) = biweight(self.value,
                                                    axis=axis, spread=True)
        else:
            if self.error is not None:
                self.value = biweight(self.value[data_sel], axis=axis)

                self.error = biweight(self.error[data_sel], axis=axis)