From a7569a0b2d080a759a4fc0fdee7b85699ca6efae Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Thu, 20 Jul 2023 12:26:43 +0800 Subject: [PATCH] tools: add scale_from_metadata helper func --- artiq/tools.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/artiq/tools.py b/artiq/tools.py index c0c49620e..61678f9bc 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -18,7 +18,8 @@ from artiq.language.environment import is_public_experiment from artiq.language import units -__all__ = ["parse_arguments", "elide", "short_format", "file_import", +__all__ = ["parse_arguments", "elide", "scale_from_metadata", + "short_format", "file_import", "get_experiment", "exc_to_warning", "asyncio_wait_or_cancel", "get_windows_drives", "get_user_config_dir"] @@ -54,12 +55,15 @@ def elide(s, maxlen): s += "..." return s +def scale_from_metadata(metadata): + unit = metadata.get("unit", "") + default_scale = getattr(units, unit, 1) + return metadata.get("scale", default_scale) def short_format(v, metadata={}): m = metadata unit = m.get("unit", "") - default_scale = getattr(units, unit, 1) - scale = m.get("scale", default_scale) + scale = scale_from_metadata(m) precision = m.get("precision", None) if v is None: return "None"