def angles(self):
        diff = self.points[0].means - self.points[3].means
        #diff=[x0-x1,y0-y1]
        a1 = unp.arctan(diff[1] / diff[0])
        diff = self.points[1].means - self.points[2].means
        a2 = unp.arctan(diff[1] / diff[0])

        print("\n{} {}\n".format(a1, a2))
        return np.array([a1, a2])
Example #2
0
    def pitch_angle(self, y=1, halo='hernquist', relation='michikoshi'):
        Gamma = self.total_shear(y, halo)
        #tanpsi = 1.932 - 5.186*(0.5*Gamma) + 4.704*(0.5*Gamma)**2
        if relation == 'michikoshi':
            tanpsi = 2 / 7 * unp.sqrt(4 - 2 * Gamma) / Gamma
            self.psi = unp.arctan(tanpsi) * 360 / (2 * math.pi)
        elif relation == 'fuchs':
            tanpsi = 1.932 - 5.186 * (0.5 * Gamma) + 4.704 * (0.5 * Gamma)**2
            self.psi = unp.arctan(tanpsi) * 360 / (2 * math.pi)
        elif relation == 'seigar':
            m = uf(-36.62, 2.77)
            c = uf(64.25, 2.87)
            self.psi = m * Gamma + c

        return self.psi
Example #3
0
def theta(theta_cm, n):
    """
    function to convert θ in the center-of-mass system to θ in the lab system

    Arguments
    ---------
    theta_cm : scattering angle in the center-of-mass system [rad]
    n        : A_t / A_i; A_t, A_i means mass number of target particle or incident particle

    Return
    ------
    theta_lab : scattering angle in the lab system [rad]

    Notice
    ------
    This function does not consider relativity
    """
    if isinstance(theta_cm, uncertainties.core.AffineScalarFunc):
        return umath.arctan(
            umath.sin(theta_cm) / (1.0 / n + umath.cos(theta_cm)))
    elif isinstance(theta_cm, np.ndarray) and isinstance(
            theta_cm[0], uncertainties.core.AffineScalarFunc):
        return unp.arctan(unp.sin(theta_cm) / (1.0 / n + unp.cos(theta_cm)))
    else:
        return np.arctan(np.sin(theta_cm) / (1.0 / n + np.cos(theta_cm)))
Example #4
0
 def burkert_mass_22(self):
     a_h = self.R_halo()[0]
     rho0 = self.burkert_rho0()
     R22 = 2.2 * self.baryonic_scalelength()
     a = 2 * math.pi * rho0 * a_h**3
     b = (unp.log((R22 + a_h) / a_h) + 0.5 * unp.log(
         (R22**2 + a_h**2) / a_h**2) - unp.arctan(R22 / a_h))
     self.M_burkert_22 = a * b
     return self.M_burkert_22
Example #5
0
    def total_shear(self, y=1, halo='hernquist'):
        r = 2 * y * self.baryonic_scalelength()

        a_b = self.R_bulge
        M_b = self.M_bulge
        kappa2_b = M_b * (4 / (r * (r + a_b)**2) - (3 * r + a_b) /
                          (r * (r + a_b)**3))
        omega2_b = M_b * (1 / (r * (r + a_b)**2))

        R_d = self.R_disc
        M_d = self.M_disc
        C = M_d / (2 * R_d)
        kappa2_d = C * ((r / (4 * R_d) *
                         (3 * I(1, y) * K(0, y) - 3 * I(0, y) * K(1, y) +
                          I(1, y) * K(2, y) - I(2, y) * K(1, y))) + 4 *
                        (I(0, y) * K(0, y) - I(1, y) * K(1, y)))

        omega2_d = C * (I(0, y) * K(0, y) - I(1, y) * K(1, y))

        if halo == 'hernquist':
            a_h = self.R_halo()[0]
            M_h = self.M_halo_hernquist()
            kappa2_h = M_h * (4 / (r * (r + a_h)**2) - (3 * r + a_h) /
                              (r * (r + a_h)**3))
            omega2_h = M_h * (1 / (r * (r + a_h)**2))

        else:
            a_h = self.R_halo()[0]
            rho0 = self.burkert_rho0()
            C = 2 * math.pi * rho0 * a_h**3
            kappa2_h = (C / r**3) * (r**2 / (r**2 + a_h**2) - r / (a_h * (
                (r / a_h)**2 + 1)) + r / (r + a_h) + unp.log(
                    (r + a_h) / a_h) + (1 / 2) * unp.log(
                        (r**2 + a_h**2) / a_h**2) - unp.arctan(r / a_h))
            omega2_h = (C / r**3) * (unp.log(
                (r + a_h) / a_h) + (1 / 2) * unp.log(
                    (r**2 + a_h**2) / a_h**2) - unp.arctan(r / a_h))

        omega2 = omega2_b + omega2_d + omega2_h
        kappa2 = kappa2_b + kappa2_d + kappa2_h

        self.Gamma = 2 - kappa2 / (2 * omega2)
        return self.Gamma
