def test ():
    from uncertainties import ufloat
    from uncertainties import unumpy
    from uncertainties.umath import *
    numbers = unumpy.uarray(([1,2,3,4,5],[0.1,0.2,0.3,0.4,0.5]))
    print numbers
    print "Mean: {}".format(numbers.mean())
    print unumpy.sin(numbers)
    for i in numbers:
       print "Number: {}, Uncertainty: {}, Square of number: {}".format(i.nominal_value, i.std_dev(), i**2)
def inertia_components(jay, beta):
    '''Returns the 2D orthogonal inertia tensor.

    When at least three moments of inertia and their axes orientations are
    known relative to a common inertial frame of a planar object, the orthoganl
    moments of inertia relative the frame are computed.

    Parameters
    ----------
    jay : ndarray, shape(n,)
        An array of at least three moments of inertia. (n >= 3)
    beta : ndarray, shape(n,)
        An array of orientation angles corresponding to the moments of inertia
        in jay.

    Returns
    -------
    eye : ndarray, shape(3,)
        Ixx, Ixz, Izz

    '''
    sb = unumpy.sin(beta)
    cb = unumpy.cos(beta)
    betaMat = unumpy.matrix(np.vstack((cb**2, -2 * sb * cb, sb**2)).T)
    eye = np.squeeze(np.asarray(np.dot(betaMat.I, jay)))
    return eye
Exemple #3
0
def dsin(number):
    if isinstance(number, fr.Fraction):
        number = Mixed(number)
    elif isinstance(number, uc.UFloat):
        number = Mixed(number)
    elif isinstance(number, float):
        number = Mixed(number)
    elif isinstance(number, int):
        number = Mixed(number)
    assert isinstance(number, Mixed), \
        "Connot calculate cos of an object of type %s." % (type(number))
    if isinstance(number.value, fr.Fraction):
        x = number.value % 360
        if x == 0:
            return Mixed(0)
        elif x == 30:
            return Mixed(fr.Fraction(1,2))
        elif x == 90:
            return Mixed(1)
        elif x == 150:
            return Mixed(fr.Fraction(1,2))
        elif x == 180:
            return Mixed(0)
        elif x == 210:
            return Mixed(-fr.Fraction(1, 2))
        elif x == 270:
            return Mixed(-1)
        elif x == 330:
            return Mixed(-fr.Fraction(1, 2))
        else:
            return Mixed(np.sin(float(deg2rad(number).value)))
    elif isinstance(number.value, uc.UFloat):
        return Mixed(unumpy.sin(deg2rad(number).value).item())
    elif isinstance(number.value, float):
        return Mixed(np.sin(deg2rad(number).value))
    elif isinstance(number.value, int):
        x = number.value % 360
        if x == 0:
            return Mixed(0)
        elif x == 30:
            return Mixed(fr.Fraction(1,2))
        elif x == 90:
            return Mixed(1)
        elif x == 150:
            return Mixed(fr.Fraction(1,2))
        elif x == 180:
            return Mixed(0)
        elif x == 210:
            return Mixed(-fr.Fraction(1, 2))
        elif x == 270:
            return Mixed(-1)
        elif x == 330:
            return Mixed(-fr.Fraction(1, 2))
        else:
            return Mixed(np.sin(deg2rad(number).value))
Exemple #4
0
def sin(number):
    if isinstance(number, fr.Fraction):
        number = Mixed(number)
    elif isinstance(number, uc.UFloat):
        number = Mixed(number)
    elif isinstance(number, float):
        number = Mixed(number)
    elif isinstance(number, int):
        number = Mixed(number)
    assert isinstance(number, Mixed), \
        "Connot calculate cos of an object of type %s." % (type(number))
    if isinstance(number.value, fr.Fraction):
        return Mixed(np.sin(float(number.value)))
    elif isinstance(number.value, uc.UFloat):
        return Mixed(unumpy.sin(number.value).item())
    elif isinstance(number.value, float):
        return Mixed(np.sin(number.value))
    elif isinstance(number.value, int):
        return Mixed(np.sin(number.value))
Exemple #5
0
import numpy as np 
import math
import pandas as pd
from uncertainties import ufloat
from uncertainties import unumpy as unp

R = 13.6
alpha = 7.297e-3
z = 79
c=3*10**8
h=4.135*10**(-15)
d=201.4*10**(-12)

theta3 = ufloat(15.2, 0.35)
theta2 = ufloat(12.8, 0.35)
lam3 = 2 * d * unp.sin(theta3*(np.pi/180))
lam2 = 2 * d * unp.sin(theta2*(np.pi/180))
E3 = c * h /lam3
E2 = c * h /lam2

dE = E2 - E3

print("E2", E2, "E3", E3, "dE", dE)

sigma = z - unp.sqrt(4/alpha * unp.sqrt(dE/R) - (5* dE)/(R)) * unp.sqrt(1 + 19/32 * alpha**2 * dE/R)
print(sigma)
Exemple #6
0
    return I_max*(((x-d)/w)**2)*np.exp(-2*((x-d)/w)**2)

#Gitter
#100 Spalte/mm -> 1*10^5 Spalte pro m
d_1=ufloat(6.3, 0.2) #cm
d_2=ufloat(6.2, 0.2) #cm
l=ufloat(95.7, 0.2) #cm
g=10**(-5)
#HIER DIE AUSWERTUNG FÜR DIE WELLENLÄNGE
d_1=d_1*1e-2
d_2=d_2*1e-2
l=l*1e-2
d=np.mean([d_1, d_2])
print('Mittelwert der Abstände:', d)

lamda=g*unp.sin(unp.arctan(d/l))
print('lambda= ', lamda)
print('Abweichung von der Theorie:', (lamda*1e9/632.8-1)*100)

#plankonkav
print('plankonkav:')
l, I = np.genfromtxt('data/plankonkav.txt', unpack=True)

hr = ['$L$/cm', '$I$/µA']
m = np.zeros((21, 2))
m[:,0] = l
m[:,1] = I
t=matrix2latex(m, headerRow=hr, format='%.2f')
print(t)

params, covariance_matrix = optimize.curve_fit(linfit, l, I)
    A_error = sigma_y * np.sqrt(N / Delta)
    B_error = sigma_y * np.sqrt(np.sum(x**2) / Delta)

    return A, A_error, B, B_error

#Innenwinkel des Prismas:
phil = 320
phir = 72.3

phi = (360-phil+phir)/2

#Daten:
lamda, eta = np.genfromtxt('Daten/Datenb.txt',unpack=True)
n = np.sin((eta+phi)*2*np.pi/720)/np.sin(phi*2*np.pi/720)
n = n**2
nausgabe = unp.sin((eta+phi)*2*np.pi/720)/unp.sin(phi*2*np.pi/720)
plt.plot(lamda,n,'kx', label = r'Messwerte')

lc = 656
ld = 589
lf = 486

#erste Regression:
lamda1 = 1/(lamda**2)

m1,dm1,b1,db1 = linregress(lamda1,n)

s1 = 7/5 * np.mean((n-b1-m1*lamda1)**2)  #Summe Abweichungsquadrate:

