diff --git a/index-mqtt.html b/index-mqtt.html index 29ff1906ace618014b935ec0ca14238cea54532e..f976c2cc9402922f253b4dbb5fda75750e82b2d2 100755 --- a/index-mqtt.html +++ b/index-mqtt.html @@ -62,7 +62,6 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl <!-- Inversion plot --> <select id="surveySelectInv" class='custom-select'> - <option>measurement_20220206T194552.csv</option> </select> <button id="invertBtn" type="button" class="btn btn-info">Run inversion</button> <input id="cminInv" type="number" value="0"/> @@ -504,7 +503,8 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl // processMessage function processMessage(ddic) { - if ('status' in ddic) { + //if (('status' in ddic) | ('data' in ddic)) { + if (ddic.constructor == Object) { // it's a dictionnary // acquisition related processData(ddic) } else { @@ -550,6 +550,19 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl // (as progammatically chaging the value does not trigger the event) surveySelectFunc({'target': surveySelect}) + // update list of survey for inversion + surveySelectInv.removeEventListener('change', showInvFunc) + surveySelectInv.innerHTML = '' // clearing all child nodes + for (let surveyName of surveyNames) { + let option = document.createElement('option') + option.innerText = surveyName + option.value = surveyName + surveySelectInv.appendChild(option) + } + surveySelectInv.addEventListener('change', showInvFunc) + surveySelectInv.value = surveyNames[surveyNames.length - 1] + + // update list of quadrupoles if any if (quads.length == 0) { console.log('updating list of quadrupoles') @@ -630,7 +643,7 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl x: invertedData[0]['x'], y: invertedData[0]['z'], type: 'contour', - colorscale: 'Jet', + colorscale: 'Viridis', autocontour: true, // set to false if cmin is given contours: { start: cmin, @@ -650,16 +663,23 @@ mosquitto_sub -h raspberrypi.local -t ohmpi_0001/ctrl } Plotly.newPlot('inv', invData, invLayout) + var btn = document.getElementById('invertBtn') + btn.innerText = 'Run inversion' + btn.className = 'btn btn-info' + } showInvFunc() - //invert data + // invert data function invertBtnFunc() { let survey_name = document.getElementById('surveySelectInv').value + var btn = document.getElementById('invertBtn') + btn.innerText = 'Inverting...' + btn.className = 'btn btn-warning' sendCommand(JSON.stringify({ 'cmd': 'run_inversion', 'kwargs': { - 'survey_names': [survey_name] + 'survey_names': [survey_name + '.csv'] } }), function(x) { console.log('inversion results', x) diff --git a/ohmpi/ohmpi.py b/ohmpi/ohmpi.py index efecdb58c85a7aa5a70350340757c440ee468aee..c9df403fc5cce9ec61c05899ba0473979c658638 100644 --- a/ohmpi/ohmpi.py +++ b/ohmpi/ohmpi.py @@ -180,6 +180,11 @@ class OhmPi(object): cmd_id : str, optional Unique command identifier """ + # check if directory 'data' exists + ddir = os.path.join(os.path.dirname(__file__), '../data/') + if os.path.exists(ddir) is not True: + os.mkdir(ddir) + last_measurement = deepcopy(last_measurement) if 'fulldata' in last_measurement: d = last_measurement['fulldata'] @@ -246,7 +251,8 @@ class OhmPi(object): # get all .csv file in data folder if survey_names is None: survey_names = [] - fnames = [fname for fname in os.listdir('data/') if fname[-4:] == '.csv'] + ddir = os.path.join(os.path.dirname(__file__), '../data/') + fnames = [fname for fname in os.listdir(ddir) if fname[-4:] == '.csv'] ddic = {} if cmd_id is None: cmd_id = 'unknown' @@ -254,19 +260,28 @@ class OhmPi(object): if ((fname != 'readme.txt') and ('_rs' not in fname) and (fname.replace('.csv', '') not in survey_names)): - try: - data = np.loadtxt('data/' + fname, delimiter=',', - skiprows=1, usecols=(1, 2, 3, 4, 8)) - data = data[None, :] if len(data.shape) == 1 else data - ddic[fname.replace('.csv', '')] = { - 'a': data[:, 0].astype(int).tolist(), - 'b': data[:, 1].astype(int).tolist(), - 'm': data[:, 2].astype(int).tolist(), - 'n': data[:, 3].astype(int).tolist(), - 'rho': data[:, 4].tolist(), - } - except Exception as e: - print(fname, ':', e) + #try: + # reading headers + with open(os.path.join(ddir, fname), 'r') as f: + headers = f.readline().split(',') + + # fixing possible incompatibilities with cod eversion + for i, header in enumerate(headers): + if header == 'R [ohm]': + headers[i] = 'R [Ohm]' + icols = np.where(np.in1d(headers, ['A', 'B', 'M', 'N', 'R [Ohm]']))[0] + data = np.loadtxt(os.path.join(ddir, fname), delimiter=',', + skiprows=1, usecols=icols) + data = data[None, :] if len(data.shape) == 1 else data + ddic[fname.replace('.csv', '')] = { + 'a': data[:, 0].astype(int).tolist(), + 'b': data[:, 1].astype(int).tolist(), + 'm': data[:, 2].astype(int).tolist(), + 'n': data[:, 3].astype(int).tolist(), + 'rho': data[:, 4].tolist(), + } + #except Exception as e: + # print(fname, ':', e) rdic = {'cmd_id': cmd_id, 'data': ddic} self.data_logger.info(json.dumps(rdic)) return ddic @@ -497,7 +512,7 @@ class OhmPi(object): "inj time [ms]": injection_duration, # NOTE: check this "Vmn [mV]": Vmn, "I [mA]": I, - "R [ohm]": R, + "R [Ohm]": R, "R_std [%]": R_std, "Ps [mV]": self._hw.sp, "nbStack": nb_stack,