Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python version supported #76

Closed
eduardacenteno opened this issue Jan 24, 2022 · 4 comments
Closed

Python version supported #76

eduardacenteno opened this issue Jan 24, 2022 · 4 comments

Comments

@eduardacenteno
Copy link

Hey everyone,
I would like to use Spectrum, but my analysis are all in python 3.9+, and I wouldn't like to send it back to <3.9. I see that the package works until 3.7? Is that correct?

Any plans of making this compatible with newer versions soon?

big thanks,
Best.

@cokelaer
Copy link
Owner

cokelaer commented Mar 1, 2022

@eduardacenteno spectrum is developed under 3.7 . It is tested under 3.6, 3.7, 3.8
There is no reason to not support 3.9 and more. Actually, it may work for 3.9. Have you seen any issues ?

@chmendoza
Copy link

I am getting this error when using Multitapering and the plot method:


ImportError Traceback (most recent call last)
psd = MultiTapering(df.x[t_range], NW=3, NFFT=2048, sampling=fs)
psd.plot()

File ~/local/bin/anaconda/anaconda3/envs/x/lib/python3.9/site-packages/spectrum/psd.py:651, in Spectrum.plot(self, filename, norm, ylim, sides, **kargs)
]()648 from pylab import ylim as plt_ylim
649 #First, check that psd attribute is up-to-date
650 # just to get the PSD to be recomputed if needed
-->
651 _ = self.psd
654 # check that the input sides parameter is correct if provided
655[ if sides is not None:

File ~/local/bin/anaconda/anaconda3/envs/x/lib/python3.9/site-packages/spectrum/psd.py:460, in Spectrum._getPSD(self)
]()458 if self.__psd is None or self.modified is True:
459 logging.debug('Computing PSD.')
-->
460 self()
461 self.modified = False
462[ return self.__psd

File ~/local/bin/anaconda/anaconda3/envs/x/lib/python3.9/site-packages/spectrum/mtm.py:74, in MultiTapering.call(self)
]()73 def call(self):
--->
74 Sk_complex, weights, eigenvalues = pmtm(self.data, self.NW, self.k,
75 NFFT=self.NFFT, e=self.e, v=self.v, method=self.method, show=False)
76 Sk = abs(Sk_complex)**2
78[ if self.method == "adapt":

File ~/local/bin/anaconda/anaconda3/envs/runelabs/lib/python3.9/site-packages/spectrum/mtm.py:164, in pmtm(x, NW, k, NFFT, e, v, method, show)
]()162 if e is None and v is None:
163 if NW is not None:
-->
164 [tapers, eigenvalues] = dpss(N, NW, k=k)
165 else:
166[ raise ValueError("NW must be provided (e.g. 2.5, 3, 3.5, 4")

File ~/local/bin/anaconda/anaconda3/envs/x/lib/python3.9/site-packages/spectrum/mtm.py:348, in dpss(N, NW, k)
]()341 tapers[:,i] *= -1
343 # Now find the eigenvalues of the original
344 # Use the autocovariance sequence technique from Percival and Walden, 1993
345 # pg 390 to get the eigenvalues more precisely (same as matlab output)
346
347 # The values returned in lam are not exacly the same as in the following methods.
-->
348 acvs = _autocov(tapers.transpose(), debias=False) * N
349 nidx = arange(N)
350 W = float(NW)/N

File ~/local/bin/anaconda/anaconda3/envs/x/lib/python3.9/site-packages/spectrum/mtm.py:434, in _autocov(s, **kwargs)
432 s = _remove_bias(s, axis)
433 kwargs['debias'] = False
-->
434[ return _crosscov(s, s, **kwargs)

File ~/local/bin/anaconda/anaconda3/envs/x/lib/python3.9/site-packages/spectrum/mtm.py:470, in _crosscov(x, y, axis, all_lags, debias)
]()468 slicing = [slice(d) for d in x.shape]
469 slicing[axis] = slice(None,None,-1)
-->
470 sxy = _fftconvolve(x, y[tuple(slicing)], axis=axis, mode='full')
471 N = x.shape[axis]
472[ sxy /= N

File ~/local/bin/anaconda/anaconda3/envs/x/lib/python3.9/site-packages/spectrum/mtm.py:527, in _fftconvolve(in1, in2, mode, axis)
]()525 #Locally import stuff only required for this:
526 from scipy.fftpack import fftn, fft, ifftn, ifft
-->
527 from scipy.signal.signaltools import _centered
528 from numpy import array, product
531[ s1 = array(in1.shape)

ImportError: cannot import name '_centered' from 'scipy.signal.signaltools' (/x/local/bin/anaconda/anaconda3/envs/x/lib/python3.9/site-packages/scipy/signal/signaltools.py)]()

Awesome work with this package, btw, thank you for your contribution!

@eduardacenteno
Copy link
Author

I have the same issue as @chmendoza ! trying to repeat the example in https://pyspectrum.readthedocs.io/en/latest/ref_mtm.html?highlight=multitaper

from spectrum import data_cosine, dpss, pmtm

data = data_cosine(N=2048, A=0.1, sampling=1024, freq=200)
# If you already have the DPSS windows
[tapers, eigen] = dpss(2048, 2.5, 4)
res = pmtm(data, e=eigen, v=tapers, show=False)
# You do not need to compute the DPSS before end
res = pmtm(data, NW=2.5, show=False)
res = pmtm(data, NW=2.5, k=4, show=True)

throws 'cannot import name '_centered' from 'scipy.signal.signaltools'

@cokelaer
Copy link
Owner

@eduardacenteno @chmendoza should be fixed now both in the github and also in v0.8.1 on pypi.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants