phenotypic.tools_.register package#

Registry utilities for PhenoTypic components.

Provides registration decorators and lookup functions for extensible components like plotters and dashboards.

Examples

Register a new plotter:

from phenotypic.tools\_.register import register_plotter

@register_plotter
class MyPlotter(BasePlotter):
    name = "my_plot"

    def my_plot(self, **kwargs):
        ...

Query available plotters:

from phenotypic.tools\_.register import available_plotters, get_plotter

print(available_plotters())
# ('all', 'diagnostics', 'morph_progression', ...)

plotter_cls = get_plotter("overlay")
class phenotypic.tools_.register.AnalysisPluginRegistry[source]#

Bases: BaseRegistry[BaseAnalysisPlugin]

Registry for dashboard analysis plugins.

Plugins are registered by their call_name class attribute, which is used as the HTML element ID prefix and sub-tab identifier.

classmethod available() tuple[str, ...]#

Return names of all registered components.

Returns:

Tuple of registered component names, sorted alphabetically.

Return type:

tuple[str, …]

classmethod get(name: str) type[T]#

Look up registered class by name.

Parameters:

name (str) – The registered name of the component.

Returns:

The registered class.

Raises:

ValueError – If name is not registered.

Return type:

type[T]

classmethod register(target_cls: type[T]) type[T]#

Decorator that registers a class by its call_name class attribute.

If call_name is not defined on the class, defaults to the class name.

Parameters:

target_cls (type[T]) – The class to register.

Returns:

The registered class (unchanged).

Raises:

ValueError – If a component with the same name is already registered.

Return type:

type[T]

class phenotypic.tools_.register.BaseRegistry[source]#

Bases: Generic[T]

Base class for component registries.

Subclasses define _REGISTRY dict and implement register/get/available. Registered classes may define a call_name class attribute; if not set, the class name is used as the default.

Examples

Create a custom registry:

class MyComponentRegistry(BaseRegistry["MyComponent"]):
    _REGISTRY: ClassVar[dict[str, type["MyComponent"]]] = {}
    _registry_name: ClassVar[str] = "component"

@MyComponentRegistry.register
class ConcreteComponent:
    call_name = "concrete"

# Look up by name
cls = MyComponentRegistry.get("concrete")
classmethod available() tuple[str, ...][source]#

Return names of all registered components.

Returns:

Tuple of registered component names, sorted alphabetically.

Return type:

tuple[str, …]

classmethod get(name: str) type[T][source]#

Look up registered class by name.

Parameters:

name (str) – The registered name of the component.

Returns:

The registered class.

Raises:

ValueError – If name is not registered.

Return type:

type[T]

classmethod register(target_cls: type[T]) type[T][source]#

Decorator that registers a class by its call_name class attribute.

If call_name is not defined on the class, defaults to the class name.

Parameters:

target_cls (type[T]) – The class to register.

Returns:

The registered class (unchanged).

Raises:

ValueError – If a component with the same name is already registered.

Return type:

type[T]

class phenotypic.tools_.register.DashboardRegistry[source]#

Bases: BaseRegistry

Registry for dashboard classes (duck-typed, no strict base).

Dashboards are registered by their call_name class attribute, which must match the method name used for dispatch (e.g., call_name = "detect_modes" corresponds to image.panel.detect_modes()).

Dashboards may have optional dependencies (e.g., Panel). Classes should only be registered when their dependencies are available.

classmethod available() tuple[str, ...]#

Return names of all registered components.

Returns:

Tuple of registered component names, sorted alphabetically.

Return type:

tuple[str, …]

classmethod get(name: str) type[T]#

Look up registered class by name.

Parameters:

name (str) – The registered name of the component.

Returns:

The registered class.

Raises:

ValueError – If name is not registered.

Return type:

type[T]

classmethod register(target_cls: type[T]) type[T]#

Decorator that registers a class by its call_name class attribute.

If call_name is not defined on the class, defaults to the class name.

Parameters:

target_cls (type[T]) – The class to register.

Returns:

The registered class (unchanged).

Raises:

ValueError – If a component with the same name is already registered.

Return type:

type[T]

class phenotypic.tools_.register.PlotterRegistry[source]#

