Ejemplo n.º 1
0
def getAverageDeltaEnergy(lowprog, highprog):
    # load data
    lp = I2Data.fromPath(lowprog)
    lp.correctValues(useX=False)
    lp.invertY()
    lp.multiplyY(1e7)  # from 1/nm to 1/cm
    hp = I2Data.fromPath(highprog)
    hp.correctValues(useX=False)
    hp.invertY()
    hp.multiplyY(1e7)  # from 1/nm to 1/cm

    # get same values for same nus
    sameNus = intersect(lp.getX(), hp.getX())
    deltas = []
    deltas_errors = []
    for nu in sameNus:
        hv = hp.getByX(nu)  # high value
        hy = hv[1]          # high y
        hye = hv[3]         # high error
        lv = lp.getByX(nu)  # low value
        ly = lv[1]          # low y
        lye = lv[3]         # low error
        deltas.append(hy - ly)
        deltas_errors.append(np.sqrt(hye ** 2 + lye ** 2))
    return avgerrors(deltas, deltas_errors)
Ejemplo n.º 2
0
def calculateExcitationEnergy():
    prog = 1
    n = 18
    m = 0

    # get G'(nu = n)
    absEnergy = I2Data.fromPath('../data/prog%dnl.txt' % prog)
    absEnergy.correctValues(useX=False)
    absEnergy.invertY()
    absEnergy.multiplyY(1e7)
    G = absEnergy.getByX(n)[1]
    Ge = absEnergy.getByX(n)[3]

    # get DeltaG from model
    params = getParamsFromFittingInfo('../calc/prog%d_fit1ord.txt' % prog)
    rho = getCorrelationFrom2DMatrix('../calc/prog%d_fit1ord.txt' % prog)
    a = params['a']['value']
    ae = params['a']['error']
    b = params['b']['value']
    be = params['b']['error']
    dg = a - b * (2 * m + 2)
    dge = np.sqrt(ae ** 2 - 4 * (1 + m) * rho * ae * be + 4 * ((1 + m) * be) ** 2)
    dgn = a - b * (2 * n + 2)
    dgne = np.sqrt(ae ** 2 - 4 * (1 + n) * rho * ae * be + 4 * ((1 + n) * be) ** 2)

    # calculate excitation energy
    E = G - n / 2 * (dg + dgn)
    Ee = np.sqrt(Ge ** 2 + (dge * n) ** 2 / 4 + (dgne * n) ** 2 / 4)

    # output to file
    with TxtFile('../calc/ExcitationEnergy.txt', 'w') as f:
        f.writeline('\t', str(E), str(Ee))
Ejemplo n.º 3
0
def evalHalogenLamp():
    data = I2Data.fromPath('../data/03_Halogen_ngg10.txt')

    c = TCanvas('c1', '', 1280, 720)
    g = data.makeGraph('g', 'wavelength #lambda / nm', 'intensity / a.u.')
    g.GetXaxis().SetRangeUser(415, 620)
    g.GetYaxis().SetTitleOffset(1.3)
    g.SetMarkerStyle(1)
    g.Draw('AP')

    c.Update()
    c.Print('../img/halogen_lamp.pdf', 'pdf')
Ejemplo n.º 4
0
def makeProgTables():
    name = 'prog%dnl.txt'
    for i in range(1, 3 + 1):
        prog = I2Data.fromPath('../data/' + name % i)
        x = prog.getX()
        y = prog.getY()
        prog.correctValues(False)
        yc = prog.getY()
        yce = prog.getEY()
        f = TxtFile('../src/prog%d.tex' % i, 'w')
        f.write2DArrayToLatexTable(zip(x, y, yc, yce),
                                   ['$\\nu\'$', r'$\lambda_{\text{exp}}$ / nm', r'$\lambda_{\text{cor}}$ / nm', r'$s_{\lambda_{\text{cor}}}$ / nm'],
                                   ['%0.f', '%3.2f', '%3.2f', '%.8f'],
                                   'Measured position of transmission minima in $I_2$-spectrum and corrected values of progession %d.' % i,
                                   'tab:prog%d' % i)
        f.close()
Ejemplo n.º 5
0
def evalHgPeaks():
    data = I2Data.fromPath('../data/02_Hg_full_ngg11.txt')
    mins = data.findExtrema(10, 425, 630, False)
    mins.filterY(1300)
    with TxtFile.fromRelPath('../calc/hg_lines.txt', 'w') as f:
        for min in mins.points:
            f.writeline(str(min[0]))

    c = TCanvas('c1', '', 1280, 720)
    c.SetLogy()
    g = data.makeGraph('g', 'wavelength #lambda / nm', 'intensity / a.u.')
    g.GetXaxis().SetRangeUser(415, 620)
    g.SetMarkerStyle(1)
    g.Draw('AP')

    m = mins.makeGraph()
    if m:
        m.SetMarkerColor(2)
        m.Draw('P')

    c.Update()
    c.Print('../img/HgPeaks.pdf', 'pdf')
Ejemplo n.º 6
0
def evalNaPeaks():
    data = I2Data.fromPath('../data/01_Na_ngg13.txt')
    mins = data.findExtrema(200, 508, 630, False)
    mins.filterY(40000)
    with TxtFile.fromRelPath('../calc/na_lines.txt', 'w') as f:
        for min in mins.points:
            f.writeline(str(min[0]))

    c = TCanvas('c1', '', 1280, 720)
    g = data.makeGraph('g', 'wavelength #lambda / nm', 'intensity / a.u.')
    g.GetXaxis().SetRangeUser(415, 620)
    g.GetYaxis().SetTitleOffset(1.2)
    g.SetMarkerStyle(1)
    g.Draw('AP')

    m = mins.makeGraph()
    if m:
        m.SetMarkerColor(2)
        m.Draw('P')

    c.Update()
    c.Print('../img/NaPeaks.pdf', 'pdf')
