-
Notifications
You must be signed in to change notification settings - Fork 97
/
plot_real.py
executable file
·42 lines (35 loc) · 1.18 KB
/
plot_real.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
"""
Real
====
This example shows how to use the :py:class:`pylops.basicoperators.Real`
operator.
This operator returns the real part of the data in forward and adjoint mode,
but the forward output will be a real number, while the adjoint output will
be a complex number with a zero-valued imaginary part.
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as pltgs
import pylops
plt.close('all')
###############################################################################
# Let's define a Real operator :math:`\mathbf{\Re}` to extract the real
# component of the input.
M = 5
x = np.arange(M) + 1j * np.arange(M)[::-1]
Rop = pylops.basicoperators.Real(M, dtype='complex128')
y = Rop*x
xadj = Rop.H*y
_, axs = plt.subplots(1, 3, figsize=(10, 4))
axs[0].plot(np.real(x), lw=2, label='Real')
axs[0].plot(np.imag(x), lw=2, label='Imag')
axs[0].legend()
axs[0].set_title('Input')
axs[1].plot(np.real(y), lw=2, label='Real')
axs[1].plot(np.imag(y), lw=2, label='Imag')
axs[1].legend()
axs[1].set_title('Forward of Input')
axs[2].plot(np.real(xadj), lw=2, label='Real')
axs[2].plot(np.imag(xadj), lw=2, label='Imag')
axs[2].legend()
axs[2].set_title('Adjoint of Forward')