Skip to content

Commit 6f95bea

Browse files
authored
Merge pull request #171 from arokem/mpl_iterable
Address warnings
2 parents 542f4b1 + ca72309 commit 6f95bea

File tree

11 files changed

+20
-31
lines changed

11 files changed

+20
-31
lines changed

doc/examples/resting_state_fmri.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#Import from other libraries:
3232
import numpy as np
3333
import matplotlib.pyplot as plt
34-
from matplotlib.mlab import csv2rec
3534

3635
import nitime
3736
#Import the time-series objects:
@@ -49,14 +48,12 @@
4948

5049
"""
5150
52-
We use csv2rec to read the data in from file to a recarray:
51+
We use Numpy to read the data in from file to a recarray:
5352
5453
"""
5554

5655
data_path = os.path.join(nitime.__path__[0], 'data')
5756

58-
data_rec = csv2rec(os.path.join(data_path, 'fmri_timeseries.csv'))
59-
6057
data_rec = np.genfromtxt(os.path.join(data_path, 'fmri_timeseries.csv'),
6158
names=True, delimiter=',')
6259

nitime/algorithms/cohere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ def cache_fft(time_series, ij, lb=0, ub=None,
975975

976976
n_freqs = ub_idx - lb_idx
977977
# Make the window:
978-
if mlab.cbook.iterable(window):
978+
if np.iterable(window):
979979
assert(len(window) == NFFT)
980980
window_vals = window
981981
else:

nitime/algorithms/event_related.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ def fir(timeseries, design):
5555
and Unbiased Approach. Human Brain Mapping, 11:249-260
5656
5757
"""
58-
X = np.matrix(design)
59-
y = np.matrix(timeseries)
60-
h = np.array(linalg.pinv(X.T * X) * X.T * y.T)
58+
X = np.array(design)
59+
y = np.array(timeseries)
60+
h = np.array(linalg.pinv(X.T @ X) @ X.T @ y.T)
6161
return h
6262

6363

nitime/algorithms/spectral.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def get_spectra(time_series, method=None):
105105
Fs = method.get('Fs', 2 * np.pi)
106106
detrend = method.get('detrend', mlab.detrend_none)
107107
window = method.get('window', mlab.window_hanning)
108-
n_overlap = method.get('n_overlap', int(np.ceil(NFFT / 2)))
108+
n_overlap = method.get('n_overlap', int(np.ceil(NFFT // 2)))
109109

110110
# The length of the spectrum depends on how many sides are taken, which
111111
# depends on whether or not this is a complex object:
@@ -587,7 +587,7 @@ def multi_taper_psd(
587587
sdf_est /= Fs
588588

589589
if sides == 'onesided':
590-
freqs = np.linspace(0, Fs / 2, NFFT / 2 + 1)
590+
freqs = np.linspace(0, Fs / 2, NFFT // 2 + 1)
591591
else:
592592
freqs = np.linspace(0, Fs, NFFT, endpoint=False)
593593

@@ -726,7 +726,7 @@ def multi_taper_csd(s, Fs=2 * np.pi, NW=None, BW=None, low_bias=True,
726726
csdfs /= Fs
727727

728728
if sides == 'onesided':
729-
freqs = np.linspace(0, Fs / 2, NFFT / 2 + 1)
729+
freqs = np.linspace(0, Fs / 2, NFFT // 2 + 1)
730730
else:
731731
freqs = np.linspace(0, Fs, NFFT, endpoint=False)
732732

nitime/algorithms/tests/test_autoregressive.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22
import numpy.testing as npt
3-
import numpy.testing.decorators as dec
43

54
import nitime.algorithms as tsa
65
import nitime.utils as utils
@@ -87,7 +86,6 @@ def test_AR_LD():
8786
npt.assert_almost_equal(avg_pwr, avg_pwr_est, decimal=0)
8887

8988

90-
@dec.slow
9189
def test_MAR_est_LWR():
9290
"""
9391

nitime/algorithms/tests/test_spectral.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import scipy
88
from scipy import fftpack
99
import numpy.testing as npt
10-
import numpy.testing.decorators as dec
1110
import pytest
1211

1312
import nitime.algorithms as tsa
@@ -320,7 +319,6 @@ def test_mtm_cross_spectrum():
320319
tsa.mtm_cross_spectrum(tspectra, np.r_[tspectra, tspectra], (w, w))
321320

322321

323-
@dec.slow
324322
def test_multi_taper_psd_csd():
325323
"""
326324

nitime/analysis/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from inspect import getargspec
2+
from inspect import getfullargspec
33

44
from nitime import descriptors as desc
55

@@ -16,7 +16,7 @@ class BaseAnalyzer(desc.ResetMixin):
1616

1717
@desc.setattr_on_read
1818
def parameterlist(self):
19-
plist = getargspec(self.__init__).args
19+
plist = getfullargspec(self.__init__).args
2020
plist.remove('self')
2121
plist.remove('input')
2222
return plist

nitime/analysis/snr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def __init__(self, input=None, bandwidth=None, adaptive=False,
9090
@desc.setattr_on_read
9191
def mt_frequencies(self):
9292
return np.linspace(0, self.input.sampling_rate / 2,
93-
self.input.data.shape[-1] / 2 + 1)
93+
self.input.data.shape[-1] // 2 + 1)
9494

9595
@desc.setattr_on_read
9696
def mt_signal_psd(self):

nitime/tests/test_algorithms.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import numpy as np
44
import numpy.testing as npt
5-
import numpy.testing.decorators as dec
65

76
from scipy.signal import signaltools
87
from scipy import fftpack
@@ -161,7 +160,7 @@ def test_psd_matlab():
161160

162161
npt.assert_almost_equal(fxx_mlab, fxx_matlab, decimal=5)
163162

164-
@dec.slow
163+
165164
def test_long_dpss_win():
166165
""" Test that very long dpss windows can be generated (using interpolation)"""
167166

nitime/utils.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ def adaptive_weights(yk, eigvals, sides='onesided', max_iter=150):
493493
""")
494494
# we'll hope this is a correct length for L
495495
N = yk.shape[-1]
496-
L = N / 2 + 1 if sides == 'onesided' else N
496+
L = N // 2 + 1 if sides == 'onesided' else N
497497
return (np.multiply.outer(np.sqrt(eigvals), np.ones(L)), 2 * K)
498498
rt_eig = np.sqrt(eigvals)
499499

