units

utils.units

Unit and Dimension Utilities

Central mapping between TVBO’s UnitEnum (QUDT-backed), LEMS dimensions, SymPy units, and legacy free-text unit strings found in older model YAMLs.

The UnitEnum values use conventional abbreviations (ms, mV, nA, etc.) as defined in the LinkML schema (schema/tvbo_datamodel.yaml).

  • unit_to_lems_dimension(unit) — map a UnitEnum value to a LEMS dimension name
  • unit_to_lems_symbol(unit) — map a UnitEnum value to the LEMS unit symbol
  • unit_has_time_dimension(unit) — whether the unit carries a time component
  • normalize_unit(raw) — convert legacy free-text strings to UnitEnum values

Functions

Name Description
normalize_unit Convert a legacy free-text unit string to a UnitEnum value name.
unit_has_time_dimension Return True if the unit carries a time component (T or T⁻¹).
unit_to_latex Return a LaTeX string for the unit, suitable for wrapping in $...$.
unit_to_lems_dimension Return the LEMS dimension name for a UnitEnum value (or string).
unit_to_lems_symbol Return the LEMS unit symbol string for appending to numeric values.
unit_to_symbol Return the conventional display symbol for a UnitEnum value.

normalize_unit

utils.units.normalize_unit(raw)

Convert a legacy free-text unit string to a UnitEnum value name.

Accepts both abbreviations and full names. Returns None if the string cannot be mapped.

normalize_unit(“mV”) ‘mV’ normalize_unit(“millivolt”) ‘mV’ normalize_unit(“ms^-1”) ‘per_ms’ normalize_unit(None)

unit_has_time_dimension

utils.units.unit_has_time_dimension(unit)

Return True if the unit carries a time component (T or T⁻¹).

This is the key signal for NeuroML LEMS export: if any parameter in the RHS equation has a time dimension, the equation already carries time normalisation and / SEC is not needed.

unit_to_latex

utils.units.unit_to_latex(unit)

Return a LaTeX string for the unit, suitable for wrapping in $...$.

Converts enum values like per_ms\mathrm{ms}^{-1}, rad_per_ms\mathrm{rad}\,\mathrm{ms}^{-1}. Returns an empty string for dimensionless / unknown units.

unit_to_lems_dimension

utils.units.unit_to_lems_dimension(unit)

Return the LEMS dimension name for a UnitEnum value (or string).

Returns the proper LEMS dimension (e.g. "voltage", "capacitance") when the unit has a known mapping, or "none" for dimensionless / unknown units.

unit_to_lems_symbol

utils.units.unit_to_lems_symbol(unit)

Return the LEMS unit symbol string for appending to numeric values.

For dimensioned parameters (e.g. pF, nS, mV), returns the matching LEMS unit symbol. For dimensionless or unknown units, returns "".

unit_to_symbol

utils.units.unit_to_symbol(unit)

Return the conventional display symbol for a UnitEnum value.

For simple abbreviations (ms, mV, nA), the enum value IS the symbol. For compound forms (per_ms, mV_per_ms), returns conventional notation.

unit_to_symbol(“ms”) ‘ms’ unit_to_symbol(“per_ms”) ‘1/ms’ unit_to_symbol(None) ’’