# 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/swir_texp.py
# def swir_exp_time(int_delay: int, int_hold: int) -> float:
#     """
#     Parameters
#     ----------
#     int_delay :  int
#       parameters int_delay from the instrument_settings
#     int_hold  :  int
#       parameters int_holt from the instrument_settings
#     Returns
#     -------
#     float
#         exact (SWIR) pixel exposure time
#     """
#     return 1.25e-6 * (65540 - int_delay + int_hold)


from datetime import datetime, timedelta
from pathlib import Path, PurePosixPath
from setuptools_scm import get_version
from .biweight import biweight
from .swir_texp import swir_exp_time
import h5py
import numpy as np
        #
        grp = self.fid[str(PurePosixPath(msm_path, 'INSTRUMENT'))]
        instr = np.empty(grp['instrument_settings'].shape,
                         dtype=grp['instrument_settings'].dtype)
        grp['instrument_settings'].read_direct(instr)
        # for name in grp['instrument_settings'].dtype.names:
        #     instr[name][:] = grp['instrument_settings'][name]

        return instr

    def get_exposure_time(self, band=None):
        """
        Returns pixel exposure time of the measurements, which is calculated
        from the parameters 'int_delay' and 'int_hold' for SWIR.

        Parameters
        ----------
        band      :  None or {'1', '2', '3', ..., '8'}
            Select one of the band present in the product
            Default is 'None' which returns the first available band
        """
        if band is None:
            band = self.bands[0]

        instr_arr = self.get_instrument_settings(band)

        # calculate exact exposure time
        if int(band) < 7:
            return [instr['exposure_time'] for instr in instr_arr]


# 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/swir_texp.py
# def swir_exp_time(int_delay: int, int_hold: int) -> float:
#     """
#     Parameters
#     ----------
#     int_delay :  int
#       parameters int_delay from the instrument_settings
#     int_hold  :  int
#       parameters int_holt from the instrument_settings
#     Returns
#     -------
#     float
#         exact (SWIR) pixel exposure time
#     """
#     return 1.25e-6 * (65540 - int_delay + int_hold)


# Path: src/pys5p/l1b_io.py
from datetime import datetime, timedelta
from pathlib import Path, PurePosixPath
from setuptools_scm import get_version
from .biweight import biweight
from .swir_texp import swir_exp_time
import h5py
import numpy as np

        #
        grp = self.fid[str(PurePosixPath(msm_path, 'INSTRUMENT'))]
        instr = np.empty(grp['instrument_settings'].shape,
                         dtype=grp['instrument_settings'].dtype)
        grp['instrument_settings'].read_direct(instr)
        # for name in grp['instrument_settings'].dtype.names:
        #     instr[name][:] = grp['instrument_settings'][name]

        return instr

    def get_exposure_time(self, band=None):
        """
        Returns pixel exposure time of the measurements, which is calculated
        from the parameters 'int_delay' and 'int_hold' for SWIR.

        Parameters
        ----------
        band      :  None or {'1', '2', '3', ..., '8'}
            Select one of the band present in the product
            Default is 'None' which returns the first available band
        """
        if band is None:
            band = self.bands[0]

        instr_arr = self.get_instrument_settings(band)

        # calculate exact exposure time
        if int(band) < 7:
            return [instr['exposure_time'] for instr in instr_arr]


        return [swir_exp_time(instr['int_delay'], instr['int_hold'])