Reporting
This module is used to report data to the disk and to extract data for visualisation. After initialization of the reporter in the model, the honeybees.report.Reporter.step()
method is called every timestep, which can obtain data from the agents, and report to disk or save the data for visualiation or writing to disk once the model is finished. The variables to be reported can be configured in the config file. All data is saved to the report folder by default.
In the configuration file you can specify which data should be reported. In this file you can configure which data should be saved from the model in the report folder. This should be formatted as follows:
- report:
- name: name of the folder to which the data is saved.
type: agent type e.g., farmer. Should be identical to attribute name in Agents class.
function: whether to use a function to parse the data. ‘null’ means the data is saved literally, ‘mean’ takes the mean etc. Options are sum/mean.
varname: attribute name of variable in agent class.
format: format to save to. Can be ‘csv’ to save to csv-file per timestep, ‘npy’ to save in NumPy binary format, or ‘npz’ to save in NumPy compressed binary format.
initial_only: if true only save the data for the first timestep.
save: save variable in model run, or export, or both (save/save+export/export).
- name2:
…
…
- …:
…
…
- class Reporter(model, folder)[source]
This class is used to report data to disk or for visualisation. The step method is called each timestep from the model.
- Parameters:
model – The model.
subfolder – Optional name of the subfolder to be reported in. By default the report folder from the configuration file is used (general:report_folder).
- check_value(value)[source]
Check whether the value is a Python integer or float, and is not infinite.
- Parameters:
value (
Any
) – The value to be checked.
- export_value(name, value, conf)[source]
Exports an array of values to the export folder.
- Parameters:
name (
str
) – Name of the value to be exported.value (
ndarray
) – The array itself.conf (
dict
) – Configuration for saving the file. Contains options such a file format, and whether to export the array in this timestep at all.
- Return type:
None
- extract_agent_data(name, conf)[source]
This method is used to extract agent data and apply the relevant function to the given data.
- Parameters:
name (
str
) – Name of the data to report.conf (
dict
) – Dictionary with report configuration for values.
- Return type:
None
- finalize()[source]
This method can be called to save the data that is currently saved in memory to disk.
- Return type:
dict
- static mean_per_ID(values, group_ids, n_groups)[source]
Calculates the mean value per group.
- Parameters:
values (
ndarray
) – Numpy array of values.group_ids (
ndarray
) – Group IDs for each value. Must be same size as values.n_groups (
int
) – The total number of groups.
- Returns:
mean_per_ID – The mean value for each of the groups.
- Return type:
ndarray
- parse_agent_data(name, values, agents, conf)[source]
This method is used to apply the relevant function to the given data.
- Parameters:
name (
str
) – Name of the data to report.values (
Any
) – Numpy array of values.agents – The relevant agent class.
conf (
dict
) – Dictionary with report configuration for values.
- Return type:
None
- report_value(name, value, conf)[source]
This method is used to save and/or export model values.
- Parameters:
name (
Union
[str
,tuple
[str
,Any
]]) – Name of the value to be exported.value (
Any
) – The array itself.conf (
dict
) – Configuration for saving the file. Contains options such a file format, and whether to export the data or save the data in the model.
- Return type:
None
- step()[source]
This method is called every timestep. First appends the current model time to the list of times for the reporter. Then iterates through the data to be reported on and calls the extract_agent_data method for each of them.
- Return type:
None
- static sum_per_ID(values, group_ids, n_groups)[source]
Calculates the sum value per group.
- Parameters:
values (
ndarray
) – Numpy array of values.group_ids (
ndarray
) – Group IDs for each value. Must be same size as values.n_groups (
int
) – The total number of groups.
- Returns:
sum_per_ID – The sum value for each of the groups.
- Return type:
ndarray