x = np.linspace(400,800)
plt.plot(x,m1*(1/(x**2)) + b1,'r-',label = r'Ausgleichsfunktion')
Exemple #8
0
def main():

    print('\n#################### Analyse für Salz ####################\n')

    Xi2_best = [
        'SC', 20, 'CuF'
    ]  # SC ist in dem Fall ein Platzhalter. Die 20 garantiert, dass ein jedes Xi zunächst kleiner ist.

    # daten1, daten2 = np.genfromtxt('SalzRadius.txt', unpack=True)
    # daten = np.array([23, 34.50, 41, 43, 51, 57, 58.5, 65, 70, 78, 83, 84.5, 90,95.5, 103, 108,110,116, 123, 133, 116 +43])
    daten = np.array([
        23, 34.50, 43, 51, 57, 65, 78, 83, 90, 95.5, 103, 108, 123, 133,
        116 + 43
    ])
    # daten = np.array([23, 34.50, 43, 51, 57, 65, 78, 83,95.5, 103, 108, 123, 133, 116 +43]) #9. raus

    # maske = [True,True,False,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True,True]
    # daten = daten[maske]
    daten = daten + 4.5
    # daten = daten[daten != 0]
    daten = (daten * np.pi) / (360)

    print('Daten: ', daten)

    # theta = theta_radiant(radius())
    theta = daten

    print('Theta mit Fehler: ', theta)
    netzebenenabstand = bragg(lambda_1, noms(theta))

    reflexe_Zinkblende = []
    reflexe_Steinsalz = []
    reflexe_Caesiumchlorid = []
    reflexe_Fluorit = []

    verhaeltnisse_temp = []

    for gitter in gitter_moegl:
        if gitter == 'Zinkblende':
            ############## CuF ##################
            argg = 'CuF'
            print('Berechnung ' + gitter + ' für ' + argg + ':')
            infos = Strukturamplitude_Salz(28, 10, gitter=gitter)
            reflexe = np.array(infos[0])
            # print(gitter +': ',reflexe[np.argsort(infos[1])])
            m = infos[1]
            m = np.sort(m)

            verhaeltnisse = findStructure(m, netzebenenabstand)
            verhaeltnisse_temp = verhaeltnisse[0]
            # verhaeltnis_m = np.sort(verhaeltnisse[0])
            verhaeltnis_m = verhaeltnisse[0]
            if gitter == 'Zinkblende':
                reflexe_Zinkblende = verhaeltnis_m
            elif gitter == 'Steinsalz':
                reflexe_Steinsalz = verhaeltnis_m
            elif gitter == 'Caesiumchlorid':
                reflexe_Caesiumchlorid = verhaeltnis_m
            elif gitter == 'Fluorit':
                reflexe_Fluorit = verhaeltnis_m

            verhaeltnis_d = np.sort(verhaeltnisse[1])

            print('sqrt(m_i/m_1): ', verhaeltnis_m)
            print('d_1/d_i: ', verhaeltnis_d)

            print('Verhältnisse für die m Werte: ', verhaeltnis_m)
            print('Verhältnisse für die d Werte: ', verhaeltnis_d)
            print(
                'Abweichung Xi^2 für die ' + gitter + ' Struktur für ' + argg +
                ': ', abweichung(verhaeltnis_m, verhaeltnis_d))

            if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
                Xi2_best = [
                    gitter,
                    abweichung(verhaeltnis_m, verhaeltnis_d), argg
                ]

            ############## CuCl ##################

            argg = 'CuCl'
            print('Berechnung ' + gitter + ' für ' + argg + ':')
            infos = Strukturamplitude_Salz(28, 18, gitter=gitter)
            reflexe = np.array(infos[0])
            # print(gitter +': ',reflexe[np.argsort(infos[1])])
            m = infos[1]
            m = np.sort(m)

            verhaeltnisse = findStructure(m, netzebenenabstand)
            verhaeltnisse_temp = verhaeltnisse[0]
            # verhaeltnis_m = np.sort(verhaeltnisse[0])
            verhaeltnis_m = verhaeltnisse[0]
            if gitter == 'Zinkblende':
                reflexe_Zinkblende = verhaeltnis_m
            elif gitter == 'Steinsalz':
                reflexe_Steinsalz = verhaeltnis_m
            elif gitter == 'Caesiumchlorid':
                reflexe_Caesiumchlorid = verhaeltnis_m
            elif gitter == 'Fluorit':
                reflexe_Fluorit = verhaeltnis_m

            verhaeltnis_d = np.sort(verhaeltnisse[1])

            print('sqrt(m_i/m_1): ', verhaeltnis_m)
            print('d_1/d_i: ', verhaeltnis_d)

            print('Verhältnisse für die m Werte: ', verhaeltnis_m)
            print('Verhältnisse für die d Werte: ', verhaeltnis_d)
            print(
                'Abweichung Xi^2 für die ' + gitter + ' Struktur für ' + argg +
                ': ', abweichung(verhaeltnis_m, verhaeltnis_d))

            if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
                Xi2_best = [
                    gitter,
                    abweichung(verhaeltnis_m, verhaeltnis_d), argg
                ]
        elif gitter == 'Steinsalz':
            ############## KF ##################
            argg = 'KF'
            print('Berechnung ' + gitter + ' für ' + argg + ':')
            infos = Strukturamplitude_Salz(18, 10, gitter=gitter)
            reflexe = np.array(infos[0])
            # print(gitter +': ',reflexe[np.argsort(infos[1])])
            m = infos[1]
            m = np.sort(m)

            verhaeltnisse = findStructure(m, netzebenenabstand)
            verhaeltnisse_temp = verhaeltnisse[0]
            # verhaeltnis_m = np.sort(verhaeltnisse[0])
            verhaeltnis_m = verhaeltnisse[0]
            if gitter == 'Zinkblende':
                reflexe_Zinkblende = verhaeltnis_m
            elif gitter == 'Steinsalz':
                reflexe_Steinsalz = verhaeltnis_m
            elif gitter == 'Caesiumchlorid':
                reflexe_Caesiumchlorid = verhaeltnis_m
            elif gitter == 'Fluorit':
                reflexe_Fluorit = verhaeltnis_m

            verhaeltnis_d = np.sort(verhaeltnisse[1])

            print('sqrt(m_i/m_1): ', verhaeltnis_m)
            print('d_1/d_i: ', verhaeltnis_d)

            print('Verhältnisse für die m Werte: ', verhaeltnis_m)
            print('Verhältnisse für die d Werte: ', verhaeltnis_d)
            print(
                'Abweichung Xi^2 für die ' + gitter + ' Struktur für ' + argg +
                ': ', abweichung(verhaeltnis_m, verhaeltnis_d))

            if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
                Xi2_best = [
                    gitter,
                    abweichung(verhaeltnis_m, verhaeltnis_d), argg
                ]

            ############## KCl ##################

            argg = 'KCl'
            print('Berechnung ' + gitter + ' für ' + argg + ':')
            infos = Strukturamplitude_Salz(18, 18, gitter=gitter)
            reflexe = np.array(infos[0])
            # print(gitter +': ',reflexe[np.argsort(infos[1])])
            m = infos[1]
            m = np.sort(m)

            verhaeltnisse = findStructure(m, netzebenenabstand)
            verhaeltnisse_temp = verhaeltnisse[0]
            # verhaeltnis_m = np.sort(verhaeltnisse[0])
            verhaeltnis_m = verhaeltnisse[0]
            if gitter == 'Zinkblende':
                reflexe_Zinkblende = verhaeltnis_m
            elif gitter == 'Steinsalz':
                reflexe_Steinsalz = verhaeltnis_m
            elif gitter == 'Caesiumchlorid':
                reflexe_Caesiumchlorid = verhaeltnis_m
            elif gitter == 'Fluorit':
                reflexe_Fluorit = verhaeltnis_m

            verhaeltnis_d = np.sort(verhaeltnisse[1])

            print('sqrt(m_i/m_1): ', verhaeltnis_m)
            print('d_1/d_i: ', verhaeltnis_d)

            print('Verhältnisse für die m Werte: ', verhaeltnis_m)
            print('Verhältnisse für die d Werte: ', verhaeltnis_d)
            print(
                'Abweichung Xi^2 für die ' + gitter + ' Struktur für ' + argg +
                ': ', abweichung(verhaeltnis_m, verhaeltnis_d))

            if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
                Xi2_best = [
                    gitter,
                    abweichung(verhaeltnis_m, verhaeltnis_d), argg
                ]
        elif gitter == 'Caesiumchlorid':
            ############## CsJ ##################
            argg = 'CsJ'
            print('Berechnung ' + gitter + ' für ' + argg + ':')
            infos = Strukturamplitude_Salz(54, 54, gitter=gitter)
            reflexe = np.array(infos[0])
            # print(gitter +': ',reflexe[np.argsort(infos[1])])
            m = infos[1]
            m = np.sort(m)

            verhaeltnisse = findStructure(m, netzebenenabstand)
            verhaeltnisse_temp = verhaeltnisse[0]
            # verhaeltnis_m = np.sort(verhaeltnisse[0])
            verhaeltnis_m = verhaeltnisse[0]
            if gitter == 'Zinkblende':
                reflexe_Zinkblende = verhaeltnis_m
            elif gitter == 'Steinsalz':
                reflexe_Steinsalz = verhaeltnis_m
            elif gitter == 'Caesiumchlorid':
                reflexe_Caesiumchlorid = verhaeltnis_m
            elif gitter == 'Fluorit':
                reflexe_Fluorit = verhaeltnis_m

            verhaeltnis_d = np.sort(verhaeltnisse[1])

            print('sqrt(m_i/m_1): ', verhaeltnis_m)
            print('d_1/d_i: ', verhaeltnis_d)

            print('Verhältnisse für die m Werte: ', verhaeltnis_m)
            print('Verhältnisse für die d Werte: ', verhaeltnis_d)
            print(
                'Abweichung Xi^2 für die ' + gitter + ' Struktur für ' + argg +
                ': ', abweichung(verhaeltnis_m, verhaeltnis_d))

            if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
                Xi2_best = [
                    gitter,
                    abweichung(verhaeltnis_m, verhaeltnis_d), argg
                ]

            ############## CsCl ################## -> könnte komisch sein

            argg = 'CsCl'
            print('Berechnung ' + gitter + ' für ' + argg +
                  '(könnte komisch sein):')
            infos = Strukturamplitude_Salz(54, 18, gitter=gitter)
            reflexe = np.array(infos[0])
            # print(gitter +': ',reflexe[np.argsort(infos[1])])
            m = infos[1]
            m = np.sort(m)

            verhaeltnisse = findStructure(m, netzebenenabstand)
            verhaeltnisse_temp = verhaeltnisse[0]
            # verhaeltnis_m = np.sort(verhaeltnisse[0])
            verhaeltnis_m = verhaeltnisse[0]
            if gitter == 'Zinkblende':
                reflexe_Zinkblende = verhaeltnis_m
            elif gitter == 'Steinsalz':
                reflexe_Steinsalz = verhaeltnis_m
            elif gitter == 'Caesiumchlorid':
                reflexe_Caesiumchlorid = verhaeltnis_m
            elif gitter == 'Fluorit':
                reflexe_Fluorit = verhaeltnis_m

            verhaeltnis_d = np.sort(verhaeltnisse[1])

            print('sqrt(m_i/m_1): ', verhaeltnis_m)
            print('d_1/d_i: ', verhaeltnis_d)

            print('Verhältnisse für die m Werte: ', verhaeltnis_m)
            print('Verhältnisse für die d Werte: ', verhaeltnis_d)
            print(
                'Abweichung Xi^2 für die ' + gitter + ' Struktur für ' + argg +
                ': ', abweichung(verhaeltnis_m, verhaeltnis_d))

            if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
                Xi2_best = [
                    gitter,
                    abweichung(verhaeltnis_m, verhaeltnis_d), argg
                ]
        elif gitter == 'Fluorit':
            ############## CaF ##################
            argg = 'CaF'
            print('Berechnung ' + gitter + ' für ' + argg + ':')
            infos = Strukturamplitude_Salz(18, 10, gitter=gitter)
            reflexe = np.array(infos[0])
            # print(gitter +': ',reflexe[np.argsort(infos[1])])
            m = infos[1]
            m = np.sort(m)

            verhaeltnisse = findStructure(m, netzebenenabstand)
            verhaeltnisse_temp = verhaeltnisse[0]
            # verhaeltnis_m = np.sort(verhaeltnisse[0])
            verhaeltnis_m = verhaeltnisse[0]
            if gitter == 'Zinkblende':
                reflexe_Zinkblende = verhaeltnis_m
            elif gitter == 'Steinsalz':
                reflexe_Steinsalz = verhaeltnis_m
            elif gitter == 'Caesiumchlorid':
                reflexe_Caesiumchlorid = verhaeltnis_m
            elif gitter == 'Fluorit':
                reflexe_Fluorit = verhaeltnis_m

            verhaeltnis_d = np.sort(verhaeltnisse[1])

            print('sqrt(m_i/m_1): ', verhaeltnis_m)
            print('d_1/d_i: ', verhaeltnis_d)

            print('Verhältnisse für die m Werte: ', verhaeltnis_m)
            print('Verhältnisse für die d Werte: ', verhaeltnis_d)
            print(
                'Abweichung Xi^2 für die ' + gitter + ' Struktur für ' + argg +
                ': ', abweichung(verhaeltnis_m, verhaeltnis_d))

            if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
                Xi2_best = [
                    gitter,
                    abweichung(verhaeltnis_m, verhaeltnis_d), argg
                ]

            ############## CaCl ################## -> könnte komisch sein

            argg = 'CaCl'
            print('Berechnung ' + gitter + ' für ' + argg +
                  '(könnte komisch sein):')
            infos = Strukturamplitude_Salz(18, 18, gitter=gitter)
            reflexe = np.array(infos[0])
            # print(gitter +': ',reflexe[np.argsort(infos[1])])
            m = infos[1]
            m = np.sort(m)

            verhaeltnisse = findStructure(m, netzebenenabstand)
            verhaeltnisse_temp = verhaeltnisse[0]
            # verhaeltnis_m = np.sort(verhaeltnisse[0])
            verhaeltnis_m = verhaeltnisse[0]
            if gitter == 'Zinkblende':
                reflexe_Zinkblende = verhaeltnis_m
            elif gitter == 'Steinsalz':
                reflexe_Steinsalz = verhaeltnis_m
            elif gitter == 'Caesiumchlorid':
                reflexe_Caesiumchlorid = verhaeltnis_m
            elif gitter == 'Fluorit':
                reflexe_Fluorit = verhaeltnis_m

            verhaeltnis_d = np.sort(verhaeltnisse[1])

            print('sqrt(m_i/m_1): ', verhaeltnis_m)
            print('d_1/d_i: ', verhaeltnis_d)

            print('Verhältnisse für die m Werte: ', verhaeltnis_m)
            print('Verhältnisse für die d Werte: ', verhaeltnis_d)
            print(
                'Abweichung Xi^2 für die ' + gitter + ' Struktur für ' + argg +
                ': ', abweichung(verhaeltnis_m, verhaeltnis_d))

            if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
                Xi2_best = [
                    gitter,
                    abweichung(verhaeltnis_m, verhaeltnis_d), argg
                ]

    print('Struktur mit der kleinsten Abweichung: ', Xi2_best[0], ' für ',
          Xi2_best[2])
    print('Abweichung Xi^2: ', Xi2_best[1])

    m = Strukturamplitude_Salz(18, 18, gitter=Xi2_best[0])[1]
    a = np.array(gitterkonstanteBragg(m, netzebenenabstand))

    print('Gitterkonstanten für ' + Xi2_best[0] + ' Struktur: ', ' für ',
          Xi2_best[2], a)

    ####################################################################################################
    # Systematischer Fehler
    ####################################################################################################

    # systematischer Fehler Absorption der Röntgenstrahlung

    DeltaA = (radius_rohr /
              (2 * Radius_kamera)) * (1 - Radius_kamera / Abstand_FP) * (
                  np.cos(noms(theta))**2 / noms(theta)) * a

    a_mitFehler = unp.uarray(a, DeltaA)
    print('Gitterkonstanten mit Fehler durch die Absorption: ', a_mitFehler)

    ####################################################################################################
    # curve_fit zeugs
    ####################################################################################################

    # linearer fit für a gegen cos^2
    # params, cov = curve_fit(lin,np.cos(noms(theta))**2,noms(a_mitFehler), sigma = stds(a_mitFehler))
    params, cov = curve_fit(lin, np.cos(noms(theta))**2, noms(a_mitFehler))
    err = np.sqrt(np.diag(cov))
    a_extrp = ufloat(params[1], err[1])
    print('Extrapolierte Gitterkonstante: ', a_extrp)

    ####################################################################################################
    # Plots
    ####################################################################################################

    cos2Theta = unp.cos(theta)**2
    cos2Theta_fit = np.linspace(0, 1)

    ####### ab hier der a gegen cos^2 Plot ########
    plt.errorbar(np.cos(noms(theta))**2,
                 a,
                 xerr=stds(cos2Theta),
                 yerr=DeltaA,
                 fmt='x',
                 label='Daten')
    plt.plot(cos2Theta_fit, lin(cos2Theta_fit, *params), label='Fit')
    plt.legend(loc='best')
    plt.xlabel('cos$^2(\Theta)$')
    plt.ylabel('$a$ in Angtröm')
    # plt.xlim(0.6,1)
    # plt.ylim(4.8e-10,5.8e-10)
    plt.tight_layout()
    plt.grid()
    plt.savefig('Plots/Salz_Fit_Egor.pdf')
    plt.close()

    i = np.linspace(1, len(daten), len(daten))

    verhaeltnisse_daten = []
    for j in range(0, len(daten)):
        verhaeltnisse_daten.append(unp.sin(daten[j]) / unp.sin(daten[0]))

    plt.plot(i, reflexe_Zinkblende, 'x', label='Zinkblende')
    plt.plot(i, reflexe_Steinsalz, 'x', label='Steinsalz')
    plt.plot(i, reflexe_Caesiumchlorid, 'x', label='Caesiumchlorid')
    plt.plot(i, reflexe_Fluorit, 'o', label='Fluorit')
    plt.plot(i, noms(verhaeltnisse_daten), 'x', label='data')
    plt.xlabel('i')
    # plt.xlim(0,7)
    # plt.ylim(0,4.5)
    plt.ylabel('verhältnisse')
    plt.legend(loc='best')
    plt.tight_layout()
    plt.grid()
    plt.savefig('Plots/verhaeltnisse_Salz.pdf')
    plt.close()
    I_K = I_K[0]
    print(f'Intensitätsmax. = {I_K}')

    test = np.abs(N - I_K)
    mask_test = test == np.amin(test)
    theta_K = theta[mask_test]

    # Sonderbehandlung für Gallium
    if Z == 31:
        theta_K = 17.35

    theta_K = ufloat(theta_K, 0.5)
    print(f'Winkel = {theta_K}')

    # energias
    E_K = h_ev * c / (2 * d_lif * unp.sin(theta_K * np.pi / 180))
    E_K_array[i] = unp.nominal_values(E_K)
    E_K_errs[i] = unp.std_devs(E_K)

    E_dev = 100 * (theo - E_K) / theo
    print(f'Absorptionsenergie = {E_K}, Abweichung = {E_dev}')

    # Abschirmkonstanten
    sigma_K = Z - unp.sqrt(E_K / R_inf - a**2 * Z**4 / 4)
    sigma_theo = Z - unp.sqrt(theo / R_inf - a**2 * Z**4 / 4)
    sigma_dev = 100 * (sigma_K - sigma_theo) / sigma_theo
    print(
        f'Abschirmkonstante = {sigma_K}, Theoriewert = {sigma_theo}, Abweichung = {sigma_dev}'
    )

    i += 1
Exemple #10
0
def lam(x, n=1, s=s, d=d):
    alpha = unp.arctan(x/d)
    return s / n * unp.sin(alpha)
def discrete_time_modeling_function(n, p):
    Vp = p[0]
    phi = p[1]
    Vos = p[2]
    return Vp * unp.sin(2 * np.pi * generator_frequency / sampling_frequency *
                        n + phi) + Vos
Exemple #12
0
d = misura(value=_d, name="$d$")
thetaI = misura(value=_thetaI, name="$\\theta_i$")
l_h2o = misura(value=_l_h2o, name="$l$")

#---------------------------------------------------------------------------------------#
#-/////////////////////// CALCULATIONS ////////////////////////////////////////////////-#
#---------------------------------------------------------------------------------------#
_thetaT_h2o = []
_nT_h2o = []
_index = []
_thetaT_Th = []

for i in range(len(_l_h2o)):
    _thetaT_h2o.append(unp.arctan2(_l_h2o[i], _h1_h2o[i]) * 180 / np.pi)
    _nT_h2o.append(
        unp.sin(_thetaI[i] / 180 * np.pi) /
        unp.sin(_thetaT_h2o[i] / 180 * np.pi))
    _index.append((1.334 - _nT_h2o[i]) / 1.334)
    _thetaT_Th.append(
        asin(0.749625 * unp.sin(_thetaI[i] / 180 * np.pi)) / np.pi * 180)

