From 8917ed5adf26467f5e8a1059dc8e03282cef131b Mon Sep 17 00:00:00 2001
From: awatlet <arnaud.watlet@umons.ac.be>
Date: Tue, 10 Oct 2023 13:55:22 +0200
Subject: [PATCH] Fixing Vmn calculation

---
 ohmpi/hardware_system.py | 2 +-
 ohmpi/ohmpi.py           | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py
index 215264f3..214729f9 100644
--- a/ohmpi/hardware_system.py
+++ b/ohmpi/hardware_system.py
@@ -290,7 +290,7 @@ class OhmPiHardware:
             mean_vmn = []
             mean_iab = []
             for i in range(n_pulses + 1):
-                mean_vmn.append(polarity[i] * np.mean(self.readings[self.readings[:, 1] == i, 4]))
+                mean_vmn.append(np.mean(self.readings[self.readings[:, 1] == i, 4]))
                 mean_iab.append(np.mean(self.readings[self.readings[:, 1] == i, 3]))
             mean_vmn = np.array(mean_vmn)
             mean_iab = np.array(mean_iab)
diff --git a/ohmpi/ohmpi.py b/ohmpi/ohmpi.py
index 397659a4..5833b4c9 100644
--- a/ohmpi/ohmpi.py
+++ b/ohmpi/ohmpi.py
@@ -463,12 +463,13 @@ class OhmPi(object):
                 delay = 0.
             x = np.where((self._hw.readings[:, 0] >= delay) & (self._hw.readings[:, 2] != 0))
             print(f'length of series: {len(x)}')
-            R = np.mean((self._hw.readings[x, 2] * (self._hw.readings[x, 4] - self._hw.sp)) / self._hw.readings[x, 3])
+            # R = np.mean((self._hw.readings[x, 2] * (self._hw.readings[x, 4] - self._hw.sp)) / self._hw.readings[x, 3])
             R_std = 100. * np.std((self._hw.readings[x, 2] * (self._hw.readings[x, 4] - self._hw.sp)) / self._hw.readings[x, 3]) / R
-            Vmn = np.mean(self._hw.readings[x, 2] * (self._hw.readings[x, 4] - self._hw.sp))
-            Vmn_std = 100. * np.std(self._hw.readings[x, 2] * (self._hw.readings[x, 4] - self._hw.sp))
+            Vmn = np.mean(self._hw.readings[x, 2] * (self._hw.readings[x, 4])) # - self._hw.sp))
+            Vmn_std = 100. * np.std(self._hw.readings[x, 2] * (self._hw.readings[x, 4])) # - self._hw.sp))
             I = np.mean(self._hw.readings[x, 3])
             I_std = 100. * np.std(self._hw.readings[x, 3])
+            R = Vmn / I
             d = {
                 "time": datetime.now().isoformat(),
                 "A": quad[0],
-- 
GitLab