igwn_ligolw.types Module

Definitions of type strings found in LIGO Light Weight XML files.

Notes. To guarantee that a double-precision floating-point number can be reconstructed exactly from its representation as a decimal number, one must use 17 decimal digits; for single-precision, the number is 9. Python uses only double-precision numbers, but LIGO Light Weight XML allows for single-precision values, so I provide distinct format specifiers for those cases here. In both cases, I have elected to use 1 fewer digits than are required to uniquely reconstruct the number: the XML written by this library is lossy. I made this choice to reduce the file size, for example

>>> "%.17g" % 0.1
'0.10000000000000001'

while

>>> "%.16g" % 0.1
'0.1'

In this worst case, storing full precision increases the size of the XML by more than an order of magnitude. If you wish to make a different choice for your files, for example if you wish your XML files to be lossless, simply include the lines:

igwn_ligolw.types.FormatFunc.update({
        "real_4": "%.9g".__mod__,
        "real_8": "%.17g".__mod__,
        "float": "%.9g".__mod__,
        "double": "%.17g".__mod__,
        "complex_8": igwn_ligolw.types.mk_complex_format_func("%.9g"),
        "complex_16": igwn_ligolw.types.mk_complex_format_func("%.17g")
})

anywhere in your code, but before you write the document to a file.

References:

Functions

blob_format_func(b)

Function used internally to format binary data.

mk_complex_format_func(fmt)

Function used internally to generate functions to format complex valued data.

string_format_func(s)

Function used internally to format string data for output to XML.

Classes

Class Inheritance Diagram

Inheritance diagram of igwn_ligolw.types.FromPyTypeCls