#! /usr/bin/python3

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

lognum = 2

plt.ioff()
plt.style.use('bmh')
plt.figure(figsize=(11.88, 8.40))
data = pd.read_csv("./log_poticalib_ana_{:02d}.csv".format(lognum))

print(data)

#plt.errorbar(
#    data['time'],
#    data['act_curr_ps'], 
#    yerr=data['act_curr_ps']*.002, 
#    label="Spannungsquelle Ausgang",
#    fmt='.'
#)
#plt.errorbar(
#    data['time'],
#    data['act_curr_el']-.125, 
#    label="Elektronische Last Eingang",
#    fmt='.'
#)#

data['val_poti'] = data['val_poti'].map(lambda x: int(x, base=16))
data['r_bcu/kohm'] = 2*4.7+1/(1/data['r_restheo/kohm']+1/75)

data['v_bcutheo/v'] = 0.7+0.7*30.1/(data['r_bcu/kohm']+6.49)

plt.errorbar(
    data['r_bcu/kohm'],
    data['v_keith/v'],
    yerr=data['dv_keith/v'],
    label="V$_{Keith,IV8A}$",
    fmt='.'
)
plt.errorbar(
    data['r_bcu/kohm'],
    data['v_pit/v'],
    yerr=data['dv_pit/v)'],
    label="V$_{PIT,IV8A}$",
    fmt='.'
)
plt.plot(
    data['r_bcu/kohm'],
    data['v_bcutheo/v'],
    label="V$_{BCU,O}$"
)

plt.xlabel('$R_{BCU,Set}$/k$\Omega$')
plt.ylabel('V$_{1V8A}$/V')
plt.title("PowerIt Calibration: Analog Potentiometer")
plt.legend()
#-plt.savefig("2kw_direct.png")

plt.tight_layout()
plt.savefig("adccalib_{:02d}.eps".format(lognum), format='eps', dpi=1000)
