From c0289c1d69a49ea10b369759029ccb6fa484855c Mon Sep 17 00:00:00 2001 From: jupfi Date: Fri, 8 Dec 2023 18:14:04 +0100 Subject: [PATCH 1/8] Updated view to new handling of IQ samples. --- src/nqrduck_spectrometer/pulseparameters.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nqrduck_spectrometer/pulseparameters.py b/src/nqrduck_spectrometer/pulseparameters.py index 72d41a3..479809a 100644 --- a/src/nqrduck_spectrometer/pulseparameters.py +++ b/src/nqrduck_spectrometer/pulseparameters.py @@ -97,7 +97,7 @@ class Function: td = self.get_time_points(pulse_length) yd = self.evaluate(pulse_length) xdf, ydf = sp.fft(td, yd) - mpl_widget.canvas.ax.plot(xdf, ydf) + mpl_widget.canvas.ax.plot(xdf, abs(ydf)) mpl_widget.canvas.ax.set_xlabel("Frequency in Hz") mpl_widget.canvas.ax.set_ylabel("Magnitude") mpl_widget.canvas.ax.grid(True) From 9371f1fc36d7483f731f8da759993dd608b9b4a0 Mon Sep 17 00:00:00 2001 From: jupfi Date: Fri, 8 Dec 2023 18:14:25 +0100 Subject: [PATCH 2/8] Started implementation on sequence automation. --- src/nqrduck_spectrometer/pulsesequence.py | 42 +++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/nqrduck_spectrometer/pulsesequence.py b/src/nqrduck_spectrometer/pulsesequence.py index c84372a..40b74c7 100644 --- a/src/nqrduck_spectrometer/pulsesequence.py +++ b/src/nqrduck_spectrometer/pulsesequence.py @@ -127,9 +127,47 @@ class PulseSequence: On execution of the pulse sequence the event duration will be set to the first value in the list. Then the pulse sequence will be executed with the second value of the list. This is repeated until the pulse sequence has been executed with all values in the list.""" - pass + + @property + def name(self): + return self._name + + @name.setter + def name(self, name : str): + if not isinstance(name, str): + raise TypeError("Name needs to be a string") + self._name = name + + @property + def values(self): + return self._values + + @values.setter + def values(self, values : list): + if not isinstance(values, list): + raise TypeError("Values needs to be a list") + self._values = values class VariableGroup: """ Variables can be grouped together. If we have groups a and b the pulse sequence will be executed for all combinations of variables in a and b.""" - pass \ No newline at end of file + + @property + def name(self): + return self._name + + @name.setter + def name(self, name : str): + if not isinstance(name, str): + raise TypeError("Name needs to be a string") + self._name = name + + @property + def variables(self): + return self._variables + + @variables.setter + def variables(self, variables : list): + if not isinstance(variables, list): + raise TypeError("Variables needs to be a list") + self._variables = variables \ No newline at end of file From 9844c0df0cdd77e460d9066760e9554de06b95fb Mon Sep 17 00:00:00 2001 From: jupfi Date: Sun, 10 Dec 2023 08:18:05 +0100 Subject: [PATCH 3/8] Added get setting by name. --- src/nqrduck_spectrometer/base_spectrometer_model.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/nqrduck_spectrometer/base_spectrometer_model.py b/src/nqrduck_spectrometer/base_spectrometer_model.py index 359eeb3..b25004e 100644 --- a/src/nqrduck_spectrometer/base_spectrometer_model.py +++ b/src/nqrduck_spectrometer/base_spectrometer_model.py @@ -29,6 +29,12 @@ class BaseSpectrometerModel(ModuleModel): def get_setting(self): return float(self.value) + def get_setting_by_name(self, name : str) -> "Setting": + for setting in self.settings: + if setting.name == name: + return setting + raise ValueError("Setting with name %s not found" % name) + class PulseParameter: """A pulse parameter is a value that can be different for each event in a pulse sequence. From 9c17c99f5326724b529b8b4336c62d3457094941 Mon Sep 17 00:00:00 2001 From: jupfi Date: Sun, 10 Dec 2023 10:01:42 +0100 Subject: [PATCH 4/8] Upsi. Implemented this in the wrong method. --- src/nqrduck_spectrometer/base_spectrometer_model.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/nqrduck_spectrometer/base_spectrometer_model.py b/src/nqrduck_spectrometer/base_spectrometer_model.py index b25004e..3a7062d 100644 --- a/src/nqrduck_spectrometer/base_spectrometer_model.py +++ b/src/nqrduck_spectrometer/base_spectrometer_model.py @@ -28,14 +28,6 @@ class BaseSpectrometerModel(ModuleModel): def get_setting(self): return float(self.value) - - def get_setting_by_name(self, name : str) -> "Setting": - for setting in self.settings: - if setting.name == name: - return setting - raise ValueError("Setting with name %s not found" % name) - - class PulseParameter: """A pulse parameter is a value that can be different for each event in a pulse sequence. E.g. the transmit pulse power or the phase of the transmit pulse. From 50fb662e906395a3385b5713c70eb8899a88af75 Mon Sep 17 00:00:00 2001 From: jupfi Date: Tue, 12 Dec 2023 19:21:49 +0100 Subject: [PATCH 5/8] Updated measurement with IF frequency. --- src/nqrduck_spectrometer/measurement.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/nqrduck_spectrometer/measurement.py b/src/nqrduck_spectrometer/measurement.py index 4c4ec38..5e15550 100644 --- a/src/nqrduck_spectrometer/measurement.py +++ b/src/nqrduck_spectrometer/measurement.py @@ -13,15 +13,17 @@ class Measurement(): tdy (np.array): Time axis for the y axis of the measurement data. target_frequency (float): Target frequency of the measurement. frequency_shift (float): Frequency shift of the measurement. + IF_frequency (float): Intermediate frequency of the measurement. xf (np.array): Frequency axis for the x axis of the measurement data. yf (np.array): Frequency axis for the y axis of the measurement data. """ - def __init__(self, tdx, tdy, target_frequency, frequency_shift : float = 0) -> None: + def __init__(self, tdx, tdy, target_frequency, frequency_shift : float = 0, IF_frequency : float = 0) -> None: self.tdx = tdx self.tdy = tdy self.target_frequency = target_frequency self.fdx, self.fdy = sp.fft(tdx, tdy, frequency_shift) + self.IF_frequency = IF_frequency # Measurement data @property From b93967666d1ef3fbb11ecf088c8730729ec48bc4 Mon Sep 17 00:00:00 2001 From: jupfi Date: Sat, 16 Dec 2023 09:55:39 +0100 Subject: [PATCH 6/8] Added to and from json. --- src/nqrduck_spectrometer/measurement.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/nqrduck_spectrometer/measurement.py b/src/nqrduck_spectrometer/measurement.py index 5e15550..997397d 100644 --- a/src/nqrduck_spectrometer/measurement.py +++ b/src/nqrduck_spectrometer/measurement.py @@ -1,4 +1,5 @@ import logging +import numpy as np from nqrduck.helpers.signalprocessing import SignalProcessing as sp logger = logging.getLogger(__name__) @@ -25,6 +26,29 @@ class Measurement(): self.fdx, self.fdy = sp.fft(tdx, tdy, frequency_shift) self.IF_frequency = IF_frequency + # Data saving and loading + + def to_json(self): + """Converts the measurement to a json-compatible format.""" + return { + "tdx": [[x.real, x.imag] for x in self.tdx], # Convert complex numbers to list + "tdy": [[x.real, x.imag] for x in self.tdy], # Convert complex numbers to list + "target_frequency": self.target_frequency, + "IF_frequency": self.IF_frequency + } + + @classmethod + def from_json(cls, json): + """Converts the json format to a measurement.""" + tdx = np.array([complex(x[0], x[1]) for x in json["tdx"]]) + tdy = np.array([complex(y[0], y[1]) for y in json["tdy"]]) + return cls( + tdx, + tdy, + json["target_frequency"], + json["IF_frequency"] + ) + # Measurement data @property def tdx(self): From 44c7f9a4081c1f88567e97ec83862eb86d27991f Mon Sep 17 00:00:00 2001 From: jupfi Date: Sat, 16 Dec 2023 11:09:14 +0100 Subject: [PATCH 7/8] Flattened data arrays. --- src/nqrduck_spectrometer/measurement.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/nqrduck_spectrometer/measurement.py b/src/nqrduck_spectrometer/measurement.py index 997397d..ce60173 100644 --- a/src/nqrduck_spectrometer/measurement.py +++ b/src/nqrduck_spectrometer/measurement.py @@ -31,7 +31,7 @@ class Measurement(): def to_json(self): """Converts the measurement to a json-compatible format.""" return { - "tdx": [[x.real, x.imag] for x in self.tdx], # Convert complex numbers to list + "tdx": self.tdx.tolist(), "tdy": [[x.real, x.imag] for x in self.tdy], # Convert complex numbers to list "target_frequency": self.target_frequency, "IF_frequency": self.IF_frequency @@ -40,13 +40,12 @@ class Measurement(): @classmethod def from_json(cls, json): """Converts the json format to a measurement.""" - tdx = np.array([complex(x[0], x[1]) for x in json["tdx"]]) tdy = np.array([complex(y[0], y[1]) for y in json["tdy"]]) return cls( - tdx, + np.array(json["tdx"]), tdy, - json["target_frequency"], - json["IF_frequency"] + target_frequency = json["target_frequency"], + IF_frequency = json["IF_frequency"] ) # Measurement data From fdb68f8412991e780ec8add91d445003f7f523e2 Mon Sep 17 00:00:00 2001 From: jupfi Date: Sat, 16 Dec 2023 13:46:00 +0100 Subject: [PATCH 8/8] Added emission of active spectrometer name. --- src/nqrduck_spectrometer/model.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/nqrduck_spectrometer/model.py b/src/nqrduck_spectrometer/model.py index 73977d7..7e7fc31 100644 --- a/src/nqrduck_spectrometer/model.py +++ b/src/nqrduck_spectrometer/model.py @@ -24,6 +24,9 @@ class SpectrometerModel(ModuleModel): def active_spectrometer(self, value): self._active_spectrometer = value self.active_spectrometer_changed.emit(value) + spectrometer_module_name = value.model.toolbar_name + logger.debug("Active spectrometer changed to %s", spectrometer_module_name) + self.module.nqrduck_signal.emit("active_spectrometer_changed", spectrometer_module_name) @property def available_spectrometers(self):