exporter

class sysdynpy.exporter.Exporter[source]

Bases: abc.ABC

An abstract class that can be used to export simulation results to different formats.

__init__()

Initialize self. See help(type(self)) for accurate signature.

classmethod _check_file_format(file_format)[source]

Checks if the given file format is supported.

Parameters

file_format (str) – file format to check

Raises

ValueError – If the file format is not supported

classmethod _prepare_export(results, file_format, system_elements, rel_path)[source]

Prepares the export.

Contains actions that have to be done regardless of export format. These actions include:

  • check if file format is supported

  • check if given system elements are in results

  • filter results to only contain given system elements

  • join the given relative path to the location the script is executed from

All these actions are done in separate methods.

Parameters
  • file_format (str) – One of the file formats in _supported_formats

  • results (dict, see get_simulation_results() for more details.) – The result of the simulation

  • system_elements (list of strings) – Names of the system elements to export data for.

  • rel_path (str) –

    The path where to store the exported file (including the filename). Relative to the current working directory. Can include the file format. If it is not included it will be appended. Make sure the folder already exists, it will not be created. Defaults to “./results”.

    Examples:

    .\\path\\to\\file.csv
    ./path/to/file.json
    ..\\path\\to\\file.json
    ../path/to/file

Returns

A tuple with two elements:

  • the joined, absolute output path

  • a filtered version of the result dictionary, including only the

    system elements to export

Return type

(str, dict)

classmethod export_data(results, file_format, system_elements, rel_path='./results')[source]

Saves the simulation results to the file system.

rel path: .somepath ./somepath somepath ../somepath ..somepath

Parameters
  • results (dict, see get_simulation_results() for more details.) – The result of the simulation

  • file_format (str) – ‘csv’ or ‘json’

  • system_elements (list of strings) – Names of the system elements to export data for.

  • rel_path (str) –

    The path where to store the exported file (including the filename). Relative to the current working directory. Can include the file format. If it is not included it will be appended. Make sure the folder already exists, it will not be created. Defaults to “./results”.

    Examples:

    .\\path\\to\\file.csv
    ./path/to/file.json
    ..\\path\\to\\file.json
    ../path/to/file

classmethod export_graph(results, file_format, system_elements, range_x, range_y, colors, title='', label_x='', label_y='', line_width=1, legend_pos='upper left', rel_path='./results')[source]

Creates a diagram from the simulation results and saves it to the file system.

Many arguments get piped through to Matplotlib. See the Documentation for details. This method serves as a quick way to create a graph, but is fairly limited in its options. Use the Matplotlib API directly if you need more customization.

Parameters
  • results (dict, see get_simulation_results() for more details.) – The result of the simulation

  • file_format (str) – ‘jpg’ or ‘png’

  • system_elements (list of strings) – Names of the system elements to export data for.

  • range_y (list of integers) – Matplotlib parameter. Defines the range of the y-axis. List with two integers. The first is the lower boundary, the second is the upper boundary.

  • colors (list of strings.) – Matplotlib parameter. Colors to use for the trajectories. Each color corresponds to the system element at the same index.

  • title (str) – Matplotlib parameter. Headline of the plot, defaults to “”

  • label_x (str) – Matplotlib parameter. Label for the x-axis, defaults to “”

  • label_y (str) – Matplotlib parameter. Label for the y-axis, defaults to “”

  • line_width (float) – Matplotlib parameter. Width of the trajectories, defaults to 1

  • legend_pos (str) – Matplotlib parameter. Position of the legend in the canvas, defaults to “upper left”

  • rel_path (str) –

    The path where to store the exported file (including the filename). Relative to the current working directory. Can include the file format. If it is not included it will be appended. Make sure the folder already exists, it will not be created. Defaults to “./results”.

    Examples:

    .\\path\\to\\file.csv
    ./path/to/file.json
    ..\\path\\to\\file.json
    ../path/to/file

_abc_impl = <_abc_data object>
_supported_formats = ['csv', 'json', 'jpg', 'png']

A list of supported file formats. Used internally to validate a given input format.

sysdynpy.exporter._check_if_system_elements_in_results(results, system_elements)[source]

Checks if the given system elements are included in the result dictionary.

Parameters
  • results (dict) – The dictionary with simulation results.

  • system_elements (list of strings) – List of system element names

Raises

ValueError – If any of the system element names in not in the simulation results.

sysdynpy.exporter._create_abs_output_path(rel_path, file_format)[source]

Joins the current working directory with the relative path.

Parameters
  • rel_path (str) –

    The path to join.

    Examples:

    .\\path\\to\\file.csv
    ./path/to/file.json
    ..\\path\\to\\file.json
    ../path/to/file

  • file_format (str) – The file format to append to the path.

Returns

The joined, absolute path

Return type

str

sysdynpy.exporter._filter_results(results, system_elements)[source]

Filters the simulation results to only include certain system elements.

Parameters
  • results (dict) – The simulation results

  • system_elements (list of strings) – List of system element names to keep

Returns

The filtered results

Return type

dict