Other core classes and functions#

The core package defines base classes used throughout the full pydidas suite.

exception pydidas.core.FileReadError#

Bases: Exception

An Exception for signalling an error in reading a file.

FileReadError can be raised if the input cannot be processed. The exception handling for FileReadError is different from the generic exception handling to allow pydidas to raise less severe Exceptions in case of missing files etc.

class pydidas.core.Hdf5key(text: str)#

Bases: str

Inherits from str.

A class used for referencing hdf5 keys.

property hdf5_filename: Path#

Get the filename of the associated hdf5 file.

Returns:

The filename of the associated hdf5 file.

Return type:

str

class pydidas.core.ParameterCollectionMixIn#

Bases: object

MixIn class with ParameterCollection convenience methods.

The ParameterCollectionMixIn class will create the generic .params attribute to be used. It will not overwrite existing params attributes.

add_param(param: Parameter)#

Add a parameter to the ParameterCollection.

This is a wrapper for the ParameterCollection.add_parameter method.

Parameters:

param (Parameter) – An instance of a Parameter object.

add_params(*params: tuple[Parameter | dict | ParameterCollection])#

Add parameters to the object.

This method adds Parameters to the ParameterCollection of the object. Parameters can be either supplies as args or a ParameterCollection or dictionary in the form of <ref_key>: <Parameter>. This method is explicitly separate from the __init__ method to allow subclasses full control over args and kwargs.

Parameters:

*params (Tuple[Union[Parameter, dict, ParameterCollection]]) – Any Parameter or ParameterCollection

classmethod get_default_params_copy() ParameterCollection#

Get a copy of the default ParameterCollection.

Returns:

A copy of the default ParameterCollection.

Return type:

ParameterCollection

get_param(param_key: str) Parameter#

Get a parameter.

Note: This method returns the Parameter itself, not a copy.

Parameters:

param_key (str) – The key name of the Parameter.

Returns:

The Parameter object.

Return type:

Parameter

get_param_keys() list[str]#

Get the keys of all registered Parameters.

Returns:

The keys of all registered Parameters.

Return type:

list

get_param_value(param_key: str, *default: object, dtype: type | None = None, for_export: bool = False) object#

Get a Parameter value.

Parameters:
  • param_key (str) – The key name of the Parameter.

  • default (object) – The default value if the param_key does not exist.

  • dtype (type, optional) – A datatype to convert the value into. If None, the native datatype is returned. The default is None.

  • for_export (bool, optional) – An optional flag to force converting the Parameter value to an export-compatible format. This flag is not compatible with a specific dtype. The default is False.

Returns:

The value of the Parameter.

Return type:

object

get_param_values_as_dict(filter_types_for_export: bool = False) dict#

Get a dictionary with Parameter names and values only.

Parameters:

filter_types_for_export (bool) – Flag to return objects in types suitable for exporting (i.e. pickleable).

Returns:

name_val_pairs – The dictionary with Parameter <name>: <value> pairs.

Return type:

dict

get_params(*param_keys: tuple[str, ...]) list[Parameter]#

Get multiple parameters based on their reference keys.

Parameters:

*param_keys (Tuple[str, ...]) – Any number of reference keys.

Returns:

A list with the Parameter instances referenced by the supplied keys.

Return type:

list

property param_keys: list[str]#

Get the keys of all stored Parameters.

Returns:

The keys of all stored Parameters.

Return type:

list[str]

property param_values: dict#

Get the values of all stored Parameters along with their refkeys.

Returns:

The refkey, value pairs for all stored Parameters.

Return type:

Dict

print_param_values()#

Print the name and value of all Parameters.

restore_all_defaults(confirm: bool = False)#

Restore the default values to all entries.

Parameters:

confirm (bool) – Confirmation flag as safety feature.

set_default_params()#

Set default entries.

This method will go through the supplied defaults iterable. If there are no entries for the Parameter keys, it will add a Parameter with default value.

set_param_value(param_key: str, value: object)#

Set a parameter value.

Parameters:
  • param_key (str) – The key name of the Parameter.

  • value (object) – The value to be set. This has to be the datatype associated with the Parameter.

set_param_values(**kwargs: dict)#

Set multiple parameter values at once.

Parameters:

**kwargs (dict) – The reference key and value pairs for all Parameters to be set.

set_param_values_from_dict(value_dict: dict)#

Set the Parameter values from a dict with name, value paris.

Parameters:

value_dict (dict) – The dictionary with the stored information.

update_param_values_from_kwargs(**kwargs: dict)#

