diff --git a/.dev/test_mb_2023_4_mux_2023.py b/.dev/test_mb_2023_4_mux_2023.py index 2841a90d1f53f85ed13e8abceb646b5129f441cf..059a78ebd3a5529054e2e82fd787e4daad6f969e 100644 --- a/.dev/test_mb_2023_4_mux_2023.py +++ b/.dev/test_mb_2023_4_mux_2023.py @@ -85,11 +85,11 @@ if within_ohmpi: print('Starting test with OhmPi.') k = OhmPi() # k.get_data() - k.load_sequence(os.path.join(os.path.dirname(__file__), '../sequences/wenner1-16.txt')) + k.load_sequence(os.path.join(os.path.dirname(__file__), '../sequences/wenner16.txt')) k.reset_mux() # k.run_multiple_sequences(sequence_delay=20, nb_meas=3) - k.run_sequence(injection_duration=0.2) - # k.rs_check(tx_volt=4) + # k.run_sequence(injection_duration=0.2) + k.rs_check(tx_volt=4) # k.test_mux(mux_id=None, activation_time=0.2) # k._hw.switch_mux([A, B, M, N], state='on') # k._hw.vab_square_wave(12.,1., cycles=2) @@ -103,11 +103,11 @@ if within_ohmpi: # k._hw.switch_mux([A, B, M, N], state='off') # print(f'OhmPiHardware Resistance: {k._hw.last_rho :.2f} ohm, dev. {k._hw.last_dev:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') # k._hw._plot_readings() - # A, B, M, N = (17, 20, 18, 19) + A, B, M, N = (17, 20, 18, 19) # A, B, M, N = (1, 4, 2, 3) - # d = k.run_measurement([A, B, M, N], injection_duration=0.5, nb_stack=2, duty_cycle=0.5) - # print(d) - # k._hw._plot_readings() + d = k.run_measurement([A, B, M, N], injection_duration=0.5, nb_stack=2, duty_cycle=0.5) + print(d) + k._hw._plot_readings() # print(f'OhmPiHardware: Resistance: {k._hw.last_resistance() :.2f} ohm, dev. {k._hw.last_dev():.2f} %, sp: {k._hw.sp:.2f} mV, rx bias: {k._hw.rx._bias:.2f} mV') # print(f'OhmPi: Resistance: {d["R [ohm]"] :.2f} ohm, dev. {d["R_std [%]"]:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') # k._hw._plot_readings(save_fig=False) diff --git a/.dev/test_mb_2024_4_mux_2023.py b/.dev/test_mb_2024_4_mux_2023.py index d0700b5a241004a238865277e513f357ce1c8d2b..84d5f5ce4634d8382967575729c4639b240f802a 100644 --- a/.dev/test_mb_2024_4_mux_2023.py +++ b/.dev/test_mb_2024_4_mux_2023.py @@ -91,20 +91,19 @@ if within_ohmpi: # print(f'Resistance: {k._hw.last_rho :.2f} ohm, dev. {k._hw.last_dev:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') # k._hw._plot_readings() A, B, M, N = (1, 4, 2, 3) - k._hw.switch_mux([A, B, M, N], state='on') - k._hw.vab_square_wave(12., cycle_duration=10., cycles=3) - k._hw.switch_mux([A, B, M, N], state='off') + # k._hw.switch_mux([A, B, M, N], state='on') + # k._hw.vab_square_wave(12., cycle_duration=10., cycles=3) + # k._hw.switch_mux([A, B, M, N], state='off') # print(f'OhmPiHardware Resistance: {k._hw.last_rho :.2f} ohm, dev. {k._hw.last_dev:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') - k._hw._plot_readings() - # k.load_sequence('sequences/test_circuit_1423.txt') - #k.load_sequence('sequences/wenner1-16.txt') - # k.run_sequence(tx_volt=5, injection_duration=1., nb_stack=2, duty_cycle=0.5) + # k._hw._plot_readings() + k.load_sequence('sequences/test_circuit_1423.txt') + k.run_sequence(tx_volt=5, injection_duration=1., nb_stack=2, duty_cycle=0.5) print('using OhmPi') #d = k.run_measurement([A, B, M, N], injection_duration=1., nb_stack=2, duty_cycle=0.5) #print(d) #k._hw._plot_readings() - # print(f'OhmPiHardware: Resistance: {k._hw.last_resistance() :.2f} ohm, dev. {k._hw.last_dev():.2f} %, sp: {k._hw.sp:.2f} mV, rx bias: {k._hw.rx._bias:.2f} mV') - # print(f'OhmPi: Resistance: {d["R [ohm]"] :.2f} ohm, dev. {d["R_std [%]"]:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') + print(f'OhmPiHardware: Resistance: {k._hw.last_resistance() :.2f} ohm, dev. {k._hw.last_dev():.2f} %, sp: {k._hw.sp:.2f} mV, rx bias: {k._hw.rx._bias:.2f} mV') + print(f'OhmPi: Resistance: {d["R [ohm]"] :.2f} ohm, dev. {d["R_std [%]"]:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') # k._hw._plot_readings(save_fig=False) # plot_exec_log('ohmpi/logs/exec.log') change_config('../configs/config_default.py', verbose=False) diff --git a/.dev/test_mb_2024_4_mux_2023_dps5005.py b/.dev/test_mb_2024_4_mux_2023_dps5005.py index 347d670e6e70dca58eb6f58f89df36df68394812..bc1c87b7bd96e6de43e7ae2776d75c4dc152f5cd 100644 --- a/.dev/test_mb_2024_4_mux_2023_dps5005.py +++ b/.dev/test_mb_2024_4_mux_2023_dps5005.py @@ -82,9 +82,6 @@ if within_ohmpi: k = OhmPi() # A, B, M, N = (32, 29, 31, 30) k.reset_mux() - # k.export(ftype='protocol') - # k.export(fnames=['data/measurements_20240226T180635.csv'], ftype='bert') - # k.download_data() # k.test_mux(mux_id='mux_03') # k._hw.switch_mux([A, B, M, N], state='on') # k._hw.vab_square_wave(12.,1., cycles=2) @@ -93,23 +90,20 @@ if within_ohmpi: # k._hw.rx._bias = -1.38 # print(f'Resistance: {k._hw.last_rho :.2f} ohm, dev. {k._hw.last_dev:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') # k._hw._plot_readings() - # A, B, M, N = (1, 4, 2, 3) - # A, B, M, N = (5, 8, 6, 7) + A, B, M, N = (1, 4, 2, 3) # k._hw.switch_mux([A, B, M, N], state='on') - # k._hw.vab_square_wave(5., cycle_duration=0.500, cycles=2, duty_cycle=0.5) + # k._hw.vab_square_wave(12., cycle_duration=10., cycles=3) # k._hw.switch_mux([A, B, M, N], state='off') # print(f'OhmPiHardware Resistance: {k._hw.last_rho :.2f} ohm, dev. {k._hw.last_dev:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') - # if k._hw.sp is None: - # k._hw.sp = 0 # if not off-time, sp is None # k._hw._plot_readings() - # k.load_sequence('sequences/test_circuit_1423.txt') - # k.run_sequence(tx_volt=5, injection_duration=1., nb_stack=2, duty_cycle=0.5) + k.load_sequence('sequences/test_circuit_1423.txt') + k.run_sequence(tx_volt=5, injection_duration=1., nb_stack=2, duty_cycle=0.5) print('using OhmPi') #d = k.run_measurement([A, B, M, N], injection_duration=1., nb_stack=2, duty_cycle=0.5) #print(d) #k._hw._plot_readings() - # print(f'OhmPiHardware: Resistance: {k._hw.last_resistance() :.2f} ohm, dev. {k._hw.last_dev():.2f} %, sp: {k._hw.sp:.2f} mV, rx bias: {k._hw.rx._bias:.2f} mV') - # print(f'OhmPi: Resistance: {d["R [ohm]"] :.2f} ohm, dev. {d["R_std [%]"]:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') + print(f'OhmPiHardware: Resistance: {k._hw.last_resistance() :.2f} ohm, dev. {k._hw.last_dev():.2f} %, sp: {k._hw.sp:.2f} mV, rx bias: {k._hw.rx._bias:.2f} mV') + print(f'OhmPi: Resistance: {d["R [ohm]"] :.2f} ohm, dev. {d["R_std [%]"]:.2f} %, rx bias: {k._hw.rx._bias:.2f} mV') # k._hw._plot_readings(save_fig=False) # plot_exec_log('ohmpi/logs/exec.log') change_config('../configs/config_default.py', verbose=False) diff --git a/configs/config_mb_2024_0_2__4_mux_2023_dps5005.py b/configs/config_mb_2024_0_2__4_mux_2023_dps5005.py index d555152def25298a3851167e5220267dae4c02f7..57cd2686ed8f30c6445d53d2a56586e10896a052 100644 --- a/configs/config_mb_2024_0_2__4_mux_2023_dps5005.py +++ b/configs/config_mb_2024_0_2__4_mux_2023_dps5005.py @@ -64,7 +64,7 @@ HARDWARE_CONFIG = { 'electrodes': range(1, 65), } }, - 'default': {'interface_name': 'i2c', + 'default': {'interface_name': 'i2c_ext', 'voltage_max': 50., 'current_max': 3.} } diff --git a/index.html b/index.html index c4ebc192716eaae0361373339cdf4a0b98290908..21caa76d685b42d74567744124ced49aaa490b7f 100755 --- a/index.html +++ b/index.html @@ -33,7 +33,6 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl <!-- <button id="removeDataBtn" type="button" class="btn btn-danger">Clear data</button> --> <button id="rmDataModal" type="button" class="btn btn-danger" data-toggle="modal" data-target="#rmModal">Clear data</button> <button id="getDataBtn" type="button" class="btn btn-info">Get data</button> - <div><b id='connection'>Connecting...</b></div> <div class="form-check"> <input id="dataRetrievalCheck" class="form-check-input" type="checkbox" value=""> <label class="form-check-label" for="dataRetrievalCheck"> @@ -190,16 +189,13 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl let commands = {} // store commands and their id let callbacks = {} // store callback (might not be needed) let invertedData = [{ - // rho: [[10, 10.625, 12.5, 15.625, 20], - // [5.625, 6.25, 8.125, 11.25, 15.625], - // [2.5, 3.125, 5., 8.125, 12.5], - // [0.625, 1.25, 3.125, 6.25, 10.625], - // [0, 0.625, 2.5, 5.625, 10]], - // x: [-9, -6, -5 , -3, -1], - // y: [0, 1, 4, 5, 7], - rho: [], - x: [], - y: [] + rho: [[10, 10.625, 12.5, 15.625, 20], + [5.625, 6.25, 8.125, 11.25, 15.625], + [2.5, 3.125, 5., 8.125, 12.5], + [0.625, 1.25, 3.125, 6.25, 10.625], + [0, 0.625, 2.5, 5.625, 10]], + x: [-9, -6, -5 , -3, -1], + y: [0, 1, 4, 5, 7], }] // store inverted data // function with MQTT @@ -231,11 +227,9 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl message = new Paho.MQTT.Message("Hello from index.html") message.destinationName = topic_ctrl client.send(message) - document.getElementById('connection').innerText = 'Connected' } function onConnectionLost(responseObject) { - document.getElementById('connection').innerText = 'Connecting...' if (responseObject.errorCode !== 0) console.log("onConnectionLost:" + responseObject.errorMessage) console.log("trying to reconnect...") @@ -666,7 +660,7 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl surveySelect.value = surveyNames[surveyNames.length - 1] // call the function directly - // (as progammatically changing the value does not trigger the event) + // (as progammatically chaging the value does not trigger the event) surveySelectFunc({'target': surveySelect}) // update list of survey for inversion diff --git a/ohmpi/hardware_system.py b/ohmpi/hardware_system.py index 38e2dd6d06f9033ec594e552b19b80096af7c9e5..3e908438e5b4634ef54d44d4e53daf05221dd5e4 100644 --- a/ohmpi/hardware_system.py +++ b/ohmpi/hardware_system.py @@ -589,11 +589,6 @@ class OhmPiHardware: def _plot_readings(self, save_fig=False, filename=None): # Plot graphs - flag = False - if self.sp is None: - flag = True - print('self.sp is None, setting it 0') - self.sp = 0 warnings.filterwarnings("ignore", category=DeprecationWarning) fig, ax = plt.subplots(nrows=5, sharex=True) ax[0].plot(self.readings[:, 0], self.readings[:, 3], '-r', marker='.', label='iab') @@ -608,8 +603,6 @@ class OhmPiHardware: ax[3].set_ylabel('R [ohm]') ax[4].plot(self.readings[v, 0], np.ones_like(self.readings[v, 0]) * self.sp, '-k', marker='.', label='SP [mV]') ax[4].set_ylabel('SP [mV]') - if flag: # if it was None, we put it back to None to not interfere with the rest - self.sp = None # fig.legend() if save_fig: if filename is None: diff --git a/ohmpi/ohmpi.py b/ohmpi/ohmpi.py index 4b11209b4f55eb8a0da626548b10021e894e0710..dc277a4467f211a8b822413ece7ef6d09d5f7795 100644 --- a/ohmpi/ohmpi.py +++ b/ohmpi/ohmpi.py @@ -436,9 +436,9 @@ class OhmPi(object): def download_data(self, cmd_id=None): """Create a zip of the data folder to then download it easily. """ - datadir, _ = os.path.split(self.settings['export_path']) - zippath = os.path.abspath(os.path.join(os.path.dirname(__file__), '../data')) - make_archive(zippath, 'zip', datadir) + datadir = os.path.split(self.settings['export_path']) + # datadir = os.path.join(os.path.dirname(__file__), '../data/') + make_archive(datadir, 'zip', 'data') self.data_logger.info(json.dumps({'download': 'ready'})) def shutdown(self, cmd_id=None): @@ -1061,75 +1061,6 @@ class OhmPi(object): export_dir = os.path.split(os.path.dirname(__file__))[0] self.settings['export_path'] = os.path.join(export_dir, self.settings['export_path']) - def export(self, fnames=None, outputdir=None, ftype='bert', elec_spacing=1): - """Export surveys stored in the 'data/' folder into an output - folder. - - Parameters - ---------- - fnames : list of str, optional - List of path (not filename) to survey in ohmpi format to be converted. - outputdir : str, optional - Path of the output directory where the new files are stored. If None, - a directory called 'output' is created in OhmPi. - ftype : str, optional - Type of export. To be chosen between: - - bert (same as pygimli) - - pygimli (same as bert) - - protocol (for resipy, R2 codes) - elec_spacing : float, optional - Electrode spacing in meters. Same electrode spacing is assumed. - """ - # handle parameters default values - if fnames is None: - datadir = os.path.join(os.path.dirname(__file__), '../data/') - fnames = [os.path.join(datadir, f) for f in os.listdir(datadir) if f[-4:] == '.csv'] - if outputdir is None: - outputdir = os.path.join(os.path.dirname(__file__), '../output/') - if os.path.exists(outputdir) is False: - os.mkdir(outputdir) - - # define parser - def ohmpi_parser(fname): - df = pd.read_csv(fname) - 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'] - df['ip'] = np.nan - emax = np.max(df[['a', 'b', 'm', 'n']].values) - elec = np.zeros((emax, 3)) - elec[:, 0] = np.arange(emax) * elec_spacing - return elec, df[['a', 'b', 'm', 'n', 'vp', 'i', 'resist', 'ip']] - - # read all files and save them in the desired format - for fname in tqdm(fnames): - try: - elec, df = ohmpi_parser(fname) - fout = os.path.join(outputdir, os.path.basename(fname).replace('.csv', '')) - if ftype == 'protocol': - fout = fout + '.dat' - with open(fout, 'w') as f: - f.write('{:d}\n'.format(df.shape[0])) - with open(fout, 'a') as f: - df['index'] = np.arange(1, df.shape[0]+1) - df[['index', 'a', 'b', 'm', 'n', 'resist']].to_csv( - f, index=False, sep=' ', header=False) - elif ftype == 'bert' or ftype == 'pygimli': - fout = fout + '.dat' - with open(fout, 'w') as f: - f.write('{:d} # positions electrodes\n'.format(elec.shape[0])) - f.write('#\tx\ty\tz\n') - for j in range(elec.shape[0]): - f.write('{:.2f}\t{:.2f}\t{:.2f}\n'.format(*elec[j, :])) - f.write('{:d} # number of data\n'.format(df.shape[0])) - f.write('#\ta\tb\tm\tn\tR\n') - with open(fout, 'a') as f: - df[['a', 'b', 'm', 'n', 'resist']].to_csv( - f, index=False, sep='\t', header=False) - except Exception as e: - print('export(): could not save file', fname) - def run_inversion(self, survey_names=None, elec_spacing=1, **kwargs): """Run a simple 2D inversion using ResIPy (https://gitlab.com/hkex/resipy). @@ -1173,7 +1104,7 @@ class OhmPi(object): from scipy.interpolate import griddata # noqa import pandas as pd # noqa import sys - sys.path.append(os.path.join(pdir, '../../resipy/src')) + sys.path.append(os.path.join(pdir, '/home/pi/resipy/src')) from resipy import Project # noqa except Exception as e: self.exec_logger.error('Cannot import ResIPy, scipy or Pandas, error: ' + str(e)) diff --git a/run_http_interface.sh b/run_http_interface.sh index a49589629b4c70d35feff1de992df09f0a50de3d..0dabb4f00ed81f52ae7b30d7d4a6b409f48bd21b 100755 --- a/run_http_interface.sh +++ b/run_http_interface.sh @@ -1,3 +1,3 @@ export PYTHONPATH=`pwd` source $PYTHONPATH/ohmpy/bin/activate -python start_mqtt_html.py +python3 start_mqtt_html.py diff --git a/start_mqtt_html.py b/start_mqtt_html.py index 6c59c7fe4263d03002f6384d00a429b566481bea..7e5ec9ea80ae22f15afd035f450abb3515a39a90 100644 --- a/start_mqtt_html.py +++ b/start_mqtt_html.py @@ -5,7 +5,7 @@ from ohmpi.utils import change_config # change_config('../configs/config_mb_2023.py', verbose=False) # change_config('../configs/config_mb_2023__4_mux_2023.py', verbose=False) -# change_config('../configs/config_mb_2024_0_2__4_mux_2023_dps5005.py', verbose=False) +#change_config('../configs/config_mb_2024_0_2__4_mux_2023_dps5005.py', verbose=False) # start html interface import subprocess @@ -16,9 +16,9 @@ try: from ohmpi.ohmpi import OhmPi from ohmpi.config import OHMPI_CONFIG k = OhmPi(settings=OHMPI_CONFIG['settings']) - # import os - # k.load_sequence(os.path.join(os.path.dirname(__file__), './sequences/wenner1-16.txt')) - # k.reset_mux() + import os + k.load_sequence(os.path.join(os.path.dirname(__file__), './sequences/wenner16.txt')) + k.reset_mux() #k.run_multiple_sequences(sequence_delay=20, nb_meas=3) if k.controller is not None: