Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mat = dm.make_first_level_design_matrix(
frame_times=np.arange(vols) * info['repetition_time'],
events=sparse,
add_regs=dense,
add_reg_names=column_names,
drift_model=drift_model,
)
mat.to_csv('design.tsv', sep='\t')
self._results['design_matrix'] = os.path.join(runtime.cwd,
'design.tsv')
return runtime
class FirstLevelModel(NistatsBaseInterface, FirstLevelEstimatorInterface, SimpleInterface):
def _run_interface(self, runtime):
import nibabel as nb
from nistats import first_level_model as level1
mat = pd.read_csv(self.inputs.design_matrix, delimiter='\t', index_col=0)
img = nb.load(self.inputs.bold_file)
mask_file = self.inputs.mask_file
if not isdefined(mask_file):
mask_file = None
smoothing_fwhm = self.inputs.smoothing_fwhm
if not isdefined(smoothing_fwhm):
smoothing_fwhm = None
flm = level1.FirstLevelModel(
mask_img=mask_file, smoothing_fwhm=smoothing_fwhm)
flm.fit(img, design_matrices=mat)
return runtime
def _flatten(x):
return [elem for sublist in x for elem in sublist]
def _match(query, metadata):
for key, val in query.items():
if metadata.get(key) != val:
return False
return True
class SecondLevelModel(NistatsBaseInterface, SecondLevelEstimatorInterface, SimpleInterface):
def _run_interface(self, runtime):
from nistats import second_level_model as level2
smoothing_fwhm = self.inputs.smoothing_fwhm
if not isdefined(smoothing_fwhm):
smoothing_fwhm = None
model = level2.SecondLevelModel(smoothing_fwhm=smoothing_fwhm)
effect_maps = []
variance_maps = []
stat_maps = []
zscore_maps = []
pvalue_maps = []
contrast_metadata = []
out_ents = self.inputs.contrast_info[0]['entities'] # Same for all
fname_fmt = os.path.join(runtime.cwd, '{}_{}.nii.gz').format
if v != 0 and n not in all_regressors]
for row in contrast['weights']])
if not missing:
# Fill in zeros
weights = np.array([
[row[col] if col in row else 0 for col in all_regressors]
for row in contrast['weights']
])
out_contrasts.append(
(contrast['name'], weights, contrast['type']))
return out_contrasts
class DesignMatrix(NistatsBaseInterface, DesignMatrixInterface, SimpleInterface):
def _run_interface(self, runtime):
import nibabel as nb
from nistats import design_matrix as dm
info = self.inputs.session_info
img = nb.load(self.inputs.bold_file)
vols = img.shape[3]
drop_missing = bool(self.inputs.drop_missing)
if info['sparse'] not in (None, 'None'):
sparse = pd.read_hdf(info['sparse'], key='sparse').rename(
columns={'condition': 'trial_type',
'amplitude': 'modulation'})
sparse = sparse.dropna(subset=['modulation']) # Drop NAs
else: