def test_srl_xcorr(self): """ Tests if example in ObsPy paper submitted to the Electronic Seismologist section of SRL is still working. The test shouldn't be changed because the reference gets wrong. """ np.random.seed(815) data1 = np.random.randn(1000).astype(np.float32) data2 = data1.copy() window_len = 100 corp = np.empty(2 * window_len + 1, dtype=np.float64) lib = _load_cdll("signal") # shift = C.c_int() coe_p = C.c_double() res = lib.X_corr(data1.ctypes.data_as(C.c_void_p), data2.ctypes.data_as(C.c_void_p), corp.ctypes.data_as(C.c_void_p), window_len, len(data1), len(data2), C.byref(shift), C.byref(coe_p)) self.assertEqual(0, res) self.assertAlmostEqual(0.0, shift.value) self.assertAlmostEqual(1.0, coe_p.value)
unicode_literals) from future.builtins import * # NOQA from future.utils import native_str import ctypes as C import doctest import warnings import numpy as np from obspy import UTCDateTime from obspy.core.util.libnames import _load_cdll # Import shared libgse2 clibgse2 = _load_cdll("gse2") clibgse2.decomp_6b_buffer.argtypes = [ C.c_int, np.ctypeslib.ndpointer(dtype=np.int32, ndim=1, flags=native_str('C_CONTIGUOUS')), C.CFUNCTYPE(C.c_char_p, C.POINTER(C.c_char), C.c_void_p), C.c_void_p] clibgse2.decomp_6b_buffer.restype = C.c_int clibgse2.rem_2nd_diff.argtypes = [ np.ctypeslib.ndpointer(dtype=np.int32, ndim=1, flags=native_str('C_CONTIGUOUS')), C.c_int] clibgse2.rem_2nd_diff.restype = C.c_int clibgse2.check_sum.argtypes = [
unicode_literals) from future.builtins import * # NOQA from future.utils import native_str import ctypes as C import numpy as np from obspy.core.util.libnames import _load_cdll HPTERROR = -2145916800000000 ENDIAN = {0: '<', 1: '>'} # Import shared libmseed clibmseed = _load_cdll("mseed") # XXX: Do we still support Python 2.4 ???? # Figure out Py_ssize_t (PEP 353). # # Py_ssize_t is only defined for Python 2.5 and above, so it defaults to # ctypes.c_int for earlier versions. # # https://svn.python.org/projects/ctypes/trunk/ # ctypeslib/ctypeslib/contrib/pythonhdr.py if hasattr(C.pythonapi, 'Py_InitModule4'): Py_ssize_t = C.c_int elif hasattr(C.pythonapi, 'Py_InitModule4_64'): Py_ssize_t = C.c_int64 else: # XXX: just hard code it for now
# -*- coding: utf-8 -*- """ C wrappers for some crucial inner loops of TauPy written in C. """ from __future__ import (absolute_import, division, print_function, unicode_literals) from future.builtins import * # NOQA from future.utils import native_str import ctypes as C # NOQA import numpy as np from obspy.core.util.libnames import _load_cdll from .helper_classes import SlownessLayer, TimeDist clibtau = _load_cdll("tau") clibtau.tau_branch_calc_time_dist_inner_loop.argtypes = [ # ray_params np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags=native_str('C_CONTIGUOUS')), # time np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags=native_str('C_CONTIGUOUS')), # dist np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags=native_str('C_CONTIGUOUS')), # layer, record array, 64bit floats. 2D array in memory
# -*- coding: utf-8 -*- from __future__ import (absolute_import, division, print_function, unicode_literals) from future.builtins import * # NOQA from struct import pack, unpack from obspy.core.util.libnames import _load_cdll # Import shared libsegy clibsegy = _load_cdll("segy") def unpack_header_value(endian, packed_value, length, special_format): """ Unpacks a single value. """ # Use special format if necessary. if special_format: fmt = ('%s%s' % (endian, special_format)).encode('ascii', 'strict') return unpack(fmt, packed_value)[0] # Unpack according to different lengths. elif length == 2: format = ('%sh' % endian).encode('ascii', 'strict') return unpack(format, packed_value)[0] # Update: Seems to be correct. Two's complement integers seem to be # the common way to store integer values. elif length == 4: format = ('%si' % endian).encode('ascii', 'strict') return unpack(format, packed_value)[0] # The unassigned field. Since it is unclear how this field is
from future.builtins import * # NOQA from future.utils import native_str import ctypes as C import numpy as np from obspy.core.util.libnames import _load_cdll HPTERROR = -2145916800000000 ENDIAN = {0: '<', 1: '>'} # Import shared libmseed clibmseed = _load_cdll("mseed") # XXX: Do we still support Python 2.4 ???? # Figure out Py_ssize_t (PEP 353). # # Py_ssize_t is only defined for Python 2.5 and above, so it defaults to # ctypes.c_int for earlier versions. # # https://svn.python.org/projects/ctypes/trunk/ # ctypeslib/ctypeslib/contrib/pythonhdr.py if hasattr(C.pythonapi, 'Py_InitModule4'): Py_ssize_t = C.c_int elif hasattr(C.pythonapi, 'Py_InitModule4_64'): Py_ssize_t = C.c_int64 else:
# -*- coding: utf-8 -*- from __future__ import (absolute_import, division, print_function, unicode_literals) from future.builtins import * # NOQA from struct import pack, unpack from obspy.core.util.libnames import _load_cdll # Import shared libsegy clibsegy = _load_cdll("segy") def unpack_header_value(endian, packed_value, length, special_format): """ Unpacks a single value. """ # Use special format if necessary. if special_format: fmt = ('%s%s' % (endian, special_format)).encode('ascii', 'strict') return unpack(fmt, packed_value)[0] # Unpack according to different lengths. elif length == 2: format = ('%sh' % endian).encode('ascii', 'strict') return unpack(format, packed_value)[0] # Update: Seems to be correct. Two's complement integers seem to be # the common way to store integer values. elif length == 4: format = ('%si' % endian).encode('ascii', 'strict') return unpack(format, packed_value)[0]
# -*- coding: utf-8 -*- """ Defines the libsignal and evalresp structures and blockettes. """ import ctypes as C # NOQA import numpy as np from obspy.core.util.libnames import _load_cdll # Import shared libsignal clibsignal = _load_cdll("signal") # Import shared libevresp clibevresp = _load_cdll("evresp") clibsignal.calcSteer.argtypes = [ C.c_int, C.c_int, C.c_int, C.c_int, C.c_int, C.c_float, np.ctypeslib.ndpointer(dtype=np.float32, ndim=3, flags='C_CONTIGUOUS'), np.ctypeslib.ndpointer(dtype=np.complex128, ndim=4, flags='C_CONTIGUOUS'), ] clibsignal.calcSteer.restype = C.c_void_p clibsignal.generalizedBeamformer.argtypes = [ np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags='C_CONTIGUOUS'), np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags='C_CONTIGUOUS'), np.ctypeslib.ndpointer(dtype=np.complex128, ndim=4, flags='C_CONTIGUOUS'),
# -*- coding: utf-8 -*- """ C wrappers for some crucial inner loops of TauPy written in C. """ from __future__ import absolute_import, division, print_function, unicode_literals from future.builtins import * # NOQA from future.utils import native_str import ctypes as C import numpy as np from obspy.core.util.libnames import _load_cdll from .helper_classes import SlownessLayer, TimeDist clibtau = _load_cdll("tau") clibtau.tau_branch_calc_time_dist_inner_loop.argtypes = [ # ray_params np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags=native_str("C_CONTIGUOUS")), # time np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags=native_str("C_CONTIGUOUS")), # dist np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags=native_str("C_CONTIGUOUS")), # layer, record array, 64bit floats. 2D array in memory np.ctypeslib.ndpointer(dtype=SlownessLayer, ndim=1, flags=native_str("C_CONTIGUOUS")), # time_dist, record array, 64bit floats. 2D array in memory np.ctypeslib.ndpointer(dtype=TimeDist, ndim=1, flags=native_str("C_CONTIGUOUS")), # max_i C.c_int32,
Defines the libsignal and evalresp structures and blockettes. """ from __future__ import (absolute_import, division, print_function, unicode_literals) from future.builtins import * # NOQA from future.utils import native_str import ctypes as C import numpy as np from obspy.core.util.libnames import _load_cdll # Import shared libsignal clibsignal = _load_cdll("signal") # Import shared libevresp clibevresp = _load_cdll("evresp") clibsignal.calcSteer.argtypes = [ C.c_int, C.c_int, C.c_int, C.c_int, C.c_int, C.c_float, np.ctypeslib.ndpointer(dtype=np.float32, ndim=3, flags=native_str('C_CONTIGUOUS')), np.ctypeslib.ndpointer(dtype=np.complex128, ndim=4, flags=native_str('C_CONTIGUOUS')), ] clibsignal.calcSteer.restype = C.c_void_p clibsignal.generalizedBeamformer.argtypes = [ np.ctypeslib.ndpointer(dtype=np.float64, ndim=2, flags=native_str('C_CONTIGUOUS')),