示例#1
0
    def test_SRLXcorr(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)
示例#2
0
    def test_SRLXcorr(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)
示例#3
0
文件: util.py 项目: jshridha/obspy
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from future.builtins import *  # NOQA

from struct import 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
示例#4
0
# -*- 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,
示例#5
0
# -*- 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')),
    # mask
    np.ctypeslib.ndpointer(dtype=np.int32,
                           ndim=2,
                           flags=native_str('C_CONTIGUOUS')),
    # time
    np.ctypeslib.ndpointer(dtype=np.float64,
                           ndim=2,
                           flags=native_str('C_CONTIGUOUS')),
    # dist
示例#6
0
文件: util.py 项目: rpratt20/obspy
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from future.builtins import *  # NOQA

from struct import 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
示例#7
0
# -*- coding: utf-8 -*-
"""
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')),
示例#8
0
    (http://www.gnu.org/copyleft/lesser.html)
"""
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from future.builtins import *  # NOQA
from future.utils import native_str

from obspy import UTCDateTime
from obspy.core.util.libnames import _load_CDLL
import ctypes as C
import doctest
import numpy as np
import warnings

# 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 = [
示例#9
0
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


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.
#
# http://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:
示例#10
0
文件: headers.py 项目: 3rdcycle/obspy
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.
#
# http://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:
示例#11
0
"""
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,