Python numpy 模块,arcsin() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用numpy.arcsin()

项目:qgis-stereonet    作者:daniel-childs    | 项目源码 | 文件源码
def cart2sph(x, y, z):
    """
    Converts cartesian coordinates `x`, `y`, `z` into a longitude and latitude.
    x=0, y=0, z=0 is assumed to correspond to the center of the globe.
    Returns lon and lat in radians.

    Parameters
    ----------
    `x`, `y`, `z` : Arrays of cartesian coordinates

    Returns
    -------
    lon : Longitude in radians
    lat : Latitude in radians
    """
    r = np.sqrt(x**2 + y**2 + z**2)
    lat = np.arcsin(z/r)
    lon = np.arctan2(y, x)
    return lon, lat
项目:MKLMM    作者:omerwe    | 项目源码 | 文件源码
def getTrainTestKernel(self, params, Xtest):
        self.checkParams(params)
        ell2 = np.exp(2*params[0])

        z = Xtest / np.sqrt(Xtest.shape[1])
        S = 1 + self.X_scaled.dot(z.T)
        sz = 1 + np.sum(z**2, axis=1)
        sqrtEll2Psx = np.sqrt(ell2+self.sx)
        sqrtEll2Psz = np.sqrt(ell2+sz)
        K = S / np.outer(sqrtEll2Psx, sqrtEll2Psz)
        return np.arcsin(K)
项目:MulensModel    作者:rpoleski    | 项目源码 | 文件源码
def _B_0_function(self, z):
        """
        calculate B_0(z) function defined in:

        Gould A. 1994 ApJ 421L, 71 "Proper motions of MACHOs
        http://adsabs.harvard.edu/abs/1994ApJ...421L..71G

        Yoo J. et al. 2004 ApJ 603, 139 "OGLE-2003-BLG-262: Finite-Source
        Effects from a Point-Mass Lens"
        http://adsabs.harvard.edu/abs/2004ApJ...603..139Y

        """
        out = 4. * z / np.pi
        function = lambda x: (1.-value**2*np.sin(x)**2)**.5

        for (i, value) in enumerate(z):
            if value < 1.:
                out[i] *= ellipe(value*value)
            else:
                out[i] *= integrate.quad(function, 0., np.arcsin(1./value))[0]
        return out
项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
def distance(self, lon1, lat1, lon2, lat2):
        """
        Calculate the great circle distance between two points
        on the earth (specified in decimal degrees)
        """

        # convert decimal degrees to radians
        lon1 = lon1*pi/180
        lat1 = lat1*pi/180
        lon2 = lon2*pi/180
        lat2 = lat2*pi/180
        # haversine formula
        dlon = lon2 - lon1
        dlat = lat2 - lat1
        a = np.sin(dlat/2)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2)**2
        c = 2 * np.arcsin(np.sqrt(a))
        km = 6371 * c
        return km
项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
def distance(self, lon1, lat1, lon2, lat2):
        """
        Calculate the great circle distance between two points
        on the earth (specified in decimal degrees)
        """

        # convert decimal degrees to radians
        lon1 = lon1*pi/180
        lat1 = lat1*pi/180
        lon2 = lon2*pi/180
        lat2 = lat2*pi/180
        # haversine formula
        dlon = lon2 - lon1
        dlat = lat2 - lat1
        a = numpy.sin(dlat/2)**2 + numpy.cos(lat1) * numpy.cos(lat2) * numpy.sin(dlon/2)**2
        c = 2 * numpy.arcsin(numpy.sqrt(a))
        km = 6371 * c
        return km
项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
def distance(lon1, lat1, lon2, lat2):
    """
    Calculate the great circle distance between two points
    on the earth (specified in decimal degrees)
    """

    # convert decimal degrees to radians
    lon1 = lon1*pi/180
    lat1 = lat1*pi/180
    lon2 = lon2*pi/180
    lat2 = lat2*pi/180
    # haversine formula
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = np.sin(dlat/2)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon/2)**2
    c = 2 * np.arcsin(np.sqrt(a))
    km = 6371 * c
    return km
