-
Notifications
You must be signed in to change notification settings - Fork 529
/
test_differentiate_and_integrate.py
58 lines (47 loc) · 1.68 KB
/
test_differentiate_and_integrate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tests for differentiation and integration functions.
"""
import numpy as np
from obspy.signal.differentiate_and_integrate import (
integrate_cumtrapz, integrate_spline)
class TestIntegrate():
"""
Test cases for the integration methods.
"""
def test_cumtrapz_integration(self):
"""
Test the basic and obvious cases. We are using external methods which
are tested extensively elsewhere.
"""
np.testing.assert_allclose(
integrate_cumtrapz(np.ones(10), dx=1.0),
np.arange(10))
np.testing.assert_allclose(
integrate_cumtrapz(np.ones(10), dx=2.0),
np.arange(10) * 2.0)
np.testing.assert_allclose(
integrate_cumtrapz(np.ones(10), dx=0.5),
np.arange(10) * 0.5)
np.testing.assert_allclose(
integrate_cumtrapz(np.zeros(10), dx=0.5),
np.zeros(10))
def test_spline_integration(self):
"""
Test the basic and obvious cases. We are using external methods which
are tested extensively elsewhere.
"""
for k in (1, 2, 3):
np.testing.assert_allclose(
integrate_spline(np.ones(10), dx=1.0, k=k),
np.arange(10))
np.testing.assert_allclose(
integrate_spline(np.ones(10), dx=2.0, k=k),
np.arange(10) * 2.0)
np.testing.assert_allclose(
integrate_spline(np.ones(10), dx=0.5, k=k),
np.arange(10) * 0.5)
np.testing.assert_allclose(
integrate_spline(np.zeros(10), dx=0.5, k=k),
np.zeros(10))