From 05e8812204c1589bfca6dd41be19decc93b2c1e8 Mon Sep 17 00:00:00 2001 From: jupfi Date: Sat, 29 Jul 2023 16:56:16 +0200 Subject: [PATCH] Added check for valid event duration. --- src/nqrduck_spectrometer/pulseparameters.py | 2 ++ src/nqrduck_spectrometer/pulsesequence.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/nqrduck_spectrometer/pulseparameters.py b/src/nqrduck_spectrometer/pulseparameters.py index 92a5ba6..b48829a 100644 --- a/src/nqrduck_spectrometer/pulseparameters.py +++ b/src/nqrduck_spectrometer/pulseparameters.py @@ -60,6 +60,7 @@ class Function: mpl_widget.canvas.ax.plot(xdf, ydf) mpl_widget.canvas.ax.set_xlabel("Frequency in Hz") mpl_widget.canvas.ax.set_ylabel("Magnitude") + mpl_widget.canvas.ax.grid(True) return mpl_widget def time_domain_plot(self, pulse_length: float) -> MplWidget: @@ -68,6 +69,7 @@ class Function: mpl_widget.canvas.ax.plot(td, self.evaluate(pulse_length)) mpl_widget.canvas.ax.set_xlabel("Time in s") mpl_widget.canvas.ax.set_ylabel("Magnitude") + mpl_widget.canvas.ax.grid(True) return mpl_widget def get_pulse_amplitude(self, pulse_length: float) -> np.array: diff --git a/src/nqrduck_spectrometer/pulsesequence.py b/src/nqrduck_spectrometer/pulsesequence.py index 882130e..9c60f00 100644 --- a/src/nqrduck_spectrometer/pulsesequence.py +++ b/src/nqrduck_spectrometer/pulsesequence.py @@ -62,6 +62,23 @@ class PulseSequence: ) return obj + + @property + def duration(self): + return self._duration + + @duration.setter + def duration(self, duration : float): + # Duration needs to be a positive number + try: + duration = float(duration) + except ValueError: + raise ValueError("Duration needs to be a number") + if duration < 0: + raise ValueError("Duration needs to be a positive number") + + self._duration = duration + def to_json(self): """Returns a dict with all the data in the pulse sequence