2024-11-28 10:07:44 +00:00
|
|
|
import numpy as np
|
2024-12-15 17:34:05 +00:00
|
|
|
import matplotlib.pyplot as plt
|
2024-11-28 10:07:44 +00:00
|
|
|
|
2024-12-15 17:34:05 +00:00
|
|
|
from python.helpers import read_parameter_file
|
2024-11-28 10:07:44 +00:00
|
|
|
|
|
|
|
# parameter for spectrum simulations
|
|
|
|
lb = 2e3
|
|
|
|
pulse_length = 2e-6
|
|
|
|
|
|
|
|
|
|
|
|
def dampening(x: np.ndarray, apod: float) -> np.ndarray:
|
|
|
|
"""
|
|
|
|
Calculate additional dampening to account e.g. for field inhomogeneities.
|
|
|
|
|
|
|
|
:param x: Time axis in seconds
|
|
|
|
:param apod: Dampening factor in 1/seconds
|
|
|
|
:return: Exponential dampening
|
|
|
|
"""
|
|
|
|
|
|
|
|
return np.exp(-apod * x)
|
|
|
|
|
|
|
|
|
|
|
|
def pulse_attn(freq: np.ndarray, t_pulse: float) -> np.ndarray:
|
|
|
|
"""
|
|
|
|
Calculate attenuation of signal to account for finite pulse lengths.
|
|
|
|
|
|
|
|
See Schmitt-Rohr/Spieß, eq. 2.126 for more information.
|
|
|
|
|
|
|
|
:param freq: Frequency axis in Hz
|
|
|
|
:param t_pulse: Assumed pulse length in s
|
|
|
|
:return: Attenuation factor.
|
|
|
|
"""
|
|
|
|
# cf. Schmitt-Rohr/Spieß eq. 2.126; omega_1 * t_p = pi/2
|
|
|
|
pi_half_squared = np.pi**2 / 4
|
|
|
|
omega = 2 * np.pi * freq
|
|
|
|
|
|
|
|
numerator = np.sin(np.sqrt(pi_half_squared + omega**2 * t_pulse**2 / 2))
|
|
|
|
denominator = np.sqrt(pi_half_squared + omega**2 * t_pulse**2 / 4)
|
|
|
|
|
|
|
|
return np.pi * numerator / denominator / 2
|
|
|
|
|
|
|
|
|
2024-12-15 17:34:05 +00:00
|
|
|
def post_process_spectrum(parameter_file, apod, tpulse):
|
|
|
|
parameter = read_parameter_file(parameter_file)
|
|
|
|
|
|
|
|
# files have form ste_arg=0.000000e+01_parameter.txt, first remove ste part then parameter.txt to get variables
|
|
|
|
varied_string = str(parameter_file).partition('_')[-1].rpartition('_')[0]
|
|
|
|
|
|
|
|
# make evolution times
|
|
|
|
tevo = np.linspace(parameter['techo_start'], parameter['techo_stop'], num=int(parameter['techo_steps']))
|
2024-11-28 10:07:44 +00:00
|
|
|
|
2024-12-15 17:34:05 +00:00
|
|
|
if varied_string:
|
|
|
|
raw_data = np.loadtxt(parameter_file.with_name(f'timesignal_{varied_string}.dat'))
|
|
|
|
else:
|
|
|
|
raw_data = np.loadtxt(parameter_file.with_name(f'timesignal.dat'))
|
2024-11-28 10:07:44 +00:00
|
|
|
|
2024-12-15 17:34:05 +00:00
|
|
|
t = raw_data[:, 0]
|
|
|
|
timesignal = raw_data[:, 1:]
|
2024-11-28 10:07:44 +00:00
|
|
|
|
2024-12-15 17:34:05 +00:00
|
|
|
timesignal *= dampening(t, apod)[:, None]
|
|
|
|
timesignal[0, :] /= 2
|
2024-11-28 10:07:44 +00:00
|
|
|
|
2024-12-15 17:34:05 +00:00
|
|
|
# FT to spectrum
|
|
|
|
freq = np.fft.fftshift(np.fft.fftfreq(t.size, d=parameter['dwell_time']))
|
|
|
|
spec = np.fft.fftshift(np.fft.fft(timesignal, axis=0), axes=0).real
|
|
|
|
spec *= pulse_attn(freq, t_pulse=tpulse)[:, None]
|
2024-11-28 10:07:44 +00:00
|
|
|
|
2024-12-15 17:34:05 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# reduction_factor[i, :] = 2*timesignal[0, :]
|
2024-11-28 10:07:44 +00:00
|
|
|
|
|
|
|
|
2024-12-15 17:34:05 +00:00
|
|
|
plt.plot(freq, spec)
|
|
|
|
plt.gca().set_title(varied_string)
|
2024-11-28 10:07:44 +00:00
|
|
|
plt.show()
|
2024-12-15 17:34:05 +00:00
|
|
|
#
|
|
|
|
# plt.semilogx(taus, reduction_factor, '.')
|
|
|
|
# plt.show()
|