From 6dd31dbb98375b715fcbe463cebd35850f2781e3 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 22 Dec 2022 10:23:45 +0100 Subject: allow limiting precision of dataref exports --- lib/cli.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/cli.py b/lib/cli.py index e821d9a..5ab0cb0 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -6,6 +6,7 @@ from dfatool.functions import ( StaticFunction, FOLFunction, ) +import numpy as np def print_static(model, static_model, name, attribute): @@ -148,7 +149,7 @@ def model_quality_table(header, result_lists, info_list): print(buf) -def export_dataref(dref_file, dref): +def export_dataref(dref_file, dref, precision=None): with open(dref_file, "w") as f: for k, v in sorted(dref.items()): if type(v) is not tuple: @@ -157,7 +158,11 @@ def export_dataref(dref_file, dref): prefix = r"\drefset{" else: prefix = r"\drefset" + f"[unit={v[1]}]" + "{" - print(f"{prefix}/{k}" + "}{" + str(v[0]) + "}", file=f) + if type(v[0]) in (float, np.float64) and precision is not None: + print(f"Limiting precision to {precision}") + print(f"{prefix}/{k}" + "}{" + f"{v[0]:.{precision}f}" + "}", file=f) + else: + print(f"{prefix}/{k}" + "}{" + str(v[0]) + "}", file=f) def export_dot(model, dot_prefix): @@ -212,6 +217,12 @@ def add_standard_arguments(parser): type=str, help="Export raw (parameter-independent) observations in tikz-pgf-compatible format to {PREFIX}{name}-{attribute}.txt", ) + parser.add_argument( + "--dref-precision", + metavar="NDIG", + type=int, + help="Limit precision of dataref export to NDIG decimals", + ) parser.add_argument( "--export-xv", metavar="FILE", -- cgit v1.2.3