-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest2dwavelets.py
More file actions
66 lines (50 loc) · 1.43 KB
/
Copy pathtest2dwavelets.py
File metadata and controls
66 lines (50 loc) · 1.43 KB
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
59
60
61
62
63
64
65
66
import numpy as np
import libwaveletspy as lw
import matplotlib.pyplot as plt
x0 = 10
y0 = 10
nx = 100
ny = 100
x = np.linspace(-x0, x0, nx, dtype=np.float64)
y = np.linspace(-y0, y0, ny, dtype=np.float64)
[xx, yy] = np.meshgrid(x, y)
xx = np.sqrt(xx ** 2 + yy ** 2)
data = np.sin(3 * xx) + np.exp(xx / 5) + np.cos(1 / (0.01 + xx))
dataCpy = data.flatten()
wavelets = np.zeros_like(dataCpy)
result = np.zeros_like(dataCpy)
print(data.shape, dataCpy.shape, wavelets.shape, result.shape)
lw.wavelet_transform2D(dataCpy.ctypes.data, nx, ny, wavelets.ctypes.data)
lw.invwavelet_transform2D(wavelets.ctypes.data, nx, ny, result.ctypes.data)
dataCpy = dataCpy.reshape((nx, ny))
wavelets = wavelets.reshape((nx, ny))
result = result.reshape((nx, ny))
plt.close("all")
if 1:
xp = nx / 2
plt.figure(1)
plt.subplot(3, 1, 1)
plt.plot(data[xp, :], label="data")
plt.plot(result[xp, :], label="result")
plt.legend()
plt.subplot(3, 1, 2)
plt.plot(result[xp, :] - data[xp, :], label="result-data")
plt.legend()
plt.subplot(3, 1, 3)
plt.plot(wavelets[xp, :], label="wavelets")
plt.legend()
if 1:
plt.figure(2)
plt.subplot(2, 2, 1)
plt.imshow(data)
plt.title("data")
plt.subplot(2, 2, 2)
plt.imshow(dataCpy)
plt.title("dataCpy")
plt.subplot(2, 2, 3)
plt.imshow(wavelets)
plt.title("wavelets")
plt.subplot(2, 2, 4)
plt.imshow(result)
plt.title("result")
plt.show()