Skip to content

Commit

Permalink
feat(SineGeneratorAgent): added default sine generator agent to metro…
Browse files Browse the repository at this point in the history
…logical_agents.py
  • Loading branch information
anupam-prasad committed Mar 29, 2021
1 parent d0ab29a commit 54f4035
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
51 changes: 50 additions & 1 deletion agentMET4FOF/metrological_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
from time_series_buffer import TimeSeriesBuffer
from time_series_metadata.scheme import MetaData
from agentMET4FOF.agents import AgentMET4FOF
from .metrological_streams import (
MetrologicalDataStreamMET4FOF,
MetrologicalSineGenerator,
)


class MetrologicalAgent(AgentMET4FOF):
Expand Down Expand Up @@ -120,7 +124,6 @@ def init_parameters(self, *args, **kwargs):
self.plots = {}
self.custom_plot_parameters = {}


def on_received_message(self, message):
"""
Handles incoming data from 'default' and 'plot' channels.
Expand Down Expand Up @@ -198,3 +201,49 @@ def custom_plot_function(self, data, sender_agent, **kwargs):
else:
trace = go.Scatter()
return trace

class MetrologicalSineGeneratorAgent(MetrologicalAgent):
"""An agent streaming a sine signal
Takes samples from an instance of :py:class:`MetrologicalSineGenerator` with sampling frequency `sfreq` and
signal frequency `sine_freq` and pushes them sample by sample to connected agents via its output channel.
"""

# The datatype of the stream will be MetrologicalSineGenerator.
_stream: MetrologicalDataStreamMET4FOF

def init_parameters(
self,
signal: MetrologicalDataStreamMET4FOF = MetrologicalSineGenerator(),
**kwargs
):
"""Initialize the input data stream
Parameters
----------
sine_freq : float
the frequency of the
sfreq : int
the sampling frequency of the generated signal
value_unc : iterable of floats or float, optional
standard uncertainty(ies) of the quantity values. Defaults to 0.1.
time_unc : iterable of floats or float, optional
standard uncertainty of the time stamps. Defaults to 0.
"""
self._stream = signal
super().init_parameters()
self.set_output_data(channel="default", metadata=self._stream.metadata)

@property
def device_id(self):
return self._stream.metadata.metadata["device_id"]

def agent_loop(self):
"""Model the agent's behaviour
On state *Running* the agent will extract sample by sample the input
datastream's content and push it into its output buffer.
"""
if self.current_state == "Running":
self.set_output_data(channel="default", data=self._stream.next_sample())
super().agent_loop()
2 changes: 1 addition & 1 deletion agentMET4FOF/metrological_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class MetrologicalSineGenerator(MetrologicalDataStreamMET4FOF):
the corresponding attribute of the created :class:`Metadata` object. Defaults to
'Simple sine wave generator'.
value_unc : iterable of floats or float, optional
standard uncertainty(ies) of the quantity values. Defaults to 0.5.
standard uncertainty(ies) of the quantity values. Defaults to 0.1.
time_unc : iterable of floats or float, optional
standard uncertainty of the time stamps. Defaults to 0.
"""
Expand Down

0 comments on commit 54f4035

Please sign in to comment.