summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lab_control/frequency_response.py10
-rw-r--r--lab_control/measurement.py4
-rw-r--r--lab_control/test/frequency_response_test.py19
3 files changed, 28 insertions, 5 deletions
diff --git a/lab_control/frequency_response.py b/lab_control/frequency_response.py
index 8d46689..af78840 100644
--- a/lab_control/frequency_response.py
+++ b/lab_control/frequency_response.py
@@ -1,3 +1,5 @@
+from pathlib import Path
+
from lab_control.function_generator import FunctionGenerator
from lab_control.oscilloscope import Oscilloscope
from lab_control.measurement import Measurement, getLinearRange
@@ -23,5 +25,9 @@ class FrequencyResponseMeasurement(Measurement):
self.measurementDone = True
- def saveToCSV(self, path: str) -> None:
- pass
+ def dumpToCSV(self, path: Path) -> None:
+ with open(path, "w") as f:
+ f.write("Frequency (Hz),Amplitude (V)")
+
+ for entry in self.data:
+ f.write(f"\n{entry[0]},{entry[1]}")
diff --git a/lab_control/measurement.py b/lab_control/measurement.py
index eca228d..18a933c 100644
--- a/lab_control/measurement.py
+++ b/lab_control/measurement.py
@@ -1,3 +1,5 @@
+from pathlib import Path
+
from lab_control.function_generator import FunctionGenerator
from lab_control.oscilloscope import Oscilloscope
@@ -11,5 +13,5 @@ class Measurement:
def measure(self, osc: Oscilloscope, fg: FunctionGenerator) -> None:
pass
- def saveToCSV(self, path: str) -> None:
+ def dumpToCSV(self, path: Path) -> None:
pass
diff --git a/lab_control/test/frequency_response_test.py b/lab_control/test/frequency_response_test.py
index 014b4f6..ad47d53 100644
--- a/lab_control/test/frequency_response_test.py
+++ b/lab_control/test/frequency_response_test.py
@@ -37,7 +37,7 @@ def test_frequencyResponseDefaults(uut):
assert uut.functionGeneratorChannel == 1
assert uut.oscilloscopeChannel == 1
-def test_frequencyResponseRamp(mockLab, uut):
+def test_frequencyResponseRamp(uut, mockLab):
uut.minFrequency = 100.0
uut.maxFrequency = 200.0
uut.steps = 11
@@ -49,8 +49,23 @@ def test_frequencyResponseRamp(mockLab, uut):
assert not uut.measurementDone
assert uut.data == None
- response = uut.measure(mockLab, mockLab)
+ uut.measure(mockLab, mockLab)
assert uut.measurementDone
assert uut.data == expectedData
+def test_dumpToCSV(uut, mockLab, tmp_path):
+ uut.minFrequency = 10.0
+ uut.maxFrequency = 30.0
+ uut.steps = 5
+
+ expectedData = prepareRampResponse(uut, mockLab)
+ uut.measure(mockLab, mockLab)
+
+ csv = tmp_path / "data.csv"
+ uut.dumpToCSV(csv)
+ savedData = csv.read_text().split("\n")
+
+ assert savedData[0] == "Frequency (Hz),Amplitude (V)"
+ for i, l in enumerate(savedData[1:]):
+ assert l == f"{expectedData[i][0]},{expectedData[i][1]}"