import pandas as pd
import numpy as np
import scipy.optimize as opt
from scipy import stats
%matplotlib inline
import matplotlib.pyplot as plt
import sympy
from lab import Dataset, Variable
from ops import avg, sin, tan
cos = lambda x, terms=20: sin(np.pi/2 - x, terms=terms)
atan = lambda x, terms=20: sum([ (-1)**i * x**(2*i +1) / (2*i + 1) for i in range(terms) ])
def value(symbol, vals, err): return avg([Variable(symbol+f"{i}", val, err) for i, val in enumerate(vals)])
def rad(theta): return theta * float(np.pi) / 180
exp2 = Dataset(pd.read_csv("exp2.csv").query('`label` == 1'))
# exp2.newCol('Angle Var', (lambda t: Variable('theta', int(t), 1)), "Relative Angle")
exp2.newCol('Max Int Var', (lambda i, i_err: Variable('Imax', int(i), int(i_err) + float(i*0.20))), "Max Intensity", "Max Intensity Error")
exp2.newCol('Min Int Var', (lambda i, i_err: Variable('Imin', int(i), int(i_err) + float(i*0.20))), "Min Intensity", "Min Intensity Error")
exp2.newCol('Ecc Var', (lambda mx, mi: mi/mx), "Max Int Var", "Min Int Var")
exp2.newCol('Eccentricity', (lambda var: np.float64(var._numerical().value)), "Ecc Var")
exp2.newCol('Eccentricity Error', (lambda var: np.float64(var._numerical().error)), "Ecc Var")
exp2.newCol('Intensity Ecc Varr', (lambda ratio: (1 - ratio)**0.5), "Ecc Var")
exp2.newCol('Angle Ecc', (lambda theta: (1 - (piecewisef(tan)(theta))**2)**0.5), "Relative Angle")
exp2.newCol('Int Ecc Var', (lambda rat: (1 - rat)**0.5), 'Ecc Var')
exp2.newCol('Int Ecc', (lambda var: np.float64(var._numerical().value)), "Int Ecc Var")
exp2.newCol('Int Ecc Err', (lambda var: np.float64(var._numerical().error)), "Int Ecc Var")
exp2.data