*3.6. Storage and Retrieval of Uncertain Numbers*

Section 2.3 explained that traceable measurements can be preformed in stages and that, by reporting uncertain numbers when data are processed at each stage, the final uncertainty can be evaluated correctly. The results at one stage will be required at a later time and place. Thus, uncertain numbers must be stored somehow and their identities, which correspond to physical quantities in the actual measurement, must be retained. In GTC, an Archive object is used to manage storage and retrieval of uncertain numbers. The unique identifiers described in Section 3.2 keep track of uncertain-number identities in different Python sessions.

As an example, the code below saves an uncertain number for the voltage difference *V*<sup>20</sup> − *V*<sup>10</sup> in a text file using a JSON format. Note that the GTC function result() is applied to designate V\_20 - V\_10 as an intermediate result. This is a prerequisite for storage.

from GTC import pr

a = pr.Archive()

```
a.add( V_20_V_10 = result(V_20 - V_10) )
with open("file_name.json", "w") as f:
pr.dump_json(f,a,indent=4)
```
The uncertain number V\_20\_V\_10 for the voltage difference is retrieved by the following:

with open("file\_name.json", "r") as f: a = pr.load\_json(f) display( a["V\_20\_V\_10"] ,"V\_20\_V\_10")

which produces the following output.

```
V_20_V_10: 0.25973(25)
E_rel: 0.00020778240000000003
E_rnd_1: 0.0001
E_rnd_2: 0.0001
E_off: 0.0
```
This shows that the necessary information about influence quantities has been retained. Alternatively, the measurements of *V*<sup>10</sup> and *V*<sup>20</sup> can be saved individually.

```
a = pr.Archive()
a.add( V_10 = result(V_10) )
a.add( V_20 = result(V_20) )
with open("file_name.json", "w") as f:
pr.dump_json(f,a,indent=4)
```
Then, in a later session, the difference between the individual results can be evaluated by the following:

```
with open("file_name.json", "r") as f:
a = pr.load_json(f)
V_10 = a["V_10"]
V_20 = a["V_20"]
display(V_20 - V_10,"V_20_V_10")
```
which provides exactly the same results.

```
V_20_V_10: 0.25973(25)
E_rel: 0.00020778240000000003
E_rnd_1: 0.0001
E_rnd_2: 0.0001
E_off: 0.0
```
Although the code here suggests that uncertain-number objects are simply being saved and restored, there is more to it: information about related elementary and intermediate uncertain numbers is also included in the digital record. When an uncertain number is 'added' to an archive, objects that hold information about related influences are identified from the component-of-uncertainty sequences. For instance, we showed earlier that the calculation associated with V\_10 could be decomposed into stages (Figure 1). Referring again to that figure and thinking about data processing, the error terms, *E*rel, *E*off, and *E*rnd, correspond to elementary uncertain numbers, and each of the circled mathematical operations represents an intermediate stage in the calculation. If the intention is to store the uncertain-number V\_10, then information is also required about the voltmeter errors. Figure 6 shows objects with information that would be saved. Later, when the contents of an Archive is loaded back into a different session, this contextual information is immediately restored (nodes are created with the appropriate identifiers). This ensures that when uncertain numbers are retrieved from an archive, they behave as they would have in the context of the original session, which maintains the integrity of information in a traceability chain.

**Figure 6.** A UML object diagram showing information that would be collected when the uncertain number V\_10 is stored. The three Leaf objects contain information about the error terms in the voltmeter measurement model: the fixed offset, the relative error and the random noise. Only one Leaf for the influence of noise is shown; however, if several readings had been taken there would be a different node for each reading.
