Skip to content

Support the anyUnits pseudo unit class when matching units #863

Description

@VisLab

HED specification 4.0.0 (in progress, hed-specification #697 follow-up) adds a way for a # placeholder to accept a number followed by a unit from any unit class: the schema lists a unit class named anyUnits with no units of its own, and the placeholder carries unitClass=anyUnits. The first use is the tag Quantity under Quantitative-value (Quantity/# with unitClass=anyUnits, valueClass=numericClass) in a later standard schema (hed-schemas #335). A placeholder still has exactly one unit class and valueClass=numericClass.

Expected behavior

  • When the placeholder's unit class is anyUnits, match the unit string against every unit class of the schema, listed units and derived forms (SI modifier per component, plural of a unit name) alike, with the usual case-sensitive rules.
  • Tie-break when a string resolves in more than one class: a unit listed in some class wins over a form that another class only derives. In 8.5.0 the only such string is dB (listed decibel in intensityUnits, derived d + B in memorySizeUnits), so dB is a decibel.
  • Conversion, where hed-javascript converts, is to the default unit of the class the matched unit belongs to; a value with no unit on an anyUnits placeholder has no default unit.
  • Invalid unit strings on such a placeholder are UNITS_INVALID as today; the message should not present the empty unit list of anyUnits as the valid units.

Examples (on a placeholder with unitClass=anyUnits, valueClass=numericClass)

  • valid: 3 ms, 3 cm-per-us, 3 dB, 2 kOhm, 5 dollars
  • invalid: 3 foo, 3 MS (wrong case), 3ms (no blank), 3 kmm-per-s

Tests: hed-tests will add UNITS_INVALID cases on an inline library schema that defines anyUnits, until a released standard schema carries the tag.

Where: src/schema/entries.js (unit lookup on the placeholder's unit class) and the tag value parsing. Same change is needed in hed-typescript. Schema compliance (empty anyUnits, cross-class uniqueness) is hed-python only.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions