gnomon.utils documentation

gnomonPlugin module

exception gnomon.utils.gnomonPlugin.InterruptProcess(*args)
__init__(*args)
gnomon.utils.gnomonPlugin.load_plugin_group(group_name: str)

Load a plugin group by importing the module of every entry point in the group

Parameters

group_name (str) – Entry point group

gnomon.utils.gnomonPlugin.available_plugins(group_name: str) list[str]

Return the name of every entry point registered in the group (group_name)

Parameters

group_name (str) – plugin group

Returns

list of the plugin names in the plugin group (keys of the related factory)

Return type

list[str]

gnomon.utils.gnomonPlugin.plugin_metadata(group_name: str, plugin_name: str) dict[str, str]

Returns a dict of metadata regarding the plugin and its package.

Package information:
  • package: the name of the package (in conda for instance as it may differ from the import statement)

  • conda_channel: channel from which to pull this package

Parameters
  • group_name (str) – Name of the plugin group (or entry_point group)

  • plugin_name (str) – Name of the plugin

Return type

Returns a dictionary of string to string containing metadata regarding the plugin and the package.

gnomon.utils.gnomonPlugin.default_input_accessors(algo_class, form_class: type) tuple[str, str]

Returns the default accessors for an input of type form_class from algo_class.

Requires algo_class to define the static methods:

defaultGetter(form_class.__name__)

defaultSetter(form_class.__name__)

Parameters
  • algo_class (gnomon.core.gnomonAbstractAlgorithm) – base class of the plugin which must implement two static methods defaultGetter(form_class.__name__) and defaultSetter(form_class.__name__)

  • form_class (gnomon.core.gnomonAbstractForm) – type of the form for those accessors

Return type

tuple[str, str]

gnomon.utils.gnomonPlugin.default_output_accessors(algo_class, form_class) str

Returns the default getter for an output of type form_class from algo_class.

Requires algo_class to define the static methods:

defaultOutput(form_class.__name__)

Parameters
  • algo_class (gnomon.core.gnomonAbstractAlgorithm) – base class of the plugin which must implement two static methods defaultOutput(form_class.__name__)

  • form_class (gnomon.core.gnomonAbstractForm) – type of the form for those accessors

Return type

str

gnomon.utils.gnomonPlugin.register_input(cls: type, attribute: str)

Register attribute of cls as input storage for cleaning later.

Parameters
  • cls (type) –

  • attribute (str) –

gnomon.utils.gnomonPlugin.register_output(cls: type, attribute: str)

Register attribute of cls as output storage for cleaning later.

Parameters
  • cls (type) –

  • attribute (str) –

gnomon.utils.gnomonPlugin.gnomon_declare_plugins(path: str) dict[str, list[str]]

Returns the entry_points dict used to declare the plugins in plugin groups.

Pre-defines setuptools entry_points by parsing every python file in path (recursively) scanning for the class name and the base class to generate the correct entry point.

Parsing as follows: class [class name](gnomonAbstract[base class]) where [base class] is the entry_points group and [class name] the entry_point name.

The entry_point exposes the module.

Parameters

path (str) – path where to scan the modules for entry_points (usually package root)

Return type

entry_points dict used to declare the plugins in setuptools

gnomon.utils.gnomonPlugin.gnomonParametric(cls)

Class decorator: implements methods and special methods related to dtkCoreParameter use.

Those methods access dtkCoreParameter (cross-parameters) which are stored in the dict attribute _parameters mapping keys to dtkCoreParameter.

Implements:

special methods __setitem__ and __getitem__ to set and get values to and from parameters

setParameter(self, parameter_name, parameter_value)

sets parameter_value to self._parameters[parameter_name]

setParameters(self, params)

params is a dict of (parameter_name, parameter_value) and setParameters sets the value of each self._parameters[parameter_name] to parameter_value. parameter_name must already be a key of self._parameters

parameters(self)

returns a copy of _parameters

parameterDict(self)

returns a dict of (parameter_name, parameter_value)

parameterGroups(self)

used the hidden attribute _parameter_groups to define a map that associates parameter names to a group name. By default, the group name “” is assigned to all parameters

Return type

decorated class

gnomon.utils.gnomonPlugin.serialize(attr)

Decorator which implements a ‘serialize’ and ‘deserialize’ method.

‘serialize’ serializes attribute attr with pickle and then encodes it in base64 ‘deserialize’ does the inverse operation

Parameters

attr (str) – name of the attribute that will be serialized

Return type

class with a ‘serialize’ and ‘deserialize’ method implemented

gnomon.utils.gnomonPlugin.seriesReader(form_attr: str, path_attr: str = 'path')

Decorator for Reader plugins which enables the use of the series container format.

Wraps the run method to extract and read the forms from the container when a .zip file is selected.

The decorated plugin must have a run method which can read multiple files (string of comma-seperated paths).

Parameters
  • form_attr (str) – Name of the form attribute where the form read are stored.

  • path_attr (str) – Name of the attribute containing the path to be read.

Returns

Decorated plugin

Return type

Class

gnomon.utils.gnomonPlugin.seriesWriter(form_attr: str, path_attr: str = 'path')

Decorator for Writer plugins which enables the use of the series container format.

Wraps the run method to write each frame of a form series in a .zip container as well as saving the timestamps. Only applies for series of more than one frame (timestamp).

