Parameter#

class pydidas.core.Parameter(refkey: str, param_type: None | Type, default: object, meta: None | dict = None, **kwargs: dict)#

Bases: object

A class used for storing a value and associated metadata.

The Parameter has the following properties which can be accessed. Only the value and choices properties can be edited at runtime, all other properties are fixed at instantiation.

property

editable

description

refkey

False

A reference key for the Parameter. This key is used for accessing the Parameter in the ParameterCollection

dtype

False

The datatype of the Parameter value. This must be a base class or None. If None, no type-checking is performed.

value

True

The current value.

choices

True

A list with choices if the value of the parameter is limited to specific values.

name

False

A readable name as description.

unit

False

The unit of the Parameter value.

optional

False

A flag whether the parameter is required or optional.

allow_None

False

A flag whether “None” is accepted as Parameter value.

tooltip

False

A readable tooltip.

default

False

The default value.

subtype

False

For Iterable datatypes, a subtype can be defined to determine the data type inside the iterating object, e.g. a list of int.

Parameters can be passed either as a complete meta_dict or as individual keyword arguments. The meta_dict will take precedence.

Parameters:
  • refkey (str) – The reference key for the Parameter in the Parameter collection. If not specified, this will default to the name.

  • param_type (Union[None, type]) – The datatype of the parameter. If None, no type-checking will be performed. If any integer or float value is used, this will be changed to the abstract base class of numbers.Integral or numbers.Real.

  • default (Union[None, type]) – The default value. The data type must be of the same type as param_type. None is only accepted if param_type is None as well.

  • meta (Union[dict, None], optional) – A dictionary with metadata. Any keys specified as meta will overwrite the kwargs dictionary. This is added merely as convenience to facility copying Parameter instances. If None, this entry will be ignored. The default is None.

  • **kwargs (dict) –

    Additional keyword arguments. Supported argument

    namestr, optional

    The name of the parameter. The default is None.

    subtypeOptional[type]

    For Iterable datatypes, a subtype can be defined to determine the data type inside the iterating object, e.g. a list of int. None does not enforce type checking. The default is None.

    optionalbool, optional

    Keyword to toggle optional parameters. The default is False.

    tooltipstr, optional

    A description of the parameter. It will be automatically extended to include certain type and unit information. The default is ‘’.

    unitstr, optional

    The unit of the parameter. The default is ‘’.

    choicesUnion[list, tuple, None]

    A list of allowed choices. If None, no checking will be enforced. The default is None.

    valueobject

    The value of the parameter. This parameter should only be used to restore saved parameters.

    allow_Nonebool, optional

    Keyword to allow None instead of the usual datatype. The default is False.

property allow_None: bool#

Returns the flag to allow “None” as value.

Returns:

The flag setting.

Return type:

bool

property choices: None | list#

Get or set the allowed choices for the Parameter value.

Returns:

The allowed choices for the Parameter.

Return type:

Union[list, None]

copy() Self#

A method to get a copy of the Parameter object.

Returns:

A full copy of the object.

Return type:

Parameter

deepcopy() Self#

A method to get a copy of the Parameter object.

Returns:

A full copy of the object.

Return type:

Parameter

property default: object#

Return the default value.

Returns:

The default value.

Return type:

default

property dtype: Type#

Get the data type of the Parameter value.

Returns:

The class of the parameter value data type.

Return type:

object

dump() tuple#

A method to get the full class information for saving.

Returns:

  • refkey (str) – The name of the Parameter

  • type (type) – The data type of the Parameter.

  • default (object) – The default value

  • meta (dict) – A dictionary with all the metadata information about the Parameter (value, unit, tooltip, refkey, default, choices)

export_refkey_and_value() tuple#

Export the refkey and value (in a pickleable format) for saving in YAML files.

Returns:

The tuple of (refkey, value as pickleable format)

Return type:

tuple

property name: str#

Return the parameter name.

Returns:

The parameter name.

Return type:

str

property optional: bool#

Get the flag whether the parameter is optional or not.

Returns:

The unit of the Parameter.

Return type:

bool

property refkey: str#

Return the parameter reference key.

Returns:

The parameter reference key.

Return type:

str

restore_default()#

Restore the parameter to its default value.

property tooltip: str#

Get the Parameter tooltip.

Returns:

The tooltip for the Parameter.

Return type:

str

property unit: str#

Get the Parameter unit.

Returns:

The unit of the Parameter.

Return type:

str

update_value_and_choices(value: object, choices: Iterable[object, ...])#

Update the value and choices of the Parameter to prevent illegal selections.

Parameters:
  • value (object) – The new Parameter values

  • choices (Iterable[object, ...]) – The new choices for the Parameter.

property value: object#

Get the Parameter value.

Returns:

The value of the parameter.

Return type:

value

property value_for_export: object#

Get the value in a pickleable format for exporting.

Note that this method does not work with Parameters without a defined data type.

Returns:

The Parameter value in a pickleable format.

Return type:

object