Storing uncertain numbers

Archiving allows uncertain numbers to be saved and restored (for further calculation).

The archiving process preserves the identity of uncertain numbers. For example, if a particular reference standard has been used in a number of different measurements, the dependence on common influences is recorded.


Archives created with GTC version 0.9.7 are not compatible with this version.

The prefix archive (or the alias ar) must be used to resolve the names of objects defined in this module.


An Archive object marshals a set of uncertain numbers for storage and recreates uncertain numbers, when restoring an archive.


An archive can be stored as a computer file, or in a string.

Functions for storing and retrieving an archive file are

Functions for storing and retrieving string archives are

Module contents

class Archive

Defines objects used to store and recover uncertain numbers


Add entries name = uncertain-number to the archive


>>> a = ar.Archive()
>>> x = ureal(1,1)
>>> y = ureal(2,1)
>>> a.add(x=x,fred=y)

Extract one or more uncertain numbers

Parameters:args – archived names of the uncertain numbers

If just one name is given a single uncertain number is returned, otherwise a sequence of uncertain numbers is returned.


>>> x, fred = a.extract('x','fred')
>>> harry = a.extract('harry')

Return a list of pairs of name-tags and uncertain-numbers


Return an iterator for pairs of name-tags and uncertain-numbers


Return an iterator for name-tags


Return an iterator for uncertain numbers


Return a list of name-tags


Return a list of uncertain numbers


Load an archive from a file

Parameters:file – a file object opened in binary read mode (with ‘rb’)

Several archives can be extracted from one file by repeatedly calling this function.

dump(file, ar)

Save an archive in a file

  • file – a file object opened in binary write mode (with ‘wb’)
  • ar – an Archive object

Several archives can be saved in a file by repeated use of this function.


This function can only be called once on a particular archive.

dumps(ar, protocol=-1)

Return a string representation of the archive

  • ar – an Archive object
  • protocol – encoding type

Possible values for protocol are described in the Python documentation for the ‘pickle’ module.

protocol=0 creates an ASCII string, but note that many (special) linefeed characters are embedded.


This function can only be called once on a particular archive.


Return an archive object restored from a string representation

Parameters:s – a string created by dumps