Skip to content

Commit

Permalink
Merge pull request #134 from vollbier/upstr
Browse files Browse the repository at this point in the history
Fix issues with Python 3 compatibility
  • Loading branch information
jaidevd committed Apr 5, 2016
2 parents cad7874 + 6c1f022 commit 38178d5
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 64 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ coverage.xml
# Sphinx documentation
doc/_build/
doc/apiref/*.rst
doc/modules/generated/

# PyBuilder
target/
Expand Down
1 change: 1 addition & 0 deletions continuous_integration/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ matplotlib
nose
libgfortran
scikit-image
six
2 changes: 1 addition & 1 deletion tftb/generators/analytic_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def anafsk(n_points, n_comp=None, Nbf=4):
.. plot:: docstring_plots/generators/analytic_signals/anafsk.py
"""
if n_comp is None:
n_comp = np.round(n_points / 5)
n_comp = int(np.round(n_points / 5))
m = np.ceil(n_points / n_comp)
m = int(np.ceil(n_points / n_comp))
freqs = 0.25 + 0.25 * (np.floor(Nbf * np.random.rand(m, 1)) / Nbf - (Nbf - 1) / (2 * Nbf))
Expand Down
28 changes: 14 additions & 14 deletions tftb/processing/affine.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, signal, fmin=None, fmax=None, **kwargs):
self.x1 = self.x2 = self.signal.copy()
self.s1 = np.real(self.x1)
self.s2 = np.real(self.x2)
self.m = (self.signal.shape[0] + (self.signal.shape[0] % 2)) / 2
self.m = (self.signal.shape[0] + (self.signal.shape[0] % 2)) // 2
if (fmin is None) or (fmax is None):
stf1 = np.fft.fft(np.fft.fftshift(self.s1[self.ts.min():self.ts.max() + 1]))
stf2 = np.fft.fft(np.fft.fftshift(self.s2[self.ts.min():self.ts.max() + 1]))
Expand Down Expand Up @@ -93,7 +93,7 @@ def _mellin_transform(self, S1, S2):
umin = -self.umax
du = np.abs(self.umax - umin) / (2 * self.m1)
u = np.linspace(umin, self.umax - du, (self.umax - umin) / du)
u[self.m1] = 0
u[int(self.m1)] = 0
self.u = u
beta = (p / float(self.n_voices) - 1) / (2 * np.log(self.q))
return beta, mellin1, mellin2
Expand Down Expand Up @@ -163,12 +163,12 @@ def run(self):
if self.waveparams > 0:
for ptr in range(self.n_voices):
nha = self.waveparams * a[ptr]
tha = np.arange(-np.round(nha), np.round(nha) + 1)
tha = np.arange(-int(np.round(nha)), int(np.round(nha)) + 1)
x = np.exp(-(2 * np.log(10) / (nha ** 2)) * tha ** 2)
y = np.exp(1j * 2 * np.pi * f[ptr] * tha)
ha = x * y
detail = np.convolve(self.z, ha) / np.sqrt(a[ptr])
ix = np.arange(round(nha), detail.shape[0] - np.round(nha) + 1,
ix = np.arange(int(np.round(nha)), detail.shape[0] - int(np.round(nha)) + 1,
dtype=int)
wt[ptr, :] = detail[self.ts]
detail = detail[ix]
Expand All @@ -178,7 +178,7 @@ def run(self):
ha = mexhat(f[ptr])
nha = (ha.shape[0] - 1) / 2
detail = np.convolve(self.z, ha) / np.sqrt(a[ptr])
ix = np.arange(round(nha) + 1, detail.shape[0] - np.round(nha) + 1)
ix = np.arange(int(np.round(nha)) + 1, detail.shape[0] - int(np.round(nha)) + 1)
detail = detail[ix]
wt[ptr, :] = detail[self.ts]
self.tfr[ptr, :] = detail[self.ts] * np.conj(detail[self.ts])
Expand Down Expand Up @@ -206,8 +206,8 @@ def run(self):

# Normalization
SP = np.fft.fft(self.z, axis=0)
indmin = 1 + np.round(self.fmin * (self.signal.shape[0] - 2))
indmax = 1 + np.round(self.fmax * (self.signal.shape[0] - 2))
indmin = 1 + int(np.round(self.fmin * (self.signal.shape[0] - 2)))
indmax = 1 + int(np.round(self.fmax * (self.signal.shape[0] - 2)))
SPana = SP[indmin:(indmax + 1)]
self.tfr = np.real(self.tfr)
self.tfr = self.tfr * (np.linalg.norm(SPana) ** 2) / integrate_2d(self.tfr, self.ts, f) / self.n_voices
Expand All @@ -225,10 +225,10 @@ def __init__(self, signal, form="A", fmin=None, fmax=None, n_voices=None,
fmax=fmax, n_voices=n_voices, **kwargs)
umaxunt = lambda x: (np.sqrt(1 + (x / 2.0) ** 2) + x / 2.0) / (np.sqrt(1 + (x / 2.0) ** 2) - x / 2.0) - self.fmax / self.fmin
self.umax = newton(umaxunt, 0)
self.m = (self.signal.shape[0] + (self.signal.shape[0] % 2)) / 2
self.m = (self.signal.shape[0] + (self.signal.shape[0] % 2)) // 2
teq = self.m / (self.fmax * self.umax)
if teq < 2 * self.m:
m0 = np.round((2 * self.m ** 2) / teq - self.m) + 1
m0 = int(np.round((2 * self.m ** 2) / teq - self.m)) + 1
m1 = self.m + m0
self.T = 2 * (self.m + m0) - 1
else:
Expand Down Expand Up @@ -299,7 +299,7 @@ def __init__(self, signal, fmin=None, fmax=None, n_voices=None, **kwargs):
self.umax = umaxdfla_solve(self.fmax / self.fmin)
teq = self.m / (self.fmax * self.umax)
if teq < 2 * self.m:
m0 = np.round((2 * self.m ** 2) / teq - self.m) + 1
m0 = int(round((2 * self.m ** 2) / teq - self.m)) + 1
self.T = 2 * (self.m + m0) - 1
else:
m0 = 0
Expand Down Expand Up @@ -341,7 +341,7 @@ def __init__(self, signal, fmin=None, fmax=None, n_voices=None, **kwargs):
self.umax = brenth(umaxbert, 0, 4)
teq = self.m / (self.fmax * self.umax)
if teq < self.signal.shape[0]:
m0 = np.round((2 * self.m ** 2) / teq - self.m) + 1
m0 = int(np.round((2 * self.m ** 2) / teq - self.m)) + 1
m1 = self.m + m0
self.T = 2 * m1 - 1
else:
Expand All @@ -357,7 +357,7 @@ def run(self):
S1, S2 = self._geometric_sample()
beta, mellin1, mellin2 = self._mellin_transform(S1, S2)
# Computation of P0(t. f, f)
waf = np.zeros((2 * self.m1, self.n_voices), dtype=complex)
waf = np.zeros((2 * int(self.m1), self.n_voices), dtype=complex)
for n in np.hstack((np.arange(1, self.m1 + 1), np.arange(self.m1 + 2, 2 * self.m1 + 1))):
mx1 = np.exp((-2 * 1j * np.pi * beta + 0.5) * np.log((self.u[n - 1] / 2) *
np.exp(-self.u[n - 1] / 2.0) / np.sinh(self.u[n - 1] / 2))) * mellin1
Expand Down Expand Up @@ -527,8 +527,8 @@ def smoothed_pseudo_wigner(signal, timestamps=None, K='bertrand', nh0=None,
# Normalization
sp1 = np.fft.fft(hilbert(s1))
sp2 = np.fft.fft(hilbert(s2))
indmin = 1 + np.round(fmin * (xrow - 2))
indmax = 1 + np.round(fmax * (xrow - 2))
indmin = 1 + int(np.round(fmin * (xrow - 2)))
indmax = 1 + int(np.round(fmax * (xrow - 2)))
sp1_ana = sp1[indmin:(indmax + 1)]
sp2_ana = sp2[indmin:(indmax + 1)]
xx = np.dot(np.real(sp1_ana), np.real(sp2_ana))
Expand Down
14 changes: 7 additions & 7 deletions tftb/processing/ambiguity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def wide_band(signal, fmin=None, fmax=None, N=None):
raise ValueError("The input signal should be one dimensional.")
s_ana = hilbert(np.real(signal))
nx = signal.shape[0]
m = np.round(nx / 2.0)
m = int(np.round(nx / 2.0))
t = np.arange(nx) - m
tmin = 0
tmax = nx - 1
Expand Down Expand Up @@ -120,16 +120,16 @@ def narrow_band(signal, lag=None, n_fbins=None):

naf = np.zeros((n_fbins, taucol), dtype=complex)
for icol in range(taucol):
taui = lag[icol]
t = np.arange(abs(taui), n - abs(taui))
taui = int(lag[icol])
t = np.arange(abs(taui), n - abs(taui)).astype(int)
naf[t, icol] = signal[t + taui] * np.conj(signal[t - taui])
naf = np.fft.fft(naf, axis=0)

_ix1 = np.arange((n_fbins + (n_fbins % 2)) / 2, n_fbins)
_ix2 = np.arange((n_fbins + (n_fbins % 2)) / 2)
_ix1 = np.arange((n_fbins + (n_fbins % 2)) // 2, n_fbins)
_ix2 = np.arange((n_fbins + (n_fbins % 2)) // 2)

_xi1 = -(n_fbins - (n_fbins % 2)) / 2
_xi2 = ((n_fbins + (n_fbins % 2)) / 2 - 1)
_xi1 = -(n_fbins - (n_fbins % 2)) // 2
_xi2 = ((n_fbins + (n_fbins % 2)) // 2 - 1)
xi = np.arange(_xi1, _xi2 + 1, dtype=float) / n_fbins
naf = naf[np.hstack((_ix1, _ix2)), :]
return naf, lag, xi
Expand Down
6 changes: 3 additions & 3 deletions tftb/processing/cohen.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Spectrogram(ShortTimeFourierTransform):
name = "spectrogram"

def run(self):
lh = (self.fwindow.shape[0] - 1) / 2
lh = (self.fwindow.shape[0] - 1) // 2
for icol in range(self.tfr.shape[1]):
ti = self.ts[icol]
start = -np.min([np.round(self.n_fbins / 2.0) - 1, lh, ti - 1])
Expand Down Expand Up @@ -103,7 +103,7 @@ def run(self):
return self.tfr, self.ts, self.freqs

def plot(self, kind='cmap', threshold=0.05, sqmod=True, **kwargs):
self.tfr = self.tfr[:(self.tfr.shape[0] / 2), :]
self.tfr = self.tfr[:(self.tfr.shape[0] // 2), :]
if sqmod:
self.tfr = np.abs(self.tfr) ** 2
_threshold = np.amax(self.tfr) * threshold
Expand Down Expand Up @@ -180,7 +180,7 @@ class PseudoWignerVilleDistribution(WignerVilleDistribution):
name = "pseudo winger-ville"

def run(self):
lh = (self.fwindow.shape[0] - 1) / 2
lh = (self.fwindow.shape[0] - 1) // 2
for icol in range(self.ts.shape[0]):
ti = self.ts[icol]
taumaxvals = (ti, self.signal.shape[0] - ti - 1,
Expand Down
10 changes: 5 additions & 5 deletions tftb/processing/linear.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run(self):
.. math:: X[m, w] = \sum_{n=-\infty}^{\infty}x[n]w[n - m]e^{-j\omega n}
Where :math:`w` is a Hamming window."""
lh = (self.fwindow.shape[0] - 1) / 2
lh = (self.fwindow.shape[0] - 1) // 2
for icol in range(self.tfr.shape[1]):
ti = self.ts[icol]
start = -np.min([np.round(self.n_fbins / 2.0) - 1, lh, ti - 1])
Expand Down Expand Up @@ -115,9 +115,9 @@ def gabor(signal, n_coeff=None, q_oversample=None, window=None):
if window is None:
window = np.exp(np.log(0.005) * np.linspace(-1, 1, nearest_odd(n_coeff)) ** 2)
window = window / np.linalg.norm(window)
m = q_oversample * signal.shape[0] / float(n_coeff)
mb = signal.shape[0] / float(n_coeff)
nb = signal.shape[0] / float(m)
m = int(q_oversample * signal.shape[0] / float(n_coeff))
mb = int(signal.shape[0] / float(n_coeff))
nb = int(signal.shape[0] / float(m))

# Zak transform?
nh = window.shape[0]
Expand All @@ -130,7 +130,7 @@ def gabor(signal, n_coeff=None, q_oversample=None, window=None):
end = np.round((signal.shape[0] + nh - 1) / 2) - alpha
hn1[np.arange(start - 1, end).astype(int)] = window

msig = hn1.reshape(nb, m, order='F')
msig = hn1.reshape(int(nb), int(m), order='F')
dzth = np.fft.fft(msig.T, axis=0) / np.sqrt(m)
mzh = np.zeros((m, mb))
x = np.arange(1, m + 1, dtype=float)
Expand Down
8 changes: 4 additions & 4 deletions tftb/processing/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ def hough_transform(image, m=None, n=None):
imax = np.amax(image)

if xmax % 2 != 0:
xc = (xmax + 1) / 2
xc = (xmax + 1) // 2
xf = xc - 1
else:
xc = xf = xmax / 2
xc = xf = xmax // 2
x0 = 1 - xc

if ymax % 2 != 0:
yc = (ymax + 1) / 2
yc = (ymax + 1) // 2
yf = yc - 1
else:
yc = yf = ymax / 2
yc = yf = ymax // 2
y0 = 1 - yc

for x in range(x0, xf + 1):
Expand Down
Loading

0 comments on commit 38178d5

Please sign in to comment.