项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
def distance(self, lon1, lat1, lon2, lat2):
        """
        Calculate the great circle distance between two points
        on the earth (specified in decimal degrees)
        """

        # convert decimal degrees to radians
        lon1 = lon1*pi/180
        lat1 = lat1*pi/180
        lon2 = lon2*pi/180
        lat2 = lat2*pi/180
        # haversine formula
        dlon = lon2 - lon1
        dlat = lat2 - lat1
        a = numpy.sin(dlat/2)**2 + numpy.cos(lat1) * numpy.cos(lat2) * numpy.sin(dlon/2)**2
        c = 2 * numpy.arcsin(numpy.sqrt(a))
        km = 6371 * c
        return km
项目:Parallel.GAMIT    作者:demiangomez    | 项目源码 | 文件源码
def distance(self, lon1, lat1, lon2, lat2):
        """
        Calculate the great circle distance between two points
        on the earth (specified in decimal degrees)
        """

        # convert decimal degrees to radians
        lon1 = lon1*pi/180
        lat1 = lat1*pi/180
        lon2 = lon2*pi/180
        lat2 = lat2*pi/180
        # haversine formula
        dlon = lon2 - lon1
        dlat = lat2 - lat1
        a = numpy.sin(dlat/2)**2 + numpy.cos(lat1) * numpy.cos(lat2) * numpy.sin(dlon/2)**2
        c = 2 * numpy.arcsin(numpy.sqrt(a))
        km = 6371 * c
        return km
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def test_branch_cuts(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def test_branch_cuts_complex64(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True, np.complex64

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True, np.complex64

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True, np.complex64
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True, np.complex64

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1, False, np.complex64

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1, False, np.complex64
项目:radar    作者:amoose136    | 项目源码 | 文件源码
def test_against_cmath(self):
        import cmath

        points = [-1-1j, -1+1j, +1-1j, +1+1j]
        name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
                    'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}
        atol = 4*np.finfo(np.complex).eps
        for func in self.funcs:
            fname = func.__name__.split('.')[-1]
            cname = name_map.get(fname, fname)
            try:
                cfunc = getattr(cmath, cname)
            except AttributeError:
                continue
            for p in points:
                a = complex(func(np.complex_(p)))
                b = cfunc(p)
                assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
项目:KRPC    作者:BevoLJ    | 项目源码 | 文件源码
def azimuth(_lAz_data):
        _inc = _lAz_data[0]
        _lat = _lAz_data[1]
        velocity_eq = _lAz_data[2]

        @jit(nopython=True)
        def _az_calc():
            inert_az = np.arcsin(max(min(np.cos(np.deg2rad(_inc)) / np.cos(np.deg2rad(_lat)), 1), -1))
            _VXRot = _lAz_data[3] * np.sin(inert_az) - velocity_eq * np.cos(np.deg2rad(_lat))
            _VYRot = _lAz_data[3] * np.cos(inert_az)

            return np.rad2deg(np.fmod(np.arctan2(_VXRot, _VYRot) + (2 * pi), (2 * pi)))
        _az = _az_calc()

        if _lAz_data[4] == "Ascending": return _az

        if _lAz_data[4] == "Descending":
            if _az <= 90: return 180 - _az
            elif _az >= 270: return 540 - _az
项目:KRPC    作者:BevoLJ    | 项目源码 | 文件源码
def azimuth(_lAz_data):
        _inc = _lAz_data[0]
        _lat = _lAz_data[1]
        velocity_eq = _lAz_data[2]

        @jit(nopython=True)
        def _az_calc():
            inert_az = np.arcsin(max(min(np.cos(np.deg2rad(_inc)) / np.cos(np.deg2rad(_lat)), 1), -1))
            _VXRot = _lAz_data[3] * np.sin(inert_az) - velocity_eq * np.cos(np.deg2rad(_lat))
            _VYRot = _lAz_data[3] * np.cos(inert_az)

            return np.rad2deg(np.fmod(np.arctan2(_VXRot, _VYRot) + (2 * pi), (2 * pi)))
        _az = _az_calc()

        if _lAz_data[4] == "Ascending": return _az

        if _lAz_data[4] == "Descending":
            if _az <= 90: return 180 - _az
            elif _az >= 270: return 540 - _az
项目:KRPC    作者:BevoLJ    | 项目源码 | 文件源码
def azimuth(_lAz_data):
        _inc = _lAz_data[0]
        _lat = _lAz_data[1]
        velocity_eq = _lAz_data[2]

        @jit(nopython=True)
        def _az_calc():
            inert_az = np.arcsin(max(min(np.cos(np.deg2rad(_inc)) / np.cos(np.deg2rad(_lat)), 1), -1))
            _VXRot = _lAz_data[3] * np.sin(inert_az) - velocity_eq * np.cos(np.deg2rad(_lat))
            _VYRot = _lAz_data[3] * np.cos(inert_az)

            return np.rad2deg(np.fmod(np.arctan2(_VXRot, _VYRot) + (2 * pi), (2 * pi)))
        _az = _az_calc()

        if _lAz_data[4] == "Ascending": return _az

        if _lAz_data[4] == "Descending":
            if _az <= 90: return 180 - _az
            elif _az >= 270: return 540 - _az
项目:KRPC    作者:BevoLJ    | 项目源码 | 文件源码
def azimuth(_lAz_data):
        _inc = _lAz_data[0]
        _lat = _lAz_data[1]
        velocity_eq = _lAz_data[2]

        @jit(nopython=True)
        def _az_calc():
            inert_az = np.arcsin(max(min(np.cos(np.deg2rad(_inc)) / np.cos(np.deg2rad(_lat)), 1), -1))
            _VXRot = _lAz_data[3] * np.sin(inert_az) - velocity_eq * np.cos(np.deg2rad(_lat))
            _VYRot = _lAz_data[3] * np.cos(inert_az)

            return np.rad2deg(np.fmod(np.arctan2(_VXRot, _VYRot) + 360, 360))
        _az = _az_calc()

        if _lAz_data[4] == "Ascending": return _az

        if _lAz_data[4] == "Descending":
            if _az <= 90: return 180 - _az
            elif _az >= 270: return 540 - _az
项目:astk    作者:openalea-incubator    | 项目源码 | 文件源码
def sun_elevation(hUTC, dayofyear, year, latitude, longitude):
    """ Sun elevation

    Args:
        hUTC: fractional hour (UTC time)
        dayofyear (int):
        year (int):
        latitude (float): the location latitude (degrees)
        longitude (float): the location longitude (degrees)

    Returns:
        (float) the sun elevation (degrees)

    Details:
        World Meteorological Organization (2006).Guide to meteorological
        instruments and methods of observation. Geneva, Switzerland.
    """
    dec = declination(hUTC, dayofyear, year)
    lat = numpy.radians(latitude)
    ha = numpy.radians(hour_angle(hUTC, dayofyear, year, longitude) * 15)
    sinel = numpy.sin(dec) * numpy.sin(lat) + numpy.cos(dec) * numpy.cos(
        lat) * numpy.cos(ha)

    return numpy.degrees(numpy.arcsin(sinel))
项目:wxgen    作者:metno    | 项目源码 | 文件源码
def distance(lat1, lon1, lat2, lon2):
   """
   Computes the great circle distance between two points using the
   haversine formula. Values can be vectors.
   """
   # Convert from degrees to radians
   pi = 3.14159265
   lon1 = lon1 * 2 * pi / 360
   lat1 = lat1 * 2 * pi / 360
   lon2 = lon2 * 2 * pi / 360
   lat2 = lat2 * 2 * pi / 360
   dlon = lon2 - lon1
   dlat = lat2 - lat1
   a = np.sin(dlat / 2)**2 + np.cos(lat1) * np.cos(lat2) * np.sin(dlon / 2)**2
   c = 2 * np.arcsin(np.sqrt(a))
   distance = 6.367e6 * c
   return distance
项目:urban-journey    作者:urbanjourney    | 项目源码 | 文件源码
def q_to_euler(q):
    """Converts Quaternions to Euler angles.

    Parameters
    ----------
    q : array_like
        Array holding Quaternions.

    Returns
    -------
    phi : float
        `phi` angle in radians.
    theta :float
        `theta` angle in radians.
    psi : float
        `psi` angle in radians.
    """

    phi = np.arctan2(2*(q[0]*q[1]+q[2]*q[3]),(q[0]**2+q[3]**2-q[1]**2-q[2]**2))
    theta = np.arcsin(2*(q[0]*q[2]-q[1]*q[3]))
    psi = np.arctan2(2*(q[0]*q[3]+q[1]*q[2]),(q[0]**2+q[1]**2-q[2]**2-q[3]**2))

    return phi, theta, psi
项目:hexmachina    作者:dnkrtz    | 项目源码 | 文件源码
def convert_to_euler(R):
    """Compute the euler angles of this rotation.
    Refer to [http://www.staff.city.ac.uk/~sbbh653/publications/euler.pdf]"""
    alpha, beta, gamma = 0, 0, 0
    if not np.isclose(np.abs(R[2,0]), 1):
        beta = - np.arcsin(R[2,0])
        alpha = np.arctan2(R[2,1] / np.cos(beta), R[2,2] / np.cos(beta))
        gamma = np.arctan2(R[1,0] / np.cos(beta), R[0,0] / np.cos(beta))
    else:
        gamma = 0
        if np.isclose(R[2,0], -1):
            beta = np.pi / 2
            alpha = gamma + np.arctan2(R[0,1], R[0,2])
        else:
            beta = - np.pi / 2
            alpha = - gamma + np.arctan2(-R[0,1], -R[0,2])
    return np.array([alpha, beta, gamma])
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def azimuth(_lAz_data):
        _inc = _lAz_data[0]
        _lat = _lAz_data[1]
        velocity_eq = _lAz_data[2]

        @jit(nopython=True)
        def _az_calc():
            inert_az = np.arcsin(max(min(np.cos(np.deg2rad(_inc)) / np.cos(np.deg2rad(_lat)), 1), -1))
            _VXRot = _lAz_data[3] * np.sin(inert_az) - velocity_eq * np.cos(np.deg2rad(_lat))
            _VYRot = _lAz_data[3] * np.cos(inert_az)

            return np.rad2deg(np.fmod(np.arctan2(_VXRot, _VYRot) + (2 * pi), (2 * pi)))
        _az = _az_calc()

        if _lAz_data[4] == "Ascending": return _az

        if _lAz_data[4] == "Descending":
            if _az <= 90: return 180 - _az
            elif _az >= 270: return 540 - _az
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def azimuth(_lAz_data):
        _inc = _lAz_data[0]
        _lat = _lAz_data[1]
        velocity_eq = _lAz_data[2]

        def _az_calc():
            inert_az = np.arcsin(max(min(np.cos(np.deg2rad(_inc)) / np.cos(np.deg2rad(_lat)), 1), -1))
            _VXRot = _lAz_data[3] * np.sin(inert_az) - velocity_eq * np.cos(np.deg2rad(_lat))
            _VYRot = _lAz_data[3] * np.cos(inert_az)

            return np.rad2deg(np.fmod(np.arctan2(_VXRot, _VYRot) + 360, 360))
        _az = _az_calc()

        if _lAz_data[4] == "Ascending": return _az

        if _lAz_data[4] == "Descending":
            if _az <= 90: return 180 - _az
            elif _az >= 270: return 540 - _az
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def test_branch_cuts(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def test_branch_cuts_complex64(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True, np.complex64

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True, np.complex64

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True, np.complex64
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True, np.complex64

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1, False, np.complex64

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1, False, np.complex64
项目:krpcScripts    作者:jwvanderbeck    | 项目源码 | 文件源码
def test_against_cmath(self):
        import cmath

        points = [-1-1j, -1+1j, +1-1j, +1+1j]
        name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
                    'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}
        atol = 4*np.finfo(np.complex).eps
        for func in self.funcs:
            fname = func.__name__.split('.')[-1]
            cname = name_map.get(fname, fname)
            try:
                cfunc = getattr(cmath, cname)
            except AttributeError:
                continue
            for p in points:
                a = complex(func(np.complex_(p)))
                b = cfunc(p)
                assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
项目:ocbpy    作者:aburrell    | 项目源码 | 文件源码
def archav(hav):
    """ Formula for the inverse haversine

    Parameters
    -----------
    hav : (float)
        Haversine of an angle

    Returns
    ---------
    alpha : (float)
        Angle in radians
    """
    alpha = 2.0 * np.arcsin(np.sqrt(hav))

    return alpha
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_branch_cuts(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_branch_cuts_complex64(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True, np.complex64

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True, np.complex64

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True, np.complex64
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True, np.complex64

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1, False, np.complex64

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1, False, np.complex64
项目:PyDataLondon29-EmbarrassinglyParallelDAWithAWSLambda    作者:SignalMedia    | 项目源码 | 文件源码
def test_against_cmath(self):
        import cmath

        points = [-1-1j, -1+1j, +1-1j, +1+1j]
        name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
                    'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}
        atol = 4*np.finfo(np.complex).eps
        for func in self.funcs:
            fname = func.__name__.split('.')[-1]
            cname = name_map.get(fname, fname)
            try:
                cfunc = getattr(cmath, cname)
            except AttributeError:
                continue
            for p in points:
                a = complex(func(np.complex_(p)))
                b = cfunc(p)
                assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
项目:pyins    作者:nmayorov    | 项目源码 | 文件源码
def _to_hpr_single(dcm):
    pitch = np.arcsin(dcm[2, 1])
    if np.abs(pitch) < 0.5 * np.pi - 1e-3:
        heading = np.arctan2(dcm[0, 1], dcm[1, 1])
        roll = np.arctan2(-dcm[2, 0], dcm[2, 2])
    elif pitch > 0:
        roll = 0
        heading = np.arctan2(-dcm[0, 2] - dcm[1, 0], dcm[0, 0] - dcm[1, 2])
    else:
        roll = 0
        heading = np.arctan2(dcm[0, 2] - dcm[1, 0], dcm[0, 0] + dcm[1, 2])

    if heading < 0:
        heading += 2 * np.pi

    if heading == 2 * np.pi:
        heading = 0

    return heading, pitch, roll
项目:pyins    作者:nmayorov    | 项目源码 | 文件源码
def _to_llw_array(dcm):
    lat = np.arcsin(dcm[:, 2, 2])
    lon = np.empty(dcm.shape[0])
    wan = np.empty(dcm.shape[0])

    mask = np.abs(lat) < 0.5 * np.pi - 1e-3
    lon[mask] = np.arctan2(dcm[mask, 1, 2], dcm[mask, 0, 2])
    wan[mask] = np.arctan2(dcm[mask, 2, 0], dcm[mask, 2, 1])

    mask = ~mask
    lon[mask] = 0

    l_mask = mask & (lat > 0)
    wan[l_mask] = np.arctan2(-dcm[l_mask, 0, 0] - dcm[l_mask, 1, 1],
                             dcm[l_mask, 1, 0] - dcm[l_mask, 0, 1])

    l_mask = mask & (lat < 0)
    wan[l_mask] = np.arctan2(dcm[l_mask, 0, 0] - dcm[l_mask, 1, 1],
                             dcm[l_mask, 0, 1] + dcm[l_mask, 1, 0])

    return lat, lon, wan
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def test_branch_cuts(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def test_branch_cuts_complex64(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True, np.complex64

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True, np.complex64

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True, np.complex64
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True, np.complex64

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1, False, np.complex64

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1, False, np.complex64
项目:aws-lambda-numpy    作者:vitolimandibhrata    | 项目源码 | 文件源码
def test_against_cmath(self):
        import cmath

        points = [-1-1j, -1+1j, +1-1j, +1+1j]
        name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
                    'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}
        atol = 4*np.finfo(np.complex).eps
        for func in self.funcs:
            fname = func.__name__.split('.')[-1]
            cname = name_map.get(fname, fname)
            try:
                cfunc = getattr(cmath, cname)
            except AttributeError:
                continue
            for p in points:
                a = complex(func(np.complex_(p)))
                b = cfunc(p)
                assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
项目:theia    作者:bandang0    | 项目源码 | 文件源码
def apexes(self):
        '''Returns the positions of the apexes of HR and AR as a tuple.'''
        if self.HRK == 0.:
            apex1 = self.HRCenter
        else:
            theta1 = np.arcsin(self.Dia * self.ARK/2.)\
                if np.abs(self.Dia * self.ARK/2.) < 1. else np.pi/2.
            apex1 = self.HRCenter - (1-np.cos(theta1))*self.HRNorm/self.HRK

        if self.ARK == 0.:
            apex2 = self.ARCenter
        else:
            theta2 = np.arcsin(self.Dia * self.ARK/(2.*np.cos(self.Wedge)))\
                if np.abs(self.Dia * self.ARK/(2.*np.cos(self.Wedge))) < 1.\
                else np.pi/2.
            apex2 = self.ARCenter - (1-np.cos(theta2))*self.ARNorm/self.ARK

        return apex1, apex2
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_branch_cuts(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_branch_cuts_complex64(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True, np.complex64

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True, np.complex64

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True, np.complex64
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True, np.complex64

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1, False, np.complex64

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1, False, np.complex64
项目:lambda-numba    作者:rlhotovy    | 项目源码 | 文件源码
def test_against_cmath(self):
        import cmath

        points = [-1-1j, -1+1j, +1-1j, +1+1j]
        name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
                    'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}
        atol = 4*np.finfo(np.complex).eps
        for func in self.funcs:
            fname = func.__name__.split('.')[-1]
            cname = name_map.get(fname, fname)
            try:
                cfunc = getattr(cmath, cname)
            except AttributeError:
                continue
            for p in points:
                a = complex(func(np.complex_(p)))
                b = cfunc(p)
                assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def galToCel(ll, bb):
    """
    Converts Galactic (deg) to Celestial J2000 (deg) coordinates
    """
    bb = numpy.radians(bb)
    sin_bb = numpy.sin(bb)
    cos_bb = numpy.cos(bb)

    ll = numpy.radians(ll)
    ra_gp = numpy.radians(192.85948)
    de_gp = numpy.radians(27.12825)
    lcp = numpy.radians(122.932)

    sin_lcp_ll = numpy.sin(lcp - ll)
    cos_lcp_ll = numpy.cos(lcp - ll)

    sin_d = (numpy.sin(de_gp) * sin_bb) \
            + (numpy.cos(de_gp) * cos_bb * cos_lcp_ll)
    ramragp = numpy.arctan2(cos_bb * sin_lcp_ll,
                            (numpy.cos(de_gp) * sin_bb) \
                            - (numpy.sin(de_gp) * cos_bb * cos_lcp_ll))
    dec = numpy.arcsin(sin_d)
    ra = (ramragp + ra_gp + (2. * numpy.pi)) % (2. * numpy.pi)
    return numpy.degrees(ra), numpy.degrees(dec)
项目:ugali    作者:DarkEnergySurvey    | 项目源码 | 文件源码
def celToGal(ra, dec):
    """
    Converts Celestial J2000 (deg) to Calactic (deg) coordinates
    """
    dec = numpy.radians(dec)
    sin_dec = numpy.sin(dec)
    cos_dec = numpy.cos(dec)

    ra = numpy.radians(ra)    
    ra_gp = numpy.radians(192.85948)
    de_gp = numpy.radians(27.12825)

    sin_ra_gp = numpy.sin(ra - ra_gp)
    cos_ra_gp = numpy.cos(ra - ra_gp)

    lcp = numpy.radians(122.932)    
    sin_b = (numpy.sin(de_gp) * sin_dec) \
            + (numpy.cos(de_gp) * cos_dec * cos_ra_gp)
    lcpml = numpy.arctan2(cos_dec * sin_ra_gp,
                          (numpy.cos(de_gp) * sin_dec) \
                          - (numpy.sin(de_gp) * cos_dec * cos_ra_gp))
    bb = numpy.arcsin(sin_b)
    ll = (lcp - lcpml + (2. * numpy.pi)) % (2. * numpy.pi)
    return numpy.degrees(ll), numpy.degrees(bb)
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def test_branch_cuts(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def test_branch_cuts_complex64(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True, np.complex64

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True, np.complex64

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True, np.complex64
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True, np.complex64

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1, False, np.complex64

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1, False, np.complex64
项目:deliver    作者:orchestor    | 项目源码 | 文件源码
def test_against_cmath(self):
        import cmath

        points = [-1-1j, -1+1j, +1-1j, +1+1j]
        name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
                    'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}
        atol = 4*np.finfo(np.complex).eps
        for func in self.funcs:
            fname = func.__name__.split('.')[-1]
            cname = name_map.get(fname, fname)
            try:
                cfunc = getattr(cmath, cname)
            except AttributeError:
                continue
            for p in points:
                a = complex(func(np.complex_(p)))
                b = cfunc(p)
                assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
项目:magphase    作者:CSTR-Edinburgh    | 项目源码 | 文件源码
def ph_dec(m_phs, m_phc, mode='angle'):  

    if mode == 'sign':    
        m_bs = np.arcsin(m_phs)
        m_bc = np.arccos(m_phc)   
        m_ph = np.sign(m_bs) * np.abs(m_bc)   

    elif mode == 'angle':
        m_ph = np.angle(m_phc + m_phs * 1j)

    return m_ph 


#==============================================================================
# From 'analysis_with_del_comp_and_ph_encoding_from_files'
# f0_type: 'f0', 'lf0'
项目:Optics    作者:danustc    | 项目源码 | 文件源码
def refraction_plane(k_vec, n_vec, n1, n2):
    '''
    k_vec: the directional vector of the incidental ray
    n_vec: the normal vector of the incidental plane
    n1, n2: the refractive indices
    '''
    s_vec, p_vec, sin_ins = incident_plane(k_vec, n_vec)

    sin_ref = n1*sin_ins /n2 # sin(phi')
    a_inc = np.arcsin(sin_ins)
    a_ref = np.arcsin(sin_ref)
    a_diff = a_inc-a_ref
    kr_vec = np.cos(a_diff)*k_vec -np.sin(a_diff)*p_vec
    if(kr_vec[2]>0):
        print(a_diff, k_vec)
    # next, let's calculate the reflectance
    cos_inc = np.cos(a_inc)
    cos_ref = np.cos(a_ref)
    Rs = ((n1*cos_inc - n2*cos_ref)/(n1*cos_inc + n2*cos_ref))**2
    Rp = ((n1*cos_ref - n2*cos_inc)/(n1*cos_ref + n2*cos_inc))**2

    return kr_vec, Rs, Rp
    # done with refraction_plane
项目:Parallel-SGD    作者:angadgill    | 项目源码 | 文件源码
def test_haversine_metric():
    def haversine_slow(x1, x2):
        return 2 * np.arcsin(np.sqrt(np.sin(0.5 * (x1[0] - x2[0])) ** 2
                                     + np.cos(x1[0]) * np.cos(x2[0]) *
                                     np.sin(0.5 * (x1[1] - x2[1])) ** 2))

    X = np.random.random((10, 2))

    haversine = DistanceMetric.get_metric("haversine")

    D1 = haversine.pairwise(X)
    D2 = np.zeros_like(D1)
    for i, x1 in enumerate(X):
        for j, x2 in enumerate(X):
            D2[i, j] = haversine_slow(x1, x2)

    assert_array_almost_equal(D1, D2)
    assert_array_almost_equal(haversine.dist_to_rdist(D1),
                              np.sin(0.5 * D2) ** 2)
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def test_branch_cuts(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def test_branch_cuts_complex64(self):
        # check branch cuts and continuity on them
        yield _check_branch_cut, np.log,   -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log2,  -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log10, -0.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.log1p, -1.5, 1j, 1, -1, True, np.complex64
        yield _check_branch_cut, np.sqrt,  -0.5, 1j, 1, -1, True, np.complex64

        yield _check_branch_cut, np.arcsin, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arccos, [ -2, 2],   [1j, 1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctan, [0-2j, 2j],  [1,  1], -1, 1, True, np.complex64

        yield _check_branch_cut, np.arcsinh, [0-2j,  2j], [1,   1], -1, 1, True, np.complex64
        yield _check_branch_cut, np.arccosh, [ -1, 0.5], [1j,  1j], 1, -1, True, np.complex64
        yield _check_branch_cut, np.arctanh, [ -2,   2], [1j, 1j], 1, -1, True, np.complex64

        # check against bogus branch cuts: assert continuity between quadrants
        yield _check_branch_cut, np.arcsin, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccos, [0-2j, 2j], [ 1,  1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctan, [ -2,  2], [1j, 1j], 1, 1, False, np.complex64

        yield _check_branch_cut, np.arcsinh, [ -2,  2, 0], [1j, 1j, 1], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arccosh, [0-2j, 2j, 2], [1,  1,  1j], 1, 1, False, np.complex64
        yield _check_branch_cut, np.arctanh, [0-2j, 2j, 0], [1,  1,  1j], 1, 1, False, np.complex64
项目:Alfred    作者:jkachhadia    | 项目源码 | 文件源码
def test_against_cmath(self):
        import cmath

        points = [-1-1j, -1+1j, +1-1j, +1+1j]
        name_map = {'arcsin': 'asin', 'arccos': 'acos', 'arctan': 'atan',
                    'arcsinh': 'asinh', 'arccosh': 'acosh', 'arctanh': 'atanh'}
        atol = 4*np.finfo(np.complex).eps
        for func in self.funcs:
            fname = func.__name__.split('.')[-1]
            cname = name_map.get(fname, fname)
            try:
                cfunc = getattr(cmath, cname)
            except AttributeError:
                continue
            for p in points:
                a = complex(func(np.complex_(p)))
                b = cfunc(p)
                assert_(abs(a - b) < atol, "%s %s: %s; cmath: %s" % (fname, p, a, b))
项目:qgis-stereonet    作者:daniel-childs    | 项目源码 | 文件源码
def transform_non_affine(self, xy):
        x = xy[:, 0:1]
        y = xy[:, 1:2]
        clong = self._center_longitude
        clat = self._center_latitude
        p = np.sqrt(x*x + y*y)
        p = np.where(p == 0.0, 1e-9, p)
        c = self._calculate_c(p)
        sin_c = np.sin(c)
        cos_c = np.cos(c)

        lat = np.arcsin(cos_c*np.sin(clat) + ((y*sin_c*np.cos(clat)) / p))
        lon = clong + np.arctan(
                (x*sin_c) / (p*np.cos(clat)*cos_c - y*np.sin(clat)*sin_c))

        return np.concatenate((lon, lat), 1)
项目:MKLMM    作者:omerwe    | 项目源码 | 文件源码
def getTrainKernel(self, params):
        self.checkParams(params)
        if (self.sameParams(params)): return self.cache['getTrainKernel']               
        ell2 = np.exp(2*params[0])

        sqrt_ell2PSx = np.sqrt(ell2+self.sx)
        K = self.S / np.outer(sqrt_ell2PSx, sqrt_ell2PSx)
        self.cache['K'] = K
        K_arcsin = np.arcsin(K)

        self.cache['getTrainKernel'] = K_arcsin
        self.saveParams(params)
        return K_arcsin