Package glue :: Package ligolw :: Module types
[hide private]
[frames] | no frames]

Module types

source code


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

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

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

References:

        - http://docs.sun.com/source/806-3568/ncg_goldberg.html


Version: git id 8cbd1b7187ce3ed9a825d6ed11cc432f3cfde9a5

Date: 2017-12-05 15:29:36 +0000

Author: Kipp Cannon <kipp.cannon@ligo.org>

Classes [hide private]
  FromPyTypeCls
Functions [hide private]
 
blob_format_func(b)
Function used internally to format binary data.
source code
 
mk_complex_format_func(fmt)
Function used internally to generate functions to format complex valued data.
source code
 
string_format_func(s)
Function used internally to format string data for output to XML.
source code
Variables [hide private]
  BlobTypes = set([u'blob', u'ilwd:char_u'])
  ComplexTypes = set([u'complex_16', u'complex_8'])
  FloatTypes = set([u'double', u'float', u'real_4', u'real_8'])
  FormatFunc = {u'blob': <function blob_format_func at 0x7f39052...
  FromNumPyType = {'complex128': u'complex_16', 'complex64': u'c...
  FromPyType = {<type 'long'>: u'int_8s', <type 'bool'>: u'int_4...
  FromSQLiteType = {'BLOB': u'blob', 'INTEGER': u'int_4s', 'REAL...
  IDTypes = set([u'ilwd:char', u'ilwd:char_u'])
  IntTypes = set([u'int', u'int_2s', u'int_2u', u'int_4s', u'int...
  NumericTypes = set([u'complex_16', u'complex_8', u'double', u'...
  StringTypes = set([u'char_s', u'char_v', u'ilwd:char', u'lstri...
  TimeTypes = set([u'GPS', u'ISO-8601', u'Unix'])
  ToMySQLType = {u'blob': 'BLOB', u'char_s': 'CHAR(20)', u'char_...
  ToNumPyType = {u'complex_16': 'complex128', u'complex_8': 'com...
  ToPyType = {u'blob': <function <lambda> at 0x7f390525e668>, u'...
  ToSQLiteType = {u'blob': 'BLOB', u'char_s': 'TEXT', u'char_v':...
  Types = set([u'GPS', u'ISO-8601', u'Unix', u'blob', u'char_s',...
  __package__ = 'glue.ligolw'
Function Details [hide private]

blob_format_func(b)

source code 

Function used internally to format binary data. Base64-encodes the data and wraps the resulting string in quotes.

string_format_func(s)

source code 

Function used internally to format string data for output to XML. Escapes back-slashes and quotes, and wraps the resulting string in quotes.


Variables Details [hide private]

FormatFunc

Value:
{u'blob': <function blob_format_func at 0x7f390525e410>,
 u'char_s': <function string_format_func at 0x7f390525e320>,
 u'char_v': <function string_format_func at 0x7f390525e320>,
 u'complex_16': <function complex_format_func at 0x7f390525e578>,
 u'complex_8': <function complex_format_func at 0x7f390525e500>,
 u'double': <method-wrapper '__mod__' of unicode object at 0x7f390525a\
e10>,
 u'float': <method-wrapper '__mod__' of unicode object at 0x7f390525ad\
...

FromNumPyType

Value:
{'complex128': u'complex_16',
 'complex64': u'complex_8',
 'float32': u'real_4',
 'float64': u'real_8',
 'int16': u'int_2s',
 'int32': u'int_4s',
 'int64': u'int_8s',
 'uint16': u'int_2u',
...

FromPyType

Value:
{<type 'long'>: u'int_8s', <type 'bool'>: u'int_4s', <type 'str'>: u'l\
string', <type 'unicode'>: u'lstring', <type 'glue.ligolw._ilwd.ilwdch\
ar'>: u'ilwd:char', <type 'memoryview'>: u'blob', <type 'complex'>: u'\
complex_16', <type 'float'>: u'real_8', <type 'int'>: u'int_8s'}

FromSQLiteType

Value:
{'BLOB': u'blob',
 'INTEGER': u'int_4s',
 'REAL': u'real_8',
 'STRING': u'lstring',
 'TEXT': u'lstring'}

IntTypes

Value:
set([u'int',
     u'int_2s',
     u'int_2u',
     u'int_4s',
     u'int_4u',
     u'int_8s',
     u'int_8u'])

NumericTypes

Value:
set([u'complex_16',
     u'complex_8',
     u'double',
     u'float',
     u'int',
     u'int_2s',
     u'int_2u',
     u'int_4s',
...

StringTypes

Value:
set([u'char_s', u'char_v', u'ilwd:char', u'lstring', u'string'])

ToMySQLType

Value:
{u'blob': 'BLOB',
 u'char_s': 'CHAR(20)',
 u'char_v': 'VARCHAR(64)',
 u'double': 'DOUBLE',
 u'float': 'FLOAT',
 u'ilwd:char': 'VARCHAR(64)',
 u'ilwd:char_u': 'BLOB',
 u'int': 'INTEGER',
...

ToNumPyType

Value:
{u'complex_16': 'complex128',
 u'complex_8': 'complex64',
 u'double': 'float64',
 u'float': 'float32',
 u'int': 'int32',
 u'int_2s': 'int16',
 u'int_2u': 'uint16',
 u'int_4s': 'int32',
...

ToPyType

Value:
{u'blob': <function <lambda> at 0x7f390525e668>,
 u'char_s': <type 'unicode'>,
 u'char_v': <type 'unicode'>,
 u'complex_16': <function <lambda> at 0x7f390525e758>,
 u'complex_8': <function <lambda> at 0x7f390525e6e0>,
 u'double': <type 'float'>,
 u'float': <type 'float'>,
 u'ilwd:char': <class 'glue.ligolw.ilwd.ilwdchar'>,
...

ToSQLiteType

Value:
{u'blob': 'BLOB',
 u'char_s': 'TEXT',
 u'char_v': 'TEXT',
 u'double': 'REAL',
 u'float': 'REAL',
 u'ilwd:char': 'TEXT',
 u'ilwd:char_u': 'BLOB',
 u'int': 'INTEGER',
...

Types

Value:
set([u'GPS',
     u'ISO-8601',
     u'Unix',
     u'blob',
     u'char_s',
     u'char_v',
     u'complex_16',
     u'complex_8',
...