Skip to content

Commit

Permalink
feat(MetrologicalGeneratorAgent): add an agent to handle generic metr…
Browse files Browse the repository at this point in the history
…ological data streams
  • Loading branch information
BjoernLudwigPTB committed Apr 21, 2021
2 parents b0c465f + a3ee041 commit 3334762
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 41 deletions.
4 changes: 3 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ workflows:
# decision and publish it on GitHub, Zenodo and PyPI.org. This requires manual
# approval in the previous step, which is only triggered on branch master,
# thus this job here is triggered only on master as well.
context: pypi.org publishing for agentMET4FOF
context:
- pypi.org publishing for agentMET4FOF
- GitHub pushes to BjoernLudwigPTB's public_repos
requires:
- confirm_previewed_release_actions

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ corresponding data analysis. An excellent way to represent such networks is a
multi-agent system (MAS), where independent software modules (agents) encapsulate
properties and functionalities. agentMET4FOF is an interactive and flexible open-source
implementation of such a MAS. The software engineering process is driven by several
industry-oriented use cases with the aim of impacting on IIoT applications. This leads
industry-oriented use cases with the aim of enabling IIoT applications. This leads
to a framework that is specialized in representing heterogeneous sensor networks.
</p>
<p align="justify">
A special emphasize is put on supporting metrological treatment of sensor streaming
A special emphasis is put on supporting metrological treatment of sensor streaming
data. This includes the consideration of measurement uncertainties during data analysis
and processing as well as propagating metadata alongside the data itself.
</p>
Expand Down
47 changes: 46 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,45 @@ def custom_plot_function(self, data, sender_agent, **kwargs):
else:
trace = go.Scatter()
return trace

class MetrologicalGeneratorAgent(MetrologicalAgent):
"""An agent streaming a specified signal
Takes samples from an instance of :py:class:`MetrologicalDataStreamMET4FOF
<agentMET4FOF.metrological_streams.MetrologicalDataStreamMET4FOF>` and pushes them
sample by sample to connected agents via its output channel.
"""

_stream: MetrologicalDataStreamMET4FOF