@@ -1161,8 +1161,8 @@ def fftconvolve(in1, in2, mode="full", axis=None):
11611161
"""
11621162
s1 = np.array(in1.shape)
11631163
s2 = np.array(in2.shape)
1164-
complex_result = (np.issubdtype(in1.dtype, np.complex) or
1165-
np.issubdtype(in2.dtype, np.complex))
1164+
complex_result = (np.issubdtype(in1.dtype, np.complex128) or
1165+
np.issubdtype(in2.dtype, np.complex128))
11661166

11671167
if axis is None:
11681168
size = s1 + s2 - 1
@@ -1206,10 +1206,10 @@ def fftconvolve(in1, in2, mode="full", axis=None):
12061206
# 'get' utils
12071207
#-----------------------------------------------------------------------------
12081208
def get_freqs(Fs, n):
1209-
"""Returns the center frequencies of the frequency decomposotion of a time
1209+
"""Returns the center frequencies of the frequency decomposition of a time
12101210
series of length n, sampled at Fs Hz"""
12111211

1212-
return np.linspace(0, float(Fs) / 2, float(n) / 2 + 1)
1212+
return np.linspace(0, Fs / 2, int(n / 2 + 1))
12131213

12141214

12151215
def circle_to_hz(omega, Fsamp):
@@ -2037,8 +2037,8 @@ def zscore(time_series, axis=-1):
20372037
st = time_series.std(axis=axis)
20382038
sl = [slice(None)] * len(time_series.shape)
20392039
sl[axis] = np.newaxis
2040-
zt = time_series - et[sl]
2041-
zt /= st[sl]
2040+
zt = time_series - et[tuple(sl)]
2041+
zt /= st[tuple(sl)]
20422042
return zt
20432043

20442044

0 commit comments

Comments
 (0)