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

NF: added ability to pass strings as event attrs; #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NF: added ability to pass strings as event attrs;
BF: updated pywt 'per' parameter;
BF: removed unused wica parameters;
vansky committed Mar 23, 2016
commit 62aca62cea5283fbfa11edf207926b8793d77b4b
7 changes: 5 additions & 2 deletions ptsa/data/events.py
Original file line number Diff line number Diff line change
@@ -97,12 +97,15 @@ def add_fields(self,**fields):
if self.dtype.fields.has_key(name):
# already exists
raise ValueError('Field "'+name+'" already exists.')

# append the array and name
if(isinstance(data,np.dtype)|
isinstance(data,type)|isinstance(data,str)):
isinstance(data,type)):
# add empty array the length of the data
arrays.append(np.empty(len(self),data))
elif isinstance(data,str):
# populate the string-like data in an array
arrays.append(np.full(len(self),data,dtype='|S{:d}'.format(len(data))))
else:
# add the data as an array
arrays.append(data)
8 changes: 4 additions & 4 deletions ptsa/wavelet.py
Original file line number Diff line number Diff line change
@@ -67,12 +67,12 @@ def swt(data, wavelet, level=None):
odd_indices = indices[1::2]

# get the even
(cA1,cD1) = pywt.dwt(idata[indices], wavelet, 'per')
(cA1,cD1) = pywt.dwt(idata[indices], wavelet, 'periodization')
cA[even_indices] = cA1
cD[even_indices] = cD1

# then the odd
(cA1,cD1) = pywt.dwt(np.roll(idata[indices],-1), wavelet, 'per')
(cA1,cD1) = pywt.dwt(np.roll(idata[indices],-1), wavelet, 'periodization')
cA[odd_indices] = cA1
cD[odd_indices] = cD1

@@ -120,8 +120,8 @@ def iswt(coefficients, wavelet):

# perform the inverse dwt on the selected indices,
# making sure to use periodic boundary conditions
x1 = pywt.idwt(output[even_indices], cD[even_indices], wavelet, 'per')
x2 = pywt.idwt(output[odd_indices], cD[odd_indices], wavelet, 'per')
x1 = pywt.idwt(output[even_indices], cD[even_indices], wavelet, 'periodization')
x2 = pywt.idwt(output[odd_indices], cD[odd_indices], wavelet, 'periodization')

# perform a circular shift right
x2 = np.roll(x2, 1)
7 changes: 3 additions & 4 deletions ptsa/wica.py
Original file line number Diff line number Diff line change
@@ -247,7 +247,7 @@ def _clean_comp(comp, Kthr, L, thld=None):
return comp, thld


def remove_strong_artifacts(data, A, icaEEG, Comp, Kthr=1.25, F=256,
def remove_strong_artifacts(icaEEG, Comp, Kthr=1.25, F=256,
Cthr=None, num_mp_procs=0):
"""
% This function denoise high amplitude artifacts (e.g. ocular) and remove them from the
@@ -487,14 +487,13 @@ def clean(self, comp_inds=None, Kthr=2.5, num_mp_procs=0):
# remove strong artifacts
if (not self._pure_range[0] is None) or (not self._pure_range[1] is None):
# figure out the thresh for the range
Cthr = remove_strong_artifacts(self._data[:,self._pure_range[0]:self._pure_range[1]], self.ICA_weights,
self._components[:,self._pure_range[0]:self._pure_range[1]],
Cthr = remove_strong_artifacts(self._components[:,self._pure_range[0]:self._pure_range[1]],
comp_inds, Kthr,
self._samplerate,
num_mp_procs=num_mp_procs)
else:
Cthr = None
Cthr = remove_strong_artifacts(self._data,self.ICA_weights,self._components,
Cthr = remove_strong_artifacts(self._components,
comp_inds, Kthr,
self._samplerate, Cthr,
num_mp_procs=num_mp_procs)