Commit 4d9ce1a2 authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

adding test_ohmpi_mux.py and redirecting measure() to run_multiple_sequences()

Showing with 80 additions and 67 deletions
+80 -67
...@@ -4,7 +4,7 @@ created on January 6, 2020. ...@@ -4,7 +4,7 @@ created on January 6, 2020.
Updates May 2022, Oct 2022. Updates May 2022, Oct 2022.
Ohmpi.py is a program to control a low-cost and open hardware resistivity meter OhmPi that has been developed by Ohmpi.py is a program to control a low-cost and open hardware resistivity meter OhmPi that has been developed by
Rémi CLEMENT (INRAE),Vivien DUBOIS (INRAE), Hélène GUYARD (IGE), Nicolas FORQUET (INRAE), Yannick FARGIER (IFSTTAR) Rémi CLEMENT (INRAE),Vivien DUBOIS (INRAE), Hélène GUYARD (IGE), Nicolas FORQUET (INRAE), Yannick FARGIER (IFSTTAR)
Olivier KAUFMANN (UMONS), Arnaud WATELET (UMONS) and Guillaume BLANCHY (ILVO). Olivier KAUFMANN (UMONS), Arnaud WATELET (UMONS) and Guillaume BLANCHY (FNRS/ULiege).
""" """
import os import os
...@@ -1042,10 +1042,7 @@ class OhmPi(object): ...@@ -1042,10 +1042,7 @@ class OhmPi(object):
reply = {'cmd_id': cmd_id, 'status': status} reply = {'cmd_id': cmd_id, 'status': status}
reply = json.dumps(reply) reply = json.dumps(reply)
self.exec_logger.debug(f'Execution report: {reply}') self.exec_logger.debug(f'Execution report: {reply}')
def measure(self, *args, **kwargs):
warnings.warn('This function is deprecated. Use load_sequence instead.', DeprecationWarning)
self.run_sequence(self, *args, **kwargs)
def set_sequence(self, args): def set_sequence(self, args):
try: try:
...@@ -1056,7 +1053,8 @@ class OhmPi(object): ...@@ -1056,7 +1053,8 @@ class OhmPi(object):
status = False status = False
def run_sequence(self, cmd_id=None, **kwargs): def run_sequence(self, cmd_id=None, **kwargs):
"""Run sequence in sync mode """Run sequence synchronously (=blocking on main thread).
Additional arguments are passed to run_measurement().
""" """
self.status = 'running' self.status = 'running'
self.exec_logger.debug(f'Status: {self.status}') self.exec_logger.debug(f'Status: {self.status}')
...@@ -1113,6 +1111,7 @@ class OhmPi(object): ...@@ -1113,6 +1111,7 @@ class OhmPi(object):
def run_sequence_async(self, cmd_id=None, **kwargs): def run_sequence_async(self, cmd_id=None, **kwargs):
""" Run the sequence in a separate thread. Can be stopped by 'OhmPi.interrupt()'. """ Run the sequence in a separate thread. Can be stopped by 'OhmPi.interrupt()'.
Additional arguments are passed to run_measurement().
""" """
# self.run = True # self.run = True
self.status = 'running' self.status = 'running'
...@@ -1175,9 +1174,14 @@ class OhmPi(object): ...@@ -1175,9 +1174,14 @@ class OhmPi(object):
self.thread = threading.Thread(target=func) self.thread = threading.Thread(target=func)
self.thread.start() self.thread.start()
def measure(self, *args, **kwargs):
warnings.warn('This function is deprecated. Use run_multiple_sequences() instead.', DeprecationWarning)
self.run_sequence(self, *args, **kwargs)
def run_multiple_sequences(self, cmd_id=None, **kwargs): def run_multiple_sequences(self, cmd_id=None, **kwargs):
""" Run multiple sequences in a separate thread for monitoring mode. """ Run multiple sequences in a separate thread for monitoring mode.
Can be stopped by 'OhmPi.interrupt()'. Can be stopped by 'OhmPi.interrupt()'.
Additional arguments are passed to run_measurement().
""" """
# self.run = True # self.run = True
self.status = 'running' self.status = 'running'
......
...@@ -9,15 +9,27 @@ import os ...@@ -9,15 +9,27 @@ import os
idps = False idps = False
board_version = '22.10' # v2.0 board_version = '22.10' # v2.0
use_mux = True use_mux = True
start_elec = 1 # start elec start_elec = 17 # start elec
nelec = 16 # max elec in the sequence for testing nelec = 16 # max elec in the sequence for testing
# nelec electrodes Wenner sequence
a = np.arange(nelec-3) + start_elec
b = a + 3
m = a + 1
n = a + 2
seq = np.c_[a, b, m, n]
# testing measurement board only # testing measurement board only
k = OhmPi(idps=idps, use_mux=use_mux) k = OhmPi(idps=idps, use_mux=use_mux)
k.sequence = seq # we need a sequence for possibly switching the mux
k.reset_mux() # just for safety k.reset_mux() # just for safety
if use_mux:
k.switch_mux_on(seq[:, 0])
out1 = k.run_measurement(injection_duration=0.25, nb_stack=4, strategy='constant', tx_volt=12, autogain=True) out1 = k.run_measurement(injection_duration=0.25, nb_stack=4, strategy='constant', tx_volt=12, autogain=True)
out2 = k.run_measurement(injection_duration=0.5, nb_stack=2, strategy='vmin', tx_volt=5, autogain=True) out2 = k.run_measurement(injection_duration=0.5, nb_stack=2, strategy='vmin', tx_volt=5, autogain=True)
out3 = k.run_measurement(injection_duration=1, nb_stack=1, strategy='vmax', tx_volt=5, autogain=True) out3 = k.run_measurement(injection_duration=1, nb_stack=1, strategy='vmax', tx_volt=5, autogain=True)
if use_mux:
k.switch_mux_off(seq[:, 0])
# visual figure of the full wave form # visual figure of the full wave form
fig, axs = plt.subplots(2, 1, sharex=True) fig, axs = plt.subplots(2, 1, sharex=True)
...@@ -40,66 +52,63 @@ fig.savefig('check-fullwave.jpg') ...@@ -40,66 +52,63 @@ fig.savefig('check-fullwave.jpg')
# test a sequence # test a sequence
if use_mux:
# nelec electrodes Wenner sequence # manually edit default settings
a = np.arange(nelec-3) + start_elec k.settings['injection_duration'] = 1
b = a + 3 k.settings['nb_stack'] = 1
m = a + 1 #k.settings['nbr_meas'] = 1
n = a + 2 k.sequence = seq
seq = np.c_[a, b, m, n] k.reset_mux()
# manually edit default settings # set quadrupole manually
k.settings['injection_duration'] = 1 k.switch_mux_on(seq[0, :])
k.settings['nb_stack'] = 1 out = k.run_measurement(quad=[3, 3, 3, 3], nb_stack=1, tx_volt=12, strategy='constant', autogain=True)
#k.settings['nbr_meas'] = 1 k.switch_mux_off(seq[0, :])
k.sequence = seq print(out)
k.reset_mux()
# run rs_check() and save data
# set quadrupole manually k.rs_check() # check all electrodes of the sequence
k.switch_mux_on([1, 4, 2, 3])
out = k.run_measurement(quad=[3, 3, 3, 3], nb_stack=1, tx_volt=12, strategy='constant', autogain=True) # check values measured
k.switch_mux_off([1, 4, 2, 3]) fname = sorted(os.listdir('data/'))[-1]
print(out) print(fname)
dfrs = pd.read_csv('data/' + fname)
# run rs_check() and save data fig, ax = plt.subplots()
k.rs_check() # check all electrodes of the sequence ax.hist(dfrs['RS [kOhm]'])
ax.set_xticks(np.arange(dfrs.shape[0]))
# check values measured ax.set_xticklabels(dfrs['A'].astype(str) + ' - ' +
fname = sorted(os.listdir('data/'))[-1] dfrs['B'].astype(str), rotation=90)
print(fname) ax.set_ylabel('Contact resistances [kOhm]')
dfrs = pd.read_csv('data/' + fname) fig.tight_layout()
fig, ax = plt.subplots() fig.savefig('check-rs.jpg')
ax.hist(dfrs['R [Ohm]']/1000)
ax.set_xticks(np.arange(df.shape[0])) # run sequence synchronously and save data to file
ax.set_xticklabels(df['A'].str + ' - ' + df['B'].str) k.run_sequence(nb_stack=1, injection_duration=0.25)
ax.set_ylabel('Contact resistances [kOhm]')
fig.tight_layout() # check values measured
fig.savefig('check-rs.jpg') fname = sorted(os.listdir('data/'))[-1]
print(fname)
# run sequence synchronously and save data to file df = pd.read_csv('data/' + fname)
k.run_sequence(nb_stack=1, injection_duration=0.25) fig, ax = plt.subplots()
ax.hist(df['R [ohm]'])
# check values measured ax.set_ylabel('Transfer resistance [Ohm]')
fname = sorted(os.listdir('data/'))[-1] ax.set_xticks(np.arange(df.shape[0]))
print(fname) ax.set_xticklabels(df['A'].astype(str) + ','
df = pd.read_csv('data/' + fname) + df['B'].astype(str) + ','
fig, ax = plt.subplots() + df['M'].astype(str) + ','
ax.hist(df['R [ohm]']) + df['N'].astype(str), rotation=90)
ax.set_ylabel('Transfer resistance [Ohm]') fig.tight_layout()
ax.set_xticks(np.arange(df.shape[0])) fig.savefig('check-r.jpg')
ax.set_xticklabels(df['A'] + ',' + df['B'] + ',' + df['M'] + ',' + df['N'])
fig.tight_layou() # run sequence asynchronously and save data to file
fig.savefig('check-r.jpg') k.run_sequence_async(nb_stack=1, injection_duration=0.25)
time.sleep(2)
# run sequence asynchronously and save data to file k.interrupt() # will kill the asynchronous sequence running
k.run_sequence_async(nb_stack=1, injection_duration=0.25)
time.sleep(2) # run a series of asynchronous sequences
k.interrupt() # will kill the asynchronous sequence running k.run_multiple_sequences(nb_stack=1, injection_duration=0.25)
time.sleep(2)
# run a series of asynchronous sequences k.interrupt()
k.run_sequences(nb_stack=1, injection_duration=0.25)
time.sleep(10)
k.interrupt()
# look at the noise frequency with FFT # look at the noise frequency with FFT
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment