Skip to content

Commit

Permalink
feat(MET4FoF redundancy): met4fof redundancy modules added
Browse files Browse the repository at this point in the history
  • Loading branch information
anupam-prasad committed Mar 15, 2021
1 parent 7b0bf4e commit bb3cb6a
Show file tree
Hide file tree
Showing 5 changed files with 923 additions and 24 deletions.
12 changes: 1 addition & 11 deletions agentMET4FOF/metrological_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,14 @@
import plotly.graph_objs as go
from time_series_buffer import TimeSeriesBuffer
from time_series_metadata.scheme import MetaData
import numpy as np
from agentMET4FOF.agents import AgentMET4FOF


class MetrologicalAgent(AgentMET4FOF):
# dict like {
# <from>: {
# "buffer": TimeSeriesBuffer(maxlen=buffer_size),
# "metadata": MetaData(**kwargs).metadata,
# }

_input_data: Dict[str, Dict[str, Union[TimeSeriesBuffer, Dict]]]
_input_data_maxlen: int

# dict like {
# <channel> : {
# "buffer" : TimeSeriesBuffer(maxlen=buffer_size),
# "metadata" : MetaData(**kwargs)
# }
_output_data: Dict[str, Dict[str, Union[TimeSeriesBuffer, MetaData]]]
_output_data_maxlen: int

Expand Down
26 changes: 13 additions & 13 deletions agentMET4FOF/metrological_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def set_generator_function(
if uncertainty_generator is None:
warnings.warn(
"No uncertainty generator function specified. Setting to default ("
"zero)."
"constant)."
)
self._generator_function_unc = self._default_uncertainty_generator
else:
Expand Down Expand Up @@ -276,8 +276,6 @@ class MetrologicalMultiWaveGenerator(MetrologicalDataStreamMET4FOF):
array with amplitudes of components included in the signal
phase_ini_arr: np.ndarray of float
array with initial phases of components included in the signal
exp_unc_abs: float
absolute expanded uncertainty of each data point of the signal
"""

def __init__(
Expand All @@ -287,15 +285,15 @@ def __init__(
ampl_arr: np.array = np.array([1]),
phase_ini_arr: np.array = np.array([0]),
intercept: float = 0,
exp_unc_abs: float = 0.1,
device_id: str = "DataGenerator",
time_name: str = "time",
time_unit: str = "s",
quantity_names: Union[str, Tuple[str, ...]] = ("Length", "Mass"),
quantity_units: Union[str, Tuple[str, ...]] = ("m", "kg"),
misc: Optional[Any] = "data generator",
misc: Optional[Any] = " Generator for a linear sum of cosines",
value_unc: Union[float, Iterable[float]] = 0.1,
time_unc: Union[float, Iterable[float]] = 0,
noisy: bool = True
):
super(MetrologicalMultiWaveGenerator, self).__init__(
value_unc=value_unc, time_unc=time_unc
Expand All @@ -308,24 +306,26 @@ def __init__(
quantity_units=quantity_units,
misc=misc
)
self.value_unc = value_unc
self.time_unc = time_unc
self.set_generator_function(
generator_function=self._multi_wave_function,
sfreq=sfreq,
intercept=intercept,
freq_arr=freq_arr,
ampl_arr=ampl_arr,
phase_ini_arr=phase_ini_arr,
exp_unc_abs=exp_unc_abs
noisy=noisy
)

def _multi_wave_function(self, time_arr, intercept, freq_arr, ampl_arr,
phase_ini_arr, exp_unc_abs=0.1):
def _multi_wave_function(self, time, intercept, freq_arr, ampl_arr,
phase_ini_arr, noisy):

value_arr = intercept + exp_unc_abs / 2 * norm.rvs(size=time_arr.shape)
value_arr = intercept
if noisy:
value_arr += self.value_unc / 2 * norm.rvs(size=time.shape)

for ampl, freq, phase_ini in zip(freq_arr, ampl_arr, phase_ini_arr):
value_arr = value_arr + ampl * np.cos(2 * np.pi * freq * time_arr + phase_ini)

value_expunc_arr = exp_unc_abs * np.ones_like(value_arr)
value_arr = value_arr + ampl * np.cos(2 * np.pi * freq * time + phase_ini)

return value_arr, value_expunc_arr
return value_arr
Empty file.
Loading

0 comments on commit bb3cb6a

Please sign in to comment.