Package glue :: Package ligolw :: Module lsctables :: Class instrumentsproperty
[hide private]
[frames] | no frames]

Class instrumentsproperty

source code

object --+
         |
        instrumentsproperty

Instance Methods [hide private]
 
__get__(self, obj, type=None) source code
 
__init__(self, name)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__set__(self, obj, instruments) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
get(ifos)
Parse the values stored in the "ifos" and "instruments" columns found in many tables.
source code
 
set(instruments)
Convert an iterable of instrument names into a value suitable for storage in the "ifos" column found in many tables.
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, name)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

get(ifos)
Static Method

source code 

Parse the values stored in the "ifos" and "instruments" columns found in many tables. This function is mostly for internal use by the .instruments properties of the corresponding row classes. The mapping from input to output is as follows (rules are applied in order):

input is None --> output is None

input contains "," --> output is set of strings split on "," with leading and trailing whitespace stripped from each piece and empty strings removed from the set

input contains "+" --> output is set of strings split on "+" with leading and trailing whitespace stripped from each piece and empty strings removed from the set

else, after stripping input of leading and trailing whitespace,

input has an even length greater than two --> output is set of two-character pieces

input is a non-empty string --> output is a set containing input as single value

else output is an empty set.

NOTE: the complexity of this algorithm is a consequence of there being several conventions in use for encoding a set of instruments into one of these columns; it has been proposed that L.L.W. documents standardize on the comma-delimited variant of the encodings recognized by this function, and for this reason the inverse function, instrumentsproperty.set(), implements that encoding only.

NOTE: to force a string containing an even number of characters to be interpreted as a single instrument name and not to be be split into two-character pieces, add a "," character to the end to force the comma-delimited decoding to be used. instrumentsproperty.set() does this for you.

Example:

>>> print(instrumentsproperty.get(None))
None
>>> instrumentsproperty.get(u"")
set([])
>>> instrumentsproperty.get(u"  ,  ,,")
set([])
>>> instrumentsproperty.get(u"H1")
set([u'H1'])
>>> instrumentsproperty.get(u"SWIFT")
set([u'SWIFT'])
>>> instrumentsproperty.get(u"H1L1")
set([u'H1', u'L1'])
>>> instrumentsproperty.get(u"H1L1,")
set([u'H1L1'])
>>> instrumentsproperty.get(u"H1,L1")
set([u'H1', u'L1'])
>>> instrumentsproperty.get(u"H1+L1")
set([u'H1', u'L1'])

set(instruments)
Static Method

source code 

Convert an iterable of instrument names into a value suitable for storage in the "ifos" column found in many tables. This function is mostly for internal use by the .instruments properties of the corresponding row classes. The input can be None or an iterable of zero or more instrument names, none of which may be zero-length, consist exclusively of spaces, or contain "," or "+" characters. The output is a single string containing the unique instrument names concatenated using "," as a delimiter. instruments will only be iterated over once and so can be a generator expression. Whitespace is allowed in instrument names but might not be preserved. Repeated names will not be preserved.

NOTE: in the special case that there is 1 instrument name in the iterable and it has an even number of characters > 2 in it, the output will have a "," appended in order to force instrumentsproperty.get() to parse the string back into a single instrument name. This is a special case included temporarily to disambiguate the encoding until all codes have been ported to the comma-delimited encoding. This behaviour will be discontinued at that time. DO NOT WRITE CODE THAT RELIES ON THIS! You have been warned.

Example:

>>> print(instrumentsproperty.set(None))
None
>>> instrumentsproperty.set(())
u''
>>> instrumentsproperty.set((u"H1",))
u'H1'
>>> instrumentsproperty.set((u"H1",u"H1",u"H1"))
u'H1'
>>> instrumentsproperty.set((u"H1",u"L1"))
u'H1,L1'
>>> instrumentsproperty.set((u"SWIFT",))
u'SWIFT'
>>> instrumentsproperty.set((u"H1L1",))
u'H1L1,'