Update U180-ToolKit.py
This commit is contained in:
parent
ad89540c37
commit
33a0cfddbc
103
U180-ToolKit.py
103
U180-ToolKit.py
@ -3,30 +3,39 @@ import os
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import csv
|
import csv
|
||||||
|
import matplotlib.dates as mdates
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from plotly.subplots import make_subplots
|
from plotly.subplots import make_subplots
|
||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
import datetime
|
import datetime
|
||||||
import numpy
|
import numpy
|
||||||
import GPIBPrologix
|
import GPIBPrologix
|
||||||
|
import git
|
||||||
|
import shutil
|
||||||
|
import bme280
|
||||||
|
import smbus2
|
||||||
|
|
||||||
GPIB = GPIBPrologix.ResourceManager("/dev/ttyACM0")
|
GPIB = GPIBPrologix.ResourceManager("/dev/ttyACM0")
|
||||||
instObj = GPIB.open_resource(22)
|
instObj = GPIB.open_resource(22)
|
||||||
instObj.write("BEEP")
|
bus = smbus2.SMBus(1)
|
||||||
instObj.write("CAL? 72")
|
calibration_params = bme280.load_calibration_params(bus, 0x76)
|
||||||
print(instObj.read())
|
|
||||||
print(instObj.query("CAL? 72"))
|
|
||||||
time.sleep(60)
|
|
||||||
## user customisable functions
|
## user customisable functions
|
||||||
def readFunc(instObj):
|
def readFunc(instObj):
|
||||||
return instObj.read()
|
return instObj.read()
|
||||||
|
|
||||||
def writeFunc(instObj, input):
|
def writeFunc(instObj, input):
|
||||||
instObj.write(input)
|
instObj.write(input)
|
||||||
|
time.sleep(1)
|
||||||
def queryFunc(instObj, input):
|
def queryFunc(instObj, input):
|
||||||
time.sleep(0.1)
|
output = instObj.query(input)
|
||||||
return instObj.query(input)
|
time.sleep(1)
|
||||||
|
print(input, output)
|
||||||
|
return output
|
||||||
|
|
||||||
|
def getEnvironment(instObj, i2cbus):
|
||||||
|
value = instObj.sample(i2cbus, 0x76, calibration_params)
|
||||||
|
return [str(round(value.humidity,2)),str(round(value.temperature,2)),str(round(value.pressure,2))]
|
||||||
|
|
||||||
## the main program functionalities, should not be adjusted
|
## the main program functionalities, should not be adjusted
|
||||||
def readRunningConfigs():
|
def readRunningConfigs():
|
||||||
@ -36,17 +45,24 @@ def readRunningConfigs():
|
|||||||
return filenames
|
return filenames
|
||||||
|
|
||||||
def doACAL(dcACAL, ohmACAL, acACAL):
|
def doACAL(dcACAL, ohmACAL, acACAL):
|
||||||
output = queryFunc(instObj, "TEMP?")
|
writeFunc(instObj,"END 2")
|
||||||
|
writeFunc(instObj,"OFORMAT ASCII")
|
||||||
|
writeFunc(instObj,"BEEP")
|
||||||
if dcACAL == "yes":
|
if dcACAL == "yes":
|
||||||
|
print("Starting DCV cal")
|
||||||
writeFunc(instObj, "ACAL DCV")
|
writeFunc(instObj, "ACAL DCV")
|
||||||
time.sleep(140+20)
|
time.sleep(140+60)
|
||||||
if acACAL == "yes":
|
if acACAL == "yes":
|
||||||
writeFunc(instObj, "ACAL ACV")
|
print("Starting AC cal")
|
||||||
time.sleep(140+20)
|
writeFunc(instObj, "ACAL AC")
|
||||||
|
time.sleep(240+60)
|
||||||
if ohmACAL == "yes":
|
if ohmACAL == "yes":
|
||||||
|
print("Starting Ohm cal")
|
||||||
writeFunc(instObj, "ACAL OHMS")
|
writeFunc(instObj, "ACAL OHMS")
|
||||||
time.sleep(600+60)
|
time.sleep(720+60)
|
||||||
return output
|
writeFunc(instObj, "DISP OFF, ;")
|
||||||
|
writeFunc(instObj,"DISP MSG,\" \"")
|
||||||
|
return 0
|
||||||
|
|
||||||
def interrogate3458A(instObj):
|
def interrogate3458A(instObj):
|
||||||
output = []
|
output = []
|
||||||
@ -66,6 +82,7 @@ def interrogate3458A(instObj):
|
|||||||
output.append(queryFunc(instObj,"CAL? 59")) # get temperature from during calibration
|
output.append(queryFunc(instObj,"CAL? 59")) # get temperature from during calibration
|
||||||
output.append(queryFunc(instObj,"CAL? 97")) # get 1mamp ACAL gain constrant
|
output.append(queryFunc(instObj,"CAL? 97")) # get 1mamp ACAL gain constrant
|
||||||
output.append(queryFunc(instObj,"CAL? 72")) # get 10v ACAL gain constrant
|
output.append(queryFunc(instObj,"CAL? 72")) # get 10v ACAL gain constrant
|
||||||
|
print(output)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
## main program
|
## main program
|
||||||
@ -78,13 +95,19 @@ for file in readRunningConfigs():
|
|||||||
if not os.path.exists(serialPath):
|
if not os.path.exists(serialPath):
|
||||||
os.makedirs(serialPath)
|
os.makedirs(serialPath)
|
||||||
with open(serialPath+configData['serial']+'.csv', 'a') as g:
|
with open(serialPath+configData['serial']+'.csv', 'a') as g:
|
||||||
|
heading = ["DateTime","TEMP","CAL RREF","CAL VREF","G10K","G100K", "G1V0","G0V1","OCOMP1K","OCOMP10K", "ACALTEMP", "CALTEMP", "G1mA", "G10V"]
|
||||||
|
if(configData['useBME']):
|
||||||
|
heading = output.append(['EnvHumidity', 'EnvTemp', 'EnvPressure'])
|
||||||
writer = csv.writer(g)
|
writer = csv.writer(g)
|
||||||
writer.writerow(["DateTime","TEMP","CAL RREF","CAL VREF","G10K","G100K", "G1V0","G0V1","OCOMP1K","OCOMP10K", "ACALTEMP", "CALTEMP", "G1mA", "G10V"])
|
writer.writerow(heading)
|
||||||
doACAL(configData['ACAL-DCV'],configData['ACAL-OHMS'],configData['ACAL-ACV'])
|
doACAL(configData['ACAL-DCV'],configData['ACAL-OHMS'],configData['ACAL-ACV'])
|
||||||
with open(serialPath+configData['serial']+'.csv', 'a') as f:
|
with open(serialPath+configData['serial']+'.csv', 'a') as f:
|
||||||
|
output = interrogate3458A(instObj)
|
||||||
|
if(configData['useBME']):
|
||||||
|
data = getEnvironment(bme280, bus)
|
||||||
|
output += data
|
||||||
writer = csv.writer(f)
|
writer = csv.writer(f)
|
||||||
writer.writerow((interrogate3458A(instObj)))
|
writer.writerow(output)
|
||||||
writeFunc(instObj,"DISP OFF,''")
|
|
||||||
|
|
||||||
## do the plotting
|
## do the plotting
|
||||||
for file in readRunningConfigs():
|
for file in readRunningConfigs():
|
||||||
@ -92,14 +115,54 @@ for file in readRunningConfigs():
|
|||||||
with open(dataPath, "r") as read_file:
|
with open(dataPath, "r") as read_file:
|
||||||
configData = json.load(read_file)
|
configData = json.load(read_file)
|
||||||
serialPath = os.path.realpath(os.path.dirname(__file__))+'/data/'+configData['serial']+'/'
|
serialPath = os.path.realpath(os.path.dirname(__file__))+'/data/'+configData['serial']+'/'
|
||||||
df = pd.read_csv(serialPath+configData['serial']+'.csv')
|
df = pd.read_csv(serialPath+configData['serial']+'.csv',delimiter=',', encoding="utf-8-sig")
|
||||||
|
df.columns = df.columns.str.strip()
|
||||||
|
|
||||||
time_x = pd.to_datetime(df['DateTime'],format='%d-%m-%y %H:%M:%S')
|
time_x = pd.to_datetime(df['DateTime'],format='%d-%m-%y %H:%M:%S')
|
||||||
coefficients = numpy.polyfit(df['TEMP'], df['G10V'], 1, rcond=None, full=False, w=None, cov=False)
|
coefficients = numpy.polyfit(df['TEMP'], df['G10V'], 1, rcond=None, full=False, w=None, cov=False)
|
||||||
polynomial = numpy.poly1d(coefficients)
|
polynomial = numpy.poly1d(coefficients)
|
||||||
|
#polynom_estimate = numpy.polyfit(mdates.date2num(time_x),df['G10V']-polynomial(df['TEMP']), 1, rcond=None, full=False, w=None, cov=False)
|
||||||
|
polynom_estimate = numpy.polyfit(mdates.date2num(time_x),df['G10V'], 1, rcond=None, full=False, w=None, cov=False)
|
||||||
|
p_est = numpy.poly1d(polynom_estimate)
|
||||||
|
|
||||||
fig = make_subplots(rows=1, cols=2)
|
fig = make_subplots(rows=1, cols=2)
|
||||||
fig.add_trace(go.Scatter(x=time_x, y=df['G10V']-polynomial(df['TEMP']),mode='lines+markers',name='time vs cal72 w tempcomp'),row=1, col=1)
|
#fig.add_trace(go.Scatter(x=time_x, y=df['G10V']-polynomial(df['TEMP']),mode='lines+markers',name='time vs cal72 w tempcomp'),row=1, col=1)
|
||||||
|
fig.add_trace(go.Scatter(x=time_x, y=df['G10V'],mode='lines+markers',name='time vs cal72 w tempcomp'),row=1, col=1)
|
||||||
|
fig.add_trace(go.Scatter(x=time_x, y=p_est(mdates.date2num(time_x)),mode='lines',line = dict(color='gray', dash='dash'),name='Estimated 1st order'), row=1, col=1)
|
||||||
fig.add_trace(go.Scatter(x=df['TEMP'], y=df['G10V'],mode='lines+markers',name='temp vs cal72'),row=1, col=2)
|
fig.add_trace(go.Scatter(x=df['TEMP'], y=df['G10V'],mode='lines+markers',name='temp vs cal72'),row=1, col=2)
|
||||||
|
fig.add_trace(go.Scatter(x=df['TEMP'], y=polynomial(df['TEMP']),mode='lines',line = dict(color='gray', dash='dash'),name='Tempco 1st order'), row=1, col=2)
|
||||||
|
|
||||||
|
datenow = datetime.datetime.now()
|
||||||
|
date = datenow + datetime.timedelta(days=1)
|
||||||
|
timeframe = (time_x.max()-time_x.min()).total_seconds()/(3600*24)
|
||||||
|
alphaday = (p_est(mdates.date2num(date))-p_est(mdates.date2num(datenow)))
|
||||||
|
driftrate = round((alphaday*1000000000)/(df.loc[:, 'G10V'].mean()*timeframe),2)
|
||||||
|
annotation = f'Estimated drift: {driftrate} ppb/day'
|
||||||
|
fig.add_annotation(dict(showarrow=False, text=annotation, xanchor='left', xref="paper", yref="paper", x=0, y=0))
|
||||||
|
tempcorate = round(((polynomial(1)-polynomial(0))*1000000000)/df.loc[:, 'G10V'].mean(),2)
|
||||||
|
annotation = f'Estimated tempco: {tempcorate} ppb/degC'
|
||||||
|
fig.add_annotation(dict(showarrow=False, text=annotation, xanchor='left', xref="paper", yref="paper", x=1, y=0))
|
||||||
|
|
||||||
|
|
||||||
fig.write_html(serialPath+configData['serial']+'.html')
|
fig.write_html(serialPath+configData['serial']+'.html')
|
||||||
fig.write_image(serialPath+configData['serial']+'.png')
|
fig.write_image(serialPath+configData['serial']+'.png',width=1280, height=720)
|
||||||
|
|
||||||
|
## do the saving
|
||||||
|
for file in readRunningConfigs():
|
||||||
|
localDataPath = os.path.realpath(os.path.dirname(__file__))+'/data/'
|
||||||
|
gitDataRepo = os.path.realpath(os.path.dirname(__file__))+'/CommitDataRepo/'
|
||||||
|
with open(dataPath, "r") as read_file:
|
||||||
|
configData = json.load(read_file)
|
||||||
|
if(configData['useGit']):
|
||||||
|
remote = f"https://{configData['gitUser']}:{configData['gitPassword']}@{configData['gitAddress']}"
|
||||||
|
if os.path.exists(gitDataRepo):
|
||||||
|
shutil.rmtree(gitDataRepo, ignore_errors=True)
|
||||||
|
git.Repo.clone_from(remote, gitDataRepo, b=configData['gitBranch'])
|
||||||
|
shutil.copytree(localDataPath, gitDataRepo+'data/',dirs_exist_ok=True)
|
||||||
|
repo = git.Repo(gitDataRepo)
|
||||||
|
repo.git.add(gitDataRepo)
|
||||||
|
repo.index.commit("Update")
|
||||||
|
repo.remotes[0].push()
|
||||||
|
|
||||||
|
## if all ok, blamk screen to save VFD
|
||||||
|
queryFunc(instObj, 'DISP OFF,""')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user