Results

class sim_explorer.case.Results(case: Case | str | Path | None = None, file: str | Path | None = None)

Bases: object

Manage the results of a case.

  • Collect results when a case is run

  • Save case results as Json5 file

  • Read results from file and work with them

Parameters:
  • case (Case,str,Path) – The case object, the results relate to. When instantiating from Case (for collecting data) this shall be explicitly provided. When instantiating from stored results, this should refer to the cases definition, or the default file name <cases-name>.cases is expected.

  • file (Path,str) – The file where results are saved (as Json5). When instantiating from stored results (for working with data) this shall be explicitly provided. When instantiating from Case, this file name will be used for storing results. If “” default file name is used, if None, results are not stored.

__init__(case: Case | str | Path | None = None, file: str | Path | None = None)

Methods

__init__([case, file])

add(time, comp, typ, refs, values)

Add the results of a get action to the results dict for the case.

inspect([component, variable])

Inspect the results and return a dictionary on which data are found.

plot_time_series(comp_var[, title])

Extract the provided alias variables and plot the data found in the same plot.

retrieve(comp_var)

Retrieve from results js5-dict the variables and return (times, values).

save([jsfile])

Dump the results dict to a json5 file.

add(time: float, comp: int, typ: int, refs: int | list[int], values: tuple)

Add the results of a get action to the results dict for the case.

Parameters:
  • time (float) – the time of the results

  • component (int) – The index of the component

  • typ (int) – The data type of the variable as enumeration int

  • ref (list) – The variable reference(s) linked to this variable definition

  • values (tuple) – the values of the variable

inspect(component: str | None = None, variable: str | None = None)

Inspect the results and return a dictionary on which data are found.

Parameters:
  • component (str) – Possibility to inspect only data with respect to a given component

  • variable (str) – Possibility to inspect only data with respect to a given variable

Returns:

  • A dictionary {<component.variable> ({‘len’:#data points, ‘range’:[tMin, tMax], ‘info’:info-dict})

  • The info-dict is and element of Cases.variables. See Cases.get_case_variables() for definition.

plot_time_series(comp_var: Iterable, title: str = '')

Extract the provided alias variables and plot the data found in the same plot.

Parameters:
  • comp_var (Iterable) – Iterable of (<component-instance>,<variable>) tuples (as used in retrieve) Alternatively, the jspath syntax <component>.<variable> is also accepted

  • title (str) – optional title of the plot

retrieve(comp_var: Iterable) list

Retrieve from results js5-dict the variables and return (times, values).

Parameters:

comp_var (Iterable) – iterable of (<component-name>, <variable_name>[, element]) Alternatively, the jspath syntax <component-name>.<variable_name>[[element]] can be used as comp_var. Time is not explicitly including in comp_var A record is only included if all variable are found for a given time

Returns:

Data table (list of lists), time and one column per variable

save(jsfile: str | Path = '')

Dump the results dict to a json5 file.

Parameters:

jsfile (str|Path) – Optional possibility to change the default name (self.case.name.js5) to use for dump.