Skip to content

radiation_weighting formula is unusable with parse_unit('1') — none vs ratio #307

Description

@withtwoemms

The shipped radiation_weighting formula cannot be used with the obvious dimensionless literal.

Reproduction

from ucon import Number, parse_unit
from ucon.system import active_kinds
L = active_kinds()

D  = Number(quantity=2,  unit=parse_unit('Gy'), kind=L.get('absorbed_dose'))
wR = Number(quantity=20, unit=parse_unit('1'),  kind=L.get('radiation_weighting_factor'))
KindDimensionMismatch: Kind 'radiation_weighting_factor' has dimension
Dimension(none), but unit 'fraction' has dimension Dimension(ratio).
A Number's kind must refine the dimension of its unit.

Cause

radiation_weighting_factor is declared dimension = "none" (ucon/comprehensive.ucon.toml:5230), but parse_unit('1') resolves to fraction, whose dimension is ratio. The __post_init__ check at ucon/core/_types.py:1631 then refuses the construction.

Constructing a Dimension.none unit by hand works, and the formula itself is correct:

none_unit = Unit(name='one', dimension=Dimension.none)
H = D * Number(quantity=20, unit=none_unit, kind=L.get('radiation_weighting_factor'))
# → 40, kind: dose_equivalent      ✓ H = D · w_R per ICRP 103

Why it matters

The formula ships in the default registry, so it is presented as ready to use. A caller reaching for it writes parse_unit('1') — the natural spelling for a dimensionless multiplier — and gets a type error naming two dimensions they did not choose. Getting it right requires knowing that none and ratio are distinct and that no shipped unit carries none.

Possible directions

  • Declare the kind as ratio so it matches the dimensionless unit callers actually have, if that is semantically acceptable.
  • Ship a none-dimensioned unit (or make parse_unit('1') yield one) so there is a spelling that works.
  • Or, if the distinction is deliberate, say so in the formula's notes and give the working incantation — the error message explains what is wrong but not what to write instead.

Found while verifying the formula for #303. Unrelated to that issue's disposition.

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions