-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(streams): refactor streams.py into a package streams with th…
…e modules base_streams and signal_streams
- Loading branch information
1 parent
1314d46
commit 11368ee
Showing
5 changed files
with
62 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |