Skip to content

Commit

Permalink
Merge branch 'dev' into 'master'
Browse files Browse the repository at this point in the history
Dev

Closes #234

See merge request it/syncopy!90
  • Loading branch information
joschaschmiedt committed Oct 10, 2019
2 parents a9c2e07 + 0f8cf20 commit c327e3c
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 90 deletions.
17 changes: 16 additions & 1 deletion syncopy/examples/ex_specest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,24 @@

if __name__ == "__main__":

data = spy.load('/mnt/hpx/it/dev/testdata.spy/')

cfg = spy.get_defaults(spy.freqanalysis)
cfg.method = 'mtmfft'
cfg.taper = 'dpss'
cfg.output = 'pow'
cfg.tapsmofrq = 20
cfg.keeptrials = False
cfg.keeptapers = False
cfg.pad = 'nextpow2'
cfg.select = {"toilim": [-0.25, 0]}

baselineSpectrum = spy.freqanalysis(cfg, data)

sys.exit()

client = spy.esi_cluster_setup(n_jobs=10, partition="DEV", mem_per_job="2GB")

data = spy.load('/mnt/hpx/it/dev/testdata.spy/')

cfg = spy.get_defaults(spy.freqanalysis)
cfg.method = 'mtmfft'
Expand Down
14 changes: 10 additions & 4 deletions syncopy/specest/freqanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Created: 2019-01-22 09:07:47
# Last modified by: Stefan Fuertinger [[email protected]]
# Last modification time: <2019-10-09 12:09:31>
# Last modification time: <2019-10-10 11:10:29>

# Builtin/3rd party package imports
import numpy as np
Expand Down Expand Up @@ -217,7 +217,7 @@ def freqanalysis(data, method='mtmfft', output='fourier',
# Construct array of maximally attainable frequencies
minTrialLength = minSampleNum/data.samplerate
nFreq = int(np.floor(minSampleNum / 2) + 1)
freqs = np.arange(nFreq)
freqs = np.linspace(0, data.samplerate / 2, nFreq)

# Match desired frequencies as close as possible to actually attainable freqs
if foi is not None:
Expand All @@ -230,7 +230,12 @@ def freqanalysis(data, method='mtmfft', output='fourier',
foi.sort()
foi = foi[foi <= freqs.max()]
foi = foi[foi >= freqs.min()]
foi = freqs[np.unique(np.searchsorted(freqs, foi, side="right") - 1)]
fidx = np.searchsorted(freqs, foi, side="left")
for k, fid in enumerate(fidx):
if np.abs(freqs[fid - 1] - foi[k]) < np.abs(freqs[fid] - foi[k]):
fidx[k] = fid -1
fidx = np.unique(fidx)
foi = freqs[fidx]
else:
foi = freqs

Expand Down Expand Up @@ -312,7 +317,8 @@ def freqanalysis(data, method='mtmfft', output='fourier',
log_dct["nTaper"] = nTaper

# Set up compute-kernel
specestMethod = MultiTaperFFT(nTaper=nTaper,
specestMethod = MultiTaperFFT(1 / data.samplerate,
nTaper=nTaper,
timeAxis=timeAxis,
taper=taper,
taperopt=taperopt,
Expand Down
13 changes: 8 additions & 5 deletions syncopy/specest/mtmfft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# Created: 2019-09-02 14:25:34
# Last modified by: Stefan Fuertinger [[email protected]]
# Last modification time: <2019-10-09 12:12:19>
# Last modification time: <2019-10-10 11:11:12>

# Builtin/3rd party package imports
import numpy as np
Expand All @@ -19,7 +19,7 @@

# Local workhorse that performs the computational heavy lifting
@unwrap_io
def mtmfft(trl_dat, nTaper=1, timeAxis=0,
def mtmfft(trl_dat, dt, nTaper=1, timeAxis=0,
taper=spwin.hann, taperopt={}, tapsmofrq=None,
pad="nextpow2", padtype="zero", padlength=None, foi=None,
keeptapers=True, polyorder=None, output_fmt="pow",
Expand All @@ -30,6 +30,8 @@ def mtmfft(trl_dat, nTaper=1, timeAxis=0,
----------
trl_dat : 2D :class:`numpy.ndarray`
Multi-channel uniformly sampled time-series
dt : float
sampling interval (between 0 and 1)
nTaper : int
number of filter windows to use
timeAxis : int
Expand Down Expand Up @@ -88,16 +90,17 @@ def mtmfft(trl_dat, nTaper=1, timeAxis=0,
nFreq = int(np.floor(nSamples / 2) + 1)
fidx = slice(None)
if foi is not None:
freqs = np.arange(nFreq)
freqs = np.linspace(0, 1 /(2 * dt), nFreq)
foi = foi[foi <= freqs.max()]
foi = foi[foi >= freqs.min()]
fidx = np.searchsorted(freqs, foi, side="right") - 1
fidx = np.searchsorted(freqs, foi, side="left")
for k, fid in enumerate(fidx):
if np.abs(freqs[fid - 1] - foi[k]) < np.abs(freqs[fid] - foi[k]):
fidx[k] = fid -1
fidx = np.unique(fidx)
nFreq = fidx.size
outShape = (1, max(1, nTaper * keeptapers), nFreq, nChannels)

# For initialization of computational routine, just return output shape and dtype
if noCompute:
return outShape, freq.spectralDTypes[output_fmt]
Expand Down
2 changes: 1 addition & 1 deletion syncopy/statistics/timelockanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import numpy as np
import syncopy as spy
from tqdm import tqdm
from tqdm.auto import tqdm
from syncopy.shared.parsers import data_parser
import syncopy as spy

Expand Down
Loading

0 comments on commit c327e3c

Please sign in to comment.