-
Notifications
You must be signed in to change notification settings - Fork 97
/
plot_sum.py
61 lines (54 loc) · 1.9 KB
/
plot_sum.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
59
60
61
"""
Sum
===
This example shows how to use the :py:class:`pylops.Sum` operator to stack
values along an axis of a multi-dimensional array
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as pltgs
import pylops
plt.close('all')
###############################################################################
# Let's start by defining a 2-dimensional data
ny, nx = 5, 7
x = (np.arange(ny*nx)).reshape(ny, nx)
###############################################################################
# We can now create the operator and peform forward and adjoint
Sop = pylops.Sum(dims=(ny, nx), dir=0)
y = Sop * x.ravel()
xadj = Sop.H * y
xadj = xadj.reshape(ny, nx)
gs = pltgs.GridSpec(1, 7)
fig = plt.figure(figsize=(7, 3))
ax = plt.subplot(gs[0, 0:3])
im = ax.imshow(x, cmap='rainbow', vmin=0, vmax=ny*nx)
ax.set_title('x', size=20, fontweight='bold')
ax.set_xticks(np.arange(nx-1)+0.5)
ax.set_yticks(np.arange(ny-1)+0.5)
ax.grid(linewidth=3, color='white')
ax.xaxis.set_ticklabels([])
ax.yaxis.set_ticklabels([])
ax.axis('tight')
ax = plt.subplot(gs[0, 3])
ax.imshow(y[:,np.newaxis], cmap='rainbow', vmin=0, vmax=ny*nx)
ax.set_title('y', size=20, fontweight='bold')
ax.set_xticks([])
ax.set_yticks(np.arange(nx-1)+0.5)
ax.grid(linewidth=3, color='white')
ax.xaxis.set_ticklabels([])
ax.yaxis.set_ticklabels([])
ax.axis('tight')
ax = plt.subplot(gs[0, 4:])
ax.imshow(xadj, cmap='rainbow', vmin=0, vmax=ny*nx)
ax.set_title('xadj', size=20, fontweight='bold')
ax.set_xticks(np.arange(nx-1)+0.5)
ax.set_yticks(np.arange(ny-1)+0.5)
ax.grid(linewidth=3, color='white')
ax.xaxis.set_ticklabels([])
ax.yaxis.set_ticklabels([])
ax.axis('tight')
###############################################################################
# Note that since the Sum operator creates and under-determined system of
# equations (data has always lower dimensionality than the model), an exact
# inverse is not possible for this operator.