thetaT_h2o = misura(value=_thetaT_h2o, name="$\\theta_t$")
nT_h2o = misura(value=_nT_h2o, name="$n_{exp}$")
index = misura(value=_index, name="$(n - n_{exp}) / n$")
thetaT_Th = misura(value=_thetaT_Th, name="$\\theta_t$")

### Correlazione lineare tra due valori (x,y)
fitLine = poly_fit(thetaI, thetaT_h2o)

#---------------------------------------------------------------------------------------#
#-/////////////////////// RESULTS /////////////////////////////////////////////////////-#
Exemple #13
0
from uncertainties import unumpy as unp
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
h = 4.136e-15
c = 299792458
d = 2.014e-10

theta = ufloat(13.0, 0.35) * np.pi / 180
#theta = 22.5 *np.pi/180
#theta = 20.29 *np.pi/180
thetab = ufloat(20.00, 0, 35) * np.pi / 180
thetaa = ufloat(22.21, 0.35) * np.pi / 180
K = 8979
R = 13.8

E = h * c / (2 * d * unp.sin(theta))
Ea = h * c / (2 * d * unp.sin(thetaa))
Eb = h * c / (2 * d * unp.sin(thetab))

print(Eb)
#sig1 = 38 - unp.sqrt(17998/R)
#print("sig11", sig1)
#Wellenlänge
#l = h *c / E
#print(l)
#Abschirmkonstante Kupfer
sig1 = 29 - unp.sqrt(K / R)
print("sig1", sig1)
Eb = Eb - 22
sig2 = 29 - 2 * unp.sqrt((R * (29 - sig1)**2 - Ea) / R)
print("sig2", sig2)
Exemple #14
0
def XYfun(a):
    return a[0], unumpy.sin(pi / 2 - unumpy.arctan((a[1] - zero) / D))