def init_parameters(
self,
signal: MetrologicalDataStreamMET4FOF = MetrologicalSineGenerator(),
**kwargs
):
"""Initialize the input data stream
Parameters
----------
signal : MetrologicalDataStreamMET4FOF, optional
the underlying signal for the generator, defaults to
:py:class:`MetrologicalSineGenerator
<agentMET4FOF.metrological_streams.MetrologicalSineGenerator>`
"""
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()
4 changes: 2 additions & 2 deletions agentMET4FOF/metrological_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,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 Expand Up @@ -303,7 +303,7 @@ def __init__(
ampl_arr: np.array = np.array([1]),
phase_ini_arr: np.array = np.array([0]),
intercept: float = 0,
device_id: str = "DataGenerator",
device_id: str = "MultiWaveDataGenerator",
time_name: str = "time",
time_unit: str = "s",
quantity_names: Union[str, Tuple[str, ...]] = ("Length", "Mass"),
Expand Down
52 changes: 28 additions & 24 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ commonmark==0.9.1
# via recommonmark
coverage==5.5
# via pytest-cov
cryptography==3.4.6
cryptography==3.4.7
# via secretstorage
decorator==4.4.2
# via
Expand All @@ -61,6 +61,7 @@ docutils==0.16
# readme-renderer
# recommonmark
# sphinx
# sphinx-rtd-theme
dotty-dict==1.3.0
# via python-semantic-release
entrypoints==0.3
Expand All @@ -69,7 +70,7 @@ filelock==3.0.12
# via
# tox
# virtualenv
gitdb==4.0.5
gitdb==4.0.7
# via gitpython
gitpython==3.1.14
# via python-semantic-release
Expand All @@ -79,8 +80,10 @@ idna==2.10
# requests
imagesize==1.2.0
# via sphinx
importlib-metadata==3.7.2
# via keyring
importlib-metadata==3.10.1
# via
# keyring
# twine
iniconfig==1.1.1
# via pytest
invoke==1.5.0
Expand All @@ -89,7 +92,7 @@ ipython-genutils==0.2.0
# via
# nbformat
# traitlets
ipython==7.21.0
ipython==7.22.0
# via -r dev-requirements.in
jedi==0.18.0
# via ipython
Expand All @@ -105,7 +108,7 @@ jinja2==2.11.3
# sphinx
jsonschema==3.2.0
# via nbformat
jupyter-client==6.1.11
jupyter-client==6.1.12
# via nbclient
jupyter-core==4.7.1
# via
Expand All @@ -114,7 +117,7 @@ jupyter-core==4.7.1
# nbformat
jupyterlab-pygments==0.1.2
# via nbconvert
keyring==23.0.0
keyring==23.0.1
# via twine
markupsafe==1.1.1
# via
Expand All @@ -126,12 +129,12 @@ nbclient==0.5.3
# via nbconvert
nbconvert==6.0.7
# via nbsphinx
nbformat==5.1.2
nbformat==5.1.3
# via
# nbclient
# nbconvert
# nbsphinx
nbsphinx==0.8.2
nbsphinx==0.8.3
# via -r dev-requirements.in
nest-asyncio==1.5.1
# via nbclient
Expand All @@ -143,7 +146,7 @@ packaging==20.9
# tox
pandocfilters==1.4.3
# via nbconvert
parso==0.8.1
parso==0.8.2
# via jedi
pexpect==4.8.0
# via ipython
Expand All @@ -155,7 +158,7 @@ pluggy==0.13.1
# via
# pytest
# tox
prompt-toolkit==3.0.17
prompt-toolkit==3.0.18
# via ipython
psutil==5.8.0
# via -r dev-requirements.in
Expand Down Expand Up @@ -184,7 +187,7 @@ pytest-cov==2.11.1
# via -r dev-requirements.in
pytest-timeout==1.4.2
# via -r dev-requirements.in
pytest==6.2.2
pytest==6.2.3
# via
# -r dev-requirements.in
# pytest-cov
Expand All @@ -193,9 +196,9 @@ python-dateutil==2.8.1
# via
# -c requirements.txt
# jupyter-client
python-gitlab==1.15.0
python-gitlab==2.6.0
# via python-semantic-release
python-semantic-release==7.15.0
python-semantic-release==7.15.3
# via -r dev-requirements.in
pytz==2021.1
# via
Expand All @@ -210,7 +213,9 @@ readme-renderer==29.0
recommonmark==0.7.1
# via -r dev-requirements.in
requests-toolbelt==0.9.1
# via twine
# via
# python-gitlab
# twine
requests==2.25.1
# via
# -c requirements.txt
Expand All @@ -226,25 +231,24 @@ secretstorage==3.3.1
# via keyring
semver==2.13.0
# via python-semantic-release
setuptools-scm==5.0.2
setuptools-scm==6.0.1
# via dotty-dict
six==1.15.0
# via
# -c requirements.txt
# bleach
# jsonschema
# python-dateutil
# python-gitlab
# readme-renderer
# tox
# virtualenv
smmap==3.0.5
smmap==4.0.0
# via gitdb
snowballstemmer==2.1.0
# via sphinx
sphinx-rtd-theme==0.5.1
sphinx-rtd-theme==0.5.2
# via -r dev-requirements.in
sphinx==3.5.2
sphinx==3.5.4
# via
# -r dev-requirements.in
# nbsphinx
Expand Down Expand Up @@ -276,7 +280,7 @@ tornado==6.1
# jupyter-client
tox==3.23.0
# via -r dev-requirements.in
tqdm==4.59.0
tqdm==4.60.0
# via
# -c requirements.txt
# twine
Expand All @@ -289,13 +293,13 @@ traitlets==5.0.5
# nbconvert
# nbformat
# nbsphinx
twine==3.3.0
twine==3.4.1
# via python-semantic-release
urllib3==1.26.3
urllib3==1.26.4
# via
# -c requirements.txt
# requests
virtualenv==20.4.2
virtualenv==20.4.3
# via tox
wcwidth==0.2.5
# via prompt-toolkit
Expand Down
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ channels:
- defaults
dependencies:
- python = 3.8
- pip
# pip dependencies have to be provided in `requirements.txt` syntax
- pip:
- -r requirements.txt
Expand Down
22 changes: 11 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ cookiecutter==1.7.2
# via mesa
cycler==0.10.0
# via matplotlib
dash-core-components==1.15.0
dash-core-components==1.16.0
# via dash
dash-cytoscape==0.2.0
# via agentMET4FOF (setup.py)
dash-html-components==1.1.2
dash-html-components==1.1.3
# via dash
dash-table==4.11.2
dash-table==4.11.3
# via dash
dash==1.19.0
dash==1.20.0
# via
# agentMET4FOF (setup.py)
# dash-cytoscape
dash_renderer==1.9.0
dash_renderer==1.9.1
# via dash
decorator==4.4.2
# via networkx
Expand Down Expand Up @@ -85,11 +85,11 @@ mpld3==0.5.2
# via agentMET4FOF (setup.py)
multiprocess==0.70.11.1
# via agentMET4FOF (setup.py)
networkx==2.5
networkx==2.5.1
# via
# agentMET4FOF (setup.py)
# mesa
numpy==1.20.1
numpy==1.20.2
# via
# agentMET4FOF (setup.py)
# matplotlib
Expand All @@ -99,7 +99,7 @@ numpy==1.20.1
# time-series-buffer
osbrain==0.6.5
# via agentMET4FOF (setup.py)
pandas==1.2.3
pandas==1.2.4
# via
# agentMET4FOF (setup.py)
# mesa
Expand Down Expand Up @@ -128,7 +128,7 @@ requests==2.25.1
# via cookiecutter
retrying==1.3.3
# via plotly
scipy==1.6.1
scipy==1.6.2
# via agentMET4FOF (setup.py)
serpent==1.30.2
# via pyro4
Expand All @@ -147,11 +147,11 @@ time-series-metadata==0.1.0
# via agentMET4FOF (setup.py)
tornado==6.1
# via mesa
tqdm==4.59.0
tqdm==4.60.0
# via mesa
uncertainties==3.1.5
# via time-series-buffer
urllib3==1.26.3
urllib3==1.26.4
# via requests
werkzeug==1.0.1
# via flask

0 comments on commit 3334762

Please sign in to comment.