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

Debug_12/15/24 #215

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
File renamed without changes.
10 changes: 5 additions & 5 deletions supereeg/brain.py → brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def update_filter_inds(self):
if self.filter == 'kurtosis':
self.filter_inds = self.kurtosis <= self.kurtosis_threshold
else:
self.filter_inds = np.ones((1, self.locs.shape[0]), dtype=np.bool)[0] #TODO: check this
self.filter_inds = np.ones((1, self.locs.shape[0]), dtype=np.bool_)[0] #TODO: check this

def update_info(self):
self.n_elecs = self.data.shape[1] # needs to be calculated by sessions
Expand Down Expand Up @@ -581,10 +581,10 @@ def to_nii(self, filepath=None, template='gray', vox_size=None, sample_rate=None
if os.path.exists(template):
img = nib.load(template)

elif template is 'gray':
elif template == 'gray':
img = _gray(v_size)

elif template is 'std':
elif template == 'std':
img = _std(v_size)

else:
Expand Down Expand Up @@ -684,10 +684,10 @@ def to_nii2(self, filepath=None, template='gray', vox_size=None, sample_rate=Non
if os.path.exists(template):
img = nib.load(template)

elif template is 'gray':
elif template == 'gray':
img = _gray(v_size)

elif template is 'std':
elif template == 'std':
img = _std(v_size)

else:
Expand Down
24 changes: 12 additions & 12 deletions supereeg/helpers.py → helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _gray(res=None):

gray_img = load('gray')
threshold = 100
gray_data = gray_img.get_data()
gray_data = gray_img.get_fdata()
gray_data[np.isnan(gray_data) | (gray_data < threshold)] = 0

if np.iterable(res) or np.isscalar(res):
Expand Down Expand Up @@ -123,8 +123,8 @@ def _resample_nii(x, target_res, precision=5):

from .nifti import Nifti

if np.any(np.isnan(x.get_data())):
img = x.get_data()
if np.any(np.isnan(x.get_fdata())):
img = x.get_fdata()
img[np.isnan(img)] = 0.0
x = nib.nifti1.Nifti1Image(img, x.affine)

Expand All @@ -140,14 +140,14 @@ def _resample_nii(x, target_res, precision=5):
target_affine[0:3, 3] -= np.squeeze(np.multiply(np.divide(target_res, 2.0), np.sign(target_affine[0:3, 3])))
target_affine[0:3, 3] += np.squeeze(np.sign(target_affine[0:3, 3]))

if len(scale) < np.ndim(x.get_data()):
assert np.ndim(x.get_data()) == 4, 'Data must be 3D or 4D'
if len(scale) < np.ndim(x.get_fdata()):
assert np.ndim(x.get_fdata()) == 4, 'Data must be 3D or 4D'
scale = np.append(scale, x.shape[3])

# z = skimage.transform.rescale(x.get_data(), scale, order=3, mode='constant', cval=0, anti_aliasing=True,
# multichannel=False)

z = transform.downscale_local_mean(x.get_data(), tuple(np.array(np.reciprocal(scale), dtype='int')),
z = transform.downscale_local_mean(x.get_fdata(), tuple(np.array(np.reciprocal(scale), dtype='int')),
cval=float(0))

try:
Expand Down Expand Up @@ -181,7 +181,7 @@ def _apply_by_file_index(bo, xform, aggregator):

for idx, session in enumerate(bo.sessions.unique()):
session_xform = xform(bo.get_slice(sample_inds=np.where(bo.sessions == session)[0], inplace=False))
if idx is 0:
if idx <= 0:
results = session_xform
else:
results = aggregator(results, session_xform)
Expand Down Expand Up @@ -230,7 +230,7 @@ def aggregate(p, n):
return p + n

def zcorr_xform(bo):
return np.multiply(bo.dur, _r2z(1 - squareform(pdist(bo.get_data().T, 'correlation'))))
return np.multiply(bo.dur, _r2z(1 - squareform(pdist(bo.data.T, 'correlation'))))

summed_zcorrs = _apply_by_file_index(bo, zcorr_xform, aggregate)

Expand All @@ -254,8 +254,8 @@ def _z_score(bo):

"""
def z_score_xform(bo):
return zscore(bo.get_data())

return zscore(bo.get_data().values)
def vstack_aggregrate(x1, x2):
return np.vstack((x1, x2))

Expand Down Expand Up @@ -629,13 +629,13 @@ def _timeseries_recon(bo, mo, chunk_size=25000, preprocess='zscore', recon_loc_i
Compiled reconstructed timeseries
"""
if preprocess==None:
data = bo.get_data().values
data = bo.get_fdata().values
elif preprocess=='zscore':
if bo.data.shape[0]<3:
warnings.warn('Not enough samples to zscore so it will be skipped.'
' Note that this will cause problems if your data are not already '
'zscored.')
data = bo.get_data().values
data = bo.get_fdata().values
else:
data = bo.get_zscore_data()
else:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.