naturalistic-data-analysis / naturalistic_data_analysis Goto Github PK
View Code? Open in Web Editor NEWA jupyter book for the OHBM educational workshop on analyzing naturalistic data.
Home Page: http://naturalistic-data.org/
A jupyter book for the OHBM educational workshop on analyzing naturalistic data.
Home Page: http://naturalistic-data.org/
Hi there,
I saw a little note in the dynamic connectivity tutorial. Probably that interactive bokeh figures were not integrated in jupyter books at the time you built the tutorial.
Anyway, I'm simply leaving a note to that matter with the solution in order for you to update the book.
Thank you for this wonderful ressource btw!
Hi there,
we are experiencing an issue when trying to execute the post-processing pipeline.
First, there appears to be a typo when loading the file_list:
file_list = [x for x in glob.glob(os.path.join(base_dir, '*/func/*preproc*gz')) if 'denoised' not in x]
Here, "denoised" should be denoise, correct?
Second, when executing the below code:
import os
import glob
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from nltools.stats import regress, zscore
from nltools.data import Brain_Data, Design_Matrix
from nltools.stats import find_spikes
from nltools.mask import expand_mask
def make_motion_covariates(mc, tr):
z_mc = zscore(mc)
all_mc = pd.concat([z_mc, z_mc**2, z_mc.diff(), z_mc.diff()**2], axis=1)
all_mc.fillna(value=0, inplace=True)
return Design_Matrix(all_mc, sampling_freq=1/tr)
base_dir = '/srv/lab/fmri/tutorials/Sherlock/fmriprep'
fwhm=6
tr = 1.5
outlier_cutoff = 3
file_list = [x for x in glob.glob(os.path.join(base_dir, '*/func/*preproc*gz')) if 'denoise' not in x]
f = file_list[0]
sub = os.path.basename(f).split('_')[0]
data = Brain_Data(f)
smoothed = data.smooth(fwhm=fwhm)
spikes = smoothed.find_spikes(global_spike_cutoff=outlier_cutoff, diff_spike_cutoff=outlier_cutoff)
covariates = pd.read_csv(glob.glob(os.path.join(base_dir, sub, 'func', '*tsv'))[0], sep='\t')
mc = covariates[['trans_x','trans_y','trans_z','rot_x', 'rot_y', 'rot_z']]
mc_cov = make_motion_covariates(mc, tr)
csf = covariates['csf'] # Use CSF from fmriprep output
dm = Design_Matrix(pd.concat([csf, mc_cov, spikes.drop(labels='TR', axis=1)], axis=1), sampling_freq=1/tr)
dm = dm.add_poly(order=2, include_lower=True) # Add Intercept, Linear and Quadratic Trends
smoothed.X = dm
stats = smoothed.regress()
stats['residual'].data = np.float32(stats['residual'].data) # cast as float32 to reduce storage space
stats['residual'].write(os.path.join(base_dir, sub, 'func', f'{sub}_denoise_smooth{fwhm}mm_task-sherlockPart1_space-MNI152NLin2009cAsym_desc-preproc_bold.nii.gz'))
We get the following error when accessing the output of the "stats" object:
---------------------------------------------------------------------------
RecursionError Traceback (most recent call last)
/usr/local/miniconda3/envs/naturalistic/lib/python3.7/site-packages/IPython/core/formatters.py in __call__(self, obj)
700 type_pprinters=self.type_printers,
701 deferred_pprinters=self.deferred_printers)
--> 702 printer.pretty(obj)
703 printer.flush()
704 return stream.getvalue()
/usr/local/miniconda3/envs/naturalistic/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
375 if cls in self.type_pprinters:
376 # printer registered in self.type_pprinters
--> 377 return self.type_pprinters[cls](obj, self, cycle)
378 else:
379 # deferred printer
/usr/local/miniconda3/envs/naturalistic/lib/python3.7/site-packages/IPython/lib/pretty.py in inner(obj, p, cycle)
605 p.pretty(key)
606 p.text(': ')
--> 607 p.pretty(obj[key])
608 p.end_group(step, end)
609 return inner
/usr/local/miniconda3/envs/naturalistic/lib/python3.7/site-packages/IPython/lib/pretty.py in pretty(self, obj)
392 if cls is not object \
393 and callable(cls.__dict__.get('__repr__')):
--> 394 return _repr_pprint(obj, self, cycle)
395
396 return _default_pprint(obj, self, cycle)
/usr/local/miniconda3/envs/naturalistic/lib/python3.7/site-packages/IPython/lib/pretty.py in _repr_pprint(obj, p, cycle)
698 """A pprint that just redirects to the normal repr function."""
699 # Find newlines and replace them with p.break_()
--> 700 output = repr(obj)
701 lines = output.splitlines()
702 with p.group():
/usr/local/miniconda3/envs/naturalistic/lib/python3.7/site-packages/nltools/data/brain_data.py in __repr__(self)
233 self.X.shape,
234 os.path.basename(self.mask.get_filename()),
--> 235 self.file_name,
236 )
237
... last 1 frames repeated, from the frame below ...
/usr/local/miniconda3/envs/naturalistic/lib/python3.7/site-packages/nltools/data/brain_data.py in __repr__(self)
233 self.X.shape,
234 os.path.basename(self.mask.get_filename()),
--> 235 self.file_name,
236 )
237
RecursionError: maximum recursion depth exceeded
Any idea/suggestion where this error emanates from?
Thanks much!
YC
Hello, thank you so much for the naturalistic imaging analysis Jupyter book, it has been extremely helpful to me. However, I think that I have either found an error or I might be understanding something incorrectly in the IS-RSA tutorial. Under the multiple comparisons section, you use a function to calculate the FDR threshold from nltools.stats. Here is the code in the Jupyter book:
fdr_thr = fdr(pd.Series(isrsa_nn_r).values)
print(f'FDR Threshold: {fdr_thr}')
view_img(threshold(isrsa_nn_r_brain, isrsa_nn_p_brain, thr=fdr_thr).to_nifti())
The input to this function is the isrsa_nn_r
values, which, as I understand, are the r correlation values, not the p-values.
From the nltools documentation:
nltools.stats.fdr(p, q=0.05)
Determine FDR threshold given a p value array and desired false discovery rate q. Written by Tal Yarkoni
Parameters
p – (np.array) vector of p-values
q – (float) false discovery rate level
Returns
(float) p-value threshold based on independence or positive
dependence
Return type
fdr_p
Given that the documentation states that the input to the fdr
function is an array of p-values, shouldn't isrsa_nn_p
be the input to the function, and not isrsa_nn_r
? Or have I misunderstood something?
Thank you!
Not sure what happened, but the figure legend is now incorrect.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.