Example #6
0
    def burkert_rho0(self):
        exists = 'rho0' in self.__dict__
        if exists is False:
            a_h, r200 = self.R_halo()
            M_h = self.M_halo()

            self.rho0 = (M_h / ((2 * np.pi * a_h**3) * (unp.log(
                (r200 + a_h) / a_h) + 0.5 * unp.log(
                    (r200**2 + a_h**2) / a_h**2) - unp.arctan(r200 / a_h))))

        return self.rho0
def wellenlaenge(d_array, mitte, L):
    d_links = unp.uarray(np.zeros(mitte), np.zeros(mitte))
    d_rechts = unp.uarray(np.zeros(12-mitte), np.zeros(12-mitte))
    for i in range(0, mitte, 1):
        d_links[i] = np.sum(d_array[mitte-(i+1):mitte])
    for i in range(0, 12-mitte, 1):
        d_rechts[i] = np.sum(d_array[mitte:mitte+(i+1)])
    g = (10**-3)/80
    print('g = ', g*10**6, 'micro meter')
    d_links = d_links*10**-2
    d_rechts = d_rechts*10**-2
    d_all = np.concatenate((noms(d_links), noms(d_rechts)))
    n_links = np.linspace(1, 6, 6)
    lamda_links = g * unp.sin(unp.arctan(d_links/L))/n_links
    n_rechts = range(1, len(d_rechts)+1, 1)
    n_all = np.concatenate((n_links, n_rechts))
    lamda_rechts = g * unp.sin(unp.arctan(d_rechts/L))/n_rechts
    lamda_all = np.concatenate((lamda_links, lamda_rechts))
    werteZuTabelle(d_all*100, n_all.astype(int), (noms(lamda_all)*10**9).astype(int), (stds(lamda_all)*10**9).astype(int), rundungen=[3, 0, 0, 0])
    print('lambda = ', (np.sum(lamda_all))/12)
    print('Abweichung = ', abweichungen(632.8*10**-9, (np.sum(lamda_all))/12))
    print('Mittelwert = ', np.mean(noms(lamda_all)), '±', np.std(noms(lamda_all)))
Example #8
0
    def burkert_arm_number(self, y=1, X=1.5):
        M_d = self.M_disc + self.M_hi
        R_d = self.baryonic_scalelength()
        rho0 = self.burkert_rho0()
        a_h = self.R_halo()[0]
        a = unp.exp(2 * y) / X
        R = y * 2 * R_d
        c = (2 * np.pi * rho0 * R**3 / M_d) * (1 / (4 * y**2)) * (
            (R**2 / (R**2 + a_h**2)) + (R / (a_h * (R**2 / a_h**2 + 1))) +
            unp.log(1 + R / a_h) + unp.log(1 +
                                           (R / a_h)**2) - unp.arctan(R / a_h))

        self.m_burkert = a * c
        return self.m_burkert
plt.plot(x_plot,
         g2(x_plot, *params),
         'k-',
         label='Anpassungsfunktion',
         linewidth=0.5)
print(params)
print(np.sqrt(np.diag(covariance_matrix)))
plt.gcf().subplots_adjust(bottom=0.18)
plt.plot(L, I, 'r.', label='Messwerte', Markersize=4)
plt.legend()
plt.grid()
plt.xlim((-16, 26))
plt.ylabel(r'$I / \mathrm{\mu A}$')
plt.xlabel('$x$ / mm')
plt.savefig('build/erstemode.pdf')
plt.clf()

print('----------------------------------------------------')
print('Wellenlaenge:')
dr = ufloat(7.2, 0.1)
dl = ufloat(7.1, 0.1)
L = ufloat(143.8, 0.1)
dg = (1 / 80) * 10**(-3)

d = np.mean([dr, dl])
print('Mittelwert:', d)
print('Gitterkonstante:', dg)
lam = dg * unp.sin(unp.arctan(d / L))
print('Wellenlaenge:', lam)
print('relative Abweichung:', 1 - lam / (633 * 10**(-9)))
Example #10
0
plt.errorbar(U_GM, N_GM, yerr, fmt='kx')
x_plot = np.linspace(350, 670, 1000)
plt.plot(x_plot ,par[0]*x_plot+par[1], 'b-', label="Lineare Regression des Plateaus")
plt.xlabel(r'Spannung$\;U\;[V]$')
plt.ylabel(r'Impulse$\;N\;$[s$^{-1}$]')
plt.legend(loc="best")
plt.grid()
plt.tight_layout
plt.savefig('build/plotGM.pdf')
plt.close()

m_GM = ufloat(par[0], err[0])
b_GM = ufloat(par[1], err[1])

m_winkel = unp.arctan(m_GM/100)
m_percent = (m_winkel*180)/np.pi

print(m_percent)

# tex file for m_GM

with open('build/m_GM.tex', 'w') as f:
  f.write(make_SI(m_GM,r'\percent\per{100}\volt', figures=1))

# tex file for b_GM

with open('build/b_GM.tex', 'w') as f:
  f.write(make_SI(b_GM,r'\per\second', figures=1))

# tex file for m_percent
Example #11
0
File: cd.py Project: Fujnky/ap
def t3(f, a, b, c, f0):
    # omega = 2 * np.pi * (f-f0)
    # return a * np.arctan((- omega*R*C)/(1-L*C*omega**2)) + b
    return a * unp.arctan(b * (f - f0)) + c
Example #12
0
def t3(f, a, b, c, f0):
    #omega = 2 * np.pi * (f-f0)
    #return a * np.arctan((- omega*R*C)/(1-L*C*omega**2)) + b
    return a * unp.arctan(b * (f - f0)) + c
Example #13
0
f, a = np.genfromtxt('data/phasenverschiebung.txt',
                     unpack=True)  # f in Hz, a in µs
a *= 1e-6  # a in s
phi = a * f * 360
phi = phi / 360 * 2 * np.pi
f *= 1e-3  # f in khZ

np.savetxt('data/berechnetephi.txt', phi, delimiter='\t', fmt='%1.2f')

flinspace2 = np.linspace(0.007, 300, 10000)

plt.plot(f, phi, 'rx', label='Messwerte')
plt.plot(flinspace2,
         np.pi / 2 + unp.nominal_values(
             unp.arctan(
                 (-2 * np.pi * flinspace2 * 1e3 * (R2 + 50) * C /
                  (1 - L * C * (2 * np.pi * flinspace2 * 1e3)**2))**(-1))),
         'k-',
         label='Theoriekurve')
plt.xscale('log')
plt.xlabel(r'$f/$kHz')
plt.ylabel(r'$\phi/$rad')
plt.axis((0.007, 300, -0.2, 4))  # 1e-3 weil f in kHZ ist
# Slicing: -3 ist drittletztes Element, : bedeutet bis zum Ende
plt.plot(f[-3:],
         phi[-3:],
         'ob',
         markersize=8,
         markeredgewidth=1,
         markerfacecolor='None')  # Sorgt für Markierung dr Außreißer
Example #14
0
z_0 = ufloat(9.0e-3, 0.2e-3)

usigma_x = unp.uarray(xsigma, xsigma_error)
usigma_y = unp.uarray(ysigma, ysigma_error)

xerror = 1e-3 * np.ones(len(xsigma)) * 0.05

a = 1
b = 1

usigma_x = usigma_x**2 * a
usigma_y = usigma_y**2 * a

uheight = unp.uarray(heigh_m, xerror) * b

alpha = unp.arctan((usigma_x - omega_0) / (uheight - z_0))

x = 150e-6

d_1 = x * unp.tan(unp.arcsin(1 / 3.551))

print(d_1)

usigma_x -= 2 * unp.sqrt(d_1**2)

print(usigma_x)
#print(alpha,uheight)

################## Plot and Fit with ROOT ############################

root.gStyle.SetLabelSize(.055, "XY")
Example #15
0
def lamb(l, L, g, n):
    return (g * unp.sin(unp.arctan(l / L))) / n
Example #16
0
deltax =(dx-dxtheo)/dxtheo*100
print('prozentuelle Abweichung', deltax, '%')
#-----------------------------------------------------------------

#Differentieller Streuquerschnitt--------------------------------------------

theta, c, t = np.genfromtxt('wirkung.txt', unpack=True)
theta = (2*np.pi)/360 *theta
cpros = c/t
errorc =np.sqrt(c)/t
cpros = unp.uarray(cpros, errorc)

x= 2*10**(-3)
y= 10*10**(-3)
L = 4.1*10**(-2)
dOmega = 4* unp.arctan((x)/(2*L)) * unp.arctan(y/(2*L))
print('dOmega =', dOmega)

#zhe= 3.204 * 10**(-19) # =2*e
print('c pro s:', cpros)
Na = 6.022*10*(23)
d = 2* 10**(-6)
G = 2*10**(-5)
Vol = 10.21*10**(-6)
Aktheo = 317.56*10**3
#print('Fehler:', errorc)
dsigmadomega2 = 1/((4*np.pi*const.epsilon_0)**2) * ((Zhe* Zau * const.e**2)/(4*Ealpha))**2 * 1/(np.sin(theta/2))**4


cproszwei = 5.320
errorcproszwei = 0.040
Example #17
0
def XYfun(a):
    return a[0], unumpy.sin(pi / 2 - unumpy.arctan((a[1] - zero) / D))
Example #18
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)
Example #19
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))
Example #20
0
    print(a1, b1)
    print(a2, b2)
    # print(a3, b3)

    with open('build/fitresults.tex', 'w') as f:
        lines = [
            r'\begin{align}',
            r'm_1 &= \num{{{:0.3f} +- {:0.3f}}} & b_1 &= \SI{{{:0.3f} +- {:0.3f}}}{{\nano\meter}} \\'.format(a1.n, a1.s, b1.n, b1.s),
            r'm_2 &= \num{{{:0.3f} +- {:0.3f}}} & b_2 &= \SI{{{:0.3f} +- {:0.3f}}}{{\nano\meter}}'.format(a2.n, a2.s, b2.n, b2.s),
            r'\end{align}',
        ]
        f.write('\n'.join(lines) + '\n')

    a = (a1 + a2) / 2

    delta_h = unp.cos(unp.arctan(a)) * (b1 - b2)
    print(delta_h)
    with open('build/height.tex', 'w') as f:
        f.write(r'\SI{{{:.1f} +- {:.1f}}}{{\pico\meter}}'.format(
            delta_h.n * 1000, delta_h.s * 1000)
        )
        f.write('\n')


    grid_constant_gold = 407.82
    step_factor =  np.sqrt(3)*delta_h*1000/grid_constant_gold
    print(step_factor)
    with open('build/step_factor.tex', 'w') as f:
        f.write(r'\num{{{:.1f} +- {:.1f}}}'.format(
            step_factor.n, step_factor.s)
        )
#Mit diesem Skript lassen sich aus eingelesenen Miller Indizes die zugehörigen Gitterabstände,
#Glanzwinkel und Wellenlängen bestimmen.

from fractions import Fraction
import numpy as np
from numpy import genfromtxt
import uncertainties.unumpy as unp
from uncertainties import ufloat

dataMiller = genfromtxt('LaueIndices.txt', delimiter=';')
h = np.array(dataMiller[1:, 0], dtype='int')
k = np.array(dataMiller[1:, 1], dtype='int')
l = np.array(dataMiller[1:, 2], dtype='int')

dataKoord = genfromtxt('Koord.txt', delimiter=';')
x = unp.uarray(dataKoord[1:, 3],dataKoord[1:, 4])
y = unp.uarray(dataKoord[1:, 5],dataKoord[1:, 6])
z = unp.uarray(dataKoord[1:, 7],dataKoord[1:, 8])

a=564.02e-12 #Gitterkonstante https://de.wikipedia.org/wiki/Natriumchlorid

d = a/(unp.sqrt(h**2+k**2+l**2))
teta = unp.arctan(l/unp.sqrt(h**2+k**2))
tetaKoord = unp.arctan(z/unp.sqrt(x**2+y**2))
lamda = 2*d*unp.sin(teta)

print('Abstand d / pm; $\\teta / ^\circ$; $\lambda$ / pm')
for i in range(0,8):
    print('%.3f'%(d[i]*1e12),180/np.pi*teta[i],lamda[i]*1e12, tetaKoord[i])
Example #22
0
#+-0.1cm/s
# 3*10^-5 * v/(cm/s)
# fehler für v berechnen
def FehlerV(v):
    return np.sqrt(0.01+(3*10**(-5)*v*v)**2)


for i in range(len(Data1)):
    d.append(ufloat(Data1[i],deltaD))
    v1.append(ufloat(Data2[i], FehlerV(Data2[i])))
    v2.append(ufloat(Data3[i], FehlerV(Data3[i])))
    #v2prime.append(ufloat(Data1[i], FehlerV(Data1[i])))
    #v1prime.append(ufloat(Data1[i], FehlerV(Data1[i])))

#Berechnung des Neigungswinkels
alpha = unumpy.arctan(h/s)
#Berechnung von g
aneu=0
gneu=[]
G=0
A=0
for i in range(len(Data1)-1):
    a=(v2[i]**2-v1[i]**2)/(2*d[i])
    g.append(a/unumpy.sin(alpha)/100)
    aneu = ((0.99*v2[i]) ** 2 - (0.99*v1[i]) ** 2) / (2 * d[i])
    gneu.append(aneu / unumpy.sin(alpha) / 100)
    #print('{:.1u}'.format(a))
    #print('{:.1u}'.format(aneu))
    A += aneu
    print('{:.1u}'.format(d[i]))
Example #23
0
def Wellenlange(a, n, d, L):
    return a / n * unp.sin(unp.arctan(d / L))
Example #24
0
             yerr=stds(N_miterr),
             fmt='kx',
             label='Messwerte mit Fehler')
x_plot = np.linspace(350, 680, 10000)
plt.plot(x_plot, par[0] * x_plot + par[1], 'r-', label='Fitkurve')
plt.legend(loc="best")
plt.xlabel(r'Spannung $U \:/\:V$')
plt.ylabel(r'Intensität $I\:/\:Imp/60s$')
plt.grid()
plt.tight_layout
plt.savefig('build/plot_kenn.pdf')
plt.close()

par_kenn = unp.uarray(par / 60, err / 60)

m_winkel = unp.arctan(par_kenn[0] / 100)
m_percent = (m_winkel * 180) / np.pi

# Plot zu Z #################################################################

N_Z = np.array([9837, 9995, 10264, 10151, 10184, 10253, 10493, 11547])
N_Z_miterr = unp.uarray(N_Z, np.sqrt(N_Z))
Z = I_miterr / (const.e * N_Z_miterr)

par, cov = np.polyfit(noms(I_miterr), noms(Z), deg=1, cov=True)
err = np.sqrt(np.diag(cov))

plt.errorbar(noms(I_miterr),
             noms(Z),
             xerr=(stds(I_miterr)),
             yerr=stds(Z),
Example #25
0
def lam(x, n=1, s=s, d=d):
    alpha = unp.arctan(x/d)
    return s / n * unp.sin(alpha)
Example #26
0
C = ufloat(2.098 * 10**(-9), 0.006 * 10**(-9))
R2 = ufloat(559.5, 0.5)
q = ufloat(3.99, 0.01)
k = np.linspace(1000, 65000, 100)

print(unp.sqrt(1 / (L * C) - R2**2 / (2 * L**2)) / (2 * np.pi))
print(34000 / (unp.sqrt(1 / (L * C) - R2**2 / (2 * L**2)) / (2 * np.pi)))
print('------------')
print(1 / (unp.sqrt(L * C) * q * 2 * np.pi))
print(7500 / (1 / (unp.sqrt(L * C) * q * 2 * np.pi)))
print(unp.sqrt(L * C) / (R2 * C))

plt.gcf().subplots_adjust(bottom=0.18)
plt.plot(k,
         unp.nominal_values(
             unp.arctan((1 - L * C * (2 * np.pi * k)**2) /
                        (-k * 2 * np.pi * R2 * C))) + np.pi / 2,
         'k-',
         label='Theoriekurve',
         linewidth=0.5)
plt.plot(f, phi, 'r.', label='Messwerte', Markersize=4)
plt.yticks(
    [0, np.pi / 4, np.pi / 2, (np.pi * 3) / 4, np.pi],
    [0, r'$\frac{\pi}{4}$', r'$\frac{\pi}{2}$', r'$\frac{3\pi}{4}$', r'$\pi$'])
plt.title('Phasenverschiebung der Spannungen (halblogarithmisch)')
plt.legend()
plt.xscale('log')
plt.grid()
plt.xlim((3 * 10**3, 6.5 * 10**4))
plt.xlabel('$f$ / Hz')
plt.ylabel(r'$\varphi$ / rad')
plt.savefig('build/plot3.pdf')
Example #27
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)
def Lambda(d, L, n, g):
    return (sin(arctan(d / L))) / (abs(n) * g)