diff --git a/doc/examples/resting_state_fmri.py b/doc/examples/resting_state_fmri.py index 84f42d24..36c4e955 100644 --- a/doc/examples/resting_state_fmri.py +++ b/doc/examples/resting_state_fmri.py @@ -31,7 +31,6 @@ #Import from other libraries: import numpy as np import matplotlib.pyplot as plt -from matplotlib.mlab import csv2rec import nitime #Import the time-series objects: @@ -49,14 +48,12 @@ """ -We use csv2rec to read the data in from file to a recarray: +We use Numpy to read the data in from file to a recarray: """ data_path = os.path.join(nitime.__path__[0], 'data') -data_rec = csv2rec(os.path.join(data_path, 'fmri_timeseries.csv')) - data_rec = np.genfromtxt(os.path.join(data_path, 'fmri_timeseries.csv'), names=True, delimiter=',') diff --git a/nitime/algorithms/cohere.py b/nitime/algorithms/cohere.py index 2a1e63ed..a98e1ed6 100644 --- a/nitime/algorithms/cohere.py +++ b/nitime/algorithms/cohere.py @@ -975,7 +975,7 @@ def cache_fft(time_series, ij, lb=0, ub=None, n_freqs = ub_idx - lb_idx # Make the window: - if mlab.cbook.iterable(window): + if np.iterable(window): assert(len(window) == NFFT) window_vals = window else: diff --git a/nitime/algorithms/event_related.py b/nitime/algorithms/event_related.py index 2e4373d5..a8c17010 100644 --- a/nitime/algorithms/event_related.py +++ b/nitime/algorithms/event_related.py @@ -55,9 +55,9 @@ def fir(timeseries, design): and Unbiased Approach. Human Brain Mapping, 11:249-260 """ - X = np.matrix(design) - y = np.matrix(timeseries) - h = np.array(linalg.pinv(X.T * X) * X.T * y.T) + X = np.array(design) + y = np.array(timeseries) + h = np.array(linalg.pinv(X.T @ X) @ X.T @ y.T) return h diff --git a/nitime/algorithms/spectral.py b/nitime/algorithms/spectral.py index 3afb1b90..5cee12bb 100644 --- a/nitime/algorithms/spectral.py +++ b/nitime/algorithms/spectral.py @@ -105,7 +105,7 @@ def get_spectra(time_series, method=None): Fs = method.get('Fs', 2 * np.pi) detrend = method.get('detrend', mlab.detrend_none) window = method.get('window', mlab.window_hanning) - n_overlap = method.get('n_overlap', int(np.ceil(NFFT / 2))) + n_overlap = method.get('n_overlap', int(np.ceil(NFFT // 2))) # The length of the spectrum depends on how many sides are taken, which # depends on whether or not this is a complex object: @@ -587,7 +587,7 @@ def multi_taper_psd( sdf_est /= Fs if sides == 'onesided': - freqs = np.linspace(0, Fs / 2, NFFT / 2 + 1) + freqs = np.linspace(0, Fs / 2, NFFT // 2 + 1) else: freqs = np.linspace(0, Fs, NFFT, endpoint=False) @@ -726,7 +726,7 @@ def multi_taper_csd(s, Fs=2 * np.pi, NW=None, BW=None, low_bias=True, csdfs /= Fs if sides == 'onesided': - freqs = np.linspace(0, Fs / 2, NFFT / 2 + 1) + freqs = np.linspace(0, Fs / 2, NFFT // 2 + 1) else: freqs = np.linspace(0, Fs, NFFT, endpoint=False) diff --git a/nitime/algorithms/tests/test_autoregressive.py b/nitime/algorithms/tests/test_autoregressive.py index d1e04dac..294de3d5 100644 --- a/nitime/algorithms/tests/test_autoregressive.py +++ b/nitime/algorithms/tests/test_autoregressive.py @@ -1,6 +1,5 @@ import numpy as np import numpy.testing as npt -import numpy.testing.decorators as dec import nitime.algorithms as tsa import nitime.utils as utils @@ -87,7 +86,6 @@ def test_AR_LD(): npt.assert_almost_equal(avg_pwr, avg_pwr_est, decimal=0) -@dec.slow def test_MAR_est_LWR(): """ diff --git a/nitime/algorithms/tests/test_spectral.py b/nitime/algorithms/tests/test_spectral.py index 61cd3e2e..08cece54 100644 --- a/nitime/algorithms/tests/test_spectral.py +++ b/nitime/algorithms/tests/test_spectral.py @@ -7,7 +7,6 @@ import scipy from scipy import fftpack import numpy.testing as npt -import numpy.testing.decorators as dec import pytest import nitime.algorithms as tsa @@ -320,7 +319,6 @@ def test_mtm_cross_spectrum(): tsa.mtm_cross_spectrum(tspectra, np.r_[tspectra, tspectra], (w, w)) -@dec.slow def test_multi_taper_psd_csd(): """ diff --git a/nitime/analysis/base.py b/nitime/analysis/base.py index 2541c3e5..d0ea92de 100644 --- a/nitime/analysis/base.py +++ b/nitime/analysis/base.py @@ -1,5 +1,5 @@ -from inspect import getargspec +from inspect import getfullargspec from nitime import descriptors as desc @@ -16,7 +16,7 @@ class BaseAnalyzer(desc.ResetMixin): @desc.setattr_on_read def parameterlist(self): - plist = getargspec(self.__init__).args + plist = getfullargspec(self.__init__).args plist.remove('self') plist.remove('input') return plist diff --git a/nitime/analysis/snr.py b/nitime/analysis/snr.py index 75a2d073..7ca3a6ae 100644 --- a/nitime/analysis/snr.py +++ b/nitime/analysis/snr.py @@ -90,7 +90,7 @@ def __init__(self, input=None, bandwidth=None, adaptive=False, @desc.setattr_on_read def mt_frequencies(self): return np.linspace(0, self.input.sampling_rate / 2, - self.input.data.shape[-1] / 2 + 1) + self.input.data.shape[-1] // 2 + 1) @desc.setattr_on_read def mt_signal_psd(self): diff --git a/nitime/tests/test_algorithms.py b/nitime/tests/test_algorithms.py index 556bc1e1..a5af87db 100644 --- a/nitime/tests/test_algorithms.py +++ b/nitime/tests/test_algorithms.py @@ -2,7 +2,6 @@ import numpy as np import numpy.testing as npt -import numpy.testing.decorators as dec from scipy.signal import signaltools from scipy import fftpack @@ -161,7 +160,7 @@ def test_psd_matlab(): npt.assert_almost_equal(fxx_mlab, fxx_matlab, decimal=5) -@dec.slow + def test_long_dpss_win(): """ Test that very long dpss windows can be generated (using interpolation)""" diff --git a/nitime/utils.py b/nitime/utils.py index 4d141a9c..62893ac3 100644 --- a/nitime/utils.py +++ b/nitime/utils.py @@ -493,7 +493,7 @@ def adaptive_weights(yk, eigvals, sides='onesided', max_iter=150): """) # we'll hope this is a correct length for L N = yk.shape[-1] - L = N / 2 + 1 if sides == 'onesided' else N + L = N // 2 + 1 if sides == 'onesided' else N return (np.multiply.outer(np.sqrt(eigvals), np.ones(L)), 2 * K) rt_eig = np.sqrt(eigvals) @@ -1161,8 +1161,8 @@ def fftconvolve(in1, in2, mode="full", axis=None): """ s1 = np.array(in1.shape) s2 = np.array(in2.shape) - complex_result = (np.issubdtype(in1.dtype, np.complex) or - np.issubdtype(in2.dtype, np.complex)) + complex_result = (np.issubdtype(in1.dtype, np.complex128) or + np.issubdtype(in2.dtype, np.complex128)) if axis is None: size = s1 + s2 - 1 @@ -1206,10 +1206,10 @@ def fftconvolve(in1, in2, mode="full", axis=None): # 'get' utils #----------------------------------------------------------------------------- def get_freqs(Fs, n): - """Returns the center frequencies of the frequency decomposotion of a time + """Returns the center frequencies of the frequency decomposition of a time series of length n, sampled at Fs Hz""" - return np.linspace(0, float(Fs) / 2, float(n) / 2 + 1) + return np.linspace(0, Fs / 2, int(n / 2 + 1)) def circle_to_hz(omega, Fsamp): @@ -2037,8 +2037,8 @@ def zscore(time_series, axis=-1): st = time_series.std(axis=axis) sl = [slice(None)] * len(time_series.shape) sl[axis] = np.newaxis - zt = time_series - et[sl] - zt /= st[sl] + zt = time_series - et[tuple(sl)] + zt /= st[tuple(sl)] return zt diff --git a/nitime/viz.py b/nitime/viz.py index 64d085a0..0d8602dd 100644 --- a/nitime/viz.py +++ b/nitime/viz.py @@ -9,9 +9,6 @@ import sys from nitime.six.moves import map from nitime.six.moves import zip -if "nose" in sys.modules: - import matplotlib - matplotlib.use('agg') # Then do all the rest of it: import numpy as np @@ -20,7 +17,7 @@ from matplotlib import pyplot as plt import matplotlib.ticker as ticker import matplotlib.colors as colors -from mpl_toolkits.axes_grid import make_axes_locatable +from mpl_toolkits.axes_grid1 import make_axes_locatable from nitime import timeseries as ts import nitime.utils as tsu