Exemplo n.º 1
0
def rel_coord(s0, s1):
    s00 = list(s0)
    s10 = list(s1)
    s00[1] = d2r(s00[1])
    s00[2] = d2r(s00[2])
    s10[1] = d2r(s10[1])
    s10[2] = d2r(s10[2])

    # print('S00_rad:',s00)
    # print('S10_rad:',s10,'\n')

    c0 = conv.sphe_to_cart(s00[0], s00[1], s00[2])
    c1 = conv.sphe_to_cart(s10[0], s10[1], s10[2])

    # print('c0:',c0)
    # print('c1:',c1,'\n')

    c_rel = []
    for i in range(3):
        c_rel.append(c1[i] - c0[i])

    # print('C_Rel:',c_rel,'\n')

    s_rel = conv.cart_to_sphe(c_rel[0], c_rel[1], c_rel[2])
    s_rel1 = s_rel[0], r2d(s_rel[1]), r2d(s_rel[2])

    # print('S_Rel_rad:',s_rel,'\n')
    # print('S_Rel_deg:',s_rel1,'\n')

    return s_rel1
Exemplo n.º 2
0
def conv(az1, el1, az2, el2):
    from numpy import deg2rad as d2r
    from numpy import rad2deg as r2d
    conv_ang = r2d(
        np.arccos(
            np.sin(d2r(el1)) * np.sin(d2r(el2)) +
            np.cos(d2r(el1)) * np.cos(d2r(el2)) * np.cos(d2r(az1 - az2))))
    return conv_ang
Exemplo n.º 3
0
 def alpha(self, jme):
     alpha = (180.0 / pi)*arctan2((sin(d2r(self.lambda_sun_long(jme)))*cos(d2r(self.epsilon(jme))) \
         - tan(d2r(self.beta_gc_lat(jme)))*sin(d2r(self.epsilon(jme)))) / cos(d2r(self.lambda_sun_long(jme))), 1.0)
     if alpha > 0.0:
         return alpha % 360.0
     elif alpha < 0.0:
         return 360.0 - alpha % 360.0
     return 0.0
Exemplo n.º 4
0
    def gamma_topo_azimuth(self, y, m, d, lat, lon, elev):
        delta_prime = self.delta_prime(y, m, d, lat, lon, elev)
        h_prime = self.h_prime(y, m, d, lat, lon, elev)

        gamma = (180 / pi) * arctan2(
            sin(h_prime) /
            (cos(h_prime) * sin(d2r(lat)) - tan(delta_prime) * cos(d2r(lat))),
            1.0)
        gamma = heaviside(gamma, 0.0) * (gamma % 360.0) + heaviside(
            -gamma, 0.0) * (360.0 - gamma % 360.0)
        return gamma
Exemplo n.º 5
0
    def incidence_angle(self,
                        omega,
                        gamma,
                        y,
                        m,
                        d,
                        lat,
                        lon,
                        elev,
                        pres=1013.25,
                        temp=20.0):
        theta = d2r(self.theta_topo_elev(y, m, d, lat, lon, elev, pres, temp))
        big_gamma = d2r(self.gamma_topo_azimuth(y, m, d, lat, lon, elev))

        return arccos(
            cos(theta) * cos(d2r(omega)) +
            sin(d2r(omega)) * sin(theta) * cos(big_gamma - d2r(gamma)))
Exemplo n.º 6
0
    def theta_topo_elev(self,
                        y,
                        m,
                        d,
                        lat,
                        lon,
                        elev,
                        pres=1013.25,
                        temp=20.0):
        # pressure in millibars
        # temperature in celcius
        delta_prime = self.delta_prime(y, m, d, lat, lon, elev)
        h_prime = self.h_prime(y, m, d, lat, lon, elev)

        e0 = (180 / pi) * arcsin(
            sin(d2r(lat)) * sin(delta_prime) +
            cos(d2r(lat)) * cos(delta_prime) * cos(h_prime))
        delta_e = (pres / 1010) * (283 / (273 + temp)) * (
            1.02 / 60.0 / tan(d2r(e0 + 10.3 / (e0 + 5.11))))

        return 90 - (e0 + delta_e)
Exemplo n.º 7
0
    def delta_prime(self, y, m, d, lat, lon, elev):
        jme = self.date_to_jme(y, m, d)
        xi = d2r(8.794 / (3600 * self.earth_hc_radius(jme)))
        u = arctan(0.99664719 * tan(d2r(lat)))
        x = cos(u) + (elev / 6378140) * cos(d2r(lat))
        y = 0.99664719 * sin(u) + (elev / 6378140) * sin(d2r(lat))
        H = d2r(self.h_hour_angle(self.jd(y, m, d), y, lon))

        delta_alpha = arctan2(
            -x * sin(xi) * sin(H) /
            (cos(d2r(self.delta(jme))) - x * sin(xi) * cos(H)), 1.0)
        #alpha_prime = d2r(self.alpha(jme)) + delta_alpha

        return arctan2(((sin(d2r(self.delta(jme))) - y*sin(xi))*cos(delta_alpha)) \
                            / (cos(d2r(self.delta(jme))) - x*sin(xi)*cos(H)), 1.0)
Exemplo n.º 8
0
def compute_source(ra, dec, lst, lat=13.602997, lon=77.427981):
    '''
    A fuction which computes unit source vector

    Input:
    ------
    ra  - The Right ascension of the object in degrees.
    dec - The declination of the object in degrees.
    lst - The local sidereal time in degrees.
    lat - The latitude of the place of observation.
    lon - The longitude of the place of observation.

    Default for lat and lon is the  coordinates of GBD terrace

    Output:
    ------
    Touple of the form (x,y,z) in NEU coordinates.

    '''
    ha = lst - ra
    if (ha > 360):
        ha = ha - 360
    if (ha < 0):
        ha = ha + 360

    sin_dec = sin(d2r(dec))
    sin_lat = sin(d2r(lat))
    cos_dec = cos(d2r(dec))
    cos_lat = cos(d2r(lat))
    cos_ha = cos(d2r(ha))
    sin_ha = sin(d2r(ha))
    sin_alt = sin_dec * sin_lat + cos_dec * cos_lat * cos_ha
    alt = np.rad2deg(np.arcsin(sin_alt))
    cos_alt = cos(d2r(alt))
    cosA = (sin_dec - sin_alt * sin_lat) / (cos_alt * cos_lat)
    A = np.rad2deg(np.arccos(cosA))
    if (sin_ha > 0):
        az = 360 - A
    else:
        az = A

    hor = [alt, az]
    x = cos(hor[0]) * cos(hor[1])
    y = cos(hor[0]) * sin(hor[1])
    z = sin(hor[0])
    return (x, y, z)
Exemplo n.º 9
0
def cls2hrz(ra,dec,lst,lat,lon):
    '''
	A fuction which converts celestial coordinates to horizontal coordinates.

	Input:
	------
	ra  - The Right ascension of the object.
    dec - The declination of the object.
    lst - The local sidereal time .
    lat - The latitude of the place of observation.
    lon - The longitude of the place of observation.

	Output:
	------
	Touple of form (altitude, azimuthal)

	'''
    ha=lst-ra
    ha=54.382617
    if(ha>360):
        ha=ha-360
        print("HA is ",ha)
    if(ha<0):
        ha=ha+360
        print("HA is ",ha)
    sin_dec= sin(d2r(dec))
    sin_lat= sin(d2r(lat))
    cos_dec= cos(d2r(dec))
    cos_lat= cos(d2r(lat))
    cos_ha = cos(d2r(ha))
    sin_ha = sin(d2r(ha))
    sin_alt= sin_dec*sin_lat+cos_dec*cos_lat*cos_ha
    alt = np.rad2deg(np.arcsin(sin_alt))
    cos_alt=cos(d2r(alt))
    cosA=(sin_dec-sin_alt*sin_lat)/(cos_alt*cos_lat)
    A=np.rad2deg(np.arccos(cosA))
    #print("A = ",A)
    if(sin_ha>0):
        az=360-A
    else:
        az=A
    #print("alt = ",alt)
    #print("az = ",az)
    return (alt,az)

def gracious_stop(t):
    ''' This function streches and in the end stops time.'''
    def f(t):
        if t <= 0.0:
            return 0.0
        return numpy.exp(-1.0 / t)

    def g(t):
        return f(t) / (f(t) + f(1.0 - t))

    return 2 * g(0.5 * t + 0.5) - 1


q_home = [0.0, d2r(-90), d2r(90), 0.0, d2r(90), 0.0]
home = kin.fk(q_home)

height = 0.1


class ptp:
    def __init__(self, T, pt_start, pt_stop):
        self.T = T
        self.set_start(pt_start)
        self.set_stop(pt_stop)

    def set_start(self, start):
        self.pt_start = numpy.array(start)

    def set_stop(self, stop):
Exemplo n.º 11
0
    gve = gve[idx, :]

    B = np.zeros((NgVec, 1))
    A = np.zeros((NgVec, 8))

    for i in range(NgVec):
        gs = La.norm(gve[i, :3]) - g_ideal
        g = np.abs(gs)
        midx = np.where(g == np.min(g))[0][0]
        val = np.min(g)
        B[i, 0] = -gs[midx] / g_ideal[midx]
    for i in range(NgVec):
        TOE = ThOmEt[~(ThOmEt == 0).all(1)]
        lmn = gve[i, :3] / La.norm(
            gve[i, :3])  # g-vector [Sample coordinate system!]
        dx_term = -( cos(d2r(TOE[i,1])) + (sin(d2r(TOE[i,1]))*sin(d2r(TOE[i,2]))\
                    /tan(d2r(TOE[i,0]))))/999654.8 # new parameter
        dy_term = -( sin(d2r(TOE[i,1])) + (cos(d2r(TOE[i,1]))*sin(d2r(TOE[i,2]))\
                   /tan(d2r(TOE[i,0]))))/999654.8 # new parameter from Ti_1516.par

        A[i, 0], A[i, 1], A[i, 2], A[
            i, 3] = lmn[0]**2, lmn[1]**2, lmn[2]**2, 2 * lmn[0] * lmn[1]
        A[i, 4], A[i, 5], A[i, 6], A[
            i,
            7] = 2 * lmn[0] * lmn[2], 2 * lmn[1] * lmn[2], -dx_term, -dy_term

    X = La.lstsq(A, B)[0]
    fit_error = B - np.dot(A, X)
    strn[igrain] = La.lstsq(A, B)[0]
    stddevs[igrain] = np.std(fit_error)
    idx = np.where(np.abs(fit_error) < 0.004)[0]
Exemplo n.º 12
0
def Summing(inc,deg,fix):
    X,L1,L2,o2  = inc
    q1,q2       = deg
    D,C         = fix
    
    f1 = X  - q2 - L1*cos(o2)
    f2 = C  - L1*sin(o2)
    f3 = q1 - X - L2*cos(o2)  
    f4 = D  - L2*sin(o2)
    
    
    return f1,f2,f3,f4

# Definição do grau de liberdade.
ANG  = d2r(np.r_[0:360:360j])
Q1   = 2*(sin(ANG) + 1)
Q2   = 2*(sin(ANG+pi/12) + 1)

# Definição de valores conhecidos. (D,C)
C = 0.15,0.08

# Estimativas iniciais. (B,o2)
x0  = 0.2,0.2,0.2,d2r(150)

# Definição do passo, para uma rotação de 1 passo.
w1  = 1.
h   = np.abs(ANG[0]-ANG[1])/w1

mec = Mechanism(Summing,[Q1,Q2],C,h,2)
Exemplo n.º 13
0
def Quick(inc, deg, fix):
    o3, X, L1, L2 = inc
    q1 = deg
    R, C, D = fix

    f1 = R * cos(q1) - L1 * cos(o3)
    f2 = R * sin(q1) - L1 * sin(o3) + C
    f3 = X - L2 * cos(o3)
    f4 = D - L2 * sin(o3)

    return f1, f2, f3, f4


# Definição do grau de liberdade.
Q1 = d2r(np.r_[0:360:360j])

# Definição de valores conhecidos.
R, C, D = 0.085, 0.4, 0.75

# Estimativas iniciais.
x0 = d2r(45), 0.4, 0.4, 0.4

# Definição do passo, para uma rotação de 1 passo.
w1 = 1.
h = np.abs(Q1[0] - Q1[1]) / w1

mec = Mechanism(Quick, Q1, [R, C, D], h)

mec.kinematics_solve(x0)
Exemplo n.º 14
0
from numpy import deg2rad as d2r


def Sliding_Four_bar(inc,deg,fix):
    B,o2        = inc
    q1,q2       = deg
    C1,C2,C3    = fix
    
    f1 = C1*cos(q1) + B*cos(o2) - C2*cos(q2) - C3
    f2 = C1*sin(q1) + B*sin(o2) - C2*sin(q2)
    
    
    return f1,f2

# Definição do grau de liberdade.
Q1  = d2r(np.r_[0:360:360j])
Q2  = d2r(np.r_[0:360:360j]*2)

# Definição de valores conhecidos. (C1,C2,C3)
C = 1.5,3,4

# Estimativas iniciais. (B,o2)
x0  = 2.,d2r([30])

# Definição do passo, para uma rotação de 1 passo.
w1  = 1.
h   = np.abs(Q1[0]-Q1[1])/w1

mec = Mechanism(Sliding_Four_bar,[Q1,Q2],C,h,2)

mec.kinematics_solve(x0)
Exemplo n.º 15
0
 def v(self, jd, year=2022):
     jde = self.jde(jd, self.deltaT(year))
     return self.v0(jd) + self.delta_psi(self.jce(jde)) * cos(
         d2r(self.epsilon(self.jme(self.jce(jde)))))
Exemplo n.º 16
0
def StressStrain(GvecTable, PeakData, UDict, a, c):

    CC = GHCP.GHCP(a, c)

    Dict_hkl = CC.DictInitialize()

    g0Cry, g_idel = CC.GHKL(Dict_hkl)


    T1twin=np.array([[0.5860,0.3380,0.7370,-0.6380,-0.3680,0.6760],\
                   [0.,0.6760,0.7370,0.,-0.7370,0.6760],\
                   [-0.5860,0.3380,0.7370,0.6380,-0.3680,0.6760],\
                   [-0.5860,-0.3380,0.7370,0.6380,0.3680,0.6760],\
                   [0.,-0.6760,0.7370,0.,0.7370,0.6760],\
                   [0.5860,-0.3380,0.7370,-0.6380,0.3680,0.6760]])

    g_ideal = g_idel
    grainNo = [x + 1 for x in range(len(UDict))]
    igrain = 0

    ThOmEt = np.zeros(
        (100, 3)
    )  #Initialize Array to hold Bragg(theta),Rotation(omega) & Azimuthal (Eta) angle values
    hklS = np.zeros((100, 3))  #Initialize Array to hold hkl values
    strn = {}
    stddevs = {}

    igrain = 0
    for ig in range(len(grainNo)):

        igrain += 1
        NgVec = len(GvecTable[ig + 1][:, 0])
        gveID = np.zeros((NgVec, ))
        count = 0

        for i in range(NgVec):
            if GvecTable[ig + 1][i, -1] < 2.0:  # Threshold for internal angle
                count += 1
                gveID[i] = np.where(PeakData[:,
                                             8] == GvecTable[ig + 1][i,
                                                                     2])[0][0]
                ThOmEt[count, 0] = GvecTable[ig + 1][i, 12]
                ThOmEt[count, 1] = GvecTable[ig + 1][i, 15]
                ThOmEt[count, 2] = GvecTable[ig + 1][i, 18]
                hklS[count, :] = GvecTable[ig + 1][i, 3:6]
        NgVec = count
        gveID = gveID[~(gveID == 0)]
        gve=np.concatenate((PeakData[gveID.astype(int),:3],\
                          PeakData[gveID.astype(int),5].reshape(len(gveID),1)),axis=1)

        ## Check to ensure that there are no existing Freidel pairs
        FriedelPairs = np.zeros((NgVec, 1))
        for i in range(NgVec):
            for j in range(NgVec):
                ThklS = hklS[~(hklS == 0).all(1)]
                if i != j:
                    if (hklS[i, :3] == -hklS[j, :3]).all():
                        FriedelPairs[i] = 1
                        FriedelPairs[j] = 1
        OutSide = np.zeros((NgVec, 1))
        for i in range(NgVec):
            if La.norm(gve[i, :3]) > 0.92 and La.norm(gve[i, :3]) < 0.95:
                OutSide[i] = 1
            else:
                OutSide[i] = 0

        idx = np.where(OutSide != 1)[0]
        NgVec = len(idx)
        gve = gve[idx, :]

        B = np.zeros((NgVec, 1))
        A = np.zeros((NgVec, 8))

        for i in range(NgVec):
            gs = La.norm(gve[i, :3]) - g_ideal
            g = np.abs(gs)
            midx = np.where(g == np.min(g))[0][0]
            val = np.min(g)
            B[i, 0] = -gs[midx] / g_ideal[midx]
        for i in range(NgVec):
            TOE = ThOmEt[~(ThOmEt == 0).all(1)]
            lmn = gve[i, :3] / La.norm(
                gve[i, :3])  # g-vector [Sample coordinate system!]
            dx_term = -( cos(d2r(TOE[i,1])) + (sin(d2r(TOE[i,1]))*sin(d2r(TOE[i,2]))\
                      /tan(d2r(TOE[i,0]))))/999654.8 # new parameter
            dy_term = -( sin(d2r(TOE[i,1])) + (cos(d2r(TOE[i,1]))*sin(d2r(TOE[i,2]))\
                     /tan(d2r(TOE[i,0]))))/999654.8 # new parameter from Ti_1516.par

            A[i, 0], A[i, 1], A[i, 2], A[
                i, 3] = lmn[0]**2, lmn[1]**2, lmn[2]**2, 2 * lmn[0] * lmn[1]
            A[i, 4], A[i, 5], A[i, 6], A[i, 7] = 2 * lmn[0] * lmn[2], 2 * lmn[
                1] * lmn[2], -dx_term, -dy_term

        X = La.lstsq(A, B)[0]
        fit_error = B - np.dot(A, X)
        strn[igrain] = La.lstsq(A, B)[0]
        stddevs[igrain] = np.std(fit_error)
        idx = np.where(np.abs(fit_error) < 0.004)[0]
        A1 = A[idx, :]
        B1 = B[idx]
        strn[igrain] = La.lstsq(A1, B1)[0]
        stddevs[igrain] = np.std(B1 - np.dot(A1, strn[igrain]))

    Rowstrn = {
    }  # Initialize Dictionary to store 6 components of elastic strain tensor and Center of mass for each grain!
    Strain = {
    }  #  Initialize Dictionary to store symmetric (9 comp) strain tensor for each grain identified![Smp Coord Sys]
    Strain_c = {}  # Initialize Dictionary to store strain in XTal Coord system
    Stress_c = {}
    Stress_Smp = {}
    for i in range(1, igrain + 1):
        Rowstrn[i] = strn[i].T
        Strain[i]=np.array([[strn[i][0,0],strn[i][3,0],strn[i][4,0]],\
                          [strn[i][3,0],strn[i][1,0],strn[i][5,0]],\
                          [strn[i][4,0],strn[i][5,0],strn[i][2,0]]])
        # Rotate Orientation Matrix by 90 degress
        UDict[i] = np.dot(
            UDict[i], np.array([[0., -1., 0.], [1., 0., 0.], [0., 0., 1.]]))
        # Rotate Strain Tensor to XTal Coordinate system
        Strain_c[i] = np.dot(UDict[i].T, Strain[i])
        Strain_c[i] = np.dot(Strain_c[i], UDict[i])
        # Stiffness Tensor
        C=np.array([[162.4e3,92.0e3,69.0e3,0.,0.,0.],\
                 [92.0e3,162.2e3,69.0e3,0.,0.,0.],\
                  [69.0e3,69.0e3,181.6e3,0.,0.,0.],\
                  [0.,0.,0.,47.2e3,0.,0.],\
                  [0.,0.,0.,0.,47.2e3,0.],\
                  [0.,0.,0.,0.,0.,35.2e3]])
        strain_c_vec=np.array([Strain_c[i][0,0],Strain_c[i][1,1],Strain_c[i][2,2],\
                             Strain_c[i][1,2]*2.0,Strain_c[i][2,0]*2,Strain_c[i][0,1]*2.0]).reshape(6,1)
        # Use generalized Hooke's Law to Evaluate Stress Tensor in XTal Coordinate System
        Stress_c_vec = np.dot(C, strain_c_vec)
        Stress_c[i]=np.array([[Stress_c_vec[0],Stress_c_vec[5],Stress_c_vec[4]],\
                            [Stress_c_vec[5],Stress_c_vec[1],Stress_c_vec[3]],\
                            [Stress_c_vec[4],Stress_c_vec[3],Stress_c_vec[2]]]).reshape(3,3)

        ## Transform Stress Tensor to Sample Coordinate System
        Stress_Smp[i] = np.dot(UDict[i], Stress_c[i])
        Stress_Smp[i] = np.dot(Stress_Smp[i], UDict[i].T)
    return Rowstrn, Strain, Strain_c, Stress_Smp, Stress_c
Exemplo n.º 17
0
 def delta(self, jme):
     return (180.0/pi)*arcsin(sin(d2r(self.beta_gc_lat(jme)))*cos(d2r(self.epsilon(jme))) \
         + cos(d2r(self.beta_gc_lat(jme)))*sin(d2r(self.epsilon(jme)))*sin(d2r(self.lambda_sun_long(jme))))