Update the Parameter values corresponding to the given keys.

Parameters:

**kwargs (dict) – The dictionary with Parameter refkeys and values.

update_params_from_init(*args: tuple, **kwargs: dict)#

Update the Parameters from the given init args and kwargs.

Parameters:
  • *args (Tuple) – The input arguments.

  • **kwargs (Dict) – The input keyword arguments.

exception pydidas.core.PydidasConfigError#

Bases: Exception

PydidasConfigError is used to signal configuration errors.

This exception is raised when the configuration (e.g. with Parameters) cannot be processed.

exception pydidas.core.PydidasGuiError#

Bases: Exception

An Exception for handling problems in the pydidas GUI.

PydidasGuiError is used for any specific issues with the graphical user interface.

class pydidas.core.PydidasQsettings(version: str | None = None)#

Bases: PydidasQsettingsMixin

A modified version of the QSettings with some additional convenience methods.

Parameters:

version (Optional[str]) – An optional version string. If None, the pydidas version will be used. The default is None.

get_all_stored_q_settings() dict#

Get all stored QSettings values as a dictionary.

Returns:

The dict with (key: stored_value) pairs.

Return type:

dict

set_value(key: str, val: object)#

Set the value of a QSettings key.

Parameters:
  • key (str) – The name of the key.

  • val (object) – The new value stored for the key.

show_all_stored_q_settings()#

Print all stored QSettings to the standard output.

value(key: str, dtype: None | type = None) object#

Get the value from a QSetting key.

This method is a wrapper for the PydidasQsettingsMixin.q_settings_get_value method.

Parameters:
  • key (str) – The QSetting reference key.

  • dtype (Union[type, None], optional) – A return datatype. If not None, the output will be returned as dtype(value).

Returns:

value – The value, converted to the type associated with the Parameter referenced by param_key or dtype, if given.

Return type:

object

class pydidas.core.PydidasQsettingsMixin(version: str | None = None)#

Bases: object

Mix-in class with access functions to pydidas QSettings values.

This class can be inherited by any class which requires access to the global QSettings defined in pydidas.

Parameters:

version (Optional[str]) – An optional version string. The default is the pydidas version number.

q_settings_get(key: str, dtype: type | None = None, default: object | None = None) object#

Get the value from a QSetting key.

Parameters:
  • key (str) – The QSetting reference key.

  • dtype (Union[type, None], optional) – A return datatype. If not None, the output will be returned as dtype(value), otherwise, the generic string/int will be returned. The default is None.

  • default (type, optional) – The default value which is returned if the key defaults to None. The default is None.

Returns:

value – The value, converted to the type associated with the Parameter referenced by param_key or dtype, if given.

Return type:

object

q_settings_set(key: str, value: object)#

Set the value of a QSettings key.

Parameters:
  • key (str) – The name of the key.

  • value (object) – The value to be stored.

class pydidas.core.SingletonFactory(cls, **permanent_kwargs: dict)#

Bases: object

Factory to create a Singleton instance of a class.

This factory also handles QObjects and removes the instance if the corresponding QObject has been destroyed.

Parameters:
  • cls (class) – The Python class which should be managed by the SingletonFactory.

  • permanent_kwargs (dict) – Permanent kwargs which should always be used when creating the class instance.

property instance: object#

Get the instance. A wrapper for __call__

Parameters:

kwargs (dict) – Any kwargs which should be passed. Note that this is only used if no instance exists yet.

exception pydidas.core.UserConfigError#

Bases: Exception

An Exception for signalling a bad configuration by the user.

UserConfigErrors can be raised if the input cannot be processed. The exception handling for UserConfigErrors is different from the generic exception handling to allow pydidas to raise less severe Exceptions in case of configuration isues caused by the user.

pydidas.core.get_generic_param_collection(*param_keys: Iterable[str, ...]) ParameterCollection#

Get an initialized ParameterCollection from a number of generic Parameter keys.

Parameters:

*param_keys (str) – Any number of Parameter keys referenced as a generic Parameter.

Returns:

The initialized ParameterCollection with a new set of Parameters based on the supplied keys.

Return type:

pydidas.core.ParameterCollection

pydidas.core.get_generic_parameter(refkey: str) Parameter#

Create a Parameter from a refkey based on pre-defined information.

Parameters:

refkey (str) – The reference key of the generic Parameter.

Raises:

KeyError – If not description is provided for the given refkey.

Returns:

A Parameter object.

Return type:

pydidas.core.Parameter