nexusLIMS.extractors.utils#

Methods (primarily intended to be private) that are used by the other extractors.

Module Contents#

Functions#

add_to_extensions

Add a field to the extensions section of nx_meta.

API#

nexusLIMS.extractors.utils.add_to_extensions(nx_meta: dict, field_name: str, value: Any) None[source]#

Add a field to the extensions section of nx_meta.

This is a convenience function that ensures the extensions dict exists before adding a field. Use this for vendor-specific, instrument-specific, or facility-specific metadata that doesn’t fit the core schema.

Parameters:
  • nx_meta (dict) – The nx_meta dictionary being built by the extractor. Will be modified in place to add the field to the extensions section.

  • field_name (str) – Name of the field to add. Use descriptive names that clearly indicate the field’s meaning (e.g., ‘quanta_spot_size’, ‘detector_contrast’).

  • value (Any) – The value to store. Can be any JSON-serializable type, including Pint Quantity objects which will be automatically serialized.

Examples:

Add vendor-specific fields during metadata extraction:

>>> nx_meta = {
...     "DatasetType": "Image",
...     "Data Type": "SEM_Imaging",
...     "Creation Time": "2024-01-15T10:30:00-05:00",
... }
>>> add_to_extensions(nx_meta, "spot_size", 3.5)
>>> add_to_extensions(nx_meta, "detector_contrast", 50.0)
>>> nx_meta["extensions"]
{'spot_size': 3.5, 'detector_contrast': 50.0}

Works with Pint Quantities:

>>> from nexusLIMS.schemas.units import ureg
>>> add_to_extensions(nx_meta, "chamber_pressure", ureg.Quantity(79.8, "pascal"))

Notes:

The extensions section preserves all metadata that doesn’t fit the core schema, ensuring no data loss during extraction. Extensions are included in the XML output and preserved through the record building process.