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*po