Commit cdb5b03b authored by Guillaume Blanchy's avatar Guillaume Blanchy
Browse files

Working inversion from mqtt html

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