From 14d1101591dd5b47fad6ddc04f7b8fc1e8fa2759 Mon Sep 17 00:00:00 2001 From: jupfi Date: Sat, 28 Dec 2024 16:08:05 +0100 Subject: [PATCH] Updated to new measurement data structure. --- examples/COMPFID.py | 12 ++++++------ examples/FID.py | 12 ++++++------ examples/SE.py | 12 ++++++------ examples/SEPC.py | 12 ++++++------ src/quackseq_simulator/simulator_controller.py | 17 +++++++---------- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/examples/COMPFID.py b/examples/COMPFID.py index 741c0dc..e43e7f5 100644 --- a/examples/COMPFID.py +++ b/examples/COMPFID.py @@ -32,17 +32,17 @@ if __name__ == "__main__": plt.title("Time domain Simulation of BiPh3 COMPFID") plt.xlabel("Time (µs)") plt.ylabel("Signal (a.u.)") - plt.plot(result.tdx[-1], result.tdy[-1].imag, label="imaginary") - plt.plot(result.tdx[-1], result.tdy[-1].real, label="real") - plt.plot(result.tdx[-1], abs(result.tdy[-1]), label="abs") + plt.plot(result.tdx, result.tdy[:, -1].imag, label="imaginary") + plt.plot(result.tdx, result.tdy[:, -1].real, label="real") + plt.plot(result.tdx, abs(result.tdy[:, -1]), label="abs") plt.subplot(1, 2, 2) plt.title("Frequency domain Simulation of BiPh3 COMPFID") plt.xlabel("Frequency (kHz)") plt.ylabel("Signal (a.u.)") - plt.plot(result.fdx[-1], result.fdy[-1].imag, label="imaginary") - plt.plot(result.fdx[-1], result.fdy[-1].real, label="real") - plt.plot(result.fdx[-1], abs(result.fdy[-1]), label="abs") + plt.plot(result.fdx, result.fdy[:, -1].imag, label="imaginary") + plt.plot(result.fdx, result.fdy[:, -1].real, label="real") + plt.plot(result.fdx, abs(result.fdy[:, -1]), label="abs") plt.legend() plt.show() diff --git a/examples/FID.py b/examples/FID.py index 95950ae..4f0cea9 100644 --- a/examples/FID.py +++ b/examples/FID.py @@ -29,17 +29,17 @@ if __name__ == "__main__": plt.title("Time domain Simulation of BiPh3 FID") plt.xlabel("Time (µs)") plt.ylabel("Signal (a.u.)") - plt.plot(result.tdx[0], result.tdy[0].imag, label="imaginary") - plt.plot(result.tdx[0], result.tdy[0].real, label="real") - plt.plot(result.tdx[0], abs(result.tdy[0]), label="abs") + plt.plot(result.tdx, result.tdy[:, 0].imag, label="imaginary") + plt.plot(result.tdx, result.tdy[:, 0].real, label="real") + plt.plot(result.tdx, abs(result.tdy[:, 0]), label="abs") plt.subplot(1, 2, 2) plt.title("Frequency domain Simulation of BiPh3 FID") plt.xlabel("Frequency (kHz)") plt.ylabel("Signal (a.u.)") - plt.plot(result.fdx[0], result.fdy[0].imag, label="imaginary") - plt.plot(result.fdx[0], result.fdy[0].real, label="real") - plt.plot(result.fdx[0], abs(result.fdy[0]), label="abs") + plt.plot(result.fdx, result.fdy[:, 0].imag, label="imaginary") + plt.plot(result.fdx, result.fdy[:, 0].real, label="real") + plt.plot(result.fdx, abs(result.fdy[:, 0]), label="abs") plt.legend() plt.show() diff --git a/examples/SE.py b/examples/SE.py index fe4af57..262c4fd 100644 --- a/examples/SE.py +++ b/examples/SE.py @@ -27,17 +27,17 @@ if __name__ == "__main__": plt.title("Time domain Simulation of BiPh3 SE") plt.xlabel("Time (µs)") plt.ylabel("Signal (a.u.)") - plt.plot(result.tdx[0], result.tdy[0].imag, label="imaginary") - plt.plot(result.tdx[0], result.tdy[0].real, label="real") - plt.plot(result.tdx[0], abs(result.tdy[0]), label="abs") + plt.plot(result.tdx, result.tdy[:, 0].imag, label="imaginary") + plt.plot(result.tdx, result.tdy[:, 0].real, label="real") + plt.plot(result.tdx, abs(result.tdy[:, 0]), label="abs") plt.subplot(1, 2, 2) plt.title("Frequency domain Simulation of BiPh3 SE") plt.xlabel("Frequency (kHz)") plt.ylabel("Signal (a.u.)") - plt.plot(result.fdx[0], result.fdy[0].imag, label="imaginary") - plt.plot(result.fdx[0], result.fdy[0].real, label="real") - plt.plot(result.fdx[0], abs(result.fdy[0]), label="abs") + plt.plot(result.fdx, result.fdy[:, 0].imag, label="imaginary") + plt.plot(result.fdx, result.fdy[:, 0].real, label="real") + plt.plot(result.fdx, abs(result.fdy[:, 0]), label="abs") plt.legend() plt.show() \ No newline at end of file diff --git a/examples/SEPC.py b/examples/SEPC.py index 07073c8..7828b78 100644 --- a/examples/SEPC.py +++ b/examples/SEPC.py @@ -27,17 +27,17 @@ if __name__ == "__main__": plt.title("Time domain Simulation of BiPh3 SEPC") plt.xlabel("Time (µs)") plt.ylabel("Signal (a.u.)") - plt.plot(result.tdx[-1], result.tdy[-1].imag, label="imaginary") - plt.plot(result.tdx[-1], result.tdy[-1].real, label="real") - plt.plot(result.tdx[-1], abs(result.tdy[-1]), label="abs") + plt.plot(result.tdx, result.tdy[:, -1].imag, label="imaginary") + plt.plot(result.tdx, result.tdy[:, -1].real, label="real") + plt.plot(result.tdx, abs(result.tdy[:, -1]), label="abs") plt.subplot(1, 2, 2) plt.title("Frequency domain Simulation of BiPh3 SEPC") plt.xlabel("Frequency (kHz)") plt.ylabel("Signal (a.u.)") - plt.plot(result.fdx[-1], result.fdy[-1].imag, label="imaginary") - plt.plot(result.fdx[-1], result.fdy[-1].real, label="real") - plt.plot(result.fdx[-1], abs(result.fdy[-1]), label="abs") + plt.plot(result.fdx, result.fdy[:, -1].imag, label="imaginary") + plt.plot(result.fdx, result.fdy[:, -1].real, label="real") + plt.plot(result.fdx, abs(result.fdy[:, -1]), label="abs") plt.legend() plt.show() \ No newline at end of file diff --git a/src/quackseq_simulator/simulator_controller.py b/src/quackseq_simulator/simulator_controller.py index d15e5d1..2497a96 100644 --- a/src/quackseq_simulator/simulator_controller.py +++ b/src/quackseq_simulator/simulator_controller.py @@ -39,8 +39,6 @@ class SimulatorController(SpectrometerController): # Empty measurement object measurement_data = None - readout_scheme = None - for cycle in range(number_phasecycles): sample = self.get_sample_from_settings() @@ -72,6 +70,8 @@ class SimulatorController(SpectrometerController): evidx = np.where((tdx > rx_begin) & (tdx < rx_stop))[0] tdx = tdx[evidx] result = result[evidx] + # Add empty second dimension to result so it has shape (n_points, 1) + result = np.expand_dims(result, axis=1) # Measurement name date + module + target frequency + averages + sequence name name = f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - Simulator - {self.simulator.model.target_frequency / 1e6} MHz - {self.simulator.model.averages} averages - {sequence.name}" @@ -85,7 +85,7 @@ class SimulatorController(SpectrometerController): sample.resonant_frequency, ) else: - measurement_data.add_dataset(tdx, result / simulation.averages) + measurement_data.add_dataset(result / simulation.averages) if (rx_begin and rx_stop) and phase: logger.debug(f"Phase: {phase}") @@ -94,15 +94,12 @@ class SimulatorController(SpectrometerController): if phase and number_phasecycles > 1: # Apply the readout scheme - tdy = np.zeros(len(measurement_data.tdx[0]), dtype=np.complex128) - for cycle in range(number_phasecycles): - tdy += (measurement_data.tdy[cycle]) + tdy_sum = np.sum(measurement_data.tdy, axis=1, keepdims=True) - measurement_data.add_dataset(measurement_data.tdx[0], tdy) - - logger.info(f"Length of tdy: {len(tdy)}") - + measurement_data.add_dataset(tdy_sum) + logger.debug(f"Measurement data shape: {measurement_data.tdy.shape}") + return measurement_data def get_sample_from_settings(self) -> Sample: