-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_figure_2.py
executable file
·157 lines (125 loc) · 4.59 KB
/
create_figure_2.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
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
import cosmoplots
from support_functions import *
import superposedpulses.forcing as frc
import superposedpulses.point_model as pm
import superposedpulses.pulse_shape as ps
from closedexpressions import PSD_periodic_arrivals, autocorr_periodic_arrivals
axes_size = cosmoplots.set_rcparams_dynamo(plt.rcParams, num_cols=1, ls="thin")
fig_PSD = plt.figure()
ax1 = fig_PSD.add_axes(axes_size)
fig_AC = plt.figure()
ax2 = fig_AC.add_axes(axes_size)
class ExpAmp(frc.ForcingGenerator):
def __init__(self):
pass
def get_forcing(self, times: np.ndarray, gamma: float) -> frc.Forcing:
total_pulses = int(max(times) * gamma)
arrival_time_indx = (
np.arange(start=0, stop=99994, step=5) * 100
) # multiplied with inverse dt
amplitudes = np.random.default_rng().exponential(scale=1.0, size=total_pulses)
durations = np.ones(shape=total_pulses)
return frc.Forcing(
total_pulses, times[arrival_time_indx], amplitudes, durations
)
def set_amplitude_distribution(
self,
amplitude_distribution_function,
):
pass
def set_duration_distribution(self, duration_distribution_function):
pass
model = pm.PointModel(gamma=0.2, total_duration=100000, dt=0.01)
model.set_pulse_shape(ps.LorentzShortPulseGenerator(tolerance=1e-5))
model.set_custom_forcing_generator(ExpAmp())
T, S = model.make_realization()
forcing = model.get_last_used_forcing()
amp = forcing.amplitudes
S_norm = (S - S.mean()) / S.std()
f, Pxx = signal.welch(x=S_norm, fs=100, nperseg=S.size / 10)
ax1.semilogy(f, Pxx, label=r"$A \sim \mathrm{Exp}$")
PSD = PSD_periodic_arrivals(2 * np.pi * f, td=1, gamma=0.2, A_rms=1, A_mean=1, dt=0.01)
ax1.semilogy(
f,
PSD,
"--k",
label=r"$S_{\widetilde{\Phi}}(\tau_\mathrm{d} f), \, \langle A \rangle \ne 0$",
)
tb, R = corr_fun(S_norm, S_norm, dt=0.01, norm=False, biased=True, method="auto")
ax2.plot(tb, R, label=r"$A \sim \mathrm{Exp}$")
t = np.linspace(0, 50, 1000)
R_an = autocorr_periodic_arrivals(t, gamma=0.2, A_mean=1, A_rms=1, norm=True)
ax2.plot(
t,
R_an,
"--k",
label=r"$R_{\widetilde{\Phi}}(t/\tau_\mathrm{d}),\, \langle A \rangle \ne 0$",
)
class AsymLaplaceAmp(frc.ForcingGenerator):
def __init__(self):
pass
def get_forcing(self, times: np.ndarray, gamma: float) -> frc.Forcing:
total_pulses = int(max(times) * gamma)
arrival_time_indx = (
np.arange(start=0, stop=99994, step=5) * 100
) # multiplied with inverse dt
kappa = 0.5
amplitudes = sample_asymm_laplace(
alpha=0.5 / np.sqrt(1.0 - 2.0 * kappa * (1.0 - kappa)),
kappa=kappa,
size=total_pulses,
)
durations = np.ones(shape=total_pulses)
return frc.Forcing(
total_pulses, times[arrival_time_indx], amplitudes, durations
)
def set_amplitude_distribution(
self,
amplitude_distribution_function,
):
pass
def set_duration_distribution(self, duration_distribution_function):
pass
model = pm.PointModel(gamma=0.2, total_duration=100000, dt=0.01)
model.set_pulse_shape(ps.LorentzShortPulseGenerator(tolerance=1e-5))
model.set_custom_forcing_generator(AsymLaplaceAmp())
T, S = model.make_realization()
forcing = model.get_last_used_forcing()
amp = forcing.amplitudes
S_norm = (S - S.mean()) / S.std()
f, Pxx = signal.welch(x=S_norm, fs=100, nperseg=S.size / 10)
ax1.semilogy(f, Pxx, label=r"$A \sim \mathrm{Laplace}$")
PSD = PSD_periodic_arrivals(2 * np.pi * f, td=1, gamma=0.2, A_rms=1, A_mean=0, dt=0.01)
ax1.semilogy(
f,
PSD,
"--g",
label=r"$S_{\widetilde{\Phi}}(\tau_\mathrm{d} f), \, \langle A \rangle = 0$",
)
tb, R = corr_fun(S_norm, S_norm, dt=0.01, norm=False, biased=True, method="auto")
ax2.plot(tb, R, label=r"$A \sim \mathrm{Laplace}$")
R_an = autocorr_periodic_arrivals(t, gamma=0.2, A_mean=0, A_rms=1, norm=True)
ax2.plot(
t,
R_an,
"--g",
label=r"$R_{\widetilde{\Phi}}(t/\tau_\mathrm{d}), \, \langle A \rangle = 0$",
)
ax1.set_xlim(-0.2, 12)
ax1.set_ylim(1e-14, 1e3)
ax1.set_xlabel(r"$\tau_\mathrm{d} f$")
ax1.set_ylabel(r"$S_{\widetilde{\Phi}}(\tau_\mathrm{d} f)$")
ax1.legend()
ax1.set_xlim(-0.03, 1)
ax1.set_ylim(1e-4, 1e3)
ax2.set_xlim(0, 50)
ax2.set_xlabel(r"$t/\tau_\mathrm{d}$")
ax2.set_ylabel(r"$R_{\widetilde{\Phi}}(t/\tau_\mathrm{d})$")
ax2.legend()
cosmoplots.change_log_axis_base(ax1, "y", base=10)
fig_PSD.savefig("PSD_exp_lap.eps", bbox_inches="tight")
fig_AC.savefig("AC_exp_lap.eps", bbox_inches="tight")
plt.show()