from typing import List, AnyStr
from numpy.typing import ArrayLike

from spatz.sensors import PressureSensor
from spatz.dataset import Dataset, Phase
from spatz.logger import Logger
from spatz.transforms import GaussianNoise, Transform


class MS5611_01BA03(PressureSensor):
    def __init__(self, dataset: Dataset, logger: Logger, transforms: List[Transform] = []):
        super().__init__(dataset, logger, transforms)

        # Noise model obtained by a test flight using this sensor.
        self.__pad_noise = GaussianNoise(0, 0.03)
        self.__flight_noise = GaussianNoise(0, 1.5)

    def _get_name(self) -> AnyStr:
        return 'MS5611_01BA03'

    def _sensor_specific_effects(self, x: ArrayLike | float) -> ArrayLike | float:
        t = self._dataset.get_time()

        # Transform from Pa to hPa
        x /= 1e2

        noisy = self.__pad_noise(t, x) if self._dataset.get_phase() == Phase.ONPAD else self.__flight_noise(t, x)

        # Log the noise added to the pressure measurements.
        self._logger.write('noise', noisy - x, domain=self._get_name())

        return noisy
