modelrunner.run.results module
Classes that describe results of simulations of models
- class MockModel(parameters=None)[source]
Bases:
ModelBase
helper class to store parameter values when the original model is not present
- Parameters:
parameters (dict) – A dictionary of parameters
- class Result(model, result, *, storage=None, info=None)[source]
Bases:
object
describes the result of a single model run together with auxillary information
Besides storing the final outcome of the model in
result
, the class also stores information about the original model inmodel
, additional information ininfo
, and potentially arbitrary objects that were added during the model run instorage
.Note
The result is represented as a hierarchical structure when safed using the
storage
. The actual result is stored in the result group, whereas the model information can be found in _model group. Additional information is stored in the storage group. Thus, the fullResult
can be read usingstorage[loc]
, where loc denotes the result location. If only the actual result is needed,storage[loc + "/result"]
can be read.- Parameters:
model (
ModelBase
) – The model from which the result was obtainedresult (Any) – The actual result
storage (StorageGroup | None) – A storage containing additional data from the model run
info (dict) – Additional information for this result
- property data
direct access to the underlying state data
- classmethod from_data(model_data, result, *, model=None, storage=None, info=None)[source]
create result from data
- Parameters:
model_data (dict) – The data identifying the model
result – The actual result data
model (
ModelBase
) – The model from which the result was obtainedstorage (StorageGroup | None) – A storage containing additional data from the model run
info (dict) – Additional information for this result
- Returns:
The result object
- Return type:
- classmethod from_file(storage, loc=None, *, model=None)[source]
load object from a file
This function loads the results from a hierachical storage. It also attempts to read information about the model that was used to create this result and additional data that might have been stored in a
storage
while the model was running.- Parameters:
store (str or
zarr.Store
) – Path or instance describing the storage, which is either a file path or azarr.Storage
.loc (Location) – The location where the result is stored in the storage. This should rarely be modified.
model (
ModelBase
) – The model which lead to this resultstorage (StorageID) –
- model: ModelBase
Model that was run. This is a
MockModel
instance if details are not available- Type:
ModelBase
- result: Any
the final outcome of the model
- storage: StorageGroup | None
Storage that might contain additional information, e.g., stored during the model run
- Type:
StorageGroup
- to_file(storage, loc=None, *, mode='insert')[source]
write the results to a file
Note that this does only write the actual results but omits additional data that might have been stored in a storage that is associated with the results.
- Parameters:
storage (
StorageBase
orStorageGroup
) – The storage where the group is defined. If this is aStorageGroup
itself, loc is interpreted relative to that grouploc (str or list of str) – Denotes the location (path) of the group within the storage
mode (str or
ModeType
) – The file mode with which the storage is accessed, which determines the allowed operations. Common options are “read”, “full”, “append”, and “truncate”.
- Return type:
None
- class ResultCollection(iterable=(), /)[source]
-
represents a collection of results
- as_dataframe(*, enforce_same_model=True)[source]
create a pandas dataframe summarizing the data
- Parameters:
enforce_same_model (bool) – If True, forces all model results to derive from the same model
- property constant_parameters: dict[str, Any]
the parameters that are constant in this result collection
- Type:
- property dataframe
create a pandas dataframe summarizing the data
- filtered(**kwargs)[source]
return a subset of the results
- Parameters:
**kwargs – Specify parameter values of results that are retained
- Returns:
The filtered collection
- Return type:
ResultColelction
- classmethod from_folder(folder, pattern='*.*', model=None, *, strict=False, progress=False)[source]
create results collection from a folder
- Parameters:
folder (str) – Path to the folder that is scanned
pattern (str) – Filename pattern that is used to detect result files
model (
ModelBase
) – Base class from which models are initializedstrict (bool) – Whether to raise an exception or just emit a warning when a file cannot be read
progress (bool) – Flag indicating whether a progress bar is shown
- get(**kwargs)[source]
return a single result with the given parameters
Warning
If there are multiple results compatible with the specified parameters, only the first one is returned.
- Parameters:
**kwargs – Specify parameter values of result that is returned
- Returns:
A single result from the collection
- Return type:
- groupby(*args)[source]
group results according to the given variables
- Parameters:
*args – Specify parameters according to which the results are sorted
- Returns:
generator that allows iterating over the groups. Each iteration returns a dictionary with the current parameters and the associated
ResultCollection
.- Return type:
Iterator[tuple[dict[str, list[Any]], ResultCollection]]
- property parameters: dict[str, set[Any]]
the parameter values in this result collection
Note that parameters that are lists in the individual models are turned into tuples, so they can be handled efficiently, e.g., in sets.
- Type: