/
plot_dispersion_function.py
77 lines (52 loc) · 2.18 KB
/
plot_dispersion_function.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
The plasma dispersion function
==============================
Let's import some basics (and `PlasmaPy`!)
"""
import numpy as np
import matplotlib.pyplot as plt
import plasmapy
#######################################################################
help(plasmapy.mathematics.plasma_dispersion_func)
#######################################################################
# We'll now make some sample data to visualize the dispersion function:
x = np.linspace(-1, 1, 1000)
X, Y = np.meshgrid(x, x)
Z = X + 1j * Y
print(Z.shape)
#######################################################################
# Before we start plotting, let's make a visualization function first:
def plot_complex(X, Y, Z, N=50):
fig, (real_axis, imag_axis) = plt.subplots(1, 2)
real_axis.contourf(X, Y, Z.real, N)
imag_axis.contourf(X, Y, Z.imag, N)
real_axis.set_title("Real values")
imag_axis.set_title("Imaginary values")
for ax in [real_axis, imag_axis]:
ax.set_xlabel("Real values")
ax.set_ylabel("Imaginary values")
fig.tight_layout()
plot_complex(X, Y, Z)
#######################################################################
# We can now apply our visualization function to our simple
F = plasmapy.mathematics.plasma_dispersion_func(Z)
plot_complex(X, Y, F)
#######################################################################
# So this is going to be a hack and I'm not 100% sure the dispersion function
# is quite what I think it is, but let's find the area where the dispersion
# function has a lesser than zero real part because I think it may be important
# (brb reading Fried and Conte):
plot_complex(X, Y, F.real < 0)
#######################################################################
# We can also visualize the derivative:
F = plasmapy.mathematics.plasma_dispersion_func_deriv(Z)
plot_complex(X, Y, F)
#######################################################################
# Plotting the same function on a larger area:
x = np.linspace(-2, 2, 2000)
X, Y = np.meshgrid(x, x)
Z = X + 1j * Y
print(Z.shape)
#######################################################################
F = plasmapy.mathematics.plasma_dispersion_func(Z)
plot_complex(X, Y, F, 100)