agentMET4FOF metrologically enabled agents¶

class agentMET4FOF.metrological_agents.MetrologicalAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]¶
_input_data = None¶

Input dictionary of all incoming data including metadata:

dict like {
    <from>: {
        "buffer": TimeSeriesBuffer(maxlen=buffer_size),
        "metadata": MetaData(**kwargs).metadata,
    }
_output_data = None¶

Output dictionary of all outgoing data including metadata:

dict like {
    <from>: {
        "buffer": TimeSeriesBuffer(maxlen=buffer_size),
        "metadata": MetaData(**kwargs).metadata,
    }
agent_loop()[source]¶

User defined method for the agent to execute for loop_wait seconds specified either in self.loop_wait or explicitly via`init_agent_loop(loop_wait)`

To start a new loop, call init_agent_loop(loop_wait) on the agent Example of usage is to check the current_state of the agent and send data periodically

init_parameters(input_data_maxlen=25, output_data_maxlen=25)[source]¶

User provided function to initialize parameters of choice.

on_received_message(message)[source]¶

User-defined method and is triggered to handle the message passed by Input.

Parameters:message (Dictionary) – The message received is in form {‘from’:agent_name, ‘data’: data, ‘senderType’: agent_class, ‘channel’:channel_name} agent_name is the name of the Input agent which sent the message data is the actual content of the message
pack_data(data, channel='default')[source]¶

Internal method to pack the data content into a dictionary before sending out.

Special case : if the data is already a message, then the from and senderType will be altered to this agent, without altering the data and channel within the message this is used for more succinct data processing and passing.

Parameters:
  • data (argument) – Data content to be packed before sending out to agents.
  • channel (str) – Key of dictionary which stores data
Returns:

Packed message data

Return type:

dict of the form {‘from’:agent_name, ‘data’: data, ‘senderType’: agent_class, ‘channel’:channel_name}.

class agentMET4FOF.metrological_agents.MetrologicalAgentBuffer(buffer_size: int = 1000)[source]¶

Buffer class which is instantiated in every metrological agent to store data

This buffer is necessary to handle multiple inputs coming from agents.

We can access the buffer like a dict with exposed functions such as .values(), .keys() and .items(). The actual dict object is stored in the attribute buffer. The list in supported_datatypes contains one more element for metrological agents, namely TimeSeriesBuffer.

_concatenate(iterable: time_series_buffer.buffer.TimeSeriesBuffer, data: Union[numpy.ndarray, list, pandas.core.frame.DataFrame], concat_axis: int = 0) → time_series_buffer.buffer.TimeSeriesBuffer[source]¶

Concatenate the given TimeSeriesBuffer with data

Add data to the TimeSeriesBuffer object.

Parameters:
  • iterable (TimeSeriesBuffer) – The current buffer to be concatenated with.
  • data (np.ndarray, DataFrame, list) – New incoming data
Returns:

the original buffer with the data appended

Return type:

TimeSeriesBuffer

convert_single_to_tsbuffer(single_data: Union[List[T], Tuple, numpy.ndarray])[source]¶

Convert common data in agentMET4FOF to TimeSeriesBuffer

Parameters:single_data (iterable of iterables (list, tuple, np.ndarrray) with shape (N, M)) –
  • M==2 (pairs): assumed to be like (time, value)
  • M==3 (triple): assumed to be like (time, value, value_unc)
  • M==4 (4-tuple): assumed to be like (time, time_unc, value, value_unc)
Returns:the new TimeSeriesBuffer object
Return type:TimeSeriesBuffer
update(agent_from: str, data: Union[Dict[KT, VT], List[T], Tuple, numpy.ndarray]) → time_series_buffer.buffer.TimeSeriesBuffer[source]¶

Overrides data in the buffer dict keyed by agent_from with value data

Parameters:
  • agent_from (str) – Name of agent sender
  • data (dict or iterable of iterables (list, tuple, np.ndarray) with shape (N, M) – the data to be stored in the metrological buffer
Returns:

the updated TimeSeriesBuffer object

Return type:

TimeSeriesBuffer

class agentMET4FOF.metrological_agents.MetrologicalMonitorAgent(name='', host=None, serializer=None, transport=None, attributes=None, backend='osbrain', mesa_model=None)[source]¶
init_parameters(*args, **kwargs)[source]¶

User provided function to initialize parameters of choice.

on_received_message(message)[source]¶

Handles incoming data from ‘default’ and ‘plot’ channels.

Stores ‘default’ data into self.memory and ‘plot’ data into self.plots

Parameters:message (dict) – Acceptable channel values are ‘default’ or ‘plot’
reset()[source]¶

This method will be called on all agents when the global reset_agents is called by the AgentNetwork and when the Reset button is clicked on the dashboard.

Method to reset the agent’s states and parameters. User can override this method to reset the specific parameters.

update_plot_memory(message)[source]¶

Updates plot figures stored in self.plots with the received message

Parameters:message (dict) – Standard message format specified by AgentMET4FOF class Message[‘data’] needs to be base64 image string and can be nested in dictionary for multiple plots Only the latest plot will be shown kept and does not keep a history of the plots.