diff --git a/ohmpi/hardware_components/abstract_hardware_components.py b/ohmpi/hardware_components/abstract_hardware_components.py index 5b98a620f4f1873104c14a6a3c6f4cc84ef6e7cb..8550820046668cc1574f11cc762a0d8dc291980c 100644 --- a/ohmpi/hardware_components/abstract_hardware_components.py +++ b/ohmpi/hardware_components/abstract_hardware_components.py @@ -363,6 +363,18 @@ class TxAbstract(ABC): assert value > 0. self._injection_duration = value + @property + def latency(self): + """ Gets the Tx latency """ + return self._latency + + @latency.setter + def latency(self, value): + """ Sets the Tx latency """ + assert isinstance(value, float) + assert value >= 0. + self._latency = value + @property def polarity(self): return self._polarity @@ -453,6 +465,17 @@ class RxAbstract(ABC): self._bias = kwargs.pop('bias', 0.) self._vmn_hardware_offset = kwargs.pop('vmn_hardware_offset', 0.) + @property + def bias(self): + """ Gets the RX bias """ + return self._bias + + @bias.setter + def bias(self, value): + """ Sets the Rx bias """ + assert isinstance(value, float) + self._bias = value + @property def gain(self): return self._gain @@ -472,6 +495,18 @@ class RxAbstract(ABC): def gain_auto(self): pass + @property + def latency(self): + """ Gets the Rx latency """ + return self._latency + + @latency.setter + def latency(self, value): + """ Sets the Rx latency """ + assert isinstance(value, float) + assert value >= 0. + self._latency = value + def reset_gain(self): self.gain = 1. @@ -498,6 +533,5 @@ class RxAbstract(ABC): @property @abstractmethod def voltage(self): - """ Gets the voltage VMN in Volts - """ + """ Gets the voltage VMN in Volts """ pass diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index ca65eba4bf4ada3fdafa39cdff4be7578de18a05..0e9835b8c41257a71f524ab5c68bf0521e491f93 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -271,7 +271,7 @@ class OhmPiHardware: if not append or self._start_time is None: self._start_time = datetime.datetime.utcnow() # TODO: Check if replacing the following two options by a reset_buffer method of TX would be OK - time.sleep(np.max([self.rx._latency, self.tx._latency])) # if continuous mode + time.sleep(np.max([self.rx.latency, self.tx.latency])) # if continuous mode # _ = self.rx.voltage # if not continuous mode while self.tx_sync.is_set(): @@ -395,9 +395,9 @@ class OhmPiHardware: return new_vab - def _compute_tx_volt(self, pulse_duration=0.1, strategy='vmax', tx_volt=5., vab_max=None, - iab_max=None, vmn_max=None, vmn_min=voltage_min, polarities=(1, -1), delay=0.05, - p_max=None, diff_vab_lim=2.5, n_steps=4): + def compute_tx_volt(self, pulse_duration=0.1, strategy='vmax', tx_volt=5., vab_max=None, + iab_max=None, vmn_max=None, vmn_min=voltage_min, polarities=(1, -1), delay=0.05, + p_max=None, diff_vab_lim=2.5, n_steps=4): # TODO: Optimise how to pass iab_max, vab_max, vmn_min # TODO: Update docstring """Estimates best Tx voltage based on different strategies. @@ -467,7 +467,6 @@ class OhmPiHardware: k = 0 vab_list = np.zeros(n_steps + 1) * np.nan - vab_list[k] = vab # self.tx.turn_on() switch_pwr_off, switch_tx_pwr_off = False, False # TODO: check if these should be moved in kwargs @@ -562,7 +561,7 @@ class OhmPiHardware: warnings.resetwarnings() def calibrate_rx_bias(self): - self.rx._bias += (np.mean(self.readings[self.readings[:, 2] == 1, 4]) + self.rx.bias += (np.mean(self.readings[self.readings[:, 2] == 1, 4]) + np.mean(self.readings[self.readings[:, 2] == -1, 4])) / 2. def vab_square_wave(self, vab, cycle_duration, sampling_rate=None, cycles=3, polarity=1, duty_cycle=1., diff --git a/ohmpi/ohmpi.py b/ohmpi/ohmpi.py index 5d6eb1d80dfade52045d75ddba14103ba234d70d..63cc418cdbc308b91c048305544e5cff8c8c2a0e 100644 --- a/ohmpi/ohmpi.py +++ b/ohmpi/ohmpi.py @@ -527,7 +527,7 @@ class OhmPi(object): bypass_check = kwargs['bypass_check'] if 'bypass_check' in kwargs.keys() else False d = {} if self.switch_mux_on(quad, bypass_check=bypass_check, cmd_id=cmd_id): - tx_volt = self._hw._compute_tx_volt(tx_volt=tx_volt, strategy=strategy, vmn_max=vmn_max, vab_max=vab_max, iab_max=iab_max) # TODO: use tx_volt and vmn_max instead of hardcoded values + tx_volt = self._hw.compute_tx_volt(tx_volt=tx_volt, strategy=strategy, vmn_max=vmn_max, vab_max=vab_max, iab_max=iab_max) # TODO: use tx_volt and vmn_max instead of hardcoded values time.sleep(0.5) # to wait for pwr discharge self._hw.vab_square_wave(tx_volt, cycle_duration=injection_duration*2/duty_cycle, cycles=nb_stack, duty_cycle=duty_cycle) if 'delay' in kwargs.keys(): @@ -556,7 +556,7 @@ class OhmPi(object): "nbStack": nb_stack, "Tx [V]": tx_volt, "CPU temp [degC]": self._hw.ctl.cpu_temperature, - "Nb samples [-]": len(self._hw.readings[x,2]), # TODO: use only samples after a delay in each pulse + "Nb samples [-]": len(self._hw.readings[x, 2]), # TODO: use only samples after a delay in each pulse "fulldata": self._hw.readings[:, [0, -2, -1]], "I_std [%]": I_std, "Vmn_std [%]": Vmn_std, @@ -812,7 +812,7 @@ class OhmPi(object): 'rsdata': { 'A': int(quad[0]), 'B': int(quad[1]), - 'rs': np.round(rab,3), # in kOhm + 'rs': np.round(rab, 3), # in kOhm } } self.data_logger.info(json.dumps(msg)) @@ -1030,7 +1030,7 @@ class OhmPi(object): # define a parser for the "ohmpi" format def ohmpiParser(fname): df = pd.read_csv(fname) - df = df.rename(columns={'A':'a', 'B':'b', 'M':'m', 'N':'n'}) + df = df.rename(columns={'A': 'a', 'B': 'b', 'M': 'm', 'N': 'n'}) df['vp'] = df['Vmn [mV]'] df['i'] = df['I [mA]'] df['resist'] = df['vp']/df['i']