Ejemplo n.º 7
0
def getExcitedStateOscillationConstants():

    # plot spectrum

    data = I2Data.fromPath('../data/04_I2_ngg10_10ms.txt')
    progression = dict()
    for i in range(1, 3 + 1):
        progression[i] = I2Data.fromPath('../data/prog%d.txt' % i)

    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('spectrum', 'wavelength #lambda / nm', 'intensity / a.u.')
    g.SetMarkerStyle(1)
    g.GetXaxis().SetRangeUser(505, 620)
    g.SetMinimum(18000)
    g.SetMaximum(49000)
    myY = TGaxis()
    myY.ImportAxisAttributes(g.GetYaxis())
    myY.SetMaxDigits(3)
    g.Draw('AL')

    pg1 = progression[1].makeGraph('prog1')
    pg1.SetMarkerColor(2)
    pg1.Draw('P')
    pg2 = progression[2].makeGraph('prog2')
    pg2.SetMarkerColor(3)
    pg2.Draw('P')
    pg3 = progression[3].makeGraph('prog3')
    pg3.SetMarkerColor(4)
    pg3.Draw('P')

    l = TLegend(0.6, 0.15, 0.85, 0.4)
    l.AddEntry('spectrum', 'measurement', 'l')
    l.AddEntry('prog1', 'first progression (#nu\'\' = 1)', 'p')
    l.AddEntry('prog2', 'second progression (#nu\'\' = 2)', 'p')
    l.AddEntry('prog3', 'third progression (#nu\'\' = 3)', 'p')
    l.Draw()

    c.Update()
    c.Print('../img/I2_absorption.pdf', 'pdf')

    # calculations

    start = [18, 7, 9]
    prog1ord = {'a': [], 'ae': [], 'b': [], 'be': []}
    for i, prog in progression.iteritems():

        # Calculate vacuum wavelength and create Birge-Sponer plot

        prog.correctValues()
        c = TCanvas('c%d' % i, '', 1280, 720)
        g = makeBirgeSponer(prog, start[i - 1]).makeGraph('prog%d_bs' % i, '#nu\' + 1/2', '#Delta G (#nu\' + 1/2) / (cm^{-1})')
        g.Draw('AP')

        # fit 2nd-order

        fit2ord = Fitter('prog%d_2ord' % i, '[0]-[1]*(2*x+2)+[2]*(3*x^2+6*x+13/4)')
        fit2ord.setParam(0, 'a', 120)
        fit2ord.setParam(1, 'b', 1)
        fit2ord.setParam(2, 'c', 0)
        fit2ord.fit(g, 4, 50)
        fit2ord.saveData('../calc/prog%d_fit2ord.txt' % i, 'w')
        l2 = TLegend(0.6, 0.7, 0.95, 0.95)
        l2.AddEntry(0, 'Fit 2nd. order', '')
        l2.AddEntry(fit2ord.function, 'y = a - b*(2*x+2) + c*(3*x^2+6*x+13/4)', 'l')
        fit2ord.addParamsToLegend(l2)
        l2.SetTextSize(0.03)
        l2.Draw()

        # fit 1st-order

        fit1ord = Fitter('prog%d_1ord' % i, '[0]-[1]*(2*x+2)')
        fit1ord.setParam(0, 'a', 120)
        fit1ord.setParam(1, 'b', 1)
        fit1ord.fit(g, 4, 50, '+')
        g.GetFunction('prog%d_1ord' % i).SetLineColor(4)
        fit1ord.saveData('../calc/prog%d_fit1ord.txt' % i, 'w')
        prog1ord['a'].append(fit1ord.params[0]['value'])
        prog1ord['ae'].append(fit1ord.params[0]['error'])
        prog1ord['b'].append(fit1ord.params[1]['value'])
        prog1ord['be'].append(fit1ord.params[1]['error'])
        l1 = TLegend(0.125, 0.15, 0.5, 0.4)
        l1.AddEntry(0, 'Fit 1st. order', '')
        l1.AddEntry(g.GetFunction('prog%d_1ord' % i), 'y = a - b*(2*x+2)', 'l')
        fit1ord.addParamsToLegend(l1)
        l1.SetTextSize(0.03)
        l1.Draw()

        c.Update()
        c.Print('../img/prog%d_birgesponer.pdf' % i, 'pdf')

    # save vibrational constants to latex file
    nus = [0, 1, 2]
    f = TxtFile('../src/ExcitedStateOscillationConstants.tex', 'w')
    f.write2DArrayToLatexTable(zip(nus, prog1ord['a'], prog1ord['ae'], prog1ord['b'], prog1ord['be']), 
                               ['$\\nu\'\'$', '$\omega_e\' / \\text{cm}^{-1}$', '$s_{\omega_e\'} / \\text{cm}^{-1}$', 
                                '$\omega_e\' x_e\' / \\text{cm}^{-1}$', '$s_{\omega_e\' x_e\'} / \\text{cm}^{-1}$'], 
                               ['%0.f', '%3.1f', '%.1f', '%.3f', '%.3f'], 
                               'Oscillation constants for first order fit of Birge-Sponer plots', 'tab:prog1ord')
    f.close()


    # calculate weighted average for fit 1st- order

    with TxtFile.fromRelPath('../calc/ExcitedStateOscillationConstants.txt', 'w') as f:
        f.writeline('\t', *map(lambda x: str(x), avgerrors(prog1ord['a'], prog1ord['ae'])))
        f.writeline('\t', *map(lambda x: str(x), avgerrors(prog1ord['b'], prog1ord['be'])))