LAL  7.2.4.1-d5ae9e8
__init__.py
Go to the documentation of this file.
1 # Import SWIG wrappings, if available
2 from .lal import *
3 
4 # Redirect standard output/error when running under IPython
5 try:
6  get_ipython()
7 except:
8  pass
9 else:
10  lal.swig_redirect_standard_output_error(True)
11 
12 __version__ = "7.2.4.1"
13 
14 ## \addtogroup lal_python
15 """This package provides Python wrappings and extensions to LAL"""
16 
17 #
18 # =============================================================================
19 #
20 # CachedDetectors Look-up Tables
21 #
22 # =============================================================================
23 #
24 
25 
26 cached_detector_by_prefix = dict((cd.frDetector.prefix, cd) for cd in CachedDetectors)
27 # make sure there were no duplicates
28 assert len(cached_detector_by_prefix) == len(CachedDetectors)
29 
30 
31 cached_detector_by_name = dict((cd.frDetector.name, cd) for cd in CachedDetectors)
32 # make sure there were no duplicates
33 assert len(cached_detector_by_name) == len(CachedDetectors)
34 
35 
36 name_to_prefix = dict((name, detector.frDetector.prefix) for name, detector in cached_detector_by_name.items())
37 prefix_to_name = dict((prefix, name) for name, prefix in name_to_prefix.items())
38 
39 #
40 # =============================================================================
41 #
42 # Make common LAL datatypes picklable
43 #
44 # =============================================================================
45 #
46 
47 
48 from six.moves import copyreg
49 
50 numpy_to_lal_types = {'char': 'CHAR',
51  'int16': 'INT2',
52  'int32': 'INT4',
53  'int64': 'INT8',
54  'uint16': 'UINT2',
55  'uint32': 'UINT4',
56  'uint64': 'UINT8',
57  'float32': 'REAL4',
58  'float64': 'REAL8',
59  'complex64': 'COMPLEX8',
60  'complex128': 'COMPLEX16'}
61 
62 
63 def pickle_gps(obj):
64  return LIGOTimeGPS, (obj.gpsSeconds, obj.gpsNanoSeconds)
65 
66 
67 def pickle_unit(obj):
68  return Unit, (str(obj),)
69 
70 
71 def unpickle_vector(data):
72  lal_type = numpy_to_lal_types[data.dtype.name]
73  creator = globals()['Create{}Vector'.format(lal_type)]
74  result = creator(len(data))
75  result.data = data
76  return result
77 
78 
79 def pickle_vector(obj):
80  return unpickle_vector, (obj.data,)
81 
82 
83 def unpickle_series(attrs):
84  lal_type = numpy_to_lal_types[attrs['data'].data.dtype.name]
85  kind = 'Frequency' if 'deltaF' in attrs else 'Time'
86  creator = globals()['{}{}Series'.format(lal_type, kind)]
87  result = creator()
88  for key, value in attrs.items():
89  setattr(result, key, value)
90  return result
91 
92 
93 def pickle_series(obj):
94  attrs = {'name': obj.name, 'epoch': obj.epoch, 'f0': obj.f0,
95  'sampleUnits': obj.sampleUnits, 'data': obj.data}
96  if hasattr(obj, 'deltaF'):
97  attrs['deltaF'] = obj.deltaF
98  else:
99  attrs['deltaT'] = obj.deltaT
100  return unpickle_series, (attrs,)
101 
102 
103 copyreg.pickle(LIGOTimeGPS, pickle_gps)
104 copyreg.pickle(Unit, pickle_unit)
105 for datatype in numpy_to_lal_types.values():
106  clazz = globals().get('{}Vector'.format(datatype))
107  if clazz:
108  copyreg.pickle(clazz, pickle_vector)
109  clazz = globals().get('{}FrequencySeries'.format(datatype))
110  if clazz:
111  copyreg.pickle(clazz, pickle_series)
112  clazz = globals().get('{}TimeSeries'.format(datatype))
113  if clazz:
114  copyreg.pickle(clazz, pickle_series)
def pickle_unit(obj)
Definition: __init__.py:67
def pickle_series(obj)
Definition: __init__.py:93
def unpickle_vector(data)
Definition: __init__.py:71
def pickle_gps(obj)
Definition: __init__.py:63
def unpickle_series(attrs)
Definition: __init__.py:83
def pickle_vector(obj)
Definition: __init__.py:79