The decorated plugin must have a run method which can write a file.

Parameters
  • form_attr (str) – Name of the form attribute where the form_series written to the disk is stored.

  • path_attr (str) – Name of the attribute containing the path where to write.

Returns

Decorated plugin

Return type

Class

gnomon.utils.gnomonPlugin.formDataPlugin(version: str, coreversion: str, data_setter: str, data_getter: str, name: str = '', base_class=None)

Registers form data plugins to the plugin factory.

Must be the top decorator as it will wrap every method of the class to suppress errors. Error suppression can be deactivated by setting gnomon.utils.gnomonPlugin.DEBUG to True.

A form data plugin is a class which implements a subclass of gnomon.core.gnomonAbstractFormData

Parameters
  • version (str) – Version of the plugin.

  • coreversion (str) – Exact version of gnomon to check for API compatibility.

  • data_setter (str) – Name of the setter method which sets the data attribute (where the data is internally stored). The setter must take only one argument of the type of the data attribute. For instance, if the data attribute is a numpy array, then the prototype of the data_setter method must be def data_setter(self, arr: np.ndarray) -> None:

  • data_getter (str) – Name of the getter method which returns a reference to the data attribute. The getter takes no arguments and returns (a reference to) the data attribute.

  • base_class

  • name (str) –

gnomon.utils.gnomonPlugin.algorithmPlugin(version: str, coreversion: str, name: str = '', base_class=None)

Registers algorithm plugins to the plugin factory.

Must be the top decorator as it will wrap every method of the class to suppress errors. Error suppression can be deactivated by setting gnomon.utils.gnomonPlugin.DEBUG to True.

A form data plugin is a class which implements a subclass of gnomon.core.gnomonAbstractAlgorithm

Applies the gnomonParametric decorator:

Implements methods and special methods related to dtkCoreParameter use. Those methods access dtkCoreParameter (cross-parameters) which are stored in the dict attribute _parameters mapping keys to dtkCoreParameter.

Implements:

special methods __setitem__ and __getitem__ to set and get values to and from parameters

setParameter(self, parameter_name, parameter_value)

sets parameter_value to self._parameters[parameter_name]

setParameters(self, params)

params is a dict of (parameter_name, parameter_value) and setParameters sets the value of each self._parameters[parameter_name] to parameter_value. parameter_name must already be a key of self._parameters

parameters(self)

returns a copy of _parameters

parameterDict(self)

returns a dict of (parameter_name, parameter_value)

Parameters
  • version (str) – Version of the plugin.

  • coreversion (str) – Exact version of gnomon to check for API compatibility.

  • base_class

  • name (str) –

gnomon.utils.gnomonPlugin.modelPlugin(version: str, coreversion: str, name: str = '', base_class=None)

Registers model plugins to the plugin factory.

Must be the top decorator as it will wrap every method of the class to suppress errors. Error suppression can be deactivated by setting gnomon.utils.gnomonPlugin.DEBUG to True.

Applies the gnomonParametric decorator:

Implements methods and special methods related to dtkCoreParameter use. Those methods access dtkCoreParameter (cross-parameters) which are stored in the dict attribute _parameters mapping keys to dtkCoreParameter.

Implements:

special methods __setitem__ and __getitem__ to set and get values to and from parameters

setParameter(self, parameter_name, parameter_value)

sets parameter_value to self._parameters[parameter_name]

setParameters(self, params)

params is a dict of (parameter_name, parameter_value) and setParameters sets the value of each self._parameters[parameter_name] to parameter_value. parameter_name must already be a key of self._parameters

parameters(self)

returns a copy of _parameters

parameterDict(self)

returns a dict of (parameter_name, parameter_value)

Parameters
  • version (str) – Version of the plugin.

  • coreversion (str) – Exact version of gnomon to check for API compatibility.

  • base_class

  • name (str) –

gnomon.utils.gnomonPlugin.visualizationPlugin(version: str, coreversion: str, name='', base_class=None)

Registers visualization plugins to the plugin factory.

Must be the top decorator as it will wrap every method of the class to suppress errors. Error suppression can be deactivated by setting gnomon.utils.gnomonPlugin.DEBUG to True.

A form data plugin is a class which implements a subclass of either gnomon.visualization.gnomonAbstractVisualization or gnomon.visualization.gnomonAbstractMatplotlibVisualization

Applies the gnomonParametric decorator:

Implements methods and special methods related to dtkCoreParameter use. Those methods access dtkCoreParameter (cross-parameters) which are stored in the dict attribute _parameters mapping keys to dtkCoreParameter.

Implements:

special methods __setitem__ and __getitem__ to set and get values to and from parameters

setParameter(self, parameter_name, parameter_value)

sets parameter_value to self._parameters[parameter_name]

setParameters(self, params)

params is a dict of (parameter_name, parameter_value) and setParameters sets the value of each self._parameters[parameter_name] to parameter_value. parameter_name must already be a key of self._parameters

parameters(self)

returns a copy of _parameters

parameterDict(self)

returns a dict of (parameter_name, parameter_value)

Parameters
  • version (str) – Version of the plugin.

  • coreversion (str) – Exact version of gnomon to check for API compatibility.

  • name (str) – Name of the plugin. Used for the UI

  • base_class