From 590edb5bc591f110b4cddf952798f918d79e3f59 Mon Sep 17 00:00:00 2001
From: su530201 <olivier.kaufmann@umons.ac.be>
Date: Sun, 23 Apr 2023 12:23:22 +0200
Subject: [PATCH] Adds a pulses property

---
 measure.py                           | 9 +++++++++
 test_measure_with_ohmpi_card_3_15.py | 3 +++
 2 files changed, 12 insertions(+)

diff --git a/measure.py b/measure.py
index 3033b3c5..6102f7a9 100644
--- a/measure.py
+++ b/measure.py
@@ -62,6 +62,15 @@ class OhmPiHardware:
             self.tx.voltage_pulse(length=duration)
             self.tx_sync.clear()
 
+    @property
+    def pulses(self):
+        pulses = {}
+        for i in np.unique(self.readings[:,1]):
+            r = self.readings[self.readings[:, 1] == i, :]
+            assert np.all(np.isclose(r[:,2], r[0, 2]))  # Polarity cannot change within a pulse
+            pulses.update({i: {'polarity': int(r[0, 2]), 'iab': r[:,3], 'vmn' : r[:,4]}})  # TODO: check how to generalize in case of multi-channel RX
+        return pulses
+
     def _read_values(self, sampling_rate, append=False):  # noqa
         if not append:
             self._clear_values()
diff --git a/test_measure_with_ohmpi_card_3_15.py b/test_measure_with_ohmpi_card_3_15.py
index c2b9576c..da5436c0 100644
--- a/test_measure_with_ohmpi_card_3_15.py
+++ b/test_measure_with_ohmpi_card_3_15.py
@@ -42,5 +42,8 @@ plt.show()
 print(f'SP: {k.sp} mV')
 r = ((k.readings[:,4]-k.sp)/k.readings[:,3])
 print(f'Mean resistance with sp correction : {np.mean(r):.3f} Ohms, Dev. {100*np.std(r)/np.mean(r):.1f} %')
+print('\nTesting with pulses')
+r = np.array([(k.pulses[i]['vmn']-k.sp)/k.pulses[i]['iab'] for i in k.pulses.keys()])
+print(f'Mean resistance with sp correction : {np.mean(r):.3f} Ohms, Dev. {100*np.std(r)/np.mean(r):.1f} %')
 change_config('config_default.py', verbose=False)
 
-- 
GitLab