convert the resistance value to scientific notation
This commit is contained in:
parent
b1498cbde1
commit
3315eed1da
|
@ -31,9 +31,10 @@ def read():
|
|||
dat_list = np.random.randint(0, v_in * 1000, SENSORS_MAX) # create a randomized voltage data
|
||||
# take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors
|
||||
dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2
|
||||
r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1)
|
||||
r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1) # *2 <-- change with actual formula for ammonia concentration
|
||||
# write + export values as .csv format
|
||||
dat = f", ".join(np.insert(r_arr.astype(str), 0, datetime.now().strftime('%H:%M:%S')))
|
||||
# converted resistance values in array to scientific notation
|
||||
dat = f", ".join(np.insert(np.format_float_scientific(r_arr.astype(str)), 0, datetime.now().strftime('%H:%M:%S')))
|
||||
print(dat)
|
||||
f = open(file_name, "a", newline="", encoding="utf-8")
|
||||
f.write(dat + '\n')
|
||||
|
@ -54,9 +55,10 @@ def read():
|
|||
|
||||
# take only the nonzero indices, and truncated to two decimal places to "filter" out some hardware errors
|
||||
dat_sel = np.trunc((np.take(dat_list, sensor_ports) / 1000) * 10**2) / 10**2
|
||||
r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1)
|
||||
r_arr = np.take(refRes, sensor_ports) * (v_in / dat_sel - 1) # *2 <-- change with actual formula for ammonia concentration
|
||||
# write + export values as .csv format
|
||||
dat = f", ".join(np.insert(r_arr.astype(str), 0, datetime.now().strftime('%H:%M:%S')))
|
||||
# converted resistance values in array to scientific notation
|
||||
dat = f", ".join(np.insert(np.format_float_scientific(r_arr.astype(str)), 0, datetime.now().strftime('%H:%M:%S')))
|
||||
print(dat)
|
||||
f = open(file_name, "a", newline="", encoding="utf-8")
|
||||
f.write(dat + '\n')
|
||||
|
|
|
@ -4,7 +4,7 @@ import os, json, traceback, wx
|
|||
import numpy as np
|
||||
import matplotlib
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
import decimal
|
||||
matplotlib.use("WXAgg") # for JetBrains IDE to force use wxPython as backend UI for plotting
|
||||
|
||||
|
||||
|
@ -74,9 +74,10 @@ class SerialPlotter:
|
|||
|
||||
self.sensorsData[i].append(row[i])
|
||||
# plot a line
|
||||
# TODO: round the number to 1-2- decimal places
|
||||
self.axs.plot(self.timeStamps[i], self.sensorsData[i], color=self.colors[i],
|
||||
label=f'sensor {i + 1}, latest: {np.floor(self.sensorsData[i][-1])} $\Omega$')
|
||||
# round the number to scientific notation
|
||||
self.axs.plot(self.timeStamps[i],self.sensorsData[i], color=self.colors[i],
|
||||
label=f'sensor {i + 1}, latest: {np.format_float_scientific(self.sensorsData[i][-1], precision = 2)} $\Omega$')
|
||||
|
||||
self.axs.set_xlabel('Time (seconds)')
|
||||
self.axs.set_ylabel(u'Resistance ($\Omega$)')
|
||||
i += 1
|
||||
|
|
Loading…
Reference in New Issue