**1. Introduction**

The worldwide dissemination of *Système International* (SI) units is a person-oriented paper-based process that is carefully managed by national bodies and coordinated by international organisations; however, that is about to change. The emergence of technologies that can measure and make critical decisions autonomously requires more of our measurement infrastructure to be implemented by digital systems. A growing number of initiatives are replacing paper-based, expert-oriented processes with automated digital ones (e.g., machine-readable formats for calibration reports [1] and a secure cloudbased platform for the legal metrology infrastructure in Europe [2]). Dissemination of SI provides what the metrology community calls traceability. Metrological traceability ensures that measurements are accompanied by information that can be used to determine the fitness-for-purpose of results in different situations. Traceability may be thought of as support for interoperability with measurement data but at present the expertise of skilled individuals is needed to interpret data and supporting information correctly. One outcome of digitalisation will be an ability to produce traceable measurement results in machine-actionable formats.

Measurement accuracy is fundamental to traceability. Traceable measurements must report information about the likely magnitude of the difference (error) between a measured value and the quantity intended to be measured. Metrologists refer to this as measurement uncertainty. During the 1980s, considerable effort went into harmonising the manner that measurement uncertainty is evaluated and communicated and this resulted in the

**Citation:** Hall, B.D. The GUM Tree Calculator: A Python Package for Measurement Modelling and Data Processing with Automatic Evaluation of Uncertainty. *Metrology* **2022**, *2*, 128–149. https://doi.org/ 10.3390/metrology2010009

Academic Editors: Simona Salicone and Richard Leach

Received: 12 November 2021 Accepted: 9 March 2022 Published: 15 March 2022

**Publisher's Note:** MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations.

**Copyright:** © 2022 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https:// creativecommons.org/licenses/by/ 4.0/).

publication of the *Guide to the Expression of Uncertainty in Measurement* (GUM) [3], which remains today the primary reference for dealing with measurement uncertainty (the GUM was produced by a group of experts representing eight international scientific and technical organisations: the BIPM, IEC, IFCC, ILAC, ISO, IUPAC, IUPAP, and OIML).

Digitalisation of metrological infrastructure will inevitably need algorithmic implementations for GUM methods. However, the GUM itself offers no specific guidance, as it was written long before this need could have been anticipated. One approach, called uncertain numbers, provides an abstract representation for physical quantities that satisfies general criteria in the GUM for an ideal format to express uncertainty [4]. Quantities in a problem, such as specific lengths, masses, etc., are always considered to have definite values that can only be estimated with limited accuracy by measurement. Therefore, an uncertain number is designed to encapsulate information about the measured value and measurement accuracy. Using this abstraction allows data processing to be expressed algorithmically in terms of the quantities involved, leaving the associated uncertainty calculations to be handled automatically in the background. The uncertain-number approach can capture the effects of influence quantities at different stages of a traceable measurement and propagate this information along the chain to an end user. Detailed information about the uncertainty budget can sometimes be used to enhance the value of results. This report describes a Python package, called the *GUM Tree Calculator* (GTC), that uses uncertain numbers [5]. GTC is a very flexible tool that has been used in two quite different applications, which have been reported on recently [6,7]. We discuss the tool's design and comment on aspects that support traceability in digital systems.

The next section provides an overview of GUM uncertainty calculations, metrological traceability, and GTC software. GTC is tested on a variety of platforms and different versions of Python 2 and 3 (refer to the github repository [5]). All code snippets use GTC version 1.3.6. The GUM presents its approach to evaluating measurement uncertainty in mathematical terms; thus, Section 2.1 summarises the key equations. However, an alternative formulation of these equations is more practical. This is described in Section 2.2, which motivates the development of the uncertain-number data type. The notion of metrological traceability is discussed in Section 2.3, and we explain why the uncertain-number format is useful to support traceability. Section 2.4 presents an example of GTC data processing applied to an electrical circuit. Section 3 looks in more detail at aspects of GTC design. The method used to automate uncertainty calculation is presented in Section 3.1. The data structures that support uncertainty propagation in uncertain-number objects are described in Sections 3.2–3.5; then, Section 3.6 describes how uncertain numbers can be saved and restored. More general considerations are discussed in Section 4. Appendix A briefly describes support for complex quantities, extensions for handling degrees of freedom, and some additional implementation details.