def lambdamittel(phi1,phi2):
    return(unp.sin(phimittelwert(phi1,phi2))*g)
Exemple #16
0
def wavelen(gconst, dist, dn):
    arr = np.array(dn)
    for n in range(1, 1 + len(dn)):
        arr[n - 1] = gconst * unp.sin(unp.arctan(dn[n - 1] / dist)) / n
    return (arr)
Exemple #17
0
x = 57.2958
e = 1.602176487 * 1e-16
E = E * e
R = 13.6 * 1.602176487 * 1e-19
sigma = z - np.sqrt(E / R)

h = 6.626 * 1e-34
c = 299792458
d = 201.4 * 1e-12
theta = np.arcsin((h * c) / (E * 2 * d)) * 57.2958



t = ufloat(10, 0.75) / 2
lambdamin = 2 * d  * unp.sin(t / 57.2958)
Emax = h * c / lambdamin
lambdamintheo = h * c /(e  * 35)
Emaxtheo = h * c / lambdamintheo
#print(Emax / e)

a = ufloat(11.89, 0.31)
b = ufloat(14.1, 0.4)
g = b - a
#print((b - a))

# Mehr Energie!!!
t = ufloat(15.0 , 0.4)
E1 = (h * c / (2 * d * unp.sin(t / x)))/ e
#E2 = h * c / (2 * d * np.sin(20.0 / 57.2958)) / e
#print(E1)
Exemple #18
0
planck = const.physical_constants["Planck constant"][0]
print(planck)

light = const.physical_constants["speed of light in vacuum"][0]
print(light)

d = 201.4 * 10**(-12)

elem = const.physical_constants["elementary charge"][0]
print(elem)

alphamain = ufloat(0.39269908169872414, winkelfehler)
betamain = ufloat(0.35255650890285456, winkelfehler)

Ealpha = planck * light / (2 * d * unp.sin(alphamain)) / elem
Ebeta = planck * light / (2 * d * unp.sin(betamain)) / elem

print(f"{Ealpha:.0f}")
print(F"{Ebeta:.0f}")

alphaleft = ufloat(0.3501130479500625, winkelfehler)
alpharight = ufloat(0.3586651612848347, winkelfehler)
betaleft = ufloat(0.3900810878207327, winkelfehler)
betaright = ufloat(0.3988077340807043, winkelfehler)

alphaleft2 = ufloat(20.06, 0.1)
alpharight2 = ufloat(20.55, 0.1)
betaleft2 = ufloat(22.35, 0.1)
betaright2 = ufloat(22.85, 0.1)
Exemple #19
0
winkelzink = np.deg2rad(18.9)
winkelgallium = np.deg2rad(18.1)
winkelbrom = np.deg2rad(14.0)
winkelrubidium = np.deg2rad(11.9)
winkelstrontium = np.deg2rad(11.3)
winkelzirkonium = np.deg2rad(10.2)

winkelzinkfehler = ufloat(np.deg2rad(18.9), winkelfehler)
winkelgalliumfehler = ufloat(np.deg2rad(18.1), winkelfehler)
winkelbromfehler = ufloat(np.deg2rad(14.0), winkelfehler)
winkelrubidiumfehler = ufloat(np.deg2rad(11.9), winkelfehler)
winkelstrontiumfehler = ufloat(np.deg2rad(11.3), winkelfehler)
winkelzirkoniumfehler = ufloat(np.deg2rad(10.2), winkelfehler)

Eabszink = planck * light / (2 * d * unp.sin(winkelzinkfehler)) / elem
Eabsgallium = planck * light / (2 * d * unp.sin(winkelgalliumfehler)) / elem
Eabsbrom = planck * light / (2 * d * unp.sin(winkelbromfehler)) / elem
Eabsrubidium = planck * light / (2 * d * unp.sin(winkelrubidiumfehler)) / elem
Eabsstrontium = planck * light / (2 * d *
                                  unp.sin(winkelstrontiumfehler)) / elem
Eabszirkonium = planck * light / (2 * d *
                                  unp.sin(winkelzirkoniumfehler)) / elem

print(F"Zink Energie ist: {Eabszink} in eV")
print(F"Gallium Energie ist: {Eabsgallium} in eV")
print(F"Brom Energie ist: {Eabsbrom} in eV")
print(F"Rubidium Energie ist: {Eabsrubidium} in eV")
print(F"Strontium Energie ist: {Eabsstrontium} in eV")
print(F"Zirkonium Energie ist: {Eabszirkonium} in eV")
Exemple #20
0
plt.clf()

print(d_selbst)
d_selbst -= 1.5
d_selbst[0] += 1.5
#d_dort -= 1.5
plt.plot(d_selbst, dB_selbst, 'rx', mew=0.5, label='Eigene Messung')
plt.plot(d_dort,
         dB_dort,
         'bo',
         mew=0.5,
         markersize=4,
         label='Herstellerangabe')
plt.grid()
plt.legend()
plt.xlabel(r'$d/$mm')
plt.ylabel(r'$D/$dB')
plt.savefig('build/daempfungMitKorrektur.pdf')

# 3db Methode
x_1 = 69.6
x_2 = 67.9
S_3db = unp.sqrt(1 + 1 / (unp.sin(np.pi * (x_1 - x_2) / lam_g))**2)
print('S durch 3db Methode', S_3db)

# Abschwächermethode
A_1 = 20
A_2 = 42
S_ab = 10**((A_2 - A_1) / 20)
print('S durch Abschwächermethode', S_ab)
Exemple #21
0
def lamb(l, L, g, n):
    return (g * unp.sin(unp.arctan(l / L))) / n
Exemple #22
0
from scipy.optimize import curve_fit
from scipy.stats import sem
import scipy.constants as const
import uncertainties.unumpy as unp

A, B = np.genfromtxt("../data/A4rot.dat", unpack=True)

a = np.deg2rad(A)  #ist alpha_1
b = np.deg2rad(B)  #ist alhpa_2
c = const.physical_constants["speed of light in vacuum"]
n = ufloat(1.45108, 0.01991)

aERR = np.array([])
bERR = np.array([])
for i in range(len(a)):
    aERR = np.append(aERR, ufloat(a[i], 0.00872665))
for i in range(len(b)):
    bERR = np.append(bERR, ufloat(b[i], 0.00872665))

#bestimme beta 1
beta = unp.arcsin(unp.sin(aERR) / n)
beta2 = np.deg2rad(60) - beta

print(beta * 180 / np.pi)
print(beta2 * 180 / np.pi)

delta = (aERR + bERR) - (beta + beta2)
deltamean = np.mean(delta)
print("###### delta rot:")
print(delta * 180 / np.pi)
print(f"Abweichung delta= {(deltamean*180/np.pi):.4f}")
Exemple #23
0
def y_bragg(b, n=1):
    global d
    return 2 * d * unp.sin(b / 360. * 2. * const.pi) / n
Exemple #24
0
plt.legend(loc="best")
plt.annotate('$K_{\\beta}$', xy=(20.1, 1700), size=15)
plt.annotate('$K_{\\alpha} $', xy=(23, 5050), size=15)
plt.annotate('Bremsspektrum', xy=(10, 700), size=20)

plt.xlabel(r'Winkel $\theta \:/\:°$')
plt.ylabel(r'Intensität $I\:/\:Imp/s$')
plt.grid()
plt.tight_layout
plt.savefig('build/plot_Cu.pdf')
plt.close()

lambda_20 = ufloat(np.deg2rad(20.1), np.deg2rad(0.1))
lambda_22 = ufloat(np.deg2rad(22.5), np.deg2rad(0.1))

