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.

Note

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.

Class

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

Functions

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(**kwargs)

Add entries name = uncertain-number to the archive

Example:

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

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.

Example:

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

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

iteritems()

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

iterkeys()

Return an iterator for name-tags

itervalues()

Return an iterator for uncertain numbers

keys()

Return a list of name-tags

values()

Return a list of uncertain numbers

load(file)

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

Parameters:
  • 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.

Note

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

dumps(ar, protocol=-1)

Return a string representation of the archive

Parameters:
  • 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.

Note

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

loads(s)

Return an archive object restored from a string representation

Parameters:s – a string created by dumps