-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspectral.py
157 lines (116 loc) · 3.52 KB
/
spectral.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""
Spectral binning
"""
import numpy as np
import matplotlib.pyplot as plt
l2_i = np.array([20.4, 22.0, 24.4, 27.6, 30.8, 34.0, 38.8, 45.2, 51.6, 58.0, \
67.6, 80.4, 93.2, 106.0, 125.2, 150.8, 176.4, 202.0, 240.4, 291.6, \
342.8, 394.0, 470.8, 573.2, 675.6, 778.0, 931.6, 1136.4, 1341.2, 1546.0, \
1853.2, 2262.8, 2672.4, 3082.0, 3696.4, 4515.6, 5334.8], dtype='float')
l2_e = np.array([20.4, 22.0, 24.4, 27.6, 30.8, 34.0, 38.8, 45.2, 51.6, 58.0, 67.6, \
80.4, 93.2, 106.0, 125.2, 150.8, 176.4, 202.0, 240.4, 291.6, 342.8])
logi = np.log(l2_i)
loge = np.log(l2_e)
#------------------------------------------------------------------------------
Ni = len(logi)
Ne = len(loge)
# log bin size
di = logi[1:] - logi[0:-1]
de = loge[1:] - loge[0:-1]
#------------------------------------------------------------------------------
# constant log bins for comparison
x = np.arange(Ni)
i = int(0.7*Ni)
m = di[i]
b = logi[i] - m * i
yy = np.exp(m*x + b)
#------------------------------------------------------------------------------
# Rebin ions
# assume the L2 ion bin number is odd, and keep the last bin intact
Mi = int((Ni-1)/2) + 1
print(f"Mi = {Mi}")
l3_i = np.zeros(Mi)
e1 = np.sqrt(l2_i[0]**3/l2_i[1])
e2 = np.sqrt(l2_i[1]*l2_i[2])
l3_i[0] = np.sqrt(e1*e2)
idx = 1
for i in np.arange(2,Ni-2,2):
e1 = np.sqrt(l2_i[i-1]*l2_i[i])
e2 = np.sqrt(l2_i[i+1]*l2_i[i+2])
l3_i[idx] = np.sqrt(e1*e2)
mm = l2_i[i-1]*l2_i[i]*l2_i[i+1]*l2_i[i+2]
mcheck = np.power(mm, 0.25)
#print(f"{idx} {e1} {l3_i[idx]} {mcheck} {e2}")
idx += 1
l3_i[-1] = l2_i[-1]
for e in l3_i:
print(e)
#------------------------------------------------------------------------------
# Rebin electrons
# assume the L2 ion bin number is odd, and keep the last bin intact
Me = int((Ne-1)/2) + 1
print(f"Me = {Me}")
l3_e = np.zeros(Me)
e1 = np.sqrt(l2_e[0]**3/l2_e[1])
e2 = np.sqrt(l2_e[1]*l2_e[2])
l3_e[0] = np.sqrt(e1*e2)
idx = 1
for i in np.arange(2,Ne-2,2):
e1 = np.sqrt(l2_e[i-1]*l2_e[i])
e2 = np.sqrt(l2_e[i+1]*l2_e[i+2])
l3_e[idx] = np.sqrt(e1*e2)
#print(f"{idx} {i} {e1} {l3_e[idx]} {e2}")
idx += 1
l3_e[-1] = l2_e[-1]
print(80*'-')
for e in l3_e:
print(e)
#------------------------------------------------------------------------------
# p = L3 bins
plogi = np.log(l3_i)
pdi = plogi[1:] - plogi[0:-1]
ploge = np.log(l3_e)
pde = ploge[1:] - ploge[0:-1]
#------------------------------------------------------------------------------
# constant log bins for comparison
px = np.arange(Mi)
i = int(.7*Mi)
m = pdi[i]
b = plogi[i] - m * i
py = np.exp(m*px + b)
#------------------------------------------------------------------------------
ions = False
fig = plt.figure(figsize=(16,8))
if ions:
ax1 = fig.add_subplot(2, 2, 1)
ax1.set_yscale('log')
ax1.plot(l2_i)
ax1.plot(l2_i, 'o')
ax1.plot(yy)
ax2 = fig.add_subplot(2, 2, 2)
ax2.plot(di)
ax2.plot(di, 'o')
ax3 = fig.add_subplot(2, 2, 3)
ax3.set_yscale('log')
ax3.plot(l3_i)
ax3.plot(l3_i, 'o')
ax3.plot(py)
ax4 = fig.add_subplot(2, 2, 4)
ax4.plot(pdi)
ax4.plot(pdi, 'o')
else:
ax1 = fig.add_subplot(2, 2, 1)
ax1.set_yscale('log')
ax1.plot(l2_e)
ax1.plot(l2_e, 'o')
ax2 = fig.add_subplot(2, 2, 2)
ax2.plot(de)
ax2.plot(de, 'o')
ax3 = fig.add_subplot(2, 2, 3)
ax3.set_yscale('log')
ax3.plot(l3_e)
ax3.plot(l3_e, 'o')
ax4 = fig.add_subplot(2, 2, 4)
ax4.plot(pde)
ax4.plot(pde, 'o')
plt.show()