mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/SPATZ.git
synced 2025-12-16 17:28:04 +00:00
Added observers for tracking data
This commit is contained in:
@@ -8,6 +8,7 @@ from spatz.sensors import Sensor
|
||||
from spatz.dataset import Dataset
|
||||
from spatz.logger import Logger
|
||||
from spatz.sensors import Sensor
|
||||
from spatz.observer import Observer
|
||||
|
||||
|
||||
class UniformTimeSteps:
|
||||
@@ -89,11 +90,34 @@ class Simulation:
|
||||
return self
|
||||
|
||||
def add_sensor(self, sensor, *args, **kwargs) -> Sensor:
|
||||
"""Register a new sensor for this simulation. A registered sensor can be called like a function and returns
|
||||
the current measurements. The class' constructor arguments have to be given aswell.
|
||||
|
||||
Args:
|
||||
sensor (_type_): A subclass of the abstract Sensor class.
|
||||
|
||||
Returns:
|
||||
Sensor: Returns an object of the provided sensor subclass.
|
||||
"""
|
||||
assert issubclass(sensor, Sensor), "Expected a subclass of Sensor."
|
||||
|
||||
self.__sensors.append(sensor(self.__dataset, self.__logger, *args, **kwargs))
|
||||
|
||||
return self.__sensors[-1]
|
||||
|
||||
|
||||
def add_observer(self, attributes: List[str]) -> Observer:
|
||||
"""Register a new observer for this simulation observing the provided attributes.
|
||||
|
||||
Args:
|
||||
attributes (List[str]): A list of strings describing the attributes to observe.
|
||||
|
||||
Returns:
|
||||
Observer: An observer object which can be called like a function to obtain the desired data.
|
||||
"""
|
||||
assert len(attributes) != 0, "Observed attributes list must be nonempty."
|
||||
|
||||
self.__sensors.append(Observer(self.__dataset, self.__logger, attributes))
|
||||
|
||||
return self.__sensors[-1]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user