Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-3a66518
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
__init__.py
Go to the documentation of this file.
1# Import SWIG wrappings, if available
2from .lal import *
3
4# Redirect standard output/error when running under IPython
5from contextlib import contextmanager
6try:
7 get_ipython()
8except:
9 @contextmanager
11 yield
12else:
13 lal.swig_redirect_standard_output_error(True)
14 @contextmanager
16 state = lal.swig_redirect_standard_output_error(False)
17 yield
18 lal.swig_redirect_standard_output_error(state)
19 import warnings
20 warnings.warn("""Wswiglal-redir-stdio:
21
22SWIGLAL standard output/error redirection is enabled in IPython.
23This may lead to performance penalties. To disable locally, use:
24
25with lal.no_swig_redirect_standard_output_error():
26 ...
27
28To disable globally, use:
29
30lal.swig_redirect_standard_output_error(False)
31
32Note however that this will likely lead to error messages from
33LAL functions being either misdirected or lost when called from
34Jupyter notebooks.
35
36To suppress this warning, use:
37
38import warnings
39warnings.filterwarnings("ignore", "Wswiglal-redir-stdio")
40import lal
41""", stacklevel=2)
42
43__version__ = "7.7.0.1"
44
45## \addtogroup lal_python
46"""This package provides Python wrappings and extensions to LAL"""
47
48#
49# =============================================================================
50#
51# CachedDetectors Look-up Tables
52#
53# =============================================================================
54#
55
56
57cached_detector_by_prefix = dict((cd.frDetector.prefix, cd) for cd in CachedDetectors)
58# make sure there were no duplicates
59assert len(cached_detector_by_prefix) == len(CachedDetectors)
60
61
62cached_detector_by_name = dict((cd.frDetector.name, cd) for cd in CachedDetectors)
63# make sure there were no duplicates
64assert len(cached_detector_by_name) == len(CachedDetectors)
65
66
67name_to_prefix = dict((name, detector.frDetector.prefix) for name, detector in cached_detector_by_name.items())
68prefix_to_name = dict((prefix, name) for name, prefix in name_to_prefix.items())
69
70#
71# =============================================================================
72#
73# Make common LAL datatypes picklable
74#
75# =============================================================================
76#
77
78
79import copyreg
80
81numpy_to_lal_types = {'char': 'CHAR',
82 'int16': 'INT2',
83 'int32': 'INT4',
84 'int64': 'INT8',
85 'uint16': 'UINT2',
86 'uint32': 'UINT4',
87 'uint64': 'UINT8',
88 'float32': 'REAL4',
89 'float64': 'REAL8',
90 'complex64': 'COMPLEX8',
91 'complex128': 'COMPLEX16'}
92
93
94def pickle_gps(obj):
95 return LIGOTimeGPS, (obj.gpsSeconds, obj.gpsNanoSeconds)
96
97
98def pickle_unit(obj):
99 return Unit, (str(obj),)
100
101
103 lal_type = numpy_to_lal_types[data.dtype.name]
104 creator = globals()['Create{}Vector'.format(lal_type)]
105 result = creator(len(data))
106 result.data = data
107 return result
108
109
111 return unpickle_vector, (obj.data,)
112
113
115 lal_type = numpy_to_lal_types[attrs['data'].data.dtype.name]
116 kind = 'Frequency' if 'deltaF' in attrs else 'Time'
117 creator = globals()['{}{}Series'.format(lal_type, kind)]
118 result = creator()
119 for key, value in attrs.items():
120 setattr(result, key, value)
121 return result
122
123
125 attrs = {'name': obj.name, 'epoch': obj.epoch, 'f0': obj.f0,
126 'sampleUnits': obj.sampleUnits, 'data': obj.data}
127 if hasattr(obj, 'deltaF'):
128 attrs['deltaF'] = obj.deltaF
129 else:
130 attrs['deltaT'] = obj.deltaT
131 return unpickle_series, (attrs,)
132
133
134copyreg.pickle(LIGOTimeGPS, pickle_gps)
135copyreg.pickle(Unit, pickle_unit)
136for datatype in numpy_to_lal_types.values():
137 clazz = globals().get('{}Vector'.format(datatype))
138 if clazz:
139 copyreg.pickle(clazz, pickle_vector)
140 clazz = globals().get('{}FrequencySeries'.format(datatype))
141 if clazz:
142 copyreg.pickle(clazz, pickle_series)
143 clazz = globals().get('{}TimeSeries'.format(datatype))
144 if clazz:
145 copyreg.pickle(clazz, pickle_series)
def no_swig_redirect_standard_output_error()
Definition: __init__.py:10
def pickle_unit(obj)
Definition: __init__.py:98
def pickle_series(obj)
Definition: __init__.py:124
def unpickle_vector(data)
Definition: __init__.py:102
def pickle_gps(obj)
Definition: __init__.py:94
def unpickle_series(attrs)
Definition: __init__.py:114
def pickle_vector(obj)
Definition: __init__.py:110