agentMET4FOF streams

class agentMET4FOF.streams.CosineGenerator(sfreq=500, F=5)[source]

Built-in class of cosine wave generator. sfreq is sampling frequency which determines the time step when next_sample is called F is frequency of wave function 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 F).to be supplied to the set_generator_function

class agentMET4FOF.streams.DataStreamMET4FOF[source]

Abstract class for creating datastreams.

Data can be fetched sequentially using next_sample() or all at once all_samples(). This increments the internal sample index sample_idx.

For sensors data, we assume: The format shape for 2D data stream (timesteps, n_sensors) The format shape for 3D data stream (num_cycles, timesteps , n_sensors)

To create a new DataStreamMET4FOF class, inherit this class and call set_metadata in the constructor. Choose one of two types of datastreams to be created: from dataset file (set_data_source), or a waveform generator function (set_generator_function). Alternatively, override the next_sample function if neither option suits the application. For generator functions, sfreq is a required variable to be set on init which sets the sampling frequency and the time-step which occurs when next_sample() is called.

For an example implementation of using generator function, see the built-in SineGenerator class. See tutorials for more implementations.

all_samples()[source]

Returns all the samples in the data stream

Returns:samples
Return type:dict of the form {‘x’: current_sample_x, ‘y’: current_sample_y}
next_sample(batch_size=1)[source]

Fetches the latest batch_size samples from the iterables: quantities, time and target. This advances the internal pointer current_idx by batch_size.

Parameters:batch_size (int) – number of batches to get from data stream
Returns:
  • samples (dict of the form `{‘time’:current_sample_time,’quantities’:)
  • current_sample_quantities, ‘target’ (current_sample_target}`)
set_data_source(quantities=None, target=None, time=None)[source]

This sets the data source by providing three iterables: quantities , time and target which are assumed to be aligned.

For sensors data, we assume: The format shape for 2D data stream (timesteps, n_sensors) The format shape for 3D data stream (num_cycles, timesteps , n_sensors)

Parameters:
  • quantities (iterable) – Measured quantities such as sensors readings.
  • target (iterable) – (Optional) Target label in the context of machine learning. This can be Remaining Useful Life in predictive maintenance application. Note this can be an unobservable variable in real-time and applies only for validation during offline analysis.
  • time (iterable) – (Optional) dtype can be either float or datetime64 to indicate the time when the quantities were measured.
set_data_source_type(dt_type='function')[source]

To explicitly account for the type of data source: either from dataset, or a generator function.

Parameters:dt_type (str) – Either “function” or “dataset”
set_generator_function(generator_function=None, sfreq=None, **kwargs)[source]

Sets the data source to a generator function. By default, this function resorts to a sine wave generator function. Initialisation of the generator’s parameters should be done here such as setting the sampling frequency and wave frequency. For setting it with a dataset instead, see set_data_source.

Parameters:
  • generator_function (method) – A generator function which takes in at least one argument time which will be used in next_sample. Parameters of the function can be fixed by providing additional arguments such as the wave frequency.
  • sfreq (int) – Sampling frequency.
  • **kwargs – Any additional keyword arguments to be supplied to the generator function. The **kwargs will be saved as generator_parameters. The generator function call for every sample will be supplied with the **generator_parameters.
class agentMET4FOF.streams.SineGenerator(sfreq=500, F=5)[source]

Built-in class of sine wave generator. sfreq is sampling frequency which determines the time step when next_sample is called F is frequency of wave function 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 set_generator_function

agentMET4FOF.streams.extract_x_y(message)[source]
Extracts features & target from message[‘data’] with expected structure such as :
  1. tuple - (x,y)
  2. dict - {‘x’:x_data,’y’:y_data}

Handle data structures of dictionary to extract features & target