print(2 * 201.4 * 1e-12 * unp.sin(lambda_20))
print(const.h * const.c / (2 * 201.4 * 1e-12 * unp.sin(lambda_20) * const.e))
print(2 * 201.4 * 1e-12 * unp.sin(lambda_22))
print(const.h * const.c / (2 * 201.4 * 1e-12 * unp.sin(lambda_22) * const.e))

#Plot des Absorptionsspektrum ohne Absorber

#Totzeitkorrektur

I_Al = R_Al / (1 - 90 * 1e-06 * R_Al)

I_Ohne = R_Ohne / (1 - 90 * 1e-06 * R_Ohne)

T = I_Al / I_Ohne

par, covm = np.polyfit(lambda1, unp.nominal_values(T), deg=1, cov=True)
Exemple #25
0
from uncertainties import ufloat
import scipy.odr as sodr

file = sys.argv[1]
data = genfromtxt(file, delimiter=';')
w_B = unumpy.uarray(data[1:, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
w_G = unumpy.uarray(data[1:, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
w_B_value = unp.nominal_values(w_B)
w_G_value = unp.nominal_values(w_G)

lamda = np.array([
    600.752, 671.643, 623.440, 579.066, 576.960, 546.074, 491.607, 435.833,
    434.749, 433.922, 410.805, 407.783, 404.656
]) * 1e-9

d = lamda / (unp.sin(unp.radians(w_G)) -
             unp.sin(unp.radians(w_G) + unp.radians(w_B)))
d_no_error = unp.nominal_values(d)
d_error = unumpy.std_devs(d)
d_avarage = np.sum(d_no_error) / len(d_no_error)
d_avarage_error = 1 / np.sqrt(len(d_error)) * np.sqrt(np.sum(
    d_error * d_error))
print(
    '$\lambda$ / nm & $w_G$ / $^\circ$ & $w_B$ / $^\circ$ & d / nm & $\Delta$ d / nm'
)
for i in range(0, len(lamda)):
    print('%.3f & %.3f \pm %.3f& %.3f \pm %.3f& %.3f \pm %.3f \\\\' %
          (lamda[i] * 1e9, w_G_value[i], 1, w_B_value[i], 1,
           d_no_error[i] * 1e9, d_error[i] * 1e9))
print('d=(%.3f \pm %.3f)\cdot 10^{-9}m' %
      (d_avarage * 1e9, d_avarage_error * 1e9))
Exemple #26
0
def angular_dispersion_uncertainties(tdata,
                                     n,
                                     position_angles,
                                     redshift=False,
                                     PT=False):

    N = len(tdata)
    RAs = np.asarray(tdata['RA'])
    DECs = np.asarray(tdata['DEC'])

    # hard fix for when n > N
    if n > len(tdata):
        print('n = %i, but this tdata only contains N=%i sources' %
              (n, len(tdata)))
        n = len(tdata) - 1
        print('Setting n=%i' % n)

    #convert RAs and DECs to an array that has following layout: [[x1,y1,z1],[x2,y2,z2],etc]
    if redshift:
        Z = tdata['z_best']
        '''
		H = 73450 # m/s/Mpc = 73.45 km/s/Mpc
		# but is actually unimportant since only relative distances are important
		from scipy.constants import c # m/s
		# assume flat Universe with q0 = 0.5 (see Hutsemekers 1998)
		# I think assuming q0 = 0.5 means flat universe
		r = 2.0*c/H * ( 1-(1+Z)**(-0.5) ) # comoving distance
		'''
        from astropy.cosmology import Planck15
        r = Planck15.comoving_distance(Z)  #better to just use this calculator
        x = r * np.cos(np.radians(RAs)) * np.cos(np.radians(DECs))
        y = r * np.sin(np.radians(RAs)) * np.cos(np.radians(DECs))
        z = r * np.sin(np.radians(DECs))
    else:
        x = np.cos(np.radians(RAs)) * np.cos(np.radians(DECs))
        y = np.sin(np.radians(RAs)) * np.cos(np.radians(DECs))
        z = np.sin(np.radians(DECs))
    coordinates = np.vstack((x, y, z)).T

    #make a KDTree for quick NN searching
    coordinates_tree = cKDTree(coordinates, leafsize=16)

    # for every source: find n closest neighbours, calculate max dispersion using PT
    position_angles_array = np.zeros(
        (N, n))  # array of shape (N,n) that contains position angles
    position_angles_array = unumpy.uarray(position_angles_array, 0)
    for i in range(N):
        if PT:
            index_NN = coordinates_tree.query(
                coordinates[i], k=n, p=2,
                n_jobs=-1)[1]  # include source itself
            # print index_NN # if this gives an error we should check whether we have the right sources (redshift selection)
            # Transport every nearest neighbour to the current source i
            angles_transported = parallel_transport_uncertainties(
                RAs[i], DECs[i], RAs[index_NN[1:]], DECs[index_NN[1:]],
                position_angles[index_NN[1:]])
            # Then concatenate the transported angles to the current source position angle and store it
            position_angles_array[i] = np.concatenate(
                ([position_angles[i]], angles_transported))
        else:
            index_NN = coordinates_tree.query(
                coordinates[i], k=n, p=2,
                n_jobs=-1)[1]  # include source itself
            position_angles_array[i] = position_angles[index_NN]

    assert position_angles_array.shape == (N, n)

    n_array = np.asarray(range(
        1, n + 1))  # have to divide different elements by different n

    x = unumpy.radians(
        2 * position_angles_array
    )  # used to use numexpr to speed it up quite significantly

    di_max = 1. / n_array * ((np.cumsum(unumpy.cos(x), axis=1))**2 +
                             (np.cumsum(unumpy.sin(x), axis=1))**2)**0.5

    assert di_max.shape == (N, n
                            )  # array of max_di for every source, for every n

    Sn = 1. / N * np.sum(
        di_max, axis=0)  # array of shape (1xn) containing S_1 (nonsense)
    # to S_n
    return Sn
Exemple #27
0
def E(grad):
    return const.h * const.c / (2 * 201.4e-12 * unp.sin(grad) * const.e)
Exemple #28
0
def main():

    print('\n#################### Analyse für Metall ####################\n')
    print('radius', radius())

    Xi2_best = [
        'SC', 20
    ]  # SC ist in dem Fall ein Platzhalter. Die 20 garantiert, dass ein jedes Xi zunächst kleiner ist.

    daten = np.array([44.5, 64.5, 81.5, 98.5, 114.5, 134.5])
    daten = (daten * np.pi) / (360)

    # theta = theta_radiant(radius())
    theta = daten
    print('Theta mit Fehler: ', theta)
    netzebenenabstand = bragg(lambda_1, noms(theta))

    reflexe_SC = []
    reflexe_FCC = []
    reflexe_BCC = []
    reflexe_Diamant = []

    verhaeltnisse_temp = []

    for gitter in gitter_moegl:
        infos = Strukturamplitude(gitter=gitter)
        reflexe = np.array(infos[0])
        # print(gitter +': ',reflexe[np.argsort(infos[1])])
        m = infos[1]
        m = np.sort(m)

        verhaeltnisse = findStructure(m, netzebenenabstand)
        verhaeltnisse_temp = verhaeltnisse[0]
        # verhaeltnis_m = np.sort(verhaeltnisse[0])
        verhaeltnis_m = verhaeltnisse[0]
        if gitter == 'SC':
            reflexe_SC = verhaeltnis_m
        elif gitter == 'FCC':
            reflexe_FCC = verhaeltnis_m
        elif gitter == 'BCC':
            reflexe_BCC = verhaeltnis_m
        elif gitter == 'Diamant':
            reflexe_Diamant = verhaeltnis_m

        verhaeltnis_d = np.sort(verhaeltnisse[1])

        print('sqrt(m_i/m_1): ', verhaeltnis_m)
        print('d_1/d_i: ', verhaeltnis_d)

        print('Verhältnisse für die m Werte: ', verhaeltnis_m)
        print('Verhältnisse für die d Werte: ', verhaeltnis_d)
        print('Abweichung Xi^2 für die ' + gitter + ' Sturktur: ',
              abweichung(verhaeltnis_m, verhaeltnis_d))

        if abweichung(verhaeltnis_m, verhaeltnis_d) < Xi2_best[1]:
            Xi2_best = [gitter, abweichung(verhaeltnis_m, verhaeltnis_d)]

    print('Struktur mit der kleinsten Abweichung: ', Xi2_best[0])
    print('Abweichung Xi^2: ', Xi2_best[1])

    m = Strukturamplitude(gitter=Xi2_best[0])[1]
    a = np.array(gitterkonstanteBragg(m, netzebenenabstand))

    print('Gitterkonstanten für ' + Xi2_best[0] + ' Struktur: ', a)

    ####################################################################################################
    # Systematischer Fehler
    ####################################################################################################

    # systematischer Fehler Absorption der Röntgenstrahlung

    DeltaA = (radius_rohr /
              (2 * Radius_kamera)) * (1 - Radius_kamera / Abstand_FP) * (
                  np.cos(noms(theta))**2 / noms(theta)) * a

    a_mitFehler = unp.uarray(a, DeltaA)
    print('Gitterkonstanten mit Fehler durch die Absorption: ', a_mitFehler)

    ####################################################################################################
    # curve_fit zeugs
    ####################################################################################################

    # linearer fit für a gegen cos^2
    # params, cov = curve_fit(lin,np.cos(noms(theta))**2,noms(a_mitFehler), sigma = stds(a_mitFehler))
    params, cov = curve_fit(lin, np.cos(noms(theta))**2, noms(a_mitFehler))
    err = np.sqrt(np.diag(cov))
    a_extrp = ufloat(params[1], err[1])
    print('Extrapolierte Gitterkonstante: ', a_extrp)

    ####################################################################################################
    # Plots
    ####################################################################################################

    cos2Theta = unp.cos(theta)**2
    cos2Theta_fit = np.linspace(0, 1)

    ####### ab hier der a gegen cos^2 Plot ########
    plt.errorbar(np.cos(noms(theta))**2,
                 a,
                 xerr=stds(cos2Theta),
                 yerr=DeltaA,
                 fmt='x',
                 label='Daten')
    plt.plot(cos2Theta_fit, lin(cos2Theta_fit, *params), label='Fit')
    plt.legend(loc='best')
    plt.xlabel('cos$^2(\Theta)$')
    plt.ylabel('$a$ in Angtröm')
    # plt.xlim(0.6,1)
    # plt.ylim(4.8e-10,5.8e-10)
    plt.tight_layout()
    plt.grid()
    plt.savefig('Plots/Metall_Fit.pdf')
    plt.close()

    i = np.linspace(1, 6, 6)

    verhaeltnisse_daten = []
    for j in range(0, len(daten)):
        verhaeltnisse_daten.append(unp.sin(daten[j]) / unp.sin(daten[0]))

    plt.plot(i, reflexe_SC, 'o', label='SC')
    plt.plot(i, reflexe_FCC, 'o', label='FCC')
    plt.plot(i, reflexe_BCC, 'o', label='BCC')
    plt.plot(i, reflexe_Diamant, 'o', label='Diamant')
    plt.plot(i, noms(verhaeltnisse_daten), 'x', label='data')
    plt.xlabel('i')
    plt.xlim(0, 7)
    plt.ylim(0, 4)
    plt.ylabel('verhältnisse')
    plt.legend(loc='best')
    plt.tight_layout()
    plt.grid()
    plt.savefig('Plots/verhaeltnisse.pdf')
    plt.close()
Exemple #29
0
d_LiF = 201.4
d_LiF *= 10**(-12)

# ------ Emissionsspektrum -------

# read values for Emission spectrum
theta, N = np.genfromtxt('EmissionCu.txt', unpack=True)

# set k_alpha and k_beta line variables
kbeta = 20.2
kalpha = 22.5

kalpha_ = unp.uarray(kalpha, 0.1)
kbeta_ = unp.uarray(kbeta, 0.1)
# K_alpha y K_beta energias
lam_alpha = 2 * d_LiF * unp.sin(kalpha_ * np.pi / 180)
lam_beta = 2 * d_LiF * unp.sin(kbeta_ * np.pi / 180)

E_alpha = h * c / lam_alpha
E_beta = h * c / lam_beta

E_alpha *= 6.242 * 10**(18)
E_beta *= 6.242 * 10**(18)

print(f'E_a = {E_alpha}')
print(f'E_b = {E_beta}')

#plot Emission spectrum
plt.plot(theta, N, 'r.', label='Messwerte')
plt.plot(theta, N, 'b-', linewidth=0.5)
Exemple #30
0
Fichier : n.py Projet : knly/PAP2
def y_bragg(b, n=1):
    global d
    return 2*d*unp.sin(b/360.*2.*const.pi)/n
Exemple #31
0
from uncertainties import ufloat
from uncertainties.unumpy import sin

x = ufloat(4.56, 0.2)
y = ufloat(2.11, 0.3)
z = ufloat(10, 1)

Q = x**2 * sin(y) + z

print('Q = {}'.format(Q))

from sympy import var, sin

x, y, z = var('x y z')

Q = x**2 * sin(y) + z

print(Q.diff(x))
print(Q.diff(y))
print(Q.diff(z))
Exemple #32
0
    r12 = (kz1 - kz2) / (kz1 + kz2) * np.exp(-2 *  kz1 * kz2 * sigma1**2)
    r23 = (kz2 - kz3) / (kz2 + kz3) * np.exp(-2 *  kz2 * kz3 * sigma2**2)
    x2 = np.exp(- 1j *2 * kz2 * z2) * r23
    # print("test",(r12 + x2),"durch", (1 + r12 * x2))
    x1 = (r12 + x2) / (1 + r12 * x2)
    antwort =  np.log(np.abs(x1)**2)
    return antwort



params_det, cov_det = curve_fit(Gaus ,THETA_det_scan,Int_det_scan,p0=[0.9e8,0,0.02])
uparams_det = unp.uarray(params_det, np.sqrt(np.diag(cov_det)))

detektor_radius = 100 # Schätzwert!!!!!!

strahl_durchmesser =  detektor_radius * 2 * unp.sin(uparams_det[2]*np.pi/180) # noch nicht richtig !!!!!
print("strahl_durchmesser=",strahl_durchmesser)
print("Intesität=",uparams_det[0])
params_rock, cov_rock = curve_fit(Betragsfunktion ,Theta_rock[(Theta_rock > -0.25) & (Theta_rock < 0.7) ],
                                    Int_rock[(Theta_rock > -0.25) & (Theta_rock < 0.7)], p0=[14e7,-0.25,7e7])
uparams_rock = unp.uarray(params_rock, np.sqrt(np.diag(cov_rock)))
print("Rocking_scan_params",uparams_rock)

# finde nullstelle von rockingscan
def betragsfunktion_params(x):
    return(Betragsfunktion(x, params_rock[0], 0, params_rock[2]))

Winkel_rock = - uparams_rock[2]/uparams_rock[0]
print("\n\nGeometry winkel ",Winkel_rock)
Winkel_rock_rad = Winkel_rock * np.pi / 180
# arrays mit der richtigen Größe initialisieren
phi_kalium_mean = unp.uarray(np.zeros(np.size(phi_kalium)/2), np.zeros(np.size(phi_kalium)/2))
phi_natrium_mean = unp.uarray(np.zeros(np.size(phi_natrium)/2), np.zeros(np.size(phi_natrium)/2))
phi_rubidium_mean = unp.uarray(np.zeros(np.size(phi_rubidium)/2), np.zeros(np.size(phi_rubidium)/2))
lambda_kalium_mean = unp.uarray(np.zeros(np.size(phi_kalium)/2), np.zeros(np.size(phi_kalium)/2))
lambda_natrium_mean = unp.uarray(np.zeros(np.size(phi_natrium)/2), np.zeros(np.size(phi_natrium)/2))
lambda_rubidium_mean = unp.uarray(np.zeros(np.size(phi_rubidium)/2), np.zeros(np.size(phi_rubidium)/2))

# Mittelwerte aus den 2 Dublettwinkeln bilden
phi_kalium_mean = make_mean_from_two_values_in_array(phi_kalium, phi_kalium_mean)         # in rad
phi_natrium_mean = make_mean_from_two_values_in_array(phi_natrium, phi_natrium_mean)      # in rad
phi_rubidium_mean = make_mean_from_two_values_in_array(phi_rubidium, phi_rubidium_mean)   # in rad

# Daraus die zugehörigen Wellenlängen errechnen
lambda_kalium_mean = g*unp.sin(phi_kalium_mean) + offset        # in m
lambda_natrium_mean = g*unp.sin(phi_natrium_mean) + offset      # in m
lambda_rubidium_mean = g*unp.sin(phi_rubidium_mean) + offset    # in m

# zur Berechnung von Delta_s
def get_difference_between_two_values_in_array(array_in, array_out):
    i=0
    for bla in array_out:
        j = 2*i
        array_out[i] = array_in[j] - array_in[j+1]
        i += 1
    return array_out

# mehr arrays initialisieren!
delta_s_kalium = np.array(np.zeros(np.size(s_kalium)/2))
delta_s_natrium = np.array(np.zeros(np.size(s_natrium)/2))
Exemple #34
0
from scipy.optimize import curve_fit
from scipy.stats import sem
import scipy.constants as const
import uncertainties.unumpy as unp

d100 = (1 / 100) * 10**(-3)
d300 = (1 / 300) * 10**(-3)
d600 = (1 / 600) * 10**(-3)

##### GRÜNES LAMBDA

k, phi = np.genfromtxt("../data/A5grün100.dat", unpack=True)
phiERR = np.array([])
for i in range(len(phi)):
    phiERR = np.append(phiERR, ufloat(np.deg2rad(phi[i]), 0.00872665))
lambda100g = d100 * unp.sin(phiERR / k)
print(f"lamda_grün/100 ={lambda100g}")

k, phi = np.genfromtxt("../data/A5grün300.dat", unpack=True)
phiERR = np.array([])
for i in range(len(phi)):
    phiERR = np.append(phiERR, ufloat(np.deg2rad(phi[i]), 0.00872665))
lambda300g = d300 * unp.sin(phiERR / k)
print(f"lamda_grün/300 ={lambda300g}")

k, phi = np.genfromtxt("../data/A5grün600.dat", unpack=True)
phiERR = np.array([])
for i in range(len(phi)):
    phiERR = np.append(phiERR, ufloat(np.deg2rad(phi[i]), 0.00872665))
lambda600g = d600 * unp.sin(phiERR / k)
print(f"lamda_grün/600 ={lambda600g}")
def test_uncertainties_cov(y=Y):
    return unumpy.sin(y)
Exemple #36
0

plt.plot(l * 2, I01, 'kx', label='Messwerte')
plt.xlabel(r'$\Delta X/\si{\milli\meter}$')
plt.ylabel(r'$I/\si{\nano\ampere}$')
params, covariance_matrix = curve_fit(Mode_01,
                                      l * 2,
                                      I01,
                                      p0=(-0.46568761, 3.29542082, 12.97749986,
                                          5))
errors = np.sqrt(np.diag(covariance_matrix))
x_plot = np.linspace(np.min(l * 2), np.max(l * 2), 1000)
plt.plot(x_plot, Mode_01(x_plot, *params), 'b-', label='Fit')
plt.legend(loc='best')
plt.tight_layout(pad=0, h_pad=1.08, w_pad=1.08)

print("Mode_01: x_0 I_0 \omega")
print(params)
print(errors)

plt.savefig('build/Moden_01.pdf')
plt.clf()

print("Wellenlänge")

d = 0.7
g = 100 * 10**3
x = unp.uarray([0.045, 0.045], [0.001, 0.001])
l = 1 / g * unp.sin(unp.arctan(x / d))
print(unp.nominal_values(l))
print(unp.std_devs(l))
Exemple #37
0
import matplotlib.pyplot as plt
import numpy as np
from uncertainties import ufloat
import uncertainties.unumpy as unp

z, E = np.genfromtxt('mess1.txt', unpack=True)

x = 57.2958
e = 1.602176487 * 1e-16
E = E * e
R = 13.6 * 1.602176487 * 1e-19

h = 6.626 * 1e-34
c = 299792458
d = 201.4 * 1e-12

t = ufloat(15.0, 0.4)
E1 = (h * c / (2 * d * unp.sin(t / x))) / e

Ex = ufloat(9.58, 0.2)

sigma1 = 29 - unp.sqrt(E1 * e / R)
sigma3 = 29 - 2 * unp.sqrt((R * (29 - sigma1)**2 - Ex * e) / R)
print(sigma3)
Exemple #38
0
print('phi_Mittel:', phi_Mittel)


write('build/Messwerte1.tex', make_table([phi_1, phi_2, phi],[1,1,1]))
write('build/Winkel_Prisma.tex', make_SI(phi_Mittel,r'',figures=1))
write('build/Messwerte2.tex', make_table([wavelength*10**9, eta_1, eta_2, eta],[2,1,1,1]))
################################################################


phi_Mittel = 60


################################################################
### Brechzahl
################################################################
n = unp.sin( 0.5 * 2 * np.pi / 360 * (eta + phi_Mittel) ) / unp.sin( 0.5 * 2 * np.pi / 360 * phi_Mittel)
print('Brechzahl:', n)


n_nom = unp.nominal_values(n)
n_std = unp.std_devs(n)


write('build/Brechzahlen.tex', make_table([wavelength*10**9, n_nom, n_std],[2,3,3]))
################################################################



################################################################
### Plotten
################################################################
Exemple #39
0
def logg_southworth(P_days, K_ms, aRp, ecc=0., inc_deg=90.):
    '''Compute the surface gravity in m/s^2 from the equation in Southworth 
    et al 2007.'''
    P, inc = days2sec(P_days), unumpy.radians(inc_deg)
    return 2 * np.pi * K_ms * aRp * aRp * unumpy.sqrt(1 - ecc * ecc) / (
        P * unumpy.sin(inc))
Exemple #40
0
def RV_mp(P_days, Ms_Msun, K_ms, ecc=0., inc_deg=90.):
    '''Compute the planet mass from RV semiamplitude in Earth masses.'''
    P, Ms, inc = days2sec(P_days), Msun2kg(Ms_Msun), unumpy.radians(inc_deg)
    return kg2Mearth(K_ms * (P*Ms*Ms/(2*np.pi*G))**(1./3) * \
                     unumpy.sqrt(1-ecc**2)/unumpy.sin(inc))
def test_uncertainties_std(x=X):
    return unumpy.sin(x)