diff --git a/setup.py b/setup.py index e62a821..e853348 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ with open('README.md', 'r') as f: setup( name='spatz', version='0.0.10', - packages=find_packages(exclude=["_tests"]), + packages=['spatz'], long_description=longdescription, long_description_content_type='text/markdown', ) \ No newline at end of file diff --git a/spatz/sensors/imu/bhi160.py b/spatz/sensors/imu/bhi160.py index 697fc56..ca7a3c7 100644 --- a/spatz/sensors/imu/bhi160.py +++ b/spatz/sensors/imu/bhi160.py @@ -1,10 +1,12 @@ +import numpy as np + from typing import List, AnyStr from numpy.typing import ArrayLike from spatz.dataset import ArrayLike, Dataset from spatz.logger import ArrayLike, Logger from spatz.sensors import IMU, Accelerometer, Gyroscope -from spatz.transforms import Transform +from spatz.transforms import Transform, GaussianNoise class BHI160Gyro(Gyroscope): @@ -27,8 +29,10 @@ class BHI160Acc(Accelerometer): def __init__(self, dataset: Dataset, logger: Logger, offset: float = 0, transforms: List[Transform] = []): super().__init__(dataset, logger, offset, transforms) + self.__noise = GaussianNoise(0, 0.05) + def _get_name(self) -> AnyStr: return 'BHI160' def _sensor_specific_effects(self, x: ArrayLike) -> ArrayLike: - return x + return self.__noise(0, x) \ No newline at end of file diff --git a/spatz/transforms/noise.py b/spatz/transforms/noise.py index dcb14e3..9425745 100644 --- a/spatz/transforms/noise.py +++ b/spatz/transforms/noise.py @@ -13,15 +13,25 @@ class GaussianNoise(Transform): self.__mu = mu self.__sigma = sigma - def __call__(self, t: float, x: ArrayLike) -> ArrayLike: - assert np.shape(self.__mu) == np.shape(x), "Mu and x have to match in shape." - + def __call__(self, _: float, x: ArrayLike) -> ArrayLike: if np.isscalar(x): noise = np.random.normal(0, 1) x += self.__sigma * noise + self.__mu else: + dim = len(x) + + if np.isscalar(self.__sigma): + sigma = np.identity(dim) * self.__sigma + else: + sigma = self.__sigma + + if np.isscalar(self.__mu): + mu = np.ones(dim) + else: + mu = self.__mu + noise = np.random.normal(0, 1, np.shape(x)) - x += self.__sigma @ noise + self.__mu + x += sigma @ noise + mu return x diff --git a/tests.ipynb b/tests.ipynb index 622c157..d10c2c0 100644 --- a/tests.ipynb +++ b/tests.ipynb @@ -631,7 +631,7 @@ { "data": { "text/plain": [ - "[]" + "[]" ] }, "execution_count": 13, @@ -819,7 +819,27 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7.767031884916352" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "max(np.array(acc_total) / g)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, "metadata": {}, "outputs": [ { @@ -839,7 +859,7 @@ "Name: altitude, Length: 1721, dtype: float64" ] }, - "execution_count": 16, + "execution_count": 17, "metadata": {}, "output_type": "execute_result" } @@ -850,7 +870,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 18, "metadata": {}, "outputs": [ { @@ -859,7 +879,7 @@ "19335.3982925117" ] }, - "execution_count": 17, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } @@ -870,7 +890,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 19, "metadata": {}, "outputs": [ { @@ -890,7 +910,7 @@ "Name: Time, Length: 1721, dtype: float64" ] }, - "execution_count": 18, + "execution_count": 19, "metadata": {}, "output_type": "execute_result" } @@ -901,7 +921,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [