Ejemplo n.º 1
0
 def _get_bs_angles(ket1):
     """ get theta and phi involved in the Bloch Sphere representation
     """
     assert (len(ket1) == 2), "should be a 2 elements array"
     assert OneQbit.is_unit_norm(ket1), "should be a unit norm vector"
     theta = 2 * np.arcos(np.abs(ket1[0]))
     phi = np.angle(ket1[1]) - np.angle(ket1[0])
     return theta, phi
Ejemplo n.º 2
0
def angle3d(v1, v2):

    if np.linalg.norm(v1) == 0.0 or np.linalg.norm(v2) == 0.0:
        print(
            "Requested angle between vectors of length 0, which is impossible. Exiting."
        )
        exit(1)
    angle = np.arcos(np.dot(uvec(v1), uvec(v2)))
    return angle
Ejemplo n.º 3
0
 def _calc_with_cos(self):
     # the dihedral between 2 planes is angle between the unit normal vectors
     # cross(a, b) == cross(-a, -b) == -cross(b, a) == -cross(-b, -a)
     self.n123 = np.cross(self.r12.r, self.r23.r)
     self.n234 = np.cross(self.r23.r, self.r34.r)
     n123 /= np.linalg.norm(n123)
     n234 /= np.linalg.norm(n234)
     self.cos = np.dot(n123, n234)
     self.phi = np.arcos(self.cos)
     return self.phi
Ejemplo n.º 4
0
def get_v12_sp3(cs): # sp3 O
    assert len(cs)==2
    c0 = cs[0]
    vs = [(ci-c0)/np.linalg.norm(ci-c0) for ci in cs[1:] ]
    _v1 = -(vs[0]+vs[1])
    _v2 = np.cross(vs[0],vs[1])
    v1,v2 = [ v/np.linalg.norm(v) for v in [_v1,_v2] ]
    c12 = np.dot(vs[0],vs[1])/np.product(np.linalg.norm(vs,axis=1)) # cos(vs[0],vs[1])
    theta = np.arcos(c12)
    cos1, sin1 = np.cos(theta/2.), np.sin(theta/2.)
    v1u = cos1*v1 + sin1*v2
    v2u = cos1*v1 - sin1*v2
    return v1u,v2u
Ejemplo n.º 5
0
    def __convert_xyz_box_to_abc_box(self) -> None:
        """
        Convert xyz simulation box to abc simulation box

        Returns
        -------
        None

        """

        self._a = self._lx

        self._b = np.hypot(self._ly, self._xy)

        self._c = np.sqrt(self._ly**2 + self._xz**2 + self._yz**2)

        self._alpha = np.arccos(
            (self._xy * self._xz + self._ly * self._yz) / (self._b * self._c))

        self._beta = np.arcos(self._xz / self._c)

        self._gamma = np.arcos(self._xy / self._b)
Ejemplo n.º 6
0
def ComputeTrajectory(V0, Gamma0=None):
    Lambda = (r0 * np.power(V0, 2)) / EarthGravCTE

    if Gamma0 == None:
        Gamma0 = 1 / 2 * np.arcos(Lambda / (2 - Lambda))

    ThetaValues = np.linspace(start=0, stop=2 * np.pi, num=250, dtype='double')
    RhoValues = (r0 * Lambda * np.power(np.cos(Gamma0), 2)) / (
        1 - np.cos(ThetaValues) + Lambda * np.cos(ThetaValues + Gamma0))

    XValues = RhoValues * np.cos(ThetaValues)
    YValues = RhoValues * np.sin(ThetaValues)

    Range = 2 * r0 * np.arctan((Lambda * np.sin(Gamma0) * np.cos(Gamma0)) /
                               (1 - Lambda * np.power(np.cos(Gamma0), 2)))

    return XValues, YValues, Range
Ejemplo n.º 7
0
def ps_21tau(kperp, kpara, z21, params, singlek=False):
    '''
    anisotropic 21-cm tau cross powers-spectrum
    Args:
        kperp, wavenumber perp to LoS (h/Mpc)
        kpara, wavenumber para to LoS (h/Mpc)
        z21, redshift
        params, parameter dictionary
        singlek, on-the-fly calculation (no precomputing splines)
    Returns:
        21-cm-optical-depth cross power spectrum K (Mpc/h)^3 K^2
        with anisotropic effects
    '''

    k = np.sqrt(kperp**2. + kpara**2.)
    mu = np.arcos(kpara / k)
    return rz_distortion(bias_hits(z21,params),mu,z21,params)\
    *rz_distortion(bias_hi(z21,mu,z21,params))\
    *virial_suppression(k,mu,z21,params)*ps_21tau_iso(k,z21,params,singlek)
Ejemplo n.º 8
0
import numpy as np

a = np.ndarray((2,6,7,3))
copy01 = np.abs(a)
copy02 = np.arcos(a)
copy03 = np.arcosh(a)
copy04 = np.arcsin(a)
copy05 = np.arcsinh(a)
copy06 = np.arctan(a)
copy07 = np.arctanh(a)
copy08 = np.cos(a)
copy09 = np.floor(a)
copy10 = np.zeros_like(a)

# show_store()
Ejemplo n.º 9
0
 def drag_area(V, a, r, h):
     area = r*h
     top = np.arcos((V[0]*a[0]+V[1]*a[1]+V[2]*a[2]))
     bottom = ((np.sqrt((a[0]**2)+(a[1]**2)+(a[1]**2)))*np.sqrt((V[0]**2)+(V[1]**2)+(V[1]**2)))
     area = area * (top/bottom)
     return area
Ejemplo n.º 10
0
# Rounding, Ceil, Floor

np.around(array, 4)  # 4dp
np.ceil(array)  # 1.8 will become 2
np.floor(array)  # 1.8 will become 1


# Trigonometric

array = np.arange(10)
np.sin(array)
np.cos(array)
np.tan(array)
np.arcsin(array)
np.arcos(array)
np.arctan(array)


# Statistical

np.amin(array1, axis)  # min in the axis
np.amax(array1, axis)  # max in the axis
np.percentile(array1, percentile)
# Additionally, following functions are available:
np.median(), np.st(), np.average(), np.mean(), np.var()


# Algebra

# 1. dot() #dot product of two arrays
Ejemplo n.º 11
0
def geo_dist(p1, p2):
    return np.arcos(
        np.sin(p1[1]) * np.sin(p2[1]) + np.cos(p1[1]) * np.cos(p2[1]) *
        (p1[0] - p2[0])) * EARTH_RADIUS
Ejemplo n.º 12
0
def arcos(x):
    return np.arcos(x)
Ejemplo n.º 13
0
def geo_dist(p1, p2):
    return np.arcos(np.sin(p1[1]) * np.sin(p2[1]) + np.cos(p1[1]) * np.cos(p2[1]) * (p1[0] - p2[0])) * EARTH_RADIUS
Ejemplo n.º 14
0
def angle(v1, v2):
    dot = np.dot(v1, v2)
    x_mod = np.sqrt((v1 * v1).sum())
    y_mod = np.sqrt((v2 * v2).sum())
    cos_angle = dot / x_mod / y_mod
    return np.degrees(np.arcos(cos_angle))
Ejemplo n.º 15
0
def vangle(v1, v2):
    """
    Return the angle between two vectors.
    """
    return np.arcos(dotproduct(v1, v2) / (length(v1) * length(v2)))