Skip to content

Commit

Permalink
Numpy types; closes #94
Browse files Browse the repository at this point in the history
  • Loading branch information
prisae committed Jul 4, 2020
1 parent 7396426 commit 81ae4ad
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
5 changes: 3 additions & 2 deletions empymod/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ def halfspace(off, angle, zsrc, zrec, etaH, etaV, freqtime, ab, signal,
if signal == -1: # Calculate DC
time = np.r_[time[:, 0], 1e4][:, None]
freqtime = time
dtype = float
dtype = np.float_

# Other defined parameters
rh = np.sqrt(xco**2 + yco**2) # Horizontal distance in space
Expand Down Expand Up @@ -1167,7 +1167,8 @@ def airwave(sval, hp, rp, res, fab, delta):

def coeff_dk(k, K):
r"""Return coefficients Dk for k, K."""
n = np.arange(int((k+1)/2), np.min([k, K/2])+.5, 1, dtype=int)
n = np.arange(
int((k+1)/2), np.min([k, K/2])+.5, 1, dtype=np.int_)
Dk = n**(K/2)*fn(2*n)
Dk /= fn(n)*fn(n-1)*fn(k-n)*fn(2*n-k)*fn(K/2-n)
return Dk.sum()*(-1)**(k+K/2)
Expand Down
18 changes: 9 additions & 9 deletions empymod/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ def hankel_qwe(zsrc, zrec, lsrc, lrec, off, ang_fact, depth, ab, etaH, etaV,
# as QWE is not designed for these intervals.
check0 = np.log(intervals[:, :-1])
check1 = np.log(intervals[:, 1:])
numerator = np.zeros((off.size, maxint), dtype=complex)
denominator = np.zeros((off.size, maxint), dtype=complex)
numerator = np.zeros((off.size, maxint), dtype=np.complex_)
denominator = np.zeros((off.size, maxint), dtype=np.complex_)

if k_used[0]:
numerator += sPJ0r(check0) + 1j*sPJ0i(check0)
Expand All @@ -325,7 +325,7 @@ def hankel_qwe(zsrc, zrec, lsrc, lrec, off, ang_fact, depth, ab, etaH, etaV,
doqwe = np.all((np.abs(numerator)/np.abs(denominator) < diff_quad), 1)

# Pre-allocate output array
fEM = np.zeros(off.size, dtype=complex)
fEM = np.zeros(off.size, dtype=np.complex_)
conv = True

# Carry out SciPy's Quad if required
Expand Down Expand Up @@ -357,7 +357,7 @@ def hankel_qwe(zsrc, zrec, lsrc, lrec, off, ang_fact, depth, ab, etaH, etaV,
sPJ0b = sPJ0br(np.log(lambd)) + 1j*sPJ0bi(np.log(lambd))

# Carry out and return the Hankel transform for this interval
sEM = np.zeros_like(numerator, dtype=complex)
sEM = np.zeros_like(numerator, dtype=np.complex_)
if k_used[1]:
sEM += np.sum(np.reshape(sPJ1*BJ1, (off.size, nquad, -1),
order='F'), 1)
Expand Down Expand Up @@ -395,7 +395,7 @@ def getkernel(i, inplambd, inpoff, inpfang):
ab, xdirect, msrc, mrec)

# Carry out and return the Hankel transform for this interval
gEM = np.zeros_like(inpoff, dtype=complex)
gEM = np.zeros_like(inpoff, dtype=np.complex_)
if k_used[1]:
gEM += inpfang*np.dot(PJ1[0, :], BJ1[iB])
if ab in [11, 12, 21, 22, 14, 24, 15, 25]: # Because of J2
Expand Down Expand Up @@ -481,7 +481,7 @@ def hankel_quad(zsrc, zrec, lsrc, lrec, off, ang_fact, depth, ab, etaH, etaV,
sPJ0bi = None

# Pre-allocate output array
fEM = np.zeros(off.size, dtype=complex)
fEM = np.zeros(off.size, dtype=np.complex_)
conv = True

# Input-dictionary for quad
Expand Down Expand Up @@ -746,7 +746,7 @@ def fourier_fftlog(fEM, time, freq, ftarg):
a = fftpack.rfft(a)

# 4.b
m = np.arange(1, n//2, dtype=int) # index variable
m = np.arange(1, n//2, dtype=np.int_) # index variable
if q == 0: # unbiased (q = 0) transform
# multiply by (kr)^[- i 2 m pi/(n dlnr)] U_mu[i 2 m pi/(n dlnr)]
ar = a[2*m-1]
Expand Down Expand Up @@ -918,7 +918,7 @@ def dlf(signal, points, out_pts, filt, pts_per_dec, kind=None, ang_fact=None,
def spline(values, points, int_pts):
r"""Return `values` at `points` interpolated in log at `int_pts`."""
out = iuSpline(np.log(points), values.real)(np.log(int_pts))
if values.dtype == complex:
if values.dtype == np.complex_:
out = out+1j*iuSpline(np.log(points), values.imag)(np.log(int_pts))
return out

Expand Down Expand Up @@ -1067,7 +1067,7 @@ def getweights(i, inpint):

# 2. Pre-allocate arrays and initialize
EM = np.zeros(EM0.size, dtype=EM0.dtype) # EM array
om = np.ones(EM0.size, dtype=bool) # Convergence array
om = np.ones(EM0.size, dtype=np.bool_) # Convergence array
S = np.zeros((EM0.size, maxint), dtype=EM0.dtype) # Working arr. 4 recurs.
relErr = np.zeros((EM0.size, maxint)) # Relative error
extrap = np.zeros((EM0.size, maxint), dtype=EM0.dtype) # extrap. result
Expand Down
6 changes: 3 additions & 3 deletions empymod/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ def check_time(time, signal, ft, ftarg, verb):
# Calculate minimum and maximum required frequency
minf = np.log10(1/time.max()) + targ['add_dec'][0]
maxf = np.log10(1/time.min()) + targ['add_dec'][1]
n = np.int(maxf - minf)*targ['pts_per_dec']
n = np.int_(maxf - minf)*targ['pts_per_dec']

# Initialize FFTLog, get required parameters
freq, tcalc, dlnr, kr, rk = transform.get_fftlog_input(
Expand Down Expand Up @@ -1329,7 +1329,7 @@ def get_abs(msrc, mrec, srcazm, srcdip, recazm, recdip, verb):
ab_calc = ab_calc % 10*10 + ab_calc // 10 # Swap alpha/beta

# Remove unnecessary ab's
bab = np.asarray(ab_calc*0+1, dtype=bool)
bab = np.asarray(ab_calc*0+1, dtype=np.bool_)

# Remove if source is x- or y-directed
check = np.atleast_1d(srcazm)
Expand Down Expand Up @@ -1468,7 +1468,7 @@ def get_layer_nr(inp, depth):
inp[2] (depths).
"""
zinp = np.array(inp[2], dtype=float)
zinp = np.array(inp[2], dtype=np.float_)

# depth = [-infty : last interface]; create additional depth-array
# pdepth = [fist interface : +infty]
Expand Down
6 changes: 3 additions & 3 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def test_multisrc_multirec(self):
out0t = bipole(src=src0, rec=rec0, signal=0, **model)

# Calculate the single-src/single-rec correspondents
out1f = np.zeros((2, 2), dtype=complex)
out1f = np.zeros((2, 2), dtype=np.complex_)
out1t = np.zeros((2, 2))
for i, rec in enumerate([rec1, rec2]):
for ii, src in enumerate([src1, src2]):
Expand Down Expand Up @@ -941,8 +941,8 @@ def test_dipole_k():
# Check that ab=36 returns zeros
res['inp']['ab'] = 36
w_res0, w_res1 = dipole_k(**res['inp'])
assert_allclose(w_res0, np.zeros(res['PJ0'].shape, dtype=complex))
assert_allclose(w_res1, np.zeros(res['PJ1'].shape, dtype=complex))
assert_allclose(w_res0, np.zeros(res['PJ0'].shape, dtype=np.complex_))
assert_allclose(w_res1, np.zeros(res['PJ1'].shape, dtype=np.complex_))


def test_fem():
Expand Down

0 comments on commit 81ae4ad

Please sign in to comment.