Skip to content

Commit

Permalink
refactor(streams): refactor streams.py into a package streams with th…
Browse files Browse the repository at this point in the history
…e modules base_streams and signal_streams
  • Loading branch information
BjoernLudwigPTB committed Jun 29, 2021
1 parent 1314d46 commit 11368ee
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 55 deletions.
2 changes: 1 addition & 1 deletion agentMET4FOF/agents/base_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from plotly.graph_objs import Scatter

from ..dashboard.default_network_stylesheet import default_agent_network_stylesheet
from ..streams import DataStreamMET4FOF
from ..streams.base_streams import DataStreamMET4FOF


__all__ = ["AgentMET4FOF", "MonitorAgent", "AgentNetwork", "AgentBuffer"]
Expand Down
2 changes: 1 addition & 1 deletion agentMET4FOF/agents/signal_agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .base_agents import AgentMET4FOF
from ..streams import SineGenerator
from ..streams.signal_streams import SineGenerator

__all__ = ["SineGeneratorAgent"]

Expand Down
2 changes: 2 additions & 0 deletions agentMET4FOF/streams/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .base_streams import DataStreamMET4FOF
from .signal_streams import SineGenerator, CosineGenerator
53 changes: 0 additions & 53 deletions agentMET4FOF/streams.py → agentMET4FOF/streams/base_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,59 +369,6 @@ def has_more_samples(self):


# Built-in classes with DataStreamMET4FOF
class SineGenerator(DataStreamMET4FOF):
"""
Built-in class of sine wave generator which inherits all
methods and attributes from :class:`DataStreamMET4FOF`.
:func:`sine_wave_function` is a custom defined function which has a required
keyword ``time`` as argument and any number of optional additional arguments
(e.g ``F``) to be supplied to the :meth:`.DataStreamMET4FOF.set_generator_function`.
Parameters
----------
sfreq : int
sampling frequency which determines the time step when :meth:`.next_sample`
is called
sine_freq : float
frequency of wave function
"""
def __init__(self, sfreq=500, sine_freq=50):
super().__init__()
self.set_metadata("SineGenerator","time","s",("Voltage"),("V"),"Simple sine wave generator")
self.set_generator_function(generator_function=self.sine_wave_function, sfreq=sfreq, sine_freq=sine_freq)

def sine_wave_function(self, time, sine_freq):
"""A simple sine wave generator"""
value = np.sin(2 * np.pi * sine_freq * time)
return value


class CosineGenerator(DataStreamMET4FOF):
"""
Built-in class of cosine wave generator which inherits all
methods and attributes from :class:`DataStreamMET4FOF`.
:func:`cosine_wave_function` is a custom defined function which has a required
keyword ``time`` as argument and any number of
optional additional arguments (e.g ``cosine_freq``) to be supplied to the
:meth:`.DataStreamMET4FOF.set_generator_function`.
Parameters
----------
sfreq : int
sampling frequency which determines the time step when :meth:`.next_sample`
is called
F : int
frequency of wave function
"""
def __init__(self, sfreq = 500, cosine_freq=5):
super().__init__()
self.set_metadata("CosineGenerator","time","s",("Voltage"),("V"),"Simple cosine wave generator")
self.set_generator_function(generator_function=self.cosine_wave_function, sfreq=sfreq, cosine_freq=cosine_freq)

def cosine_wave_function(self, time, cosine_freq=50):
"""A simple cosine wave generator"""
value = np.cos(2 * np.pi * cosine_freq * time)
return value


def extract_x_y(message):
Expand Down
58 changes: 58 additions & 0 deletions agentMET4FOF/streams/signal_streams.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np

from .base_streams import DataStreamMET4FOF


class SineGenerator(DataStreamMET4FOF):
"""
Built-in class of sine wave generator which inherits all
methods and attributes from :class:`DataStreamMET4FOF`.
:func:`sine_wave_function` is a custom defined function which has a required
keyword ``time`` as argument and any number of optional additional arguments
(e.g ``F``) to be supplied to the :meth:`.DataStreamMET4FOF.set_generator_function`.
Parameters
----------
sfreq : int
sampling frequency which determines the time step when :meth:`.next_sample`
is called
sine_freq : float
frequency of wave function
"""
def __init__(self, sfreq=500, sine_freq=50):
super().__init__()
self.set_metadata("SineGenerator","time","s",("Voltage"),("V"),"Simple sine wave generator")
self.set_generator_function(generator_function=self.sine_wave_function, sfreq=sfreq, sine_freq=sine_freq)

def sine_wave_function(self, time, sine_freq):
"""A simple sine wave generator"""
value = np.sin(2 * np.pi * sine_freq * time)
return value


class CosineGenerator(DataStreamMET4FOF):
"""
Built-in class of cosine wave generator which inherits all
methods and attributes from :class:`DataStreamMET4FOF`.
:func:`cosine_wave_function` is a custom defined function which has a required
keyword ``time`` as argument and any number of
optional additional arguments (e.g ``cosine_freq``) to be supplied to the
:meth:`.DataStreamMET4FOF.set_generator_function`.
Parameters
----------
sfreq : int
sampling frequency which determines the time step when :meth:`.next_sample`
is called
F : int
frequency of wave function
"""
def __init__(self, sfreq = 500, cosine_freq=5):
super().__init__()
self.set_metadata("CosineGenerator","time","s",("Voltage"),("V"),"Simple cosine wave generator")
self.set_generator_function(generator_function=self.cosine_wave_function, sfreq=sfreq, cosine_freq=cosine_freq)

def cosine_wave_function(self, time, cosine_freq=50):
"""A simple cosine wave generator"""
value = np.cos(2 * np.pi * cosine_freq * time)
return value

0 comments on commit 11368ee

Please sign in to comment.