modelrunner.model.base module

Base class describing a model

class ModelBase(parameters=None, output=None, *, mode='insert', strict=False)[source]

Bases: Parameterized

base class for describing models

initialize the parameters of the object

Parameters:
  • parameters (dict) – A dictionary of parameters to change the defaults of this model. The allowed parameters can be obtained from get_parameters() or displayed by calling show_parameters().

  • output (str) – Path where the output file will be written. The output will be written using storage and might contain two groups: result to which the final result of the model is written, and data, which can contain extra information that is written using 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”.

  • strict (bool) – Flag indicating whether parameters are strictly interpreted. If True, only parameters listed in parameters_default can be set and their type will be enforced.

close()[source]

close any opened storages

Return type:

None

description: str | None = None

a longer description of the model

Type:

str

classmethod from_command_line(args=None, name=None)[source]

create model from command line parameters

Parameters:
  • args (list) – Sequence of strings corresponding to the command line arguments

  • name (str) – Name of the program, which will be shown in the command line help

Returns:

An instance of this model with appropriate parameters

Return type:

ModelBase

get_result(data=None)[source]

get the result as a Result object

Parameters:

data (Any) – The result data. If omitted, the model is run to obtain results

Returns:

The result after the model is run

Return type:

Result

name: str | None = None

the name of the model

Type:

str

classmethod run_from_command_line(args=None, name=None)[source]

run model using command line parameters

Parameters:
  • args (list) – Sequence of strings corresponding to the command line arguments

  • name (str) – Name of the program, which will be shown in the command line help

Returns:

The result of running the model

Return type:

Result

property storage: StorageGroup

Storage to which data can be written

Type:

StorageGroup

write_result(result=None)[source]

write the result to the output file

Parameters:

result (Result | None) – The result data. If omitted, the model is run to obtain results

Return type:

None