Python numpy.arctan() Examples
The following are 30 code examples for showing how to use numpy.arctan(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: tf-example-models Author: aakhundov File: tf_gmm_tools.py License: Apache License 2.0 | 7 votes |
def _plot_gaussian(mean, covariance, color, zorder=0): """Plots the mean and 2-std ellipse of a given Gaussian""" plt.plot(mean[0], mean[1], color[0] + ".", zorder=zorder) if covariance.ndim == 1: covariance = np.diag(covariance) radius = np.sqrt(5.991) eigvals, eigvecs = np.linalg.eig(covariance) axis = np.sqrt(eigvals) * radius slope = eigvecs[1][0] / eigvecs[1][1] angle = 180.0 * np.arctan(slope) / np.pi plt.axes().add_artist(pat.Ellipse( mean, 2 * axis[0], 2 * axis[1], angle=angle, fill=False, color=color, linewidth=1, zorder=zorder ))
Example 2
Project: EXOSIMS Author: dsavransky File: KnownRVSurvey.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, **specs): # call prototype constructor SurveySimulation.__init__(self, **specs) TL = self.TargetList SU = self.SimulatedUniverse # reinitialize working angles and delta magnitudes used for integration self.WAint = np.zeros(TL.nStars)*u.arcsec self.dMagint = np.zeros(TL.nStars) # calculate estimates of shortest WAint and largest dMagint for each target for sInd in range(TL.nStars): pInds = np.where(SU.plan2star == sInd)[0] self.WAint[sInd] = np.arctan(np.min(SU.a[pInds])/TL.dist[sInd]).to('arcsec') phis = np.array([np.pi/2]*pInds.size) dMags = deltaMag(SU.p[pInds], SU.Rp[pInds], SU.a[pInds], phis) self.dMagint[sInd] = np.min(dMags) # populate outspec with arrays self._outspec['WAint'] = self.WAint.value self._outspec['dMagint'] = self.dMagint
Example 3
Project: HorizonNet Author: sunset1995 File: pano_lsd_align.py License: MIT License | 6 votes |
def computeUVN_vec(n, in_, planeID): ''' vectorization version of computeUVN @n N x 3 @in_ MN x 1 @planeID N ''' n = n.copy() if (planeID == 2).sum(): n[planeID == 2] = np.roll(n[planeID == 2], 2, axis=1) if (planeID == 3).sum(): n[planeID == 3] = np.roll(n[planeID == 3], 1, axis=1) n = np.repeat(n, in_.shape[0] // n.shape[0], axis=0) assert n.shape[0] == in_.shape[0] bc = n[:, [0]] * np.sin(in_) + n[:, [1]] * np.cos(in_) bs = n[:, [2]] out = np.arctan(-bc / (bs + 1e-9)) return out
Example 4
Project: tf-example-models Author: aakhundov File: utils.py License: Apache License 2.0 | 6 votes |
def _plot_gaussian(mean, covariance, color, zorder=0): """Plots the mean and 2-std ellipse of a given Gaussian""" plt.plot(mean[0], mean[1], color[0] + ".", zorder=zorder) if covariance.ndim == 1: covariance = np.diag(covariance) radius = np.sqrt(5.991) eigvals, eigvecs = np.linalg.eig(covariance) axis = np.sqrt(eigvals) * radius slope = eigvecs[1][0] / eigvecs[1][1] angle = 180.0 * np.arctan(slope) / np.pi plt.axes().add_artist(pat.Ellipse( mean, 2 * axis[0], 2 * axis[1], angle=angle, fill=False, color=color, linewidth=1, zorder=zorder ))
Example 5
Project: speech_separation Author: bill9800 File: utils.py License: MIT License | 6 votes |
def phase_enhance_pred(mix_STFT,pred_file, mode='STFT'): if mode=='wav': T_pred, _ = librosa.load(pred_file,sr=16000) F_pred = fast_stft(T_pred) if mode =='STFT': F_pred = pred_file M = np.sqrt(np.square(F_pred[:,:,0])+np.square(F_pred[:,:,1])) #magnitude print('shape M:',M.shape) P = np.arctan(np.divide(mix_STFT[:,:,0],mix_STFT[:,:,1])) #phase print('shape p:',P.shape) F_enhance = np.zeros_like(F_pred) print('shape enhance',F_enhance.shape) F_enhance[:,:,0] = np.multiply(M,np.cos(P)) F_enhance[:,:,1] = np.multiply(M,np.sin(P)) print('shape enhance', F_enhance.shape) T_enhance = fast_istft(F_enhance) return T_enhance ## test code part
Example 6
Project: ratcave Author: ratcave File: test_camera.py License: MIT License | 6 votes |
def test_look_at_updates_for_children(): dist = 2. cam = StereoCameraGroup(distance=dist) point = np.array([0, 0, 0, 1]).reshape(-1, 1) point[2] = -1 #np.random.randint(1, 6) angle = np.arctan(point[2]/(cam.distance/2))[0] cam.right.rotation.y = -np.rad2deg(angle) cam.left.rotation.y = np.rad2deg(angle) point_view_mat_left = np.dot(cam.left.view_matrix, point) point_view_mat_right = np.dot(cam.right.view_matrix, point) assert (point_view_mat_left == point_view_mat_right).all() cam2 = StereoCameraGroup(distance=dist) cam2.look_at(*point[:3]) point_view_mat_left2 = np.dot(cam2.left.view_matrix, point) point_view_mat_right2 = np.dot(cam2.right.view_matrix, point) assert (point_view_mat_left == point_view_mat_left2).all() and (point_view_mat_right == point_view_mat_right2).all()
Example 7
Project: recruit Author: Frank-qlu File: test_umath.py License: Apache License 2.0 | 6 votes |
def test_branch_cuts_complex64(self): # check branch cuts and continuity on them _check_branch_cut(np.log, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log2, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log10, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.log1p, -1.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.sqrt, -0.5, 1j, 1, -1, True, np.complex64) _check_branch_cut(np.arcsin, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arccos, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctan, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arcsinh, [0-2j, 2j], [1, 1], -1, 1, True, np.complex64) _check_branch_cut(np.arccosh, [ -1, 0.5], [1j, 1j], 1, -1, True, np.complex64) _check_branch_cut(np.arctanh, [ -2, 2], [1j, 1j], 1, -1, True, np.complex64) # check against bogus branch cuts: assert continuity between quadrants _check_branch_cut(np.arcsin, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccos, [0-2j, 2j], [ 1, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arctan, [ -2, 2], [1j, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arcsinh, [ -2, 2, 0], [1j, 1j, 1], 1, 1, False, np.complex64) _check_branch_cut(np.arccosh, [0-2j, 2j, 2], [1, 1, 1j], 1, 1, False, np.complex64) _check_branch_cut(np.arctanh, [0-2j, 2j, 0], [1, 1, 1j], 1, 1, False, np.complex64)
Example 8
Project: recruit Author: Frank-qlu File: test_umath.py License: Apache License 2.0 | 6 votes |
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(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 9
Project: buzzard Author: airware File: part2.py License: Apache License 2.0 | 6 votes |
def slopes_of_elevation(fp, primitive_fps, primitive_arrays, slopes): """A function to be fed to `compute_array` when constructing a recipe""" arr = primitive_arrays['dem'] kernel = [ [0, 1, 0], [1, 1, 1], [0, 1, 0], ] arr = ( scipy.ndimage.maximum_filter(arr, None, kernel) - scipy.ndimage.minimum_filter(arr, None, kernel) ) arr = arr[1:-1, 1:-1] arr = np.arctan(arr / fp.pxsizex) arr = arr / np.pi * 180. return arr
Example 10
Project: LSDMappingTools Author: LSDtopotools File: LSDMappingTools.py License: MIT License | 6 votes |
def Hillshade(raster_file, azimuth, angle_altitude): array = ReadRasterArrayBlocks(raster_file,raster_band=1) x, y = np.gradient(array) slope = np.pi/2. - np.arctan(np.sqrt(x*x + y*y)) aspect = np.arctan2(-x, y) azimuthrad = np.azimuth*np.pi / 180. altituderad = np.angle_altitude*np.pi / 180. shaded = np.sin(altituderad) * np.sin(slope)\ + np.cos(altituderad) * np.cos(slope)\ * np.cos(azimuthrad - aspect) return 255*(shaded + 1)/2 #==============================================================================
Example 11
Project: lambda-packs Author: ryfeus File: _continuous_distns.py License: MIT License | 6 votes |
def _cdf(self, x, c): output = np.zeros(x.shape, dtype=x.dtype) val = (1.0+c)/(1.0-c) c1 = x < np.pi c2 = 1-c1 xp = np.extract(c1, x) xn = np.extract(c2, x) if np.any(xn): valn = np.extract(c2, np.ones_like(x)*val) xn = 2*np.pi - xn yn = np.tan(xn/2.0) on = 1.0-1.0/np.pi*np.arctan(valn*yn) np.place(output, c2, on) if np.any(xp): valp = np.extract(c1, np.ones_like(x)*val) yp = np.tan(xp/2.0) op = 1.0/np.pi*np.arctan(valp*yp) np.place(output, c1, op) return output
Example 12
Project: pymoo Author: msu-coinlab File: mw.py License: Apache License 2.0 | 5 votes |
def _evaluate(self, X, out, *args, **kwargs): g = self.g1(X) f0 = g * X[:, 0] f1 = g * np.sqrt(1.0 - np.power(f0 / g, 2.0)) with np.errstate(divide='ignore'): atan = np.arctan(f1 / f0) g0 = f0 ** 2 + f1 ** 2 - np.power(1.7 - self.LA2(0.2, 2.0, 1.0, 1.0, atan), 2.0) t = 0.5 * np.pi - 2 * np.abs(atan - 0.25 * np.pi) g1 = np.power(1 + self.LA2(0.5, 6.0, 3.0, 1.0, t), 2.0) - f0 ** 2 - f1 ** 2 g2 = np.power(1 - self.LA2(0.45, 6.0, 3.0, 1.0, t), 2.0) - f0 ** 2 - f1 ** 2 out["F"] = np.column_stack([f0, f1]) out["G"] = np.column_stack([g0, g1, g2])
Example 13
Project: pymoo Author: msu-coinlab File: mw.py License: Apache License 2.0 | 5 votes |
def _evaluate(self, X, out, *args, **kwargs): g = self.g2(X) f0 = g * X[:, 0] f1 = g * np.sqrt(1.1 * 1.1 - np.power(f0 / g, 2.0)) with np.errstate(divide='ignore'): atan = np.arctan(f1 / f0) g0 = f0 ** 2 / np.power(1.0 + self.LA3(0.15, 6.0, 4.0, 10.0, atan), 2.0) + f1 ** 2 / np.power( 1.0 + self.LA3(0.75, 6.0, 4.0, 10.0, atan), 2.0) - 1 out["F"] = np.column_stack([f0, f1]) out["G"] = g0.reshape((-1, 1))
Example 14
Project: pymoo Author: msu-coinlab File: mw.py License: Apache License 2.0 | 5 votes |
def _calc_pareto_front(self, ref_dirs=None): if ref_dirs is None: F = np.zeros((100, 2)) F[:, 0] = np.linspace(0, 1, 100) else: F = ref_dirs F[:, 1] = 1 - F[:, 0] F = F / np.sqrt(np.sum(F ** 2, axis=1) / 1.21).reshape((-1, 1)) l = np.cos(6 * np.arctan(F[:, 1] / F[:, 0]) ** 4) ** 10 c = 1 - (F[:, 0] / (1 + 0.15 * l)) ** 2 - (F[:, 1] / (1 + 0.75 * l)) ** 2 return F[c >= 0]
Example 15
Project: pymoo Author: msu-coinlab File: mw.py License: Apache License 2.0 | 5 votes |
def _evaluate(self, X, out, *args, **kwargs): g = self.g3(X) f0 = g * X[:, 0] f1 = g * np.sqrt(1 - np.power(f0 / g, 2)) with np.errstate(divide='ignore'): atan = np.arctan(f1 / f0) g0 = f0 ** 2 + f1 ** 2 - np.power(1.2 + np.abs(self.LA2(0.4, 4.0, 1.0, 16.0, atan)), 2.0) g1 = np.power(1.15 - self.LA2(0.2, 4.0, 1.0, 8.0, atan), 2.0) - f0 ** 2 - f1 ** 2 out["F"] = np.column_stack([f0, f1]) out["G"] = np.column_stack([g0, g1])
Example 16
Project: pyscf Author: pyscf File: pywannier90.py License: Apache License 2.0 | 5 votes |
def g_r(grids_coor, site, l, mr, r, zona, x_axis = [1,0,0], z_axis = [0,0,1], unit = 'B'): r''' Evaluate the projection function g(r) or \Theta_{l,m_r}(\theta,\phi) on a grid ref: Chapter 3, wannier90 User Guide Attributes: grids_coor : a grids for the cell of interest site : absolute coordinate (in Borh/Angstrom) of the g(r) in the cell l, mr : l and mr value in the Table 3.1 and 3.2 of the ref Return: theta_lmr : an array (ngrid, value) of g(r) ''' unit_conv = 1 if unit == 'A': unit_conv = param.BOHR r_vec = (grids_coor - site) r_vec = np.einsum('iv,uv ->iu', r_vec, transform(x_axis, z_axis)) r_norm = np.linalg.norm(r_vec,axis=1) if (r_norm < 1e-8).any() == True: r_vec = (grids_coor - site - 1e-5) r_vec = np.einsum('iv,uv ->iu', r_vec, transform(x_axis, z_axis)) r_norm = np.linalg.norm(r_vec,axis=1) cost = r_vec[:,2]/r_norm phi = np.empty_like(r_norm) for point in range(phi.shape[0]): if r_vec[point,0] > 1e-8: phi[point] = np.arctan(r_vec[point,1]/r_vec[point,0]) elif r_vec[point,0] < -1e-8: phi[point] = np.arctan(r_vec[point,1]/r_vec[point,0]) + np.pi else: phi[point] = np.sign(r_vec[point,1]) * 0.5 * np.pi return theta_lmr(l, mr, cost, phi) * R_r(r_norm * unit_conv, r = r, zona = zona)
Example 17
Project: HorizonNet Author: sunset1995 File: pano_lsd_align.py License: MIT License | 5 votes |
def computeUVN(n, in_, planeID): ''' compute v given u and normal. ''' if planeID == 2: n = np.array([n[1], n[2], n[0]]) elif planeID == 3: n = np.array([n[2], n[0], n[1]]) bc = n[0] * np.sin(in_) + n[1] * np.cos(in_) bs = n[2] out = np.arctan(-bc / (bs + 1e-9)) return out
Example 18
Project: HorizonNet Author: sunset1995 File: post_proc.py License: MIT License | 5 votes |
def np_xy2coor(xy, z=50, coorW=1024, coorH=512, floorW=1024, floorH=512): ''' xy: N x 2 ''' x = xy[:, 0] - floorW / 2 + 0.5 y = xy[:, 1] - floorH / 2 + 0.5 u = np.arctan2(x, -y) v = np.arctan(z / np.sqrt(x**2 + y**2)) coorx = (u / (2 * PI) + 0.5) * coorW - 0.5 coory = (-v / PI + 0.5) * coorH - 0.5 return np.hstack([coorx[:, None], coory[:, None]])
Example 19
Project: HorizonNet Author: sunset1995 File: panostretch.py License: MIT License | 5 votes |
def pano_stretch(img, corners, kx, ky, order=1): ''' img: [H, W, C] corners: [N, 2] in image coordinate (x, y) format kx: Stretching along front-back direction ky: Stretching along left-right direction order: Interpolation order. 0 for nearest-neighbor. 1 for bilinear. ''' # Process image sin_u, cos_u, tan_v = uv_tri(img.shape[1], img.shape[0]) u0 = np.arctan2(sin_u * kx / ky, cos_u) v0 = np.arctan(tan_v * np.sin(u0) / sin_u * ky) refx = (u0 / (2 * np.pi) + 0.5) * img.shape[1] - 0.5 refy = (v0 / np.pi + 0.5) * img.shape[0] - 0.5 # [TODO]: using opencv remap could probably speedup the process a little stretched_img = np.stack([ map_coordinates(img[..., i], [refy, refx], order=order, mode='wrap') for i in range(img.shape[-1]) ], axis=-1) # Process corners corners_u0 = coorx2u(corners[:, 0], img.shape[1]) corners_v0 = coory2v(corners[:, 1], img.shape[0]) corners_u = np.arctan2(np.sin(corners_u0) * ky / kx, np.cos(corners_u0)) corners_v = np.arctan(np.tan(corners_v0) * np.sin(corners_u) / np.sin(corners_u0) / ky) cornersX = u2coorx(corners_u, img.shape[1]) cornersY = v2coory(corners_v, img.shape[0]) stretched_corners = np.stack([cornersX, cornersY], axis=-1) return stretched_img, stretched_corners
Example 20
Project: tangent Author: google File: functions.py License: Apache License 2.0 | 5 votes |
def numpy_arctan(a): return np.arctan(a)
Example 21
Project: tangent Author: google File: functions.py License: Apache License 2.0 | 5 votes |
def cart2polar(a, b): r = np.sqrt(a**2.0 + b**2.0) theta = np.arctan(b, a) # Should really be arctan2 return r, theta
Example 22
Project: tangent Author: google File: grads.py License: Apache License 2.0 | 5 votes |
def arctan(y, x): d[x] = d[y] / (1.0 + x * x)
Example 23
Project: RacingRobot Author: sergionr2 File: image_processing.py License: MIT License | 5 votes |
def processImage(image, debug=False): """ :param image: (bgr image) :param debug: (bool) :return:(float, float) """ x, y = predict(model, image) if debug: return x, y # Compute bezier path and target point control_points = computeControlPoints(x, y, add_current_pos=True) target = bezier(TARGET_POINT, control_points) # Linear Regression to fit a line # It estimates the line curve # Case x = cst, m = 0 if len(np.unique(x)) == 1: # pragma: no cover turn_percent = 0 else: # Linear regression using least squares method # x = m*y + b -> y = 1/m * x - b/m if m != 0 A = np.vstack([y, np.ones(len(y))]).T m, b = np.linalg.lstsq(A, x, rcond=-1)[0] # Compute the angle between the reference and the fitted line track_angle = np.arctan(1 / m) diff_angle = abs(REF_ANGLE) - abs(track_angle) # Estimation of the line curvature turn_percent = (diff_angle / MAX_ANGLE) * 100 return turn_percent, target[0]
Example 24
Project: python-control Author: python-control File: rlocus.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def _default_zetas(xlim, ylim): """Return default list of dumps coefficients""" sep1 = -xlim[0]/4 ang1 = [np.arctan((sep1*i)/ylim[1]) for i in np.arange(1, 4, 1)] sep2 = ylim[1] / 3 ang2 = [np.arctan(-xlim[0]/(ylim[1]-sep2*i)) for i in np.arange(1, 3, 1)] angules = np.concatenate((ang1, ang2)) angules = np.insert(angules, len(angules), np.pi/2) zeta = np.sin(angules) return zeta.tolist()
Example 25
Project: e2c Author: ericjang File: viz_results.py License: Apache License 2.0 | 5 votes |
def viz_z(sess, ckptfile): e2c.saver.restore(sess,ckptfile) # restore variable values dataset=PlaneData("data/plane1.npz","data/env1.png") Ps,NPs=dataset.getPSpace() batch_size=e2c.batch_size n0=NPs.shape[0] if False: Ps=np.vstack((Ps,NPs)) xy=np.zeros([Ps.shape[0], 2]) xy[:,0]=Ps[:,1] xy[:,1]=20-Ps[:,0] # for the purpose of computing theta, map centered @ origin Zs=np.zeros([Ps.shape[0], e2c.z_dim]) theta=np.arctan(xy[:,1]/xy[:,0]) for i in range(Ps.shape[0] // batch_size): print("batch %d" % i) x_val=dataset.getXPs(Ps[i*batch_size:(i+1)*batch_size,:]) Zs[i*batch_size:(i+1)*batch_size,:]=sess.run(e2c.z, {e2c.x:x_val}) # last remaining points may not fit precisely into 1 minibatch. x_val=dataset.getXPs(Ps[-batch_size:,:]) Zs[-batch_size:,:]=sess.run(e2c.z, {e2c.x:x_val}) if False: theta[-n0:]=1; fig,arr=plt.subplots(1,2) arr[0].scatter(Ps[:,1], 40-Ps[:,0], c=(np.pi+theta)/(2*np.pi)) arr[0].set_title('True State Space') arr[1].scatter(Zs[:,0],Zs[:,1], c=(np.pi+theta)/(2*np.pi)) arr[1].set_title('Latent Space Z') #plt.show() return fig
Example 26
Project: feets Author: quatrope File: ext_fourier_components.py License: MIT License | 5 votes |
def _components(self, magnitude, time, error, lscargle_kwds): time = time - np.min(time) A, PH = [], [] for i in range(3): frequency, power = lscargle( time=time, magnitude=magnitude, error=error, **lscargle_kwds ) fmax = np.argmax(power) fundamental_Freq = frequency[fmax] Atemp, PHtemp = [], [] omagnitude = magnitude for j in range(4): function_to_fit = self._yfunc_maker((j + 1) * fundamental_Freq) popt0, popt1, popt2 = curve_fit( function_to_fit, time, omagnitude )[0][:3] Atemp.append(np.sqrt(popt0 ** 2 + popt1 ** 2)) PHtemp.append(np.arctan(popt1 / popt0)) model = self._model( time, popt0, popt1, popt2, (j + 1) * fundamental_Freq ) magnitude = np.array(magnitude) - model A.append(Atemp) PH.append(PHtemp) PH = np.asarray(PH) scaledPH = PH - PH[:, 0].reshape((len(PH), 1)) return A, scaledPH
Example 27
Project: feets Author: quatrope File: ext_fourier_components_orig.py License: MIT License | 5 votes |
def _components(self, magnitude, time, ofac): time = time - np.min(time) A, PH = [], [] for i in range(3): wk1, wk2, nout, jmax, prob = lomb.fasper( time, magnitude, ofac, 100.) fundamental_Freq = wk1[jmax] Atemp, PHtemp = [], [] omagnitude = magnitude for j in range(4): function_to_fit = self._yfunc_maker((j + 1) * fundamental_Freq) popt0, popt1, popt2 = curve_fit( function_to_fit, time, omagnitude)[0][:3] Atemp.append(np.sqrt(popt0 ** 2 + popt1 ** 2)) PHtemp.append(np.arctan(popt1 / popt0)) model = self._model( time, popt0, popt1, popt2, (j+1) * fundamental_Freq) magnitude = np.array(magnitude) - model A.append(Atemp) PH.append(PHtemp) PH = np.asarray(PH) scaledPH = PH - PH[:, 0].reshape((len(PH), 1)) return A, scaledPH
Example 28
Project: pulse2percept Author: pulse2percept File: test_geometry.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_cart2pol(): npt.assert_almost_equal(cart2pol(0, 0), (0, 0)) npt.assert_almost_equal(cart2pol(10, 0), (0, 10)) npt.assert_almost_equal(cart2pol(3, 4), (np.arctan(4 / 3.0), 5)) npt.assert_almost_equal(cart2pol(4, 3), (np.arctan(3 / 4.0), 5))
Example 29
Project: pulse2percept Author: pulse2percept File: test_geometry.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_pol2cart(): npt.assert_almost_equal(pol2cart(0, 0), (0, 0)) npt.assert_almost_equal(pol2cart(0, 10), (10, 0)) npt.assert_almost_equal(pol2cart(np.arctan(4 / 3.0), 5), (3, 4)) npt.assert_almost_equal(pol2cart(np.arctan(3 / 4.0), 5), (4, 3))
Example 30
Project: MesoNet Author: DariusAf File: pipeline.py License: Apache License 2.0 | 5 votes |
def find_coordinates(self, landmark, K = 2.2): ''' We either choose K * distance(eyes, mouth), or, if the head is tilted, K * distance(eye 1, eye 2) /!\ landmarks coordinates are in (x,y) not (y,x) ''' E1 = np.mean(landmark['left_eye'], axis=0) E2 = np.mean(landmark['right_eye'], axis=0) E = (E1 + E2) / 2 N = np.mean(landmark['nose_tip'], axis=0) / 2 + np.mean(landmark['nose_bridge'], axis=0) / 2 B1 = np.mean(landmark['top_lip'], axis=0) B2 = np.mean(landmark['bottom_lip'], axis=0) B = (B1 + B2) / 2 C = N l1 = self.L2(E1, E2) l2 = self.L2(B, E) l = max(l1, l2) * K if (B[1] == E[1]): if (B[0] > E[0]): rot = 90 else: rot = -90 else: rot = np.arctan((B[0] - E[0]) / (B[1] - E[1])) / np.pi * 180 return ((floor(C[1]), floor(C[0])), floor(l), rot)