nexusLIMS.extractors.profiles#

Instrument profile system for customizing extraction behavior.

This module provides a registry for instrument-specific extraction profiles, enabling easy customization of metadata extraction for different microscopes without modifying core extractor code.

The profile system is the key extensibility mechanism for NexusLIMS - each installation has unique instruments, and profiles make it trivial to add instrument-specific behavior.

Module Contents#

Classes#

InstrumentProfileRegistry

Registry for instrument-specific extraction profiles.

Functions#

get_profile_registry

Get the global instrument profile registry (singleton).

API#

class nexusLIMS.extractors.profiles.InstrumentProfileRegistry[source]#

Registry for instrument-specific extraction profiles.

Manages registration and lookup of InstrumentProfile objects, which customize extraction behavior for specific microscopes.

This is a singleton - use get_profile_registry() to access.

Examples:

Register a profile:

>>> from nexusLIMS.extractors.base import InstrumentProfile
>>> from nexusLIMS.extractors.profiles import get_profile_registry
>>>
>>> titan_profile = InstrumentProfile(
...     instrument_id="FEI-Titan-STEM-630901",
...     parsers={"microscope": parse_643_titan},
...     static_metadata={"nx_meta.Facility": "NIST"}
... )
>>>
>>> registry = get_profile_registry()
>>> registry.register(titan_profile)

Retrieve a profile:

>>> from nexusLIMS.instruments import get_instr_from_filepath
>>> from pathlib import Path
>>>
>>> instrument = get_instr_from_filepath(Path("/path/to/file.dm3"))
>>> profile = registry.get_profile(instrument)
>>> if profile:
...     print(f"Using custom profile for {instrument.name}")
register(profile: InstrumentProfile) None[source]#

Register an instrument profile.

Parameters:

profile – The profile to register

Raises:

ValueError – If a profile with the same instrument_id is already registered

Examples:

>>> from nexusLIMS.extractors.base import InstrumentProfile
>>> profile = InstrumentProfile(instrument_id="FEI-Quanta-12345")
>>> registry = get_profile_registry()
>>> registry.register(profile)
get_profile(instrument: Instrument | None) InstrumentProfile | None[source]#

Get the profile for a specific instrument.

Parameters:

instrument – The instrument to look up, or None

Returns:

The profile for this instrument, or None if no profile registered

Return type:

InstrumentProfile | None

Examples:

>>> from nexusLIMS.instruments import get_instr_from_filepath
>>> from pathlib import Path
>>>
>>> instrument = get_instr_from_filepath(Path("/path/to/file.dm3"))
>>> registry = get_profile_registry()
>>> profile = registry.get_profile(instrument)
>>> if profile:
...     # Apply custom parsers
...     for name, parser_func in profile.parsers.items():
...         metadata = parser_func(metadata)
get_all_profiles() dict[str, InstrumentProfile][source]#

Get all registered profiles.

Returns:

Dictionary mapping instrument IDs to profiles

Return type:

dict[str, InstrumentProfile]

Examples:

>>> registry = get_profile_registry()
>>> all_profiles = registry.get_all_profiles()
>>> for instr_id, profile in all_profiles.items():
...     print(f"{instr_id}: {len(profile.parsers)} custom parsers")
clear() None[source]#

Clear all registered profiles.

Primarily used for testing.

Examples:

>>> registry = get_profile_registry()
>>> registry.clear()
nexusLIMS.extractors.profiles.get_profile_registry() InstrumentProfileRegistry[source]#

Get the global instrument profile registry (singleton).

Returns:

The global profile registry instance

Return type:

InstrumentProfileRegistry

Examples:

>>> from nexusLIMS.extractors.profiles import get_profile_registry
>>> registry = get_profile_registry()
>>> # Always returns the same instance
>>> assert get_profile_registry() is registry