精华内容
下载资源
问答
  • The following are code examples for showing how to ... They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can al...

    The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

    Example 1

    def get_polar_t(self):

    mag = self.get_magnitude()

    sizeimg = np.real(self.imgfft).shape

    pol = np.zeros(sizeimg)

    for x in range(sizeimg[0]):

    for y in range(sizeimg[1]):

    my = y - sizeimg[1] / 2

    mx = x - sizeimg[0] / 2

    if mx != 0:

    phi = np.arctan(my / float(mx))

    else:

    phi = 0

    r = np.sqrt(mx**2 + my **2)

    ix = map_range(phi, -np.pi, np.pi, sizeimg[0], 0)

    iy = map_range(r, 0, sizeimg[0], 0, sizeimg[1])

    if ix >= 0 and ix < sizeimg[0] and iy >= 0 and iy < sizeimg[1]:

    pol[x][y] = mag.data[int(ix)][int(iy)]

    pol = MyImage(pol)

    pol.limit(1)

    return pol

    Example 2

    def calc_IndCurrent_cos_range(self,f,t):

    """Induced current over a range of times"""

    Bpx = self.Bpx

    Bpz = self.Bpz

    a2 = self.a2

    azm = np.pi*self.azm/180.

    R = self.R

    L = self.L

    w = 2*np.pi*f

    Ax = np.pi*a2**2*np.sin(azm)

    Az = np.pi*a2**2*np.cos(azm)

    Phi = (Ax*Bpx + Az*Bpz)

    phi = np.arctan(R/(w*L))-np.pi # This is the phase and not phase lag

    Is = -(w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.cos(w*t + phi)

    Ire = -(w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.cos(w*t)*np.cos(phi)

    Iim = (w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.sin(w*t)*np.sin(phi)

    return Ire,Iim,Is,phi

    Example 3

    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

    Example 4

    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))

    Example 5

    def effect(self, point):

    res = []

    # print(self.centers)

    for center in self.centers:

    center_x, center_y = center

    src_x, src_y = point.pos

    # Check angle

    angle = np.arctan((center_x - src_x) / (center_y - src_y))

    if np.abs(angle) > self.angle / 2:

    continue

    angle = np.deg2rad(90) + angle

    u_len = np.sqrt((center_x - src_x) ** 2 + (center_y - src_y) ** 2)

    reverse_v = (self.r_index - 1) / self.radius - self.r_index / u_len

    v_len = 1 / reverse_v

    if v_len > 0:

    p_type = 'real'

    else:

    p_type = 'fake'

    target = line_end(point.pos, angle, u_len + v_len)

    p = Point(target, p_type, 1)

    # point.passed.append(self)

    res.append(p)

    return tuple(res)

    Example 6

    def _radian_direction(dy,dx):

    '''

    function:

    - based on given dy and dx it calculates direction in radian.

    - used in feature_eng_pt3

    input:

    dy = change in y

    dx = change in x

    output:

    returns radian value (0 to 6.28)

    '''

    if dy < 0.0 and dx > 0.0:

    return (2*np.pi + np.arctan(dy/dx))

    elif dy >=0.0 and dx > 0.0:

    return (np.arctan(dy/dx))

    else:

    return np.pi + np.arctan(dy/dx)

    Example 7

    def flow(self, Kc, Ks, Kz, Ka, numexpr):

    zeros = np.zeros

    where = np.where

    min = np.minimum

    max = np.maximum

    abs = np.absolute

    arctan = np.arctan

    sin = np.sin

    center = (slice( 1, -1,None),slice( 1, -1,None))

    rock = self.center

    ds = self.scour[center]

    rcc = rock[center]

    rock[center] = rcc - ds * Kz

    # there isn't really a bottom to the rock but negative values look ugly

    rock[center] = where(rcc<0,0,rcc)

    Example 8

    def fixOffset(self, offset, img):

    size = img.shape

    finalImg = np.ndarray(size)

    indices = np.indices((self.videoSize[0],self.videoSize[1])).swapaxes(0,2).swapaxes(0,1)

    indices = np.around(indices, decimals=1)

    indices.shape = (self.videoSize[1] * self.videoSize[0], 2)

    phi = 2 * np.arctan(np.exp(indices[:, 1] / self.videoSize[1])) - 1/2 * np.pi - offset[0]

    lamb = indices[:, 0] - offset[1]

    x = lamb

    y = np.log(np.tan(np.pi / 4 + 1/2 * phi)) * self.videoSize[1]

    finalIdx = np.ndarray((self.videoSize[1] * self.videoSize[0], 2))

    finalIdx = np.around(finalIdx, decimals=1).astype(int)

    finalIdx[:, 1] = y % self.videoSize[1]

    finalIdx[:, 0] = x % self.videoSize[0]

    finalImg[indices[:,1], indices[:,0]] = img[finalIdx[:,1], finalIdx[:,0]]

    return finalImg

    Example 9

    def _dip_slip_y(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    y = down-dip direction

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    y_bar = y2*cs + q*sn

    a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a1 = 2.0*poisson*(-y1/(cs*(r+d_bar))) - sn/cs * a5

    f = -(y_bar*q/r/(r+y1) + cs*numpy.arctan(y1*y2/q/r) - a1*sn*cs)/(2.0*3.14159)

    return f

    Example 10

    def _dip_slip_x(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    Added by Xiaoming Wang

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    #a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a4 = 2.0*poisson/cs*(numpy.log(r+d_bar) - sn*numpy.log(r+y2))

    ytilde = y2*cs + q*sn

    a3 = 2.0*poisson*(ytilde/(cs*(r+d_bar)) - numpy.log(r+y2)) + a4*sn/cs

    f = -(q/r - a3*sn*cs)/(2.0*3.14159)

    return f

    Example 11

    def _dip_slip_x(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    Added by Xiaoming Wang

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    #a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a4 = 2.0*poisson/cs*(numpy.log(r+d_bar) - sn*numpy.log(r+y2))

    ytilde = y2*cs + q*sn

    a3 = 2.0*poisson*(ytilde/(cs*(r+d_bar)) - numpy.log(r+y2)) + a4*sn/cs

    f = -(q/r - a3*sn*cs)/(2.0*3.14159)

    return f

    Example 12

    def get_q_per_pixel(self):

    '''Gets the delta-q associated with a single pixel. This is computed in

    the small-angle limit, so it should only be considered approximate.

    For instance, wide-angle detectors will have different delta-q across

    the detector face.'''

    if self.q_per_pixel is not None:

    return self.q_per_pixel

    c = (self.pixel_size_um/1e6)/self.distance_m

    twotheta = np.arctan(c) # radians

    self.q_per_pixel = 2.0*self.get_k()*np.sin(twotheta/2.0)

    return self.q_per_pixel

    # Maps

    ########################################

    Example 13

    def reset_model(self):

    self._min_strike_dist = np.inf

    self._striked = False

    self._strike_pos = None

    qpos = self.init_qpos

    self.ball = np.array([0.5, -0.175])

    while True:

    self.goal = np.concatenate([

    self.np_random.uniform(low=0.15, high=0.7, size=1),

    self.np_random.uniform(low=0.1, high=1.0, size=1)])

    if np.linalg.norm(self.ball - self.goal) > 0.17:

    break

    qpos[-9:-7] = [self.ball[1], self.ball[0]]

    qpos[-7:-5] = self.goal

    diff = self.ball - self.goal

    angle = -np.arctan(diff[0] / (diff[1] + 1e-8))

    qpos[-1] = angle / 3.14

    qvel = self.init_qvel + self.np_random.uniform(low=-.1, high=.1,

    size=self.model.nv)

    qvel[7:] = 0

    self.set_state(qpos, qvel)

    return self._get_obs()

    Example 14

    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

    Example 15

    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))

    Example 16

    def angularpixelarea(self):

    # get the first instrument element

    instruments = self.tree.xpath("//instruments/*[1]")

    if len(instruments) != 1: raise ValueError("No instruments in ski file")

    instrument = instruments[0]

    # get the distance in m

    d = self.units().convert(instrument.get("distance"), to_unit='m', quantity='distance')

    # get the field of view in m

    fovx = self.units().convert(instrument.get("fieldOfViewX"), to_unit='m', quantity='length')

    fovy = self.units().convert(instrument.get("fieldOfViewY"), to_unit='m', quantity='length')

    # get the number of pixels

    nx = int(instrument.get("pixelsX"))

    ny = int(instrument.get("pixelsY"))

    # calculate the angular pixel area

    sx = 2 * arctan(fovx / nx / d / 2)

    sy = 2 * arctan(fovy / ny / d / 2)

    return sx * sy

    ## This function returns a list of instrument names, in order of occurrence in the ski file.

    Example 17

    def orientation_angle(self):

    """

    This function ...

    :return:

    """

    diag_a = self.pixel_scale_matrix[0,1]

    diag_b = self.pixel_scale_matrix[1,0]

    if not np.isclose(diag_a, diag_b, rtol=0.05):

    warnings.warn("The diagonal elements of the pixel scale matrix are not equal: " + repr(diag_a) + " and " + repr(diag_b))

    first = self.pixel_scale_matrix[0,0]

    radians = np.arctan(diag_a / first)

    degrees = radians / math.pi * 180.

    return Angle(degrees, "deg")

    # -----------------------------------------------------------------

    Example 18

    def angularpixelarea(self):

    # get the first instrument element

    instruments = self.tree.xpath("//instruments/*[1]")

    if len(instruments) != 1: raise ValueError("No instruments in ski file")

    instrument = instruments[0]

    # get the distance in m

    d = self.units().convert(instrument.get("distance"), to_unit='m', quantity='distance')

    # get the field of view in m

    fovx = self.units().convert(instrument.get("fieldOfViewX"), to_unit='m', quantity='length')

    fovy = self.units().convert(instrument.get("fieldOfViewY"), to_unit='m', quantity='length')

    # get the number of pixels

    nx = int(instrument.get("pixelsX"))

    ny = int(instrument.get("pixelsY"))

    # calculate the angular pixel area

    sx = 2 * arctan(fovx / nx / d / 2)

    sy = 2 * arctan(fovy / ny / d / 2)

    return sx * sy

    ## This function returns a list of instrument names, in order of occurrence in the ski file.

    Example 19

    def orientation_angle(self):

    """

    This function ...

    :return:

    """

    diag_a = self.pixel_scale_matrix[0,1]

    diag_b = self.pixel_scale_matrix[1,0]

    if not np.isclose(diag_a, diag_b, rtol=0.05):

    warnings.warn("The diagonal elements of the pixel scale matrix are not equal: " + repr(diag_a) + " and " + repr(diag_b))

    first = self.pixel_scale_matrix[0,0]

    radians = np.arctan(diag_a / first)

    degrees = radians / math.pi * 180.

    return Angle(degrees, "deg")

    # -----------------------------------------------------------------

    Example 20

    def conferenceWakeOverlap(X, Y, R):

    n = np.size(X)

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    z = R/np.tan(0.34906585)

    # print z

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    # print 'theta =', theta

    if -0.34906585 < theta < 0.34906585:

    f_theta[i][j] = (1 + np.cos(9*theta))/2

    # print f_theta

    # print z

    # print f_theta

    return f_theta

    Example 21

    def conferenceWakeOverlap_tune(X, Y, R, boundAngle):

    n = np.size(X)

    boundAngle = boundAngle*np.pi/180.0

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    q = np.pi/boundAngle # factor inside the cos term of the smooth Jensen (see Jensen1983 eq.(3))

    # print 'boundAngle = %s' %boundAngle, 'q = %s' %q

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    # z = R/tan(0.34906585)

    z = R/np.tan(boundAngle) # distance from fulcrum to wake producing turbine

    # print z

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    # print 'theta =', theta

    if -boundAngle < theta < boundAngle:

    f_theta[i][j] = (1. + np.cos(q*theta))/2.

    # print f_theta

    # print z

    # print f_theta

    return f_theta

    Example 22

    def get_cosine_factor_original(X, Y, R0, bound_angle=20.0):

    n = np.size(X)

    bound_angle = bound_angle*np.pi/180.0

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    q = np.pi/bound_angle # factor inside the cos term of the smooth Jensen (see Jensen1983 eq.(3))

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    z = R0/np.tan(bound_angle) # distance from fulcrum to wake producing turbine

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    if -bound_angle < theta < bound_angle:

    f_theta[i][j] = (1. + np.cos(q*theta))/2.

    return f_theta

    Example 23

    def rotate(self,rotation_method='RTZ'):

    ####################################################################################

    #rotate-------------------------------------------------------------------------

    for i in range(0,len(self.rf_st)):

    self.rf_st[i].stats.back_azimuth = self.tr_e.stats.sac['baz']

    self.rf_st.rotate(method='NE->RT')

    if rotation_method == 'LQT':

    r_amp = np.amax(np.amax(self.rf_st[1].data))

    z_amp = np.amax(np.amax(self.rf_st[2].data))

    incidence_angle = np.arctan(r_amp/z_amp) * (180.0/np.pi)

    for i in range(0,len(self.rf_st)):

    self.rf_st[i].stats.inclination = incidence_angle

    self.rf_st.rotate(method='RT->NE')

    self.rf_st.rotate(method='ZNE->LQT')

    ####################################################################################

    Example 24

    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

    Example 25

    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

    Example 26

    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))

    Example 27

    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

    Example 28

    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))

    Example 29

    def arrow(img,p1,p2):

    cv2.line(s1,p1,p2,(100,255,100),thickness=2)

    cv2.line(s2,p1,p2,(100,255,100),thickness=2)

    dy,dx= np.array(p2)-np.array(p1)

    theta= np.arctan(dy/dx) + (0 if dx>0 else np.pi) if dx!=0 else (1 if dy>0 else -1) * np.pi/2

    phy1=theta+ np.pi*7/6

    phy2=theta+ np.pi*5/6

    R=0.4*np.linalg.norm([dx,dy])

    dx1,dx2= (R*np.cos([phy1,phy2])).astype(np.int)

    dy1,dy2= (R*np.sin([phy1,phy2])).astype(np.int)

    if R<=2:return

    Y1,X1=p1

    Y2,X2=p2

    cv2.line(s1,(dy1+Y2,dx1+X2),p2,(100,255,100),thickness=1)

    cv2.line(s1,(dy2+Y2,dx2+X2),p2,(100,255,100),thickness=1)

    cv2.line(s2,(dy1+Y2,dx1+X2),p2,(100,255,100),thickness=1)

    cv2.line(s2,(dy2+Y2,dx2+X2),p2,(100,255,100),thickness=1)

    #????????????????

    Example 30

    def convertToOpenGLCameraMatrix(K, framebufferSize, near, far):

    """ Convert a camera calibration matrix into OpenGL format. """

    width, height = framebufferSize

    # print 'framebufferSize:', framebufferSize

    fx = K[0,0]

    fy = K[1,1]

    fovy = 2*np.arctan(0.5*height/fy)#*180/np.pi

    aspect = (width*fy)/(height*fx)

    # define the near and far clipping planes

    # near = 0.1

    # far = 100.0

    # fx = 10.0

    # fy = 10.0

    # fovy = 90*(np.pi/180.0)

    # aspect = (width*fy)/(height*fx)

    proj = openGLPerspectiveMatrix(fovy,aspect,near,far)

    return proj

    Example 31

    def test_auto_size_bits_list():

    pytest.skip()

    a = [0.5, 1.2, 3.2]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == 2

    assert y.right == -15

    a = [np.arctan(2 ** -i) for i in range(8)]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == 0

    assert y.right == -17

    a = [np.arctan(2 ** -i) for i in range(8, 12)]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == -8

    assert y.right == -25

    Example 32

    def load(self, ips):

    if ips.imgtype in ('8-bit', 'rgb'):

    self.para = {'bright':0, 'contrast':45}

    self.view = [('slide', (-100,100), 'Brightness', 'bright', ''),

    ('slide', (1,89), 'Contrast', 'contrast', '')]

    if 'not_slice' in self.note:

    self.note.remove('not_slice')

    else :

    self.arange = minv, maxv = ips.img.min(), ips.img.max()

    self.para = {'bright':np.mean(ips.range) - np.mean(self.arange),

    'contrast':round(np.arctan((maxv-minv)/(ips.range[1]-ips.range[0]))/np.pi*180)}

    self.view = [('slide', (-(maxv-minv)/2, (maxv-minv)/2), 'Brightness', 'bright', ''),

    ('slide', (1,89), 'Contrast', 'contrast', '')]

    if not 'not_slice' in self.note:

    self.note.append('not_slice')

    return True

    Example 33

    def reset_model(self):

    self._min_strike_dist = np.inf

    self._striked = False

    self._strike_pos = None

    qpos = self.init_qpos

    self.ball = np.array([0.5, -0.175])

    while True:

    self.goal = np.concatenate([

    self.np_random.uniform(low=0.15, high=0.7, size=1),

    self.np_random.uniform(low=0.1, high=1.0, size=1)])

    if np.linalg.norm(self.ball - self.goal) > 0.17:

    break

    qpos[-9:-7] = [self.ball[1], self.ball[0]]

    qpos[-7:-5] = self.goal

    diff = self.ball - self.goal

    angle = -np.arctan(diff[0] / (diff[1] + 1e-8))

    qpos[-1] = angle / 3.14

    qvel = self.init_qvel + self.np_random.uniform(low=-.1, high=.1,

    size=self.model.nv)

    qvel[7:] = 0

    self.set_state(qpos, qvel)

    return self._get_obs()

    Example 34

    def FitPCA(self, hPCA_Proj):

    '''

    Determine the timing of the inflation event.

    Uses the first component of the pca projection and

    fits A * arctan( (t - t0) / c ) + B to the first pca projection.

    @param hPCA_Proj: The sklearn PCA projection

    @return [t0, c]

    '''

    fitfunc = lambda p,t: p[0]*np.arctan((t-p[1])/p[2])+p[3]

    errfunc = lambda p,x,y: fitfunc(p,x) - y

    dLen = len(hPCA_Proj[:,0])

    pA, success = optimize.leastsq(errfunc,[1.,dLen/2.,1.,0.],args=(np.arange(dLen),hPCA_Proj[:,0]))

    ct = pA[1:3]

    return ct, pA[0]

    Example 35

    def FitPCA(self, hPCA_Proj):

    '''

    Determine the timing of the inflation event from the first component of the pca projection

    fits A * arctan( (t - t0) / c ) + B to the first pca projection, in order to estimate

    source amplitude parameters

    @param hPCA_Proj: The sklearn PCA

    @return ct: the t0, c, and B parameters from the fit

    @return pA[0]: the fitted amplitude parameter

    '''

    fitfunc = lambda p,t: p[0]*np.arctan((t-p[1])/p[2])+p[3]

    errfunc = lambda p,x,y: fitfunc(p,x) - y

    dLen = len(hPCA_Proj[:,0])

    pA, success = optimize.leastsq(errfunc,[1.,dLen/2.,1.,0.],args=(np.arange(dLen),hPCA_Proj[:,0]))

    ct = pA[1:3]

    return ct, pA[0]

    Example 36

    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

    Example 37

    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))

    Example 38

    def compute_pd_control(self):

    if self.received_data:

    # given the computed wall slope, compute theta, avoid divide by zero error

    if np.abs(self.m) < EPSILON:

    theta = np.pi / 2.0

    x_intercept = 0

    else:

    theta = np.arctan(1.0/self.m)

    # solve for y=0 in y=mx+c

    x_intercept = self.c / self.m

    # x axis is perp. to robot but not perpindicular to wall

    # cosine term solves for minimum distance to wall

    wall_dist = np.abs(np.cos(theta)*x_intercept)

    # control proportional to angular error and distance from wall

    distance_term = self.direction_muliplier * KP * (wall_dist - TARGET_DISTANCE)

    angle_term = KD * theta

    control = angle_term + distance_term

    # avoid turning too sharply

    self.control = (np.clip(control, -0.3, 0.3), SPEED)

    Example 39

    def rotate_image(img_src, angle,scale ,crop=True):

    img_src,size_dest= pad_image(img_src,scale)

    size = tuple(np.array([img_src.shape[1], img_src.shape[0]]))

    org_h=size[1]

    org_w=size[0]

    src_r = np.sqrt((size[0]/2.0)**2+(size[1]/2.0)**2)

    org_angle =np.arctan(float(org_h)/org_w)

    dest_h = size_dest[0]

    dest_w = size_dest[1]

    center = tuple(np.array([img_src.shape[1] * 0.5, img_src.shape[0] * 0.5]))

    dsize= (dest_w,dest_h)

    rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)

    img_rot = cv2.warpAffine(img_src, rotation_matrix, size, flags=cv2.INTER_CUBIC)

    if crop:

    x,y,w,h = cv2.boundingRect(img_rot[:,:,3])

    return img_rot[y:y+h, x:x+w,:]

    else:

    return img_rot

    Example 40

    def rotate_image(img_src, angle,scale ):

    img_src,size_dest= pad_image(img_src,scale)

    size = tuple(np.array([img_src.shape[1], img_src.shape[0]]))

    org_h=size[1]

    org_w=size[0]

    src_r = np.sqrt((size[0]/2.0)**2+(size[1]/2.0)**2)

    org_angle =np.arctan(float(org_h)/org_w)

    dest_h = size_dest[0]

    dest_w = size_dest[1]

    center = tuple(np.array([img_src.shape[1] * 0.5, img_src.shape[0] * 0.5]))

    dsize= (dest_w,dest_h)

    rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)

    img_rot = cv2.warpAffine(img_src, rotation_matrix, size, flags=cv2.INTER_CUBIC)

    x,y,w,h = cv2.boundingRect(img_rot[:,:,3])

    return img_rot[y:y+h, x:x+w,:]

    Example 41

    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

    Example 42

    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))

    Example 43

    def arctan_func(xvals, a, b, c):

    '''

    --------------------------------------------------------------------

    This function generates predicted ability levels given data (xvals)

    and parameters a, b, and c, from the following arctan function:

    y = (-a / pi) * arctan(b * x + c) + (a / 2)

    --------------------------------------------------------------------

    INPUTS:

    xvals = (N,) vector, data inputs to arctan function

    a = scalar, scale parameter for arctan function

    b = scalar, curvature parameter for arctan function

    c = scalar, shift parameter for arctan function

    OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: None

    OBJECTS CREATED WITHIN FUNCTION:

    yvals = (N,) vector, predicted values (output) of arctan function

    RETURNS: yvals

    --------------------------------------------------------------------

    '''

    yvals = (-a / np.pi) * np.arctan(b * xvals + c) + (a / 2)

    return yvals

    Example 44

    def arctan_func(xvals, a, b, c):

    '''

    --------------------------------------------------------------------

    This function generates predicted ability levels given data (xvals)

    and parameters a, b, and c, from the following arctan function:

    y = (-a / pi) * arctan(b * x + c) + (a / 2)

    --------------------------------------------------------------------

    INPUTS:

    xvals = (N,) vector, data inputs to arctan function

    a = scalar, scale parameter for arctan function

    b = scalar, curvature parameter for arctan function

    c = scalar, shift parameter for arctan function

    OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: None

    OBJECTS CREATED WITHIN FUNCTION:

    yvals = (N,) vector, predicted values (output) of arctan function

    RETURNS: yvals

    --------------------------------------------------------------------

    '''

    yvals = (-a / np.pi) * np.arctan(b * xvals + c) + (a / 2)

    return yvals

    Example 45

    def fov(self):

    """

    Returns the field of view for each axis

    """

    return np.float32([np.arctan(self.shape[1] * 0.5 / self.fx),

    np.arctan(self.shape[0] * 0.5 / self.fy)]) * 2.0

    Example 46

    def dynamics(q, u, p):

    """

    Returns state derivative qdot.

    Takes current state q, motor input torque u, and disturbance torque p.

    See (rederived with incline).

    """

    # Angle of pendulum in incline frame

    ang = q[2] - incline

    # Mass matrix

    M = np.array([

    [(mass_wheel + mass_pend)*radius**2 + inertia_wheel, mass_pend*radius*cw_to_cm[1]*np.cos(ang)],

    [mass_pend*radius*cw_to_cm[1]*np.cos(ang), inertia_pend + mass_pend*cw_to_cm[1]**2]

    ])

    # Gravity effect

    g = np.array([

    -mass_pend*radius*cw_to_cm[1]*q[3]**2*np.sin(ang) + mass_wheel*radius*gravity[1]*np.sin(incline),

    mass_pend*gravity[1]*cw_to_cm[1]*np.sin(q[2])

    ])

    # Friction force

    d = np.array([

    -friction_wheel * (q[1] + np.arctan(q[1])),

    friction_pend * q[3]

    ])

    # Dynamics

    accel_wheel_neg, accel_pend = npl.inv(M).dot(np.array([-u, p+u]) - g - d)

    return np.array([q[1], -accel_wheel_neg*radius, q[3], accel_pend])

    ################################################# SIMULATION

    # Define time domain

    Example 47

    def cart2sph(x, y, z):

    """ Convert cartesian to spherical coordinates.

    Attributes

    ----------

    x : float

    x-coordinate

    y : float

    y-coordinate

    z : float

    z-coordinate

    Returns

    -------

    float

    radius

    float

    aziumth

    float

    elevation

    """

    r = np.sqrt(x**2 + y**2 + z**2)

    if x > 0 and y > 0:

    az = np.arctan(y / x)

    elif x > 0 and y < 0:

    az = 2*np.pi - np.arctan(-y / x)

    elif x < 0 and y > 0:

    az = np.pi - np.arctan(-y / x)

    elif x < 0 and y < 0:

    az = np.pi + np.arctan(y / x)

    elif x == 0 and y > 0:

    az = np.pi / 2

    elif x == 0 and y < 0:

    az = 3 * np.pi / 2

    elif y == 0 and x > 0:

    az = 0

    elif y == 0 and x < 0:

    az = np.pi

    elev = np.arccos(z / r)

    return r, az, elev

    Example 48

    def ellipse_angle_of_rotation( a ):

    b,c,d,f,g,a = a[1]/2, a[2], a[3]/2, a[4]/2, a[5], a[0]

    return 0.5*NP.arctan(2*b/(a-c))

    Example 49

    def ellipse_angle_of_rotation2( a ):

    b,c,d,f,g,a = a[1]/2, a[2], a[3]/2, a[4]/2, a[5], a[0]

    if b == 0:

    if a > c:

    return 0

    else:

    return NP.pi/2

    else:

    if a > c:

    return NP.arctan(2*b/(a-c))/2

    else:

    return NP.pi/2 + NP.arctan(2*b/(a-c))/2

    Example 50

    def radial_filter(order, freq, array_configuration, amp_maxdB=40):

    """Generate modal radial filter of specified order and frequency

    Parameters

    ----------

    order : array_like

    order of filter

    freq : array_like

    Frequency of modal filter

    array_configuration : ArrayConfiguration

    List/Tuple/ArrayConfiguration, see io.ArrayConfiguration

    amp_maxdB : int, optional

    Maximum modal amplification limit in dB [Default: 40]

    Returns

    -------

    dn : array_like

    Vector of modal frequency domain filter of shape [nOrders x nFreq]

    """

    array_configuration = ArrayConfiguration(*array_configuration)

    extrapolation_coeffs = array_extrapolation(order, freq, array_configuration)

    extrapolation_coeffs[extrapolation_coeffs == 0] = 1e-12

    a_max = 10 ** (amp_maxdB / 20)

    limiting_factor = 2 * a_max / _np.pi * _np.abs(extrapolation_coeffs) * _np.arctan(_np.pi / (2 * a_max * _np.abs(extrapolation_coeffs)))

    return limiting_factor / extrapolation_coeffs

    展开全文
  • 参考链接: Python中的numpy.arcsinThe following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the ...

    参考链接: Python中的numpy.arcsin

    The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

    Example 1

    def get_polar_t(self):

    mag = self.get_magnitude()

    sizeimg = np.real(self.imgfft).shape

    pol = np.zeros(sizeimg)

    for x in range(sizeimg[0]):

    for y in range(sizeimg[1]):

    my = y - sizeimg[1] / 2

    mx = x - sizeimg[0] / 2

    if mx != 0:

    phi = np.arctan(my / float(mx))

    else:

    phi = 0

    r = np.sqrt(mx**2 + my **2)

    ix = map_range(phi, -np.pi, np.pi, sizeimg[0], 0)

    iy = map_range(r, 0, sizeimg[0], 0, sizeimg[1])

    if ix >= 0 and ix < sizeimg[0] and iy >= 0 and iy < sizeimg[1]:

    pol[x][y] = mag.data[int(ix)][int(iy)]

    pol = MyImage(pol)

    pol.limit(1)

    return pol

    Example 2

    def calc_IndCurrent_cos_range(self,f,t):

    """Induced current over a range of times"""

    Bpx = self.Bpx

    Bpz = self.Bpz

    a2 = self.a2

    azm = np.pi*self.azm/180.

    R = self.R

    L = self.L

    w = 2*np.pi*f

    Ax = np.pi*a2**2*np.sin(azm)

    Az = np.pi*a2**2*np.cos(azm)

    Phi = (Ax*Bpx + Az*Bpz)

    phi = np.arctan(R/(w*L))-np.pi # This is the phase and not phase lag

    Is = -(w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.cos(w*t + phi)

    Ire = -(w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.cos(w*t)*np.cos(phi)

    Iim = (w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.sin(w*t)*np.sin(phi)

    return Ire,Iim,Is,phi

    Example 3

    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

    Example 4

    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))

    Example 5

    def effect(self, point):

    res = []

    # print(self.centers)

    for center in self.centers:

    center_x, center_y = center

    src_x, src_y = point.pos

    # Check angle

    angle = np.arctan((center_x - src_x) / (center_y - src_y))

    if np.abs(angle) > self.angle / 2:

    continue

    angle = np.deg2rad(90) + angle

    u_len = np.sqrt((center_x - src_x) ** 2 + (center_y - src_y) ** 2)

    reverse_v = (self.r_index - 1) / self.radius - self.r_index / u_len

    v_len = 1 / reverse_v

    if v_len > 0:

    p_type = 'real'

    else:

    p_type = 'fake'

    target = line_end(point.pos, angle, u_len + v_len)

    p = Point(target, p_type, 1)

    # point.passed.append(self)

    res.append(p)

    return tuple(res)

    Example 6

    def _radian_direction(dy,dx):

    '''

    function:

    - based on given dy and dx it calculates direction in radian.

    - used in feature_eng_pt3

    input:

    dy = change in y

    dx = change in x

    output:

    returns radian value (0 to 6.28)

    '''

    if dy < 0.0 and dx > 0.0:

    return (2*np.pi + np.arctan(dy/dx))

    elif dy >=0.0 and dx > 0.0:

    return (np.arctan(dy/dx))

    else:

    return np.pi + np.arctan(dy/dx)

    Example 7

    def flow(self, Kc, Ks, Kz, Ka, numexpr):

    zeros = np.zeros

    where = np.where

    min = np.minimum

    max = np.maximum

    abs = np.absolute

    arctan = np.arctan

    sin = np.sin

    center = (slice( 1, -1,None),slice( 1, -1,None))

    rock = self.center

    ds = self.scour[center]

    rcc = rock[center]

    rock[center] = rcc - ds * Kz

    # there isn't really a bottom to the rock but negative values look ugly

    rock[center] = where(rcc<0,0,rcc)

    Example 8

    def fixOffset(self, offset, img):

    size = img.shape

    finalImg = np.ndarray(size)

    indices = np.indices((self.videoSize[0],self.videoSize[1])).swapaxes(0,2).swapaxes(0,1)

    indices = np.around(indices, decimals=1)

    indices.shape = (self.videoSize[1] * self.videoSize[0], 2)

    phi = 2 * np.arctan(np.exp(indices[:, 1] / self.videoSize[1])) - 1/2 * np.pi - offset[0]

    lamb = indices[:, 0] - offset[1]

    x = lamb

    y = np.log(np.tan(np.pi / 4 + 1/2 * phi)) * self.videoSize[1]

    finalIdx = np.ndarray((self.videoSize[1] * self.videoSize[0], 2))

    finalIdx = np.around(finalIdx, decimals=1).astype(int)

    finalIdx[:, 1] = y % self.videoSize[1]

    finalIdx[:, 0] = x % self.videoSize[0]

    finalImg[indices[:,1], indices[:,0]] = img[finalIdx[:,1], finalIdx[:,0]]

    return finalImg

    Example 9

    def _dip_slip_y(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    y = down-dip direction

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    y_bar = y2*cs + q*sn

    a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a1 = 2.0*poisson*(-y1/(cs*(r+d_bar))) - sn/cs * a5

    f = -(y_bar*q/r/(r+y1) + cs*numpy.arctan(y1*y2/q/r) - a1*sn*cs)/(2.0*3.14159)

    return f

    Example 10

    def _dip_slip_x(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    Added by Xiaoming Wang

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    #a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a4 = 2.0*poisson/cs*(numpy.log(r+d_bar) - sn*numpy.log(r+y2))

    ytilde = y2*cs + q*sn

    a3 = 2.0*poisson*(ytilde/(cs*(r+d_bar)) - numpy.log(r+y2)) + a4*sn/cs

    f = -(q/r - a3*sn*cs)/(2.0*3.14159)

    return f

    Example 11

    def _dip_slip_x(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    Added by Xiaoming Wang

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    #a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a4 = 2.0*poisson/cs*(numpy.log(r+d_bar) - sn*numpy.log(r+y2))

    ytilde = y2*cs + q*sn

    a3 = 2.0*poisson*(ytilde/(cs*(r+d_bar)) - numpy.log(r+y2)) + a4*sn/cs

    f = -(q/r - a3*sn*cs)/(2.0*3.14159)

    return f

    Example 12

    def get_q_per_pixel(self):

    '''Gets the delta-q associated with a single pixel. This is computed in

    the small-angle limit, so it should only be considered approximate.

    For instance, wide-angle detectors will have different delta-q across

    the detector face.'''

    if self.q_per_pixel is not None:

    return self.q_per_pixel

    c = (self.pixel_size_um/1e6)/self.distance_m

    twotheta = np.arctan(c) # radians

    self.q_per_pixel = 2.0*self.get_k()*np.sin(twotheta/2.0)

    return self.q_per_pixel

    # Maps

    ########################################

    Example 13

    def reset_model(self):

    self._min_strike_dist = np.inf

    self._striked = False

    self._strike_pos = None

    qpos = self.init_qpos

    self.ball = np.array([0.5, -0.175])

    while True:

    self.goal = np.concatenate([

    self.np_random.uniform(low=0.15, high=0.7, size=1),

    self.np_random.uniform(low=0.1, high=1.0, size=1)])

    if np.linalg.norm(self.ball - self.goal) > 0.17:

    break

    qpos[-9:-7] = [self.ball[1], self.ball[0]]

    qpos[-7:-5] = self.goal

    diff = self.ball - self.goal

    angle = -np.arctan(diff[0] / (diff[1] + 1e-8))

    qpos[-1] = angle / 3.14

    qvel = self.init_qvel + self.np_random.uniform(low=-.1, high=.1,

    size=self.model.nv)

    qvel[7:] = 0

    self.set_state(qpos, qvel)

    return self._get_obs()

    Example 14

    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

    Example 15

    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))

    Example 16

    def angularpixelarea(self):

    # get the first instrument element

    instruments = self.tree.xpath("//instruments/*[1]")

    if len(instruments) != 1: raise ValueError("No instruments in ski file")

    instrument = instruments[0]

    # get the distance in m

    d = self.units().convert(instrument.get("distance"), to_unit='m', quantity='distance')

    # get the field of view in m

    fovx = self.units().convert(instrument.get("fieldOfViewX"), to_unit='m', quantity='length')

    fovy = self.units().convert(instrument.get("fieldOfViewY"), to_unit='m', quantity='length')

    # get the number of pixels

    nx = int(instrument.get("pixelsX"))

    ny = int(instrument.get("pixelsY"))

    # calculate the angular pixel area

    sx = 2 * arctan(fovx / nx / d / 2)

    sy = 2 * arctan(fovy / ny / d / 2)

    return sx * sy

    ## This function returns a list of instrument names, in order of occurrence in the ski file.

    Example 17

    def orientation_angle(self):

    """

    This function ...

    :return:

    """

    diag_a = self.pixel_scale_matrix[0,1]

    diag_b = self.pixel_scale_matrix[1,0]

    if not np.isclose(diag_a, diag_b, rtol=0.05):

    warnings.warn("The diagonal elements of the pixel scale matrix are not equal: " + repr(diag_a) + " and " + repr(diag_b))

    first = self.pixel_scale_matrix[0,0]

    radians = np.arctan(diag_a / first)

    degrees = radians / math.pi * 180.

    return Angle(degrees, "deg")

    # -----------------------------------------------------------------

    Example 18

    def angularpixelarea(self):

    # get the first instrument element

    instruments = self.tree.xpath("//instruments/*[1]")

    if len(instruments) != 1: raise ValueError("No instruments in ski file")

    instrument = instruments[0]

    # get the distance in m

    d = self.units().convert(instrument.get("distance"), to_unit='m', quantity='distance')

    # get the field of view in m

    fovx = self.units().convert(instrument.get("fieldOfViewX"), to_unit='m', quantity='length')

    fovy = self.units().convert(instrument.get("fieldOfViewY"), to_unit='m', quantity='length')

    # get the number of pixels

    nx = int(instrument.get("pixelsX"))

    ny = int(instrument.get("pixelsY"))

    # calculate the angular pixel area

    sx = 2 * arctan(fovx / nx / d / 2)

    sy = 2 * arctan(fovy / ny / d / 2)

    return sx * sy

    ## This function returns a list of instrument names, in order of occurrence in the ski file.

    Example 19

    def orientation_angle(self):

    """

    This function ...

    :return:

    """

    diag_a = self.pixel_scale_matrix[0,1]

    diag_b = self.pixel_scale_matrix[1,0]

    if not np.isclose(diag_a, diag_b, rtol=0.05):

    warnings.warn("The diagonal elements of the pixel scale matrix are not equal: " + repr(diag_a) + " and " + repr(diag_b))

    first = self.pixel_scale_matrix[0,0]

    radians = np.arctan(diag_a / first)

    degrees = radians / math.pi * 180.

    return Angle(degrees, "deg")

    # -----------------------------------------------------------------

    Example 20

    def conferenceWakeOverlap(X, Y, R):

    n = np.size(X)

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    z = R/np.tan(0.34906585)

    # print z

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    # print 'theta =', theta

    if -0.34906585 < theta < 0.34906585:

    f_theta[i][j] = (1 + np.cos(9*theta))/2

    # print f_theta

    # print z

    # print f_theta

    return f_theta

    Example 21

    def conferenceWakeOverlap_tune(X, Y, R, boundAngle):

    n = np.size(X)

    boundAngle = boundAngle*np.pi/180.0

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    q = np.pi/boundAngle # factor inside the cos term of the smooth Jensen (see Jensen1983 eq.(3))

    # print 'boundAngle = %s' %boundAngle, 'q = %s' %q

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    # z = R/tan(0.34906585)

    z = R/np.tan(boundAngle) # distance from fulcrum to wake producing turbine

    # print z

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    # print 'theta =', theta

    if -boundAngle < theta < boundAngle:

    f_theta[i][j] = (1. + np.cos(q*theta))/2.

    # print f_theta

    # print z

    # print f_theta

    return f_theta

    Example 22

    def get_cosine_factor_original(X, Y, R0, bound_angle=20.0):

    n = np.size(X)

    bound_angle = bound_angle*np.pi/180.0

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    q = np.pi/bound_angle # factor inside the cos term of the smooth Jensen (see Jensen1983 eq.(3))

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    z = R0/np.tan(bound_angle) # distance from fulcrum to wake producing turbine

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    if -bound_angle < theta < bound_angle:

    f_theta[i][j] = (1. + np.cos(q*theta))/2.

    return f_theta

    Example 23

    def rotate(self,rotation_method='RTZ'):

    ####################################################################################

    #rotate-------------------------------------------------------------------------

    for i in range(0,len(self.rf_st)):

    self.rf_st[i].stats.back_azimuth = self.tr_e.stats.sac['baz']

    self.rf_st.rotate(method='NE->RT')

    if rotation_method == 'LQT':

    r_amp = np.amax(np.amax(self.rf_st[1].data))

    z_amp = np.amax(np.amax(self.rf_st[2].data))

    incidence_angle = np.arctan(r_amp/z_amp) * (180.0/np.pi)

    for i in range(0,len(self.rf_st)):

    self.rf_st[i].stats.inclination = incidence_angle

    self.rf_st.rotate(method='RT->NE')

    self.rf_st.rotate(method='ZNE->LQT')

    ####################################################################################

    Example 24

    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

    Example 25

    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

    Example 26

    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))

    Example 27

    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

    Example 28

    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))

    Example 29

    def arrow(img,p1,p2):

    cv2.line(s1,p1,p2,(100,255,100),thickness=2)

    cv2.line(s2,p1,p2,(100,255,100),thickness=2)

    dy,dx= np.array(p2)-np.array(p1)

    theta= np.arctan(dy/dx) + (0 if dx>0 else np.pi) if dx!=0 else (1 if dy>0 else -1) * np.pi/2

    phy1=theta+ np.pi*7/6

    phy2=theta+ np.pi*5/6

    R=0.4*np.linalg.norm([dx,dy])

    dx1,dx2= (R*np.cos([phy1,phy2])).astype(np.int)

    dy1,dy2= (R*np.sin([phy1,phy2])).astype(np.int)

    if R<=2:return

    Y1,X1=p1

    Y2,X2=p2

    cv2.line(s1,(dy1+Y2,dx1+X2),p2,(100,255,100),thickness=1)

    cv2.line(s1,(dy2+Y2,dx2+X2),p2,(100,255,100),thickness=1)

    cv2.line(s2,(dy1+Y2,dx1+X2),p2,(100,255,100),thickness=1)

    cv2.line(s2,(dy2+Y2,dx2+X2),p2,(100,255,100),thickness=1)

    #????????????????

    Example 30

    def convertToOpenGLCameraMatrix(K, framebufferSize, near, far):

    """ Convert a camera calibration matrix into OpenGL format. """

    width, height = framebufferSize

    # print 'framebufferSize:', framebufferSize

    fx = K[0,0]

    fy = K[1,1]

    fovy = 2*np.arctan(0.5*height/fy)#*180/np.pi

    aspect = (width*fy)/(height*fx)

    # define the near and far clipping planes

    # near = 0.1

    # far = 100.0

    # fx = 10.0

    # fy = 10.0

    # fovy = 90*(np.pi/180.0)

    # aspect = (width*fy)/(height*fx)

    proj = openGLPerspectiveMatrix(fovy,aspect,near,far)

    return proj

    Example 31

    def test_auto_size_bits_list():

    pytest.skip()

    a = [0.5, 1.2, 3.2]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == 2

    assert y.right == -15

    a = [np.arctan(2 ** -i) for i in range(8)]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == 0

    assert y.right == -17

    a = [np.arctan(2 ** -i) for i in range(8, 12)]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == -8

    assert y.right == -25

    Example 32

    def load(self, ips):

    if ips.imgtype in ('8-bit', 'rgb'):

    self.para = {'bright':0, 'contrast':45}

    self.view = [('slide', (-100,100), 'Brightness', 'bright', ''),

    ('slide', (1,89), 'Contrast', 'contrast', '')]

    if 'not_slice' in self.note:

    self.note.remove('not_slice')

    else :

    self.arange = minv, maxv = ips.img.min(), ips.img.max()

    self.para = {'bright':np.mean(ips.range) - np.mean(self.arange),

    'contrast':round(np.arctan((maxv-minv)/(ips.range[1]-ips.range[0]))/np.pi*180)}

    self.view = [('slide', (-(maxv-minv)/2, (maxv-minv)/2), 'Brightness', 'bright', ''),

    ('slide', (1,89), 'Contrast', 'contrast', '')]

    if not 'not_slice' in self.note:

    self.note.append('not_slice')

    return True

    Example 33

    def reset_model(self):

    self._min_strike_dist = np.inf

    self._striked = False

    self._strike_pos = None

    qpos = self.init_qpos

    self.ball = np.array([0.5, -0.175])

    while True:

    self.goal = np.concatenate([

    self.np_random.uniform(low=0.15, high=0.7, size=1),

    self.np_random.uniform(low=0.1, high=1.0, size=1)])

    if np.linalg.norm(self.ball - self.goal) > 0.17:

    break

    qpos[-9:-7] = [self.ball[1], self.ball[0]]

    qpos[-7:-5] = self.goal

    diff = self.ball - self.goal

    angle = -np.arctan(diff[0] / (diff[1] + 1e-8))

    qpos[-1] = angle / 3.14

    qvel = self.init_qvel + self.np_random.uniform(low=-.1, high=.1,

    size=self.model.nv)

    qvel[7:] = 0

    self.set_state(qpos, qvel)

    return self._get_obs()

    Example 34

    def FitPCA(self, hPCA_Proj):

    '''

    Determine the timing of the inflation event.

    Uses the first component of the pca projection and

    fits A * arctan( (t - t0) / c ) + B to the first pca projection.

    @param hPCA_Proj: The sklearn PCA projection

    @return [t0, c]

    '''

    fitfunc = lambda p,t: p[0]*np.arctan((t-p[1])/p[2])+p[3]

    errfunc = lambda p,x,y: fitfunc(p,x) - y

    dLen = len(hPCA_Proj[:,0])

    pA, success = optimize.leastsq(errfunc,[1.,dLen/2.,1.,0.],args=(np.arange(dLen),hPCA_Proj[:,0]))

    ct = pA[1:3]

    return ct, pA[0]

    Example 35

    def FitPCA(self, hPCA_Proj):

    '''

    Determine the timing of the inflation event from the first component of the pca projection

    fits A * arctan( (t - t0) / c ) + B to the first pca projection, in order to estimate

    source amplitude parameters

    @param hPCA_Proj: The sklearn PCA

    @return ct: the t0, c, and B parameters from the fit

    @return pA[0]: the fitted amplitude parameter

    '''

    fitfunc = lambda p,t: p[0]*np.arctan((t-p[1])/p[2])+p[3]

    errfunc = lambda p,x,y: fitfunc(p,x) - y

    dLen = len(hPCA_Proj[:,0])

    pA, success = optimize.leastsq(errfunc,[1.,dLen/2.,1.,0.],args=(np.arange(dLen),hPCA_Proj[:,0]))

    ct = pA[1:3]

    return ct, pA[0]

    Example 36

    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

    Example 37

    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))

    Example 38

    def compute_pd_control(self):

    if self.received_data:

    # given the computed wall slope, compute theta, avoid divide by zero error

    if np.abs(self.m) < EPSILON:

    theta = np.pi / 2.0

    x_intercept = 0

    else:

    theta = np.arctan(1.0/self.m)

    # solve for y=0 in y=mx+c

    x_intercept = self.c / self.m

    # x axis is perp. to robot but not perpindicular to wall

    # cosine term solves for minimum distance to wall

    wall_dist = np.abs(np.cos(theta)*x_intercept)

    # control proportional to angular error and distance from wall

    distance_term = self.direction_muliplier * KP * (wall_dist - TARGET_DISTANCE)

    angle_term = KD * theta

    control = angle_term + distance_term

    # avoid turning too sharply

    self.control = (np.clip(control, -0.3, 0.3), SPEED)

    Example 39

    def rotate_image(img_src, angle,scale ,crop=True):

    img_src,size_dest= pad_image(img_src,scale)

    size = tuple(np.array([img_src.shape[1], img_src.shape[0]]))

    org_h=size[1]

    org_w=size[0]

    src_r = np.sqrt((size[0]/2.0)**2+(size[1]/2.0)**2)

    org_angle =np.arctan(float(org_h)/org_w)

    dest_h = size_dest[0]

    dest_w = size_dest[1]

    center = tuple(np.array([img_src.shape[1] * 0.5, img_src.shape[0] * 0.5]))

    dsize= (dest_w,dest_h)

    rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)

    img_rot = cv2.warpAffine(img_src, rotation_matrix, size, flags=cv2.INTER_CUBIC)

    if crop:

    x,y,w,h = cv2.boundingRect(img_rot[:,:,3])

    return img_rot[y:y+h, x:x+w,:]

    else:

    return img_rot

    Example 40

    def rotate_image(img_src, angle,scale ):

    img_src,size_dest= pad_image(img_src,scale)

    size = tuple(np.array([img_src.shape[1], img_src.shape[0]]))

    org_h=size[1]

    org_w=size[0]

    src_r = np.sqrt((size[0]/2.0)**2+(size[1]/2.0)**2)

    org_angle =np.arctan(float(org_h)/org_w)

    dest_h = size_dest[0]

    dest_w = size_dest[1]

    center = tuple(np.array([img_src.shape[1] * 0.5, img_src.shape[0] * 0.5]))

    dsize= (dest_w,dest_h)

    rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)

    img_rot = cv2.warpAffine(img_src, rotation_matrix, size, flags=cv2.INTER_CUBIC)

    x,y,w,h = cv2.boundingRect(img_rot[:,:,3])

    return img_rot[y:y+h, x:x+w,:]

    Example 41

    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

    Example 42

    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))

    Example 43

    def arctan_func(xvals, a, b, c):

    '''

    --------------------------------------------------------------------

    This function generates predicted ability levels given data (xvals)

    and parameters a, b, and c, from the following arctan function:

    y = (-a / pi) * arctan(b * x + c) + (a / 2)

    --------------------------------------------------------------------

    INPUTS:

    xvals = (N,) vector, data inputs to arctan function

    a = scalar, scale parameter for arctan function

    b = scalar, curvature parameter for arctan function

    c = scalar, shift parameter for arctan function

    OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: None

    OBJECTS CREATED WITHIN FUNCTION:

    yvals = (N,) vector, predicted values (output) of arctan function

    RETURNS: yvals

    --------------------------------------------------------------------

    '''

    yvals = (-a / np.pi) * np.arctan(b * xvals + c) + (a / 2)

    return yvals

    Example 44

    def arctan_func(xvals, a, b, c):

    '''

    --------------------------------------------------------------------

    This function generates predicted ability levels given data (xvals)

    and parameters a, b, and c, from the following arctan function:

    y = (-a / pi) * arctan(b * x + c) + (a / 2)

    --------------------------------------------------------------------

    INPUTS:

    xvals = (N,) vector, data inputs to arctan function

    a = scalar, scale parameter for arctan function

    b = scalar, curvature parameter for arctan function

    c = scalar, shift parameter for arctan function

    OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: None

    OBJECTS CREATED WITHIN FUNCTION:

    yvals = (N,) vector, predicted values (output) of arctan function

    RETURNS: yvals

    --------------------------------------------------------------------

    '''

    yvals = (-a / np.pi) * np.arctan(b * xvals + c) + (a / 2)

    return yvals

    Example 45

    def fov(self):

    """

    Returns the field of view for each axis

    """

    return np.float32([np.arctan(self.shape[1] * 0.5 / self.fx),

    np.arctan(self.shape[0] * 0.5 / self.fy)]) * 2.0

    Example 46

    def dynamics(q, u, p):

    """

    Returns state derivative qdot.

    Takes current state q, motor input torque u, and disturbance torque p.

    See (rederived with incline).

    """

    # Angle of pendulum in incline frame

    ang = q[2] - incline

    # Mass matrix

    M = np.array([

    [(mass_wheel + mass_pend)*radius**2 + inertia_wheel, mass_pend*radius*cw_to_cm[1]*np.cos(ang)],

    [mass_pend*radius*cw_to_cm[1]*np.cos(ang), inertia_pend + mass_pend*cw_to_cm[1]**2]

    ])

    # Gravity effect

    g = np.array([

    -mass_pend*radius*cw_to_cm[1]*q[3]**2*np.sin(ang) + mass_wheel*radius*gravity[1]*np.sin(incline),

    mass_pend*gravity[1]*cw_to_cm[1]*np.sin(q[2])

    ])

    # Friction force

    d = np.array([

    -friction_wheel * (q[1] + np.arctan(q[1])),

    friction_pend * q[3]

    ])

    # Dynamics

    accel_wheel_neg, accel_pend = npl.inv(M).dot(np.array([-u, p+u]) - g - d)

    return np.array([q[1], -accel_wheel_neg*radius, q[3], accel_pend])

    ################################################# SIMULATION

    # Define time domain

    Example 47

    def cart2sph(x, y, z):

    """ Convert cartesian to spherical coordinates.

    Attributes

    ----------

    x : float

    x-coordinate

    y : float

    y-coordinate

    z : float

    z-coordinate

    Returns

    -------

    float

    radius

    float

    aziumth

    float

    elevation

    """

    r = np.sqrt(x**2 + y**2 + z**2)

    if x > 0 and y > 0:

    az = np.arctan(y / x)

    elif x > 0 and y < 0:

    az = 2*np.pi - np.arctan(-y / x)

    elif x < 0 and y > 0:

    az = np.pi - np.arctan(-y / x)

    elif x < 0 and y < 0:

    az = np.pi + np.arctan(y / x)

    elif x == 0 and y > 0:

    az = np.pi / 2

    elif x == 0 and y < 0:

    az = 3 * np.pi / 2

    elif y == 0 and x > 0:

    az = 0

    elif y == 0 and x < 0:

    az = np.pi

    elev = np.arccos(z / r)

    return r, az, elev

    Example 48

    def ellipse_angle_of_rotation( a ):

    b,c,d,f,g,a = a[1]/2, a[2], a[3]/2, a[4]/2, a[5], a[0]

    return 0.5*NP.arctan(2*b/(a-c))

    Example 49

    def ellipse_angle_of_rotation2( a ):

    b,c,d,f,g,a = a[1]/2, a[2], a[3]/2, a[4]/2, a[5], a[0]

    if b == 0:

    if a > c:

    return 0

    else:

    return NP.pi/2

    else:

    if a > c:

    return NP.arctan(2*b/(a-c))/2

    else:

    return NP.pi/2 + NP.arctan(2*b/(a-c))/2

    Example 50

    def radial_filter(order, freq, array_configuration, amp_maxdB=40):

    """Generate modal radial filter of specified order and frequency

    Parameters

    ----------

    order : array_like

    order of filter

    freq : array_like

    Frequency of modal filter

    array_configuration : ArrayConfiguration

    List/Tuple/ArrayConfiguration, see io.ArrayConfiguration

    amp_maxdB : int, optional

    Maximum modal amplification limit in dB [Default: 40]

    Returns

    -------

    dn : array_like

    Vector of modal frequency domain filter of shape [nOrders x nFreq]

    """

    array_configuration = ArrayConfiguration(*array_configuration)

    extrapolation_coeffs = array_extrapolation(order, freq, array_configuration)

    extrapolation_coeffs[extrapolation_coeffs == 0] = 1e-12

    a_max = 10 ** (amp_maxdB / 20)

    limiting_factor = 2 * a_max / _np.pi * _np.abs(extrapolation_coeffs) * _np.arctan(_np.pi / (2 * a_max * _np.abs(extrapolation_coeffs)))

    return limiting_factor / extrapolation_coeffs

    展开全文
  • The following are code examples for showing how to ... They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can al...

    The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

    Example 1

    def get_polar_t(self):

    mag = self.get_magnitude()

    sizeimg = np.real(self.imgfft).shape

    pol = np.zeros(sizeimg)

    for x in range(sizeimg[0]):

    for y in range(sizeimg[1]):

    my = y - sizeimg[1] / 2

    mx = x - sizeimg[0] / 2

    if mx != 0:

    phi = np.arctan(my / float(mx))

    else:

    phi = 0

    r = np.sqrt(mx**2 + my **2)

    ix = map_range(phi, -np.pi, np.pi, sizeimg[0], 0)

    iy = map_range(r, 0, sizeimg[0], 0, sizeimg[1])

    if ix >= 0 and ix < sizeimg[0] and iy >= 0 and iy < sizeimg[1]:

    pol[x][y] = mag.data[int(ix)][int(iy)]

    pol = MyImage(pol)

    pol.limit(1)

    return pol

    Example 2

    def calc_IndCurrent_cos_range(self,f,t):

    """Induced current over a range of times"""

    Bpx = self.Bpx

    Bpz = self.Bpz

    a2 = self.a2

    azm = np.pi*self.azm/180.

    R = self.R

    L = self.L

    w = 2*np.pi*f

    Ax = np.pi*a2**2*np.sin(azm)

    Az = np.pi*a2**2*np.cos(azm)

    Phi = (Ax*Bpx + Az*Bpz)

    phi = np.arctan(R/(w*L))-np.pi # This is the phase and not phase lag

    Is = -(w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.cos(w*t + phi)

    Ire = -(w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.cos(w*t)*np.cos(phi)

    Iim = (w*Phi/(R*np.sin(phi) + w*L*np.cos(phi)))*np.sin(w*t)*np.sin(phi)

    return Ire,Iim,Is,phi

    Example 3

    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

    Example 4

    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))

    Example 5

    def effect(self, point):

    res = []

    # print(self.centers)

    for center in self.centers:

    center_x, center_y = center

    src_x, src_y = point.pos

    # Check angle

    angle = np.arctan((center_x - src_x) / (center_y - src_y))

    if np.abs(angle) > self.angle / 2:

    continue

    angle = np.deg2rad(90) + angle

    u_len = np.sqrt((center_x - src_x) ** 2 + (center_y - src_y) ** 2)

    reverse_v = (self.r_index - 1) / self.radius - self.r_index / u_len

    v_len = 1 / reverse_v

    if v_len > 0:

    p_type = 'real'

    else:

    p_type = 'fake'

    target = line_end(point.pos, angle, u_len + v_len)

    p = Point(target, p_type, 1)

    # point.passed.append(self)

    res.append(p)

    return tuple(res)

    Example 6

    def _radian_direction(dy,dx):

    '''

    function:

    - based on given dy and dx it calculates direction in radian.

    - used in feature_eng_pt3

    input:

    dy = change in y

    dx = change in x

    output:

    returns radian value (0 to 6.28)

    '''

    if dy < 0.0 and dx > 0.0:

    return (2*np.pi + np.arctan(dy/dx))

    elif dy >=0.0 and dx > 0.0:

    return (np.arctan(dy/dx))

    else:

    return np.pi + np.arctan(dy/dx)

    Example 7

    def flow(self, Kc, Ks, Kz, Ka, numexpr):

    zeros = np.zeros

    where = np.where

    min = np.minimum

    max = np.maximum

    abs = np.absolute

    arctan = np.arctan

    sin = np.sin

    center = (slice( 1, -1,None),slice( 1, -1,None))

    rock = self.center

    ds = self.scour[center]

    rcc = rock[center]

    rock[center] = rcc - ds * Kz

    # there isn't really a bottom to the rock but negative values look ugly

    rock[center] = where(rcc<0,0,rcc)

    Example 8

    def fixOffset(self, offset, img):

    size = img.shape

    finalImg = np.ndarray(size)

    indices = np.indices((self.videoSize[0],self.videoSize[1])).swapaxes(0,2).swapaxes(0,1)

    indices = np.around(indices, decimals=1)

    indices.shape = (self.videoSize[1] * self.videoSize[0], 2)

    phi = 2 * np.arctan(np.exp(indices[:, 1] / self.videoSize[1])) - 1/2 * np.pi - offset[0]

    lamb = indices[:, 0] - offset[1]

    x = lamb

    y = np.log(np.tan(np.pi / 4 + 1/2 * phi)) * self.videoSize[1]

    finalIdx = np.ndarray((self.videoSize[1] * self.videoSize[0], 2))

    finalIdx = np.around(finalIdx, decimals=1).astype(int)

    finalIdx[:, 1] = y % self.videoSize[1]

    finalIdx[:, 0] = x % self.videoSize[0]

    finalImg[indices[:,1], indices[:,0]] = img[finalIdx[:,1], finalIdx[:,0]]

    return finalImg

    Example 9

    def _dip_slip_y(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    y = down-dip direction

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    y_bar = y2*cs + q*sn

    a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a1 = 2.0*poisson*(-y1/(cs*(r+d_bar))) - sn/cs * a5

    f = -(y_bar*q/r/(r+y1) + cs*numpy.arctan(y1*y2/q/r) - a1*sn*cs)/(2.0*3.14159)

    return f

    Example 10

    def _dip_slip_x(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    Added by Xiaoming Wang

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    #a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a4 = 2.0*poisson/cs*(numpy.log(r+d_bar) - sn*numpy.log(r+y2))

    ytilde = y2*cs + q*sn

    a3 = 2.0*poisson*(ytilde/(cs*(r+d_bar)) - numpy.log(r+y2)) + a4*sn/cs

    f = -(q/r - a3*sn*cs)/(2.0*3.14159)

    return f

    Example 11

    def _dip_slip_x(self, y1, y2, ang_dip, q):

    """

    Based on Okada's paper (1985)

    Added by Xiaoming Wang

    """

    sn = numpy.sin(ang_dip)

    cs = numpy.cos(ang_dip)

    d_bar = y2*sn - q*cs;

    r = numpy.sqrt(y1**2 + y2**2 + q**2)

    xx = numpy.sqrt(y1**2 + q**2)

    #a5 = 4.*poisson/cs*numpy.arctan((y2*(xx+q*cs)+xx*(r+xx)*sn)/y1/(r+xx)/cs)

    a4 = 2.0*poisson/cs*(numpy.log(r+d_bar) - sn*numpy.log(r+y2))

    ytilde = y2*cs + q*sn

    a3 = 2.0*poisson*(ytilde/(cs*(r+d_bar)) - numpy.log(r+y2)) + a4*sn/cs

    f = -(q/r - a3*sn*cs)/(2.0*3.14159)

    return f

    Example 12

    def get_q_per_pixel(self):

    '''Gets the delta-q associated with a single pixel. This is computed in

    the small-angle limit, so it should only be considered approximate.

    For instance, wide-angle detectors will have different delta-q across

    the detector face.'''

    if self.q_per_pixel is not None:

    return self.q_per_pixel

    c = (self.pixel_size_um/1e6)/self.distance_m

    twotheta = np.arctan(c) # radians

    self.q_per_pixel = 2.0*self.get_k()*np.sin(twotheta/2.0)

    return self.q_per_pixel

    # Maps

    ########################################

    Example 13

    def reset_model(self):

    self._min_strike_dist = np.inf

    self._striked = False

    self._strike_pos = None

    qpos = self.init_qpos

    self.ball = np.array([0.5, -0.175])

    while True:

    self.goal = np.concatenate([

    self.np_random.uniform(low=0.15, high=0.7, size=1),

    self.np_random.uniform(low=0.1, high=1.0, size=1)])

    if np.linalg.norm(self.ball - self.goal) > 0.17:

    break

    qpos[-9:-7] = [self.ball[1], self.ball[0]]

    qpos[-7:-5] = self.goal

    diff = self.ball - self.goal

    angle = -np.arctan(diff[0] / (diff[1] + 1e-8))

    qpos[-1] = angle / 3.14

    qvel = self.init_qvel + self.np_random.uniform(low=-.1, high=.1,

    size=self.model.nv)

    qvel[7:] = 0

    self.set_state(qpos, qvel)

    return self._get_obs()

    Example 14

    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

    Example 15

    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))

    Example 16

    def angularpixelarea(self):

    # get the first instrument element

    instruments = self.tree.xpath("//instruments/*[1]")

    if len(instruments) != 1: raise ValueError("No instruments in ski file")

    instrument = instruments[0]

    # get the distance in m

    d = self.units().convert(instrument.get("distance"), to_unit='m', quantity='distance')

    # get the field of view in m

    fovx = self.units().convert(instrument.get("fieldOfViewX"), to_unit='m', quantity='length')

    fovy = self.units().convert(instrument.get("fieldOfViewY"), to_unit='m', quantity='length')

    # get the number of pixels

    nx = int(instrument.get("pixelsX"))

    ny = int(instrument.get("pixelsY"))

    # calculate the angular pixel area

    sx = 2 * arctan(fovx / nx / d / 2)

    sy = 2 * arctan(fovy / ny / d / 2)

    return sx * sy

    ## This function returns a list of instrument names, in order of occurrence in the ski file.

    Example 17

    def orientation_angle(self):

    """

    This function ...

    :return:

    """

    diag_a = self.pixel_scale_matrix[0,1]

    diag_b = self.pixel_scale_matrix[1,0]

    if not np.isclose(diag_a, diag_b, rtol=0.05):

    warnings.warn("The diagonal elements of the pixel scale matrix are not equal: " + repr(diag_a) + " and " + repr(diag_b))

    first = self.pixel_scale_matrix[0,0]

    radians = np.arctan(diag_a / first)

    degrees = radians / math.pi * 180.

    return Angle(degrees, "deg")

    # -----------------------------------------------------------------

    Example 18

    def angularpixelarea(self):

    # get the first instrument element

    instruments = self.tree.xpath("//instruments/*[1]")

    if len(instruments) != 1: raise ValueError("No instruments in ski file")

    instrument = instruments[0]

    # get the distance in m

    d = self.units().convert(instrument.get("distance"), to_unit='m', quantity='distance')

    # get the field of view in m

    fovx = self.units().convert(instrument.get("fieldOfViewX"), to_unit='m', quantity='length')

    fovy = self.units().convert(instrument.get("fieldOfViewY"), to_unit='m', quantity='length')

    # get the number of pixels

    nx = int(instrument.get("pixelsX"))

    ny = int(instrument.get("pixelsY"))

    # calculate the angular pixel area

    sx = 2 * arctan(fovx / nx / d / 2)

    sy = 2 * arctan(fovy / ny / d / 2)

    return sx * sy

    ## This function returns a list of instrument names, in order of occurrence in the ski file.

    Example 19

    def orientation_angle(self):

    """

    This function ...

    :return:

    """

    diag_a = self.pixel_scale_matrix[0,1]

    diag_b = self.pixel_scale_matrix[1,0]

    if not np.isclose(diag_a, diag_b, rtol=0.05):

    warnings.warn("The diagonal elements of the pixel scale matrix are not equal: " + repr(diag_a) + " and " + repr(diag_b))

    first = self.pixel_scale_matrix[0,0]

    radians = np.arctan(diag_a / first)

    degrees = radians / math.pi * 180.

    return Angle(degrees, "deg")

    # -----------------------------------------------------------------

    Example 20

    def conferenceWakeOverlap(X, Y, R):

    n = np.size(X)

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    z = R/np.tan(0.34906585)

    # print z

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    # print 'theta =', theta

    if -0.34906585 < theta < 0.34906585:

    f_theta[i][j] = (1 + np.cos(9*theta))/2

    # print f_theta

    # print z

    # print f_theta

    return f_theta

    Example 21

    def conferenceWakeOverlap_tune(X, Y, R, boundAngle):

    n = np.size(X)

    boundAngle = boundAngle*np.pi/180.0

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    q = np.pi/boundAngle # factor inside the cos term of the smooth Jensen (see Jensen1983 eq.(3))

    # print 'boundAngle = %s' %boundAngle, 'q = %s' %q

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    # z = R/tan(0.34906585)

    z = R/np.tan(boundAngle) # distance from fulcrum to wake producing turbine

    # print z

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    # print 'theta =', theta

    if -boundAngle < theta < boundAngle:

    f_theta[i][j] = (1. + np.cos(q*theta))/2.

    # print f_theta

    # print z

    # print f_theta

    return f_theta

    Example 22

    def get_cosine_factor_original(X, Y, R0, bound_angle=20.0):

    n = np.size(X)

    bound_angle = bound_angle*np.pi/180.0

    # theta = np.zeros((n, n), dtype=np.float) # angle of wake from fulcrum

    f_theta = np.zeros((n, n), dtype=np.float) # smoothing values for smoothing

    q = np.pi/bound_angle # factor inside the cos term of the smooth Jensen (see Jensen1983 eq.(3))

    for i in range(0, n):

    for j in range(0, n):

    if X[i] < X[j]:

    z = R0/np.tan(bound_angle) # distance from fulcrum to wake producing turbine

    theta = np.arctan((Y[j] - Y[i]) / (X[j] - X[i] + z))

    if -bound_angle < theta < bound_angle:

    f_theta[i][j] = (1. + np.cos(q*theta))/2.

    return f_theta

    Example 23

    def rotate(self,rotation_method='RTZ'):

    ####################################################################################

    #rotate-------------------------------------------------------------------------

    for i in range(0,len(self.rf_st)):

    self.rf_st[i].stats.back_azimuth = self.tr_e.stats.sac['baz']

    self.rf_st.rotate(method='NE->RT')

    if rotation_method == 'LQT':

    r_amp = np.amax(np.amax(self.rf_st[1].data))

    z_amp = np.amax(np.amax(self.rf_st[2].data))

    incidence_angle = np.arctan(r_amp/z_amp) * (180.0/np.pi)

    for i in range(0,len(self.rf_st)):

    self.rf_st[i].stats.inclination = incidence_angle

    self.rf_st.rotate(method='RT->NE')

    self.rf_st.rotate(method='ZNE->LQT')

    ####################################################################################

    Example 24

    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

    Example 25

    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

    Example 26

    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))

    Example 27

    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

    Example 28

    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))

    Example 29

    def arrow(img,p1,p2):

    cv2.line(s1,p1,p2,(100,255,100),thickness=2)

    cv2.line(s2,p1,p2,(100,255,100),thickness=2)

    dy,dx= np.array(p2)-np.array(p1)

    theta= np.arctan(dy/dx) + (0 if dx>0 else np.pi) if dx!=0 else (1 if dy>0 else -1) * np.pi/2

    phy1=theta+ np.pi*7/6

    phy2=theta+ np.pi*5/6

    R=0.4*np.linalg.norm([dx,dy])

    dx1,dx2= (R*np.cos([phy1,phy2])).astype(np.int)

    dy1,dy2= (R*np.sin([phy1,phy2])).astype(np.int)

    if R<=2:return

    Y1,X1=p1

    Y2,X2=p2

    cv2.line(s1,(dy1+Y2,dx1+X2),p2,(100,255,100),thickness=1)

    cv2.line(s1,(dy2+Y2,dx2+X2),p2,(100,255,100),thickness=1)

    cv2.line(s2,(dy1+Y2,dx1+X2),p2,(100,255,100),thickness=1)

    cv2.line(s2,(dy2+Y2,dx2+X2),p2,(100,255,100),thickness=1)

    #????????????????

    Example 30

    def convertToOpenGLCameraMatrix(K, framebufferSize, near, far):

    """ Convert a camera calibration matrix into OpenGL format. """

    width, height = framebufferSize

    # print 'framebufferSize:', framebufferSize

    fx = K[0,0]

    fy = K[1,1]

    fovy = 2*np.arctan(0.5*height/fy)#*180/np.pi

    aspect = (width*fy)/(height*fx)

    # define the near and far clipping planes

    # near = 0.1

    # far = 100.0

    # fx = 10.0

    # fy = 10.0

    # fovy = 90*(np.pi/180.0)

    # aspect = (width*fy)/(height*fx)

    proj = openGLPerspectiveMatrix(fovy,aspect,near,far)

    return proj

    Example 31

    def test_auto_size_bits_list():

    pytest.skip()

    a = [0.5, 1.2, 3.2]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == 2

    assert y.right == -15

    a = [np.arctan(2 ** -i) for i in range(8)]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == 0

    assert y.right == -17

    a = [np.arctan(2 ** -i) for i in range(8, 12)]

    b = Sfix.auto_size(a, 18)

    for x, y in zip(a, b):

    np.isclose(y.val, x)

    assert y.left == -8

    assert y.right == -25

    Example 32

    def load(self, ips):

    if ips.imgtype in ('8-bit', 'rgb'):

    self.para = {'bright':0, 'contrast':45}

    self.view = [('slide', (-100,100), 'Brightness', 'bright', ''),

    ('slide', (1,89), 'Contrast', 'contrast', '')]

    if 'not_slice' in self.note:

    self.note.remove('not_slice')

    else :

    self.arange = minv, maxv = ips.img.min(), ips.img.max()

    self.para = {'bright':np.mean(ips.range) - np.mean(self.arange),

    'contrast':round(np.arctan((maxv-minv)/(ips.range[1]-ips.range[0]))/np.pi*180)}

    self.view = [('slide', (-(maxv-minv)/2, (maxv-minv)/2), 'Brightness', 'bright', ''),

    ('slide', (1,89), 'Contrast', 'contrast', '')]

    if not 'not_slice' in self.note:

    self.note.append('not_slice')

    return True

    Example 33

    def reset_model(self):

    self._min_strike_dist = np.inf

    self._striked = False

    self._strike_pos = None

    qpos = self.init_qpos

    self.ball = np.array([0.5, -0.175])

    while True:

    self.goal = np.concatenate([

    self.np_random.uniform(low=0.15, high=0.7, size=1),

    self.np_random.uniform(low=0.1, high=1.0, size=1)])

    if np.linalg.norm(self.ball - self.goal) > 0.17:

    break

    qpos[-9:-7] = [self.ball[1], self.ball[0]]

    qpos[-7:-5] = self.goal

    diff = self.ball - self.goal

    angle = -np.arctan(diff[0] / (diff[1] + 1e-8))

    qpos[-1] = angle / 3.14

    qvel = self.init_qvel + self.np_random.uniform(low=-.1, high=.1,

    size=self.model.nv)

    qvel[7:] = 0

    self.set_state(qpos, qvel)

    return self._get_obs()

    Example 34

    def FitPCA(self, hPCA_Proj):

    '''

    Determine the timing of the inflation event.

    Uses the first component of the pca projection and

    fits A * arctan( (t - t0) / c ) + B to the first pca projection.

    @param hPCA_Proj: The sklearn PCA projection

    @return [t0, c]

    '''

    fitfunc = lambda p,t: p[0]*np.arctan((t-p[1])/p[2])+p[3]

    errfunc = lambda p,x,y: fitfunc(p,x) - y

    dLen = len(hPCA_Proj[:,0])

    pA, success = optimize.leastsq(errfunc,[1.,dLen/2.,1.,0.],args=(np.arange(dLen),hPCA_Proj[:,0]))

    ct = pA[1:3]

    return ct, pA[0]

    Example 35

    def FitPCA(self, hPCA_Proj):

    '''

    Determine the timing of the inflation event from the first component of the pca projection

    fits A * arctan( (t - t0) / c ) + B to the first pca projection, in order to estimate

    source amplitude parameters

    @param hPCA_Proj: The sklearn PCA

    @return ct: the t0, c, and B parameters from the fit

    @return pA[0]: the fitted amplitude parameter

    '''

    fitfunc = lambda p,t: p[0]*np.arctan((t-p[1])/p[2])+p[3]

    errfunc = lambda p,x,y: fitfunc(p,x) - y

    dLen = len(hPCA_Proj[:,0])

    pA, success = optimize.leastsq(errfunc,[1.,dLen/2.,1.,0.],args=(np.arange(dLen),hPCA_Proj[:,0]))

    ct = pA[1:3]

    return ct, pA[0]

    Example 36

    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

    Example 37

    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))

    Example 38

    def compute_pd_control(self):

    if self.received_data:

    # given the computed wall slope, compute theta, avoid divide by zero error

    if np.abs(self.m) < EPSILON:

    theta = np.pi / 2.0

    x_intercept = 0

    else:

    theta = np.arctan(1.0/self.m)

    # solve for y=0 in y=mx+c

    x_intercept = self.c / self.m

    # x axis is perp. to robot but not perpindicular to wall

    # cosine term solves for minimum distance to wall

    wall_dist = np.abs(np.cos(theta)*x_intercept)

    # control proportional to angular error and distance from wall

    distance_term = self.direction_muliplier * KP * (wall_dist - TARGET_DISTANCE)

    angle_term = KD * theta

    control = angle_term + distance_term

    # avoid turning too sharply

    self.control = (np.clip(control, -0.3, 0.3), SPEED)

    Example 39

    def rotate_image(img_src, angle,scale ,crop=True):

    img_src,size_dest= pad_image(img_src,scale)

    size = tuple(np.array([img_src.shape[1], img_src.shape[0]]))

    org_h=size[1]

    org_w=size[0]

    src_r = np.sqrt((size[0]/2.0)**2+(size[1]/2.0)**2)

    org_angle =np.arctan(float(org_h)/org_w)

    dest_h = size_dest[0]

    dest_w = size_dest[1]

    center = tuple(np.array([img_src.shape[1] * 0.5, img_src.shape[0] * 0.5]))

    dsize= (dest_w,dest_h)

    rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)

    img_rot = cv2.warpAffine(img_src, rotation_matrix, size, flags=cv2.INTER_CUBIC)

    if crop:

    x,y,w,h = cv2.boundingRect(img_rot[:,:,3])

    return img_rot[y:y+h, x:x+w,:]

    else:

    return img_rot

    Example 40

    def rotate_image(img_src, angle,scale ):

    img_src,size_dest= pad_image(img_src,scale)

    size = tuple(np.array([img_src.shape[1], img_src.shape[0]]))

    org_h=size[1]

    org_w=size[0]

    src_r = np.sqrt((size[0]/2.0)**2+(size[1]/2.0)**2)

    org_angle =np.arctan(float(org_h)/org_w)

    dest_h = size_dest[0]

    dest_w = size_dest[1]

    center = tuple(np.array([img_src.shape[1] * 0.5, img_src.shape[0] * 0.5]))

    dsize= (dest_w,dest_h)

    rotation_matrix = cv2.getRotationMatrix2D(center, angle, scale)

    img_rot = cv2.warpAffine(img_src, rotation_matrix, size, flags=cv2.INTER_CUBIC)

    x,y,w,h = cv2.boundingRect(img_rot[:,:,3])

    return img_rot[y:y+h, x:x+w,:]

    Example 41

    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

    Example 42

    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))

    Example 43

    def arctan_func(xvals, a, b, c):

    '''

    --------------------------------------------------------------------

    This function generates predicted ability levels given data (xvals)

    and parameters a, b, and c, from the following arctan function:

    y = (-a / pi) * arctan(b * x + c) + (a / 2)

    --------------------------------------------------------------------

    INPUTS:

    xvals = (N,) vector, data inputs to arctan function

    a = scalar, scale parameter for arctan function

    b = scalar, curvature parameter for arctan function

    c = scalar, shift parameter for arctan function

    OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: None

    OBJECTS CREATED WITHIN FUNCTION:

    yvals = (N,) vector, predicted values (output) of arctan function

    RETURNS: yvals

    --------------------------------------------------------------------

    '''

    yvals = (-a / np.pi) * np.arctan(b * xvals + c) + (a / 2)

    return yvals

    Example 44

    def arctan_func(xvals, a, b, c):

    '''

    --------------------------------------------------------------------

    This function generates predicted ability levels given data (xvals)

    and parameters a, b, and c, from the following arctan function:

    y = (-a / pi) * arctan(b * x + c) + (a / 2)

    --------------------------------------------------------------------

    INPUTS:

    xvals = (N,) vector, data inputs to arctan function

    a = scalar, scale parameter for arctan function

    b = scalar, curvature parameter for arctan function

    c = scalar, shift parameter for arctan function

    OTHER FUNCTIONS AND FILES CALLED BY THIS FUNCTION: None

    OBJECTS CREATED WITHIN FUNCTION:

    yvals = (N,) vector, predicted values (output) of arctan function

    RETURNS: yvals

    --------------------------------------------------------------------

    '''

    yvals = (-a / np.pi) * np.arctan(b * xvals + c) + (a / 2)

    return yvals

    Example 45

    def fov(self):

    """

    Returns the field of view for each axis

    """

    return np.float32([np.arctan(self.shape[1] * 0.5 / self.fx),

    np.arctan(self.shape[0] * 0.5 / self.fy)]) * 2.0

    Example 46

    def dynamics(q, u, p):

    """

    Returns state derivative qdot.

    Takes current state q, motor input torque u, and disturbance torque p.

    See (rederived with incline).

    """

    # Angle of pendulum in incline frame

    ang = q[2] - incline

    # Mass matrix

    M = np.array([

    [(mass_wheel + mass_pend)*radius**2 + inertia_wheel, mass_pend*radius*cw_to_cm[1]*np.cos(ang)],

    [mass_pend*radius*cw_to_cm[1]*np.cos(ang), inertia_pend + mass_pend*cw_to_cm[1]**2]

    ])

    # Gravity effect

    g = np.array([

    -mass_pend*radius*cw_to_cm[1]*q[3]**2*np.sin(ang) + mass_wheel*radius*gravity[1]*np.sin(incline),

    mass_pend*gravity[1]*cw_to_cm[1]*np.sin(q[2])

    ])

    # Friction force

    d = np.array([

    -friction_wheel * (q[1] + np.arctan(q[1])),

    friction_pend * q[3]

    ])

    # Dynamics

    accel_wheel_neg, accel_pend = npl.inv(M).dot(np.array([-u, p+u]) - g - d)

    return np.array([q[1], -accel_wheel_neg*radius, q[3], accel_pend])

    ################################################# SIMULATION

    # Define time domain

    Example 47

    def cart2sph(x, y, z):

    """ Convert cartesian to spherical coordinates.

    Attributes

    ----------

    x : float

    x-coordinate

    y : float

    y-coordinate

    z : float

    z-coordinate

    Returns

    -------

    float

    radius

    float

    aziumth

    float

    elevation

    """

    r = np.sqrt(x**2 + y**2 + z**2)

    if x > 0 and y > 0:

    az = np.arctan(y / x)

    elif x > 0 and y < 0:

    az = 2*np.pi - np.arctan(-y / x)

    elif x < 0 and y > 0:

    az = np.pi - np.arctan(-y / x)

    elif x < 0 and y < 0:

    az = np.pi + np.arctan(y / x)

    elif x == 0 and y > 0:

    az = np.pi / 2

    elif x == 0 and y < 0:

    az = 3 * np.pi / 2

    elif y == 0 and x > 0:

    az = 0

    elif y == 0 and x < 0:

    az = np.pi

    elev = np.arccos(z / r)

    return r, az, elev

    Example 48

    def ellipse_angle_of_rotation( a ):

    b,c,d,f,g,a = a[1]/2, a[2], a[3]/2, a[4]/2, a[5], a[0]

    return 0.5*NP.arctan(2*b/(a-c))

    Example 49

    def ellipse_angle_of_rotation2( a ):

    b,c,d,f,g,a = a[1]/2, a[2], a[3]/2, a[4]/2, a[5], a[0]

    if b == 0:

    if a > c:

    return 0

    else:

    return NP.pi/2

    else:

    if a > c:

    return NP.arctan(2*b/(a-c))/2

    else:

    return NP.pi/2 + NP.arctan(2*b/(a-c))/2

    Example 50

    def radial_filter(order, freq, array_configuration, amp_maxdB=40):

    """Generate modal radial filter of specified order and frequency

    Parameters

    ----------

    order : array_like

    order of filter

    freq : array_like

    Frequency of modal filter

    array_configuration : ArrayConfiguration

    List/Tuple/ArrayConfiguration, see io.ArrayConfiguration

    amp_maxdB : int, optional

    Maximum modal amplification limit in dB [Default: 40]

    Returns

    -------

    dn : array_like

    Vector of modal frequency domain filter of shape [nOrders x nFreq]

    """

    array_configuration = ArrayConfiguration(*array_configuration)

    extrapolation_coeffs = array_extrapolation(order, freq, array_configuration)

    extrapolation_coeffs[extrapolation_coeffs == 0] = 1e-12

    a_max = 10 ** (amp_maxdB / 20)

    limiting_factor = 2 * a_max / _np.pi * _np.abs(extrapolation_coeffs) * _np.arctan(_np.pi / (2 * a_max * _np.abs(extrapolation_coeffs)))

    return limiting_factor / extrapolation_coeffs

    展开全文
  • 目标:实现反正切函数的查表算法,精度0.5°。分析:f(x) = arctan(x)函数单调但非线性,越接近原点处,斜率越大。90°比较特殊,其值为正无穷大,只要得到的正切值tana大于114.59(89.5度对应的正切值),就可以认为...

    目标:实现反正切函数的查表算法,精度0.5°。

    分析:

    f(x) = arctan(x)函数单调但非线性,越接近原点处,斜率越大。

    90°比较特殊,其值为正无穷大,只要得到的正切值tana大于114.59(89.5度对应的正切值),就可以认为是90度。

    假如0-89.5°用一个查找表实现,索引为正切值,值为角度值。tan89.5为115,假如用N点uint16_t型查找表,需要保证

    arctan(115 / N) < 0.5°

    即 115 / N < 0.0087

    可选的最小值为13219,意味着至少要建立一张13K×16的表,占用26KB的Flash,对于一般的MCU来说不可接受。

    如果0-45°用一个查找表实现,由于tan45°=1,根据上面的计算公式,可以得出N的最小值为114,这个N值对一般的MCU均可以接受,甚至可以增加至256点来提高精度。对于45°以上的角度,可以根据两角和的三角公式来得到,推导过程如下:

    如果测量的正切值K大于1,那么根据最后的公式,可以求出比45°大的那个角度a,再加上45°就是实际的角度。而a的计算可以由256点查找表来快速得到,这样就实现了用一个小容量查找表计算90度以内的反正切值。

    查找表涉及两个数值:表索引idx和表的角度值angle[idx]。

    索引值idx对应0-45°的正切值,由于这些值均小于1,采用整体扩大256倍的方法,将正切值就映射到了0-256的区间,从而索引idx的范围为0-255。

    角度值angle[]是uint16_t型的,而实际的范围为0-45,根据65536/45=1456,可以用Q12的表示方式来提高分辨率。

    查找表如下:

    static const uint16_t tb_atan[256] = {

    0, 229, 458, 687, 916, 1145, 1374, 1603,

    1832, 2061, 2290, 2519, 2748, 2976, 3205, 3433,

    3662, 3890, 4118, 4346, 4574, 4802, 5029, 5257,

    5484, 5711, 5938, 6165, 6391, 6618, 6844, 7070,

    7296, 7521, 7746, 7971, 8196, 8421, 8645, 8869,

    9093, 9317, 9540, 9763, 9986, 10208, 10431, 10652,

    10874, 11095, 11316, 11537, 11757, 11977, 12197, 12416,

    12635, 12853, 13071, 13289, 13507, 13724, 13940, 14157,

    14373, 14588, 14803, 15018, 15232, 15446, 15660, 15873,

    16085, 16297, 16509, 16720, 16931, 17142, 17352, 17561,

    17770, 17979, 18187, 18394, 18601, 18808, 19014, 19220,

    19425, 19630, 19834, 20038, 20241, 20444, 20646, 20848,

    21049, 21250, 21450, 21649, 21848, 22047, 22245, 22443,

    22640, 22836, 23032, 23227, 23422, 23616, 23810, 24003,

    24196, 24388, 24580, 24771, 24961, 25151, 25340, 25529,

    25717, 25905, 26092, 26278, 26464, 26649, 26834, 27018,

    27202, 27385, 27568, 27750, 27931, 28112, 28292, 28471,

    28650, 28829, 29007, 29184, 29361, 29537, 29712, 29887,

    30062, 30236, 30409, 30582, 30754, 30925, 31096, 31266,

    31436, 31605, 31774, 31942, 32109, 32276, 32442, 32608,

    32773, 32938, 33101, 33265, 33428, 33590, 33751, 33913,

    34073, 34233, 34392, 34551, 34709, 34867, 35024, 35180,

    35336, 35492, 35646, 35801, 35954, 36107, 36260, 36412,

    36563, 36714, 36864, 37014, 37163, 37312, 37460, 37607,

    37754, 37901, 38047, 38192, 38337, 38481, 38624, 38768,

    38910, 39052, 39194, 39335, 39475, 39615, 39754, 39893,

    40032, 40169, 40307, 40443, 40580, 40715, 40850, 40985,

    41119, 41253, 41386, 41519, 41651, 41782, 41913, 42044,

    42174, 42303, 42432, 42561, 42689, 42817, 42944, 43070,

    43196, 43322, 43447, 43572, 43696, 43819, 43943, 44065,

    44188, 44309, 44431, 44551, 44672, 44792, 44911, 45030,

    45148, 45266, 45384, 45501, 45618, 45734, 45849, 45965,

    };

    static int16_t calc_phase(int16_t real, int16_t imag)

    {

    int16_t

    abs_real;

    int16_t

    abs_imag;

    int16_t

    phase;

    uint16_t

    zone;

    uint32_t

    tmp_tan;

    uint32_t

    delta_tan;

    if (real

    < 0)

    {

    abs_real = -real;

    zone = 1U;

    }

    else

    {

    abs_real = real;

    zone = 0U;

    }

    if (imag

    < 0)

    {

    abs_imag = -imag;

    zone +=

    2U; }

    else

    {

    abs_imag = imag; zone =

    0U; }

    if (abs_imag

    <= abs_real) {

    tmp_tan =

    (uint32_t)abs_imag<<8U;

    tmp_tan /= abs_real;

    phase =

    tb_atan[tmp_tan]>>3U; }

    else if

    ((abs_imag>>7U) <=

    abs_real) {

    delta_tan = ((uint32_t)(abs_imag -

    abs_real))<<15U;

    tmp_tan = (uint32_t)abs_imag + (uint32_t)abs_real;

    delta_tan /= tmp_tan;

    delta_tan >>= 7U;

    phase =

    tb_atan[delta_tan]>>3U; phase += 5760; }

    else {

    phase = 11520;

    }

    switch

    (zone)

    {

    case 0U:

    展开全文
  • 参考链接: Python中的numpy.arcsin The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the ...
  • 参考链接: Python中的numpy.right_shift 参考链接: Python中的numpy.arcsin The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up...
  • 函数应该是平滑的,并且在(0,2pi)的y范围内的0和2 pi处连接,而不接触0和2pi. 教科书情节和方程式: 应Saullo Castro的要求,我被告知: “问题可能在于提供“原理值”作为输出的反正切函数. 因此,如果x是第二象限或...
  • 教科书情节和方程式: 应索洛·卡斯特罗的要求,我被告知: 问题可能出在arctan函数中,该函数将“原理值”作为输出。 因此,如果x是第二或第三象限中的一个角,则arctan(tan(x))不产生x。如果将arctan(tan(x))从x=...
  • 讲解对象:python3 三角函数作者:融水公子 rsgz常见的三角函数#!/usr/bin/python3import math余弦弧度值math.acos(0.64)# 0.8762980611683406math.acos(0)# 1.5707963267948966正弦弧度值math.asin(0.64)# 0....
  • 原博文2018-06-16 10:50 −用Python计算三角函数之acos()方法的使用acos()方法返回x的余弦值,以弧度表示。语法以下是acos()方法的语法:acos(x)注意:此函数是无法直接访问的,所以我们需要导入math模块,然后...
  • 之前对三角函数的理解仅局限于sin,cos,tan。但是目前考研过程中遇到的都是些csc,sec,cot,arctan,arccos,arcsin。积分和求导还有一堆公式,很容易记混。我就想能不能用图像帮助记忆,就算记不起来,也能猜出来...
  • Syntax以下是atan()方法的语法:atan(x)注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数。参数x -- 这必须是一个数值。返回值此方法返回 x 的反正切值,以弧度...
  • pythonPython入门之三角函数atan2()函数详解描述atan2() 返回给定的 X 及 Y 坐标值的反正切值。语法以下是 atan2() 方法的语法:import mathmath.atan2(y, x)注意:atan2()是不能直接访问的,需要导入 math 模块...
  • Hlianbobo:python 哪个库求反三角函数能返回角度值?网上查了结果返回的都是弧度值RockShake:转换一下就好了啊SingeeKing:你的初中数学老师棺材板该压不住了… 她绝对讲过弧度和角度的换算way2explore2:对的同一...
  • 网上有朋友问:反三角函数怎么算?其实很简单,下面我来教大家如何计算反三角函数。工具/原料电脑型号:联想(Lenovo)小新Air14Win7计算机方法/步骤1第一步 首先我们将电脑打开后,看电脑屏幕的左下角有一个图标,如...
  • Python计算三角函数之acos()方法的使用acos()方法返回x的余弦值,以弧度表示。语法以下是acos()方法的语法:acos(x)注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这...
  • 解:已知:cosα=3/5有:α=arccos(3/5)经查表(或按计算器),得:α≈53.13010235°,或:α≈323.13010235°考虑到三角函数的周期性,得:α≈360°×k+53.13010235°,或:α≈360°×k+323...
  • Python中的三角函数位于math模块内。引入模块:import math输出pi:import ...下面介绍Python中的三角函数,如下:函数描述acos(x)返回x的余弦弧度值。asin(x)返回x的正弦弧度值。atan(x)返回x的反正切弧度值。...
  • 语法以下是acos()方法的语法:acos(x)注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数。参数x -- 这必须是在范围内的数字值-1到1,如果x大于1,则它会产生一个...
  • 在 总而言之,与标准库math.atan函数的输出相比,以下是对少量未经仔细选择的测试值调用上述函数的结果:test_values = [2.314, 0.0123, -0.56, 168.9] for value in test_values: print("{:20.15g} {:20.15g} {:...
  • 前提:import math函数介绍:degrees(x)将x从弧度转换为度数。radians(x)将x从度数转换为弧度。例如:>>> import math>>> math.degrees(math.pi/2)90.0>>> math.radians(90)1.5707963267948966>>> math.pi/21....
  • python——三角函数用法

    千次阅读 2020-03-29 20:39:08
    python中的三角函数一般有: 函数 描述 sin(x) 返回x弧度的正弦值 cos(x) 返回x弧度的余弦值 tan(x) 返回x弧度的正切值 asin(x) 返回x的正弦弧度值 acos(x) 返回x的余弦弧度值 atan(x) 返回x...
  • python3三角函数

    2019-09-23 22:25:41
    三角函数 acos(x) 返回x的余弦弧度值。 asin(x) 返回x的正弦弧度值。 atan(x) 返回x的反正切弧度值。 atan2(y, x) 返回给定的 X 及 Y 坐...
  • 序今儿个整点对大家十分有用的活,叫做“计算三角函数的值”。这问题听起来有点蠢,正经人谁不知道怎么算三角函数啊。别急,我们换一个情景,假设现在上帝把你丢在一个荒岛上,你手上啥工具都没有,然后告诉你你除非...
  • Python atan() 函数描述atan() 返回x的反正切弧度值。语法以下是 atan() 方法的语法:import mathmath.atan(x)注意:atan()是不能直接访问的,需要导入 math 模块,然后通过 math 静态对象调用该方法。参数x -- 一个...
  • 语法以下是acos()方法的语法:acos(x)注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数。 参数x -- 这必须是在范围内的数字值-1到1,如果x大于1,则它会产生一个...

空空如也

空空如也

1 2 3 4 5
收藏数 86
精华内容 34
关键字:

python反三角函数

python 订阅