Commit c1c46552 authored by Forquet Nicolas's avatar Forquet Nicolas
Browse files

add the function to save measurement using the feather binary format

parent d9318509
......@@ -18,6 +18,8 @@ import sys
import adafruit_ads1x15.ads1115 as ADS
from adafruit_ads1x15.analog_in import AnalogIn
import pandas as pd
import feather
from pathlib import Path
"""
display start time
......@@ -36,6 +38,7 @@ stack= 1 # repetition of the current injection for each quadripole
R_ref = 50 # reference resistance value in ohm
coef_p0 = 2.02 # slope for current conversion for ADS.P0, measurement in ???
coef_p1 = 2.02 # slope for current conversion for ADS.P1, measurement in ???
export_path = "/home/..."
"""
functions
......@@ -107,24 +110,38 @@ def run_measurement(nb_stack, injection_deltat, Rref, coefp0, coefp1):
Vm1 = AnalogIn(ads,ADS.P2).voltage # reading voltage value on ADS channel A2
Vn1 = AnalogIn(ads,ADS.P3).voltage # reading voltage value on ADS channel A3
GPIO.output(8, GPIO.LOW)# stop current injection
I1= (Ia1 - Ib1)/Rref;
sum_I=sum_I+I1;
Vmn1= (Vm1 - Vn1);
I1= (Ia1 - Ib1)/Rref
sum_I=sum_I+I1
Vmn1= (Vm1 - Vn1)
if (n % 2) == 0:
sum_Vmn=sum_Vmn-Vmn1;
sum_Ps=sum_Ps+Vmn1;
sum_Vmn=sum_Vmn-Vmn1
sum_Ps=sum_Ps+Vmn1
else:
sum_Vmn=sum_Vmn+Vmn1;
sum_Ps=sum_Ps+Vmn1;
sum_Vmn=sum_Vmn+Vmn1
sum_Ps=sum_Ps+Vmn1
# return averaged values
output = pd.DataFrame({
"time":datetime.now()
"Vmn":sum_Vmn/(3+2*nb_stack-1),
"I":sum_I/(3+2*nb_stack-1),
"R":Vmn/I,
"Ps":sum_Ps/(3+2*nb_stack-1)
"nbStack":nb_stack
})
return output
# save data
def append_and_save(path, last_measurement):
if path.is_file():
# Load data file and append data to it
df = feather.read_dataframe(path)
df.append(last_measurement)
feather.write_dataframe(df, path)
else:
# create data file
feather.write_dataframe(last_measurement, path)
"""
Initialization of GPIO channels
"""
......@@ -151,10 +168,10 @@ for g in range(0,nbr_meas): # for time-lapse monitoring
switch_mux(N[i,])
# run a measurement
run_measurement(stack, injection_duration, R_ref, coef_p0, coef_p1)
current_measurement = run_measurement(stack, injection_duration, R_ref, coef_p0, coef_p1)
# save data and print in a text file
append_data
append_and_save(export_path, current_measurement)
# reset multiplexer channels
GPIO.output(12, GPIO.HIGH); GPIO.output(16, GPIO.HIGH); GPIO.output(20, GPIO.HIGH); GPIO.output(21, GPIO.HIGH); GPIO.output(26, GPIO.HIGH)
......@@ -162,7 +179,5 @@ for g in range(0,nbr_meas): # for time-lapse monitoring
GPIO.output(6, GPIO.HIGH); GPIO.output(13, GPIO.HIGH); GPIO.output(4, GPIO.HIGH); GPIO.output(17, GPIO.HIGH); GPIO.output(27, GPIO.HIGH)
GPIO.output(22, GPIO.HIGH); GPIO.output(10, GPIO.HIGH); GPIO.output(9, GPIO.HIGH); GPIO.output(11, GPIO.HIGH); GPIO.output(5, GPIO.HIGH)
time.sleep(sequence_delay); #waiting next measurement (time-lapse)
time.sleep(sequence_delay) #waiting next measurement (time-lapse)
\ No newline at end of file
Markdown is supported
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