From e5020dbe5c46fe06b0b022b3062697178e11a5ad Mon Sep 17 00:00:00 2001 From: kajal5888 Date: Tue, 13 Dec 2022 17:06:16 +0100 Subject: [PATCH 1/6] conversion of input foilim into float for serialization --- syncopy/specest/freqanalysis.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/syncopy/specest/freqanalysis.py b/syncopy/specest/freqanalysis.py index 31099d2f3..805cc6cf9 100644 --- a/syncopy/specest/freqanalysis.py +++ b/syncopy/specest/freqanalysis.py @@ -328,7 +328,8 @@ def freqanalysis(data, method='mtmfft', output='pow', numpy.fft.fft : NumPy's reference FFT implementation scipy.signal.stft : SciPy's Short Time Fourier Transform """ - + if foilim is not None: + foilim = [float(f) for f in foilim] # Make sure our one mandatory input object can be processed try: data_parser(data, varname="data", dataclass="AnalogData", From d5850803edb013b3ff8b6ef28e9938779a832225 Mon Sep 17 00:00:00 2001 From: kajal5888 Date: Wed, 14 Dec 2022 13:49:56 +0100 Subject: [PATCH 2/6] foilim adapted to float for serialization --- syncopy/specest/freqanalysis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/syncopy/specest/freqanalysis.py b/syncopy/specest/freqanalysis.py index 805cc6cf9..04b72fc77 100644 --- a/syncopy/specest/freqanalysis.py +++ b/syncopy/specest/freqanalysis.py @@ -329,7 +329,7 @@ def freqanalysis(data, method='mtmfft', output='pow', scipy.signal.stft : SciPy's Short Time Fourier Transform """ if foilim is not None: - foilim = [float(f) for f in foilim] + foilim = [float(f) for f in foilim] # Make sure our one mandatory input object can be processed try: data_parser(data, varname="data", dataclass="AnalogData", From 9e438f022212bc88dac26b3944a1dd6784619127 Mon Sep 17 00:00:00 2001 From: kajal5888 Date: Thu, 15 Dec 2022 15:57:35 +0100 Subject: [PATCH 3/6] Foilim correction --- syncopy/specest/freqanalysis.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/syncopy/specest/freqanalysis.py b/syncopy/specest/freqanalysis.py index 04b72fc77..36906f83b 100644 --- a/syncopy/specest/freqanalysis.py +++ b/syncopy/specest/freqanalysis.py @@ -328,8 +328,6 @@ def freqanalysis(data, method='mtmfft', output='pow', numpy.fft.fft : NumPy's reference FFT implementation scipy.signal.stft : SciPy's Short Time Fourier Transform """ - if foilim is not None: - foilim = [float(f) for f in foilim] # Make sure our one mandatory input object can be processed try: data_parser(data, varname="data", dataclass="AnalogData", From 63e669ceaac89fd8c12614eef2ebc141f5a43841 Mon Sep 17 00:00:00 2001 From: kajal5888 Date: Thu, 15 Dec 2022 15:58:09 +0100 Subject: [PATCH 4/6] Foilim correction to float --- syncopy/shared/input_processors.py | 1 + 1 file changed, 1 insertion(+) diff --git a/syncopy/shared/input_processors.py b/syncopy/shared/input_processors.py index 958690764..93836a7f9 100644 --- a/syncopy/shared/input_processors.py +++ b/syncopy/shared/input_processors.py @@ -138,6 +138,7 @@ def process_foi(foi, foilim, samplerate): foi = np.array(foi, dtype="float") if foilim is not None: + foilim = [float(f) for f in foilim] if isinstance(foilim, str): if foilim == "all": foilim = None From 3b9c5f773352715f5b47c8929339299dd13a5d76 Mon Sep 17 00:00:00 2001 From: tensionhead Date: Thu, 15 Dec 2022 16:06:59 +0100 Subject: [PATCH 5/6] CHG: Cast to float only after array parsing Changes to be committed: modified: syncopy/shared/input_processors.py --- syncopy/shared/input_processors.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/syncopy/shared/input_processors.py b/syncopy/shared/input_processors.py index 93836a7f9..343fd43a1 100644 --- a/syncopy/shared/input_processors.py +++ b/syncopy/shared/input_processors.py @@ -132,13 +132,12 @@ def process_foi(foi, foilim, samplerate): else: try: array_parser(foi, varname="foi", hasinf=False, hasnan=False, - lims=[0, samplerate/2], dims=(None,)) + lims=[0, samplerate / 2], dims=(None,)) except Exception as exc: raise exc foi = np.array(foi, dtype="float") if foilim is not None: - foilim = [float(f) for f in foilim] if isinstance(foilim, str): if foilim == "all": foilim = None @@ -146,11 +145,12 @@ def process_foi(foi, foilim, samplerate): raise SPYValueError(legal="'all' or `None` or `[fmin, fmax]`", varname="foilim", actual=foilim) else: - try: - array_parser(foilim, varname="foilim", hasinf=False, hasnan=False, - lims=[0, samplerate/2], dims=(2,)) - except Exception as exc: - raise exc + array_parser(foilim, varname="foilim", hasinf=False, hasnan=False, + lims=[0, samplerate / 2], dims=(2,)) + + # QUICKFIX for #392 + foilim = [float(f) for f in foilim] + # foilim is of shape (2,) if foilim[0] > foilim[1]: msg = "Sorting foilim low to high.." @@ -175,7 +175,7 @@ def process_taper(taper, For multi-tapering with slepian tapers the default is to max out `nTaper` to achieve the desired frequency smoothing bandwidth. - For details about the Slepion settings see + For details about the Slepian settings see "The Effective Bandwidth of a Multitaper Spectral Estimator, A. T. Walden, E. J. McCoy and D. B. Percival" @@ -300,7 +300,6 @@ def process_taper(taper, maxBw = np.min([samplerate / 2 - 1 / nSamples, samplerate * (nSamples + 1) / (2 * nSamples)]) # ----------------------------------- - try: scalar_parser(tapsmofrq, varname="tapsmofrq", lims=[0, np.inf]) @@ -317,12 +316,12 @@ def process_taper(taper, msg = f'Setting tapsmofrq to the maximal attainable bandwidth of {maxBw:.2f}Hz' SPYInfo(msg) tapsmofrq = maxBw - + # -------------------------------------------------------------- # set parameters for scipy.signal.windows.dpss NW, Kmax = _get_dpss_pars(tapsmofrq, nSamples, samplerate) # -------------------------------------------------------------- - + # tapsmofrq too large # if Kmax > nSamples or NW > nSamples / 2: From 04207841287a656c499d0ee27d5f169224ab675e Mon Sep 17 00:00:00 2001 From: tensionhead Date: Thu, 15 Dec 2022 16:14:17 +0100 Subject: [PATCH 6/6] CHG: Beef up foilim valid input tests Changes to be committed: modified: syncopy/tests/test_connectivity.py --- syncopy/tests/test_connectivity.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/syncopy/tests/test_connectivity.py b/syncopy/tests/test_connectivity.py index 82597a0fb..7edbf20d4 100644 --- a/syncopy/tests/test_connectivity.py +++ b/syncopy/tests/test_connectivity.py @@ -457,7 +457,6 @@ def test_coh_selections(self): result_spec = cafunc(self.spec, method='coh', select=selections[0]) assert np.allclose(result_ad.trials[0], result_spec.trials[0], atol=1e-3) - def test_coh_foi(self): # 2 frequencies @@ -468,10 +467,17 @@ def test_coh_foi(self): assert np.all(np.isfinite(result.data)) assert np.all(result.data[0, ...] >= -1e-10) - # make sure out-of-range foi selections are detected + # make sure out-of-range foilim are detected with pytest.raises(SPYValueError, match='foilim'): result = cafunc(self.data, method='coh', foilim=[-1, 70]) + # make sure invalid foilim are detected + with pytest.raises(SPYValueError, match='foilim'): + result = cafunc(self.data, method='coh', foilim=[None, None]) + + with pytest.raises(SPYValueError, match='foilim'): + result = cafunc(self.data, method='coh', foilim='abc') + def test_coh_cfg(self): call = lambda cfg: cafunc(self.data, cfg)