Пример #1
0
 def test_save_subject(self):
     dataset = SubjectsDataset(self.subjects_list, transform=lambda x: x)
     _ = len(dataset)  # for coverage
     subject = dataset[0]
     output_path = self.dir / 'test.nii.gz'
     paths_dict = {'t1': output_path}
     with self.assertWarns(DeprecationWarning):
         dataset.save_sample(subject, paths_dict)
     nii = nib.load(str(output_path))
     ndims_output = len(nii.shape)
     ndims_subject = len(subject['t1'].shape)
     assert ndims_subject == ndims_output + 1
rp_files = gfile('/data/romain/HCPdata/suj_274542/Motion_ms','^rp')
rp_files = gfile('/data/romain/HCPdata/suj_274542/mot_separate','^rp')

rpf = rp_files[10]
res = pd.DataFrame()
for rpf in rp_files:
    dirpath,name = get_parent_path([rpf])
    fout = dirpath[0] + '/check/'+name[0][3:-4] + '.nii'

    t = RandomMotionFromTimeCourse(fitpars=rpf, nufft=True, oversampling_pct=0, keep_original=True, verbose=True)
    dataset = ImagesDataset(suj, transform=t)
    sample = dataset[0]
    dicm = sample['T1']['metrics']
    dicm['fname'] = fout
    res = res.append(dicm, ignore_index=True)
    dataset.save_sample(sample, dict(T1=fout))

fit_pars = sample['T1']['fit_pars']
plt.figure; plt.plot(fit_pars[3:].T)
plt.figure; plt.plot(fit_pars.T)


dic_no_mot ={ "noiseBasePars": (5, 20, 0),"swallowFrequency": (0, 1, 1), "suddenFrequency": (0, 1, 1),
              "oversampling_pct":0.3, "nufft":True , "keep_original": True}
t = RandomMotionFromTimeCourse(**dic_no_mot)
dataset = ImagesDataset(suj, transform=t)
sample = dataset[0]


dico_params = {"maxDisp": (1, 6),  "maxRot": (1, 6),    "noiseBasePars": (5, 20, 0),
               "swallowFrequency": (2, 6, 0),  "swallowMagnitude": (1, 6),