diff --git a/pyproject.toml b/pyproject.toml index 8ff4765..8d1fb92 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -31,7 +31,8 @@ classifiers = [ ] requires-python = ">=3.9" dependencies = [ - "numpy", + "numpy<2.0 ; python_version <= '3.9'", + "numpy ; python_version >= '3.10'", "pint", "pyg4ometry", "pylegendmeta>=v0.9.0a2", diff --git a/src/legendoptics/pyg4utils.py b/src/legendoptics/pyg4utils.py index f04990c..3a03776 100644 --- a/src/legendoptics/pyg4utils.py +++ b/src/legendoptics/pyg4utils.py @@ -62,8 +62,8 @@ def pyg4_def_scint_by_particle_type(mat, scint_cfg: ScintConfig) -> None: @pint.register_unit_format("gdml") def _gdml_format(unit, registry, **options): - proc = {u.replace("µ", "u"): e for u, e in unit.items()} - return pint.formatter( + proc = {ureg._get_symbol(u).replace("µ", "u"): e for u, e in unit.items()} + return pint.formatting.formatter( proc.items(), as_ratio=True, single_denominator=False, @@ -89,8 +89,11 @@ def _val_pint_to_gdml(v): base_unit = v.units - unit = f"{base_unit:~gdml}" + # TODO: drop the extra check for dimensionless quantities after dropping support for pint <= 0.23 + unit = "" if v.check("1") else f"{base_unit:gdml}" assert unit == f"{base_unit:~}".replace(" ", "").replace("µ", "u") + assert "dimensionless" not in unit + msg = f"Unit pint->gdml: {unit} - {base_unit}" log.debug(msg)