2023-08-22 14:06:38 +00:00
|
|
|
import unittest
|
2023-08-23 12:51:57 +00:00
|
|
|
import numpy as np
|
2024-06-04 09:27:34 +00:00
|
|
|
import logging
|
2023-08-23 12:51:57 +00:00
|
|
|
import matplotlib.pyplot as plt
|
2023-08-22 14:06:38 +00:00
|
|
|
from nqr_blochsimulator.classes.sample import Sample
|
|
|
|
from nqr_blochsimulator.classes.simulation import Simulation
|
2023-08-23 12:51:57 +00:00
|
|
|
from nqr_blochsimulator.classes.pulse import PulseArray
|
2023-08-22 14:06:38 +00:00
|
|
|
|
2024-06-04 09:27:34 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
2023-08-23 14:47:41 +00:00
|
|
|
|
2023-08-22 14:06:38 +00:00
|
|
|
class TestSimulation(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.sample = Sample(
|
2023-08-23 12:51:57 +00:00
|
|
|
"BiPh3",
|
2024-06-04 14:25:50 +00:00
|
|
|
atoms=0,
|
2023-08-23 14:47:41 +00:00
|
|
|
density=1.585e6, # g/m^3
|
|
|
|
molar_mass=440.3, # g/mol
|
|
|
|
resonant_frequency=83.56e6, # Hz
|
2024-06-04 09:27:34 +00:00
|
|
|
gamma=43.42, # MHz/T
|
2024-06-04 14:25:50 +00:00
|
|
|
nuclear_spin= "9/2",
|
2024-06-11 15:42:01 +00:00
|
|
|
spin_factor=1.94,
|
2023-08-23 14:18:22 +00:00
|
|
|
powder_factor=0.75,
|
2023-08-23 12:51:57 +00:00
|
|
|
filling_factor=0.7,
|
2024-06-04 09:27:34 +00:00
|
|
|
T1=83.5, # µs
|
|
|
|
T2=396, # µs
|
|
|
|
T2_star=50, # µs
|
2023-08-23 12:51:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
simulation_length = 300e-6
|
|
|
|
dwell_time = 1e-6
|
|
|
|
self.time_array = np.arange(0, simulation_length, dwell_time)
|
|
|
|
pulse_length = 3e-6
|
2023-08-23 14:47:41 +00:00
|
|
|
|
2023-08-23 12:51:57 +00:00
|
|
|
# Simple FID sequence with pulse length of 3µs
|
2023-08-23 14:47:41 +00:00
|
|
|
pulse_amplitude_array = np.zeros(int(simulation_length / dwell_time))
|
|
|
|
pulse_amplitude_array[: int(pulse_length / dwell_time)] = 1
|
|
|
|
pulse_phase_array = np.zeros(int(simulation_length / dwell_time))
|
2023-08-23 12:51:57 +00:00
|
|
|
|
|
|
|
self.pulse = PulseArray(
|
|
|
|
pulseamplitude=pulse_amplitude_array,
|
|
|
|
pulsephase=pulse_phase_array,
|
2023-08-23 14:47:41 +00:00
|
|
|
dwell_time=dwell_time,
|
2023-08-22 14:06:38 +00:00
|
|
|
)
|
|
|
|
|
2023-08-23 12:51:57 +00:00
|
|
|
self.simulation = Simulation(
|
|
|
|
sample=self.sample,
|
|
|
|
number_isochromats=1000,
|
|
|
|
initial_magnetization=1,
|
|
|
|
gradient=1,
|
2023-12-14 12:56:00 +00:00
|
|
|
noise=0.5,
|
2024-06-04 09:27:34 +00:00
|
|
|
length_coil=6, # mm
|
|
|
|
diameter_coil=3, # mm
|
2023-08-23 12:51:57 +00:00
|
|
|
number_turns=9,
|
2024-03-02 19:58:07 +00:00
|
|
|
q_factor_transmit=100,
|
2023-12-14 11:39:44 +00:00
|
|
|
q_factor_receive=100,
|
2023-12-14 12:56:00 +00:00
|
|
|
power_amplifier_power=110,
|
2023-08-23 14:47:41 +00:00
|
|
|
pulse=self.pulse,
|
2023-12-14 12:56:00 +00:00
|
|
|
averages=1000,
|
|
|
|
gain=5600,
|
|
|
|
temperature=300,
|
2023-08-23 14:33:02 +00:00
|
|
|
loss_TX=12,
|
2023-08-23 14:47:41 +00:00
|
|
|
loss_RX=12,
|
2024-06-04 09:27:34 +00:00
|
|
|
conversion_factor=2884, # This is for the LimeSDR based spectrometer
|
2023-08-23 12:51:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_simulation(self):
|
|
|
|
M = self.simulation.simulate()
|
|
|
|
|
|
|
|
# Plotting the results
|
2023-08-23 14:18:22 +00:00
|
|
|
plt.plot(self.time_array * 1e6, abs(M))
|
|
|
|
plt.xlabel("Time (µs)")
|
|
|
|
plt.ylabel("Magnetization (a.u.)")
|
|
|
|
plt.title("FID of BiPh3")
|
2023-08-23 14:47:41 +00:00
|
|
|
plt.show()
|
2024-06-04 09:27:34 +00:00
|
|
|
|
|
|
|
def test_spin_factor_calculation(self):
|
|
|
|
|
2024-06-11 15:42:01 +00:00
|
|
|
spin = 2.5
|
|
|
|
transition = 2
|
2024-06-04 09:27:34 +00:00
|
|
|
|
|
|
|
spin_factor = self.sample.calculate_spin_transition_factor(spin, transition)
|
|
|
|
logger.info("Spin factor: " + str(spin_factor))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
unittest.main()
|