Updated observers and Kalman Filter, added running average

This commit is contained in:
dario
2024-04-19 10:52:34 +02:00
parent 8b80a6d9d5
commit 475270e1a1
21 changed files with 20865 additions and 3544 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, List, Dict, AnyStr
from typing import Any, List, Dict, AnyStr, Tuple
from numpy.typing import ArrayLike
from spatz.dataset import Dataset
@@ -7,7 +7,7 @@ from spatz.transforms import Transform
class Observer:
def __init__(self, dataset: Dataset, logger: Logger, attributes: List[str]):
def __init__(self, dataset: Dataset, logger: Logger, attributes: List[str] = None):
self._dataset = dataset
self._logger = logger
self.__attrs = attributes
@@ -30,11 +30,22 @@ class Observer:
ArrayLike: Returns the values of the observed attributes at the start of the simulation.
"""
return self(t=self._dataset.get_start_time())
def _fetch(self, t: float) -> Tuple[ArrayLike, List[str]]:
"""Method for collecting and preprocessing the desired data. Can be overwritten by a subclass.
Args:
t (float): The current time of the simulation.
Returns:
ArrayLike: The collected values.
"""
return self._dataset.fetch_values(self.__attrs, t), self.__attrs
def __call__(self, t: float | None = None) -> ArrayLike:
data = self._dataset.fetch_values(self.__attrs, t)
data, attrs = self._fetch(t)
for attrib, value in zip(self.__attrs, data):
for attrib, value in zip(attrs, data):
self._log(attrib, value)
return data