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) None

Methods

__init__([case, file])

add(time, comp, cvar, 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: str, cvar: str, values: int | float | bool | str | Sequence[int | float | bool | str]) None

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

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

  • comp (str) – the component name

  • cvar (str) – the case variable name

  • values (TValue, Sequence[TValue]) – the value(s) to record

inspect(component: str | None = None, variable: str | None = None) dict[str, dict[str, Any]]

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[str | tuple[str, str]], title: str = '') None

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

Parameters:
  • comp_var (Iterable) – Iterable of (<component-name>, <variable_name>) 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[str | tuple[str, str]]) TDataTable

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 included in comp_var A record is only included if all variables are found for a given time

Returns:

time and one column per variable

Return type:

Data table (list of lists)

save(jsfile: str | Path = '') None

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.