Bases: BaseRegistry[BasePlotter]

Registry for plotter classes.

Plotters are registered by their call_name class attribute, which must match the method name used for dispatch (e.g., call_name = "overlay" corresponds to image.plot.size_distribution()).

classmethod available() tuple[str, ...]#

Return names of all registered components.

Returns:

Tuple of registered component names, sorted alphabetically.

Return type:

tuple[str, …]

classmethod get(name: str) type[T]#

Look up registered class by name.

Parameters:

name (str) – The registered name of the component.

Returns:

The registered class.

Raises:

ValueError – If name is not registered.

Return type:

type[T]

classmethod register(target_cls: type[T]) type[T]#

Decorator that registers a class by its call_name class attribute.

If call_name is not defined on the class, defaults to the class name.

Parameters:

target_cls (type[T]) – The class to register.

Returns:

The registered class (unchanged).

Raises:

ValueError – If a component with the same name is already registered.

Return type:

type[T]

phenotypic.tools_.register.available_analysis_plugins() tuple[str, ...][source]#

Return names of all registered analysis plugins.

Returns:

Tuple of registered plugin names, sorted alphabetically.

Return type:

tuple[str, …]

phenotypic.tools_.register.available_dashboards() tuple[str, ...][source]#

Return names of all registered dashboards.

Returns:

Tuple of registered dashboard names, sorted alphabetically.

Return type:

tuple[str, …]

phenotypic.tools_.register.available_plotters() tuple[str, ...][source]#

Return names of all registered plotters.

Returns:

Tuple of registered plotter names, sorted alphabetically.

Return type:

tuple[str, …]

phenotypic.tools_.register.get_analysis_plugin(name: str) type[BaseAnalysisPlugin][source]#

Look up registered analysis plugin by name.

Parameters:

name (str) – The registered name of the plugin.

Returns:

The registered analysis plugin class.

Raises:

ValueError – If name is not registered.

Return type:

type[BaseAnalysisPlugin]

phenotypic.tools_.register.get_dashboard(name: str) type[source]#

Look up registered dashboard by name.

Parameters:

name (str) – The registered name of the dashboard.

Returns:

The registered dashboard class.

Raises:

ValueError – If name is not registered.

Return type:

type

phenotypic.tools_.register.get_plotter(name: str) type[BasePlotter][source]#

Look up registered plotter by name.

Parameters:

name (str) – The registered name of the plotter.

Returns:

The registered plotter class.

Raises:

ValueError – If name is not registered.

Return type:

type[BasePlotter]

phenotypic.tools_.register.register_analysis(cls: type[BaseAnalysisPlugin]) type[BaseAnalysisPlugin][source]#

Decorator to register an analysis plugin class.

The class must have a call_name class attribute used as the registration key and HTML ID prefix.

Parameters:

cls (type[BaseAnalysisPlugin]) – Analysis plugin class to register.

Returns:

The registered class (unchanged).

Return type:

type[BaseAnalysisPlugin]

Examples

>>> @register_analysis
... class MyPlugin(BaseAnalysisPlugin):
...     call_name = "my_analysis"
...     display_name = "My Analysis"
...
...     def css(self): ...
...     def html(self): ...
...     def js(self): ...
phenotypic.tools_.register.register_dashboard(cls: type) type[source]#

Decorator to register a dashboard class.

The class must have a call_name class attribute that matches the method name for dispatch.

Parameters:

cls (type) – Dashboard class to register.

Returns:

The registered class (unchanged).

Return type:

type

Examples

>>> @register_dashboard
... class MyDashboard(BaseDashboard):
...     call_name = "my_dashboard"
...
...     def my_dashboard(self, **kwargs):
...         ...
phenotypic.tools_.register.register_plotter(cls: type[BasePlotter]) type[BasePlotter][source]#

Decorator to register a plotter class.

The class must have a call_name class attribute that matches the method name for dispatch.

Parameters:

cls (type[BasePlotter]) – Plotter class to register.

Returns:

The registered class (unchanged).

Return type:

type[BasePlotter]

Examples

>>> @register_plotter
... class MyPlotter(BasePlotter):
...     call_name = "my_plot"
...
...     def my_plot(self, **kwargs):
...         ...