# known data:
f1 = 4.8e9
f2 = 4.1e9
G1 = (6.47570610e+9+6.54117488e+9)/2.0  # Gain f1
G2 = (7.53189804e+9+7.51356080e+9)/2.0
Tn1 = (2.9192993 + 2.93221691)/2.0  # Noise Temp Amplifier (2K without filters)
Tn2 = (3.59712857 + 3.5890299)/2.0
uG2 = (6.47570610e+9-6.54117488e+9)/2.0   # Uncertainty values
uG2 = (7.53189804e+9-7.51356080e+9)/2.0
uTn1 = (2.9192993 - 2.93221691)/2.0
uTn2 = (3.59712857 - 3.5890299)/2.0
uPi1 = uTn1*kB/(h*f1)  # resulting Photon uncertainty at Hemt input
uPi2 = uTn2*kB/(h*f2)

vc = sn.variable_carrier()
fname = '1150_'
vc.fifolder = '1150//'
vc.LP = 0.0
vc.Texp = 0.007
vc.snr = 0.0
folder1 = fname+'ON//'
vc.filein1 = folder1 + fname + 'CovMat_cI1I1.mtx'
vc.filein2 = folder1 + fname + 'CovMat_cQ1Q1.mtx'
vc.filein3 = folder1 + fname + 'CovMat_cI2I2.mtx'
vc.filein4 = folder1 + fname + 'CovMat_cQ2Q2.mtx'
vc.filein6 = folder1 + fname + 'CovMat_cI1I2.mtx'
vc.filein7 = folder1 + fname + 'CovMat_cI1Q2.mtx'
vc.filein8 = folder1 + fname + 'CovMat_cQ1I2.mtx'
vc.filein9 = folder1 + fname + 'CovMat_cQ1Q2.mtx'
vc.filein10 = folder1 + fname + 'CovMat_cI1Q1.mtx'
    n2 = np.zeros([vc.d2.pt, vc.d3.pt])
    Ineq = np.zeros([vc.d2.pt, vc.d3.pt])
    for ii in range(vc.d2.pt):
        for jj in range(vc.d3.pt):
            a = 1.0
            CovM = createCovMat(vc, vc2, ii, jj)
            CovM, phase = rot_phase(CovM)
            N = get_LogNegNum(CovM)
            Nsq, Ineq[ii, jj], n1[ii, jj], n2[ii, jj] = get_sqIneq(vc, CovM)
            a = 1.0
            LnM[ii, jj] = N * a
            LnM2[ii, jj] = Nsq * a
    return LnM, LnM2, Ineq, n1, n2

fname = '1150_'
vc = sn.variable_carrier()
vc.resultfolder = fname+'//'
folder = '/Volumes/QDP-Backup-2/BenS/DCE2015-16/data_May20/'
vc.fifolder = folder
vc.snr = 4.5
vc.cpt = 5
vc.LP = 0.0
vc.T = 0.007
vc.Tn1 = 3.9
vc.Tn2 = 4.6
vc.G1 = 6.45e9
vc.G2 = 7.5e9
vc.f1 = 4.8e9
vc.f2 = 4.1e9
vc.Ravg = 0.0  # 69.7  # if set to 0.0 script will use differential resistance
vc.B = 1e5
import numpy as np
from scipy.constants import h, e
from scipy.constants import Boltzmann as kB
import SNfit2 as SNfit  # SNfit (traditionally) & SNfit2 (for hybrid coupler)
# import PyGnuplot as gp

vc = SNfit.variable_carrier()
vc.fifolder = ''
vc.LP = 1.0
vc.Texp = 0.009
SNR = 4.0
f1 = 4.8e9
f2 = 4.8e9
vc.Ravg = 0.0  # 69.7
vc.B = 1e5
vc.resultfolder = 'f2//'

pathf1 = '/Volumes/QDP-Backup-2/BenS/DCE2015-16/data_Jul15/1206_SN22_1/'
savename = '1150_LogN.mtx'
savename2 = '1150_ineqSq.mtx'
vc.fifolder = ''
vc.filein1 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cI1I1.mtx'
vc.filein2 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cQ1Q1.mtx'
vc.filein3 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cI2I2.mtx'
vc.filein4 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cQ2Q2.mtx'
vc.filein6 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cI1I2.mtx'
vc.filein7 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cI1Q2.mtx'
vc.filein8 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cQ1I2.mtx'
vc.filein9 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cQ1Q2.mtx'
vc.filein10 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cI1Q1.mtx'
vc.filein11 = pathf1 + '1206_SN22_1ON//1206_SN22_1CovMat_cI2Q2.mtx'