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

Fmri to dataset #127

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9593e8c
class for parsing derivatives subdirectory in BIDS format
adkipnis Sep 17, 2020
e76ae33
added / refined subsetting methods; added function to flatten lists; …
adkipnis Sep 17, 2020
de9fd8e
added docstrings and function to load SPM beta coefficients optionall…
adkipnis Sep 17, 2020
4681970
added option to not provide a dictionary for load_SPM_beta_images()
adkipnis Sep 17, 2020
2787d8e
np.stack for list of 3d images to 4d array
adkipnis Sep 18, 2020
ba435b9
renamed pooling.py to fmri.py
adkipnis Sep 18, 2020
f2585cb
inherited class for parsed data of only one subject; methods for load…
adkipnis Sep 18, 2020
f3f49ac
started coding unit tests
adkipnis Sep 18, 2020
d0f8f63
fixed __init__ bugs, first parsing unit tests
adkipnis Sep 18, 2020
3116690
example dataset
adkipnis Sep 18, 2020
f6bb711
minor bug fixes and full unit tests for all things pooling
adkipnis Sep 18, 2020
003c342
CodeFactor fixes
adkipnis Sep 18, 2020
56b495c
CodeFactor fixes
adkipnis Sep 18, 2020
38932dc
starterd coding class to read in 4d nifti files
adkipnis Sep 18, 2020
db58eb8
added nibabel and pandas to requirements.txt
adkipnis Sep 19, 2020
2b23211
Merge branch 'master' into fmri-to-dataset
HeikoSchuett Sep 21, 2020
8ef3a98
Merge branch 'master' into fmri-to-dataset
HeikoSchuett Oct 20, 2020
497a51a
merge main
HeikoSchuett Jun 23, 2021
626eb00
updated fmri-tests to folder structure
HeikoSchuett Jun 23, 2021
95a0146
fix example data for test_fmri.py
adkipnis Jun 27, 2021
5ceceff
Merge branch 'main' into fmri-to-dataset
HeikoSchuett Dec 18, 2021
ae81191
stylefix fmri
HeikoSchuett Dec 18, 2021
6207a97
moved fmri to io
HeikoSchuett Dec 18, 2021
7969629
added init to nifti_filenames
HeikoSchuett Dec 18, 2021
ea52543
style fmri_test
HeikoSchuett Dec 18, 2021
4c7c58c
Merge branch 'main' into fmri-to-dataset
JasperVanDenBosch Sep 13, 2023
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
485 changes: 485 additions & 0 deletions src/rsatoolbox/io/fmri.py

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0,res_0001_run_01
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0,cond_Face_run_01
1,cond_House_run_01
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
140 changes: 140 additions & 0 deletions tests/test_fmri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Tests for BidsDerivatives class and subclasses

"""

import unittest
import os
import rsatoolbox.io.fmri as fmri
import numpy as np


def get_fmri_data():
fmri_dir = os.path.join(
os.path.dirname(__file__), "data", "BIDS_example", "derivatives",
"SPM_example")
fmri_data = fmri.BidsDerivatives(fmri_dir)
return fmri_data


def get_subject_data():
fmri_data = get_fmri_data()
subjects = fmri_data.get_subjects()
subject_data = fmri_data.subset_subject(subjects[0]) # subset data for first subject
return subject_data


def get_subject_session_data():
subject_data = get_subject_data()
session_types = subject_data.get_session_types()
subject_data_s = subject_data.subset_session_type(session_types[0]) # further subset data for first session type
return subject_data_s


class TestParsing(unittest.TestCase):

def test_full_parsing(self):
fmri_data = get_fmri_data()
np.testing.assert_array_equal(
fmri_data.get_subjects(),
['sub-01', 'sub-02'])
np.testing.assert_array_equal(
fmri_data.get_session_types(),
['ses-perceptionTest', 'ses-perceptionTraining'])
np.testing.assert_array_equal(
fmri_data.runs_total, 2)

def test_sub_parsing(self):
subject_data = get_subject_data()
np.testing.assert_array_equal(
subject_data.get_subjects(),
['sub-01'])
np.testing.assert_array_equal(
subject_data.get_sessions(),
['ses-perceptionTest01'])
np.testing.assert_array_equal(
subject_data.runs_total, 1)
np.testing.assert_array_equal(
[os.path.isdir(run_dir)
for run_dir in subject_data.get_runs()],
[True])

def test_session_parsing(self):
subject_data = get_subject_session_data()
np.testing.assert_array_equal(
subject_data.get_sessions(),
['ses-perceptionTest01'])
np.testing.assert_array_equal(
subject_data.runs_total, 1)
np.testing.assert_array_equal(
[os.path.isdir(run_dir)
for run_dir in subject_data.get_runs()],
[True])


class TestPoolingSPM(unittest.TestCase):

def test_beta_pooling(self):
subject_data = get_subject_session_data()
beta_array, beta_descriptors = subject_data.load_betas_SPM()
np.testing.assert_array_equal(
beta_array.shape, (55, 60, 51, 2))
np.testing.assert_array_equal(
beta_array.shape[3], len(beta_descriptors))
beta_descriptors.sort()
np.testing.assert_array_equal(
np.unique(beta_descriptors),
beta_descriptors)

def test_beta_pooling_w_dict(self):
stim_ids_dict = {"Face": 1, "House": 2}
subject_data = get_subject_session_data()
beta_array, beta_descriptors = subject_data.load_betas_SPM(
stim_ids_dict=stim_ids_dict)
np.testing.assert_array_equal(
beta_array.shape, (55, 60, 51, 2))
np.testing.assert_array_equal(
beta_array.shape[3], len(beta_descriptors))
beta_descriptors.sort()
np.testing.assert_array_equal(
np.unique(beta_descriptors),
beta_descriptors)

def test_res_pooling(self):
subject_data = get_subject_session_data()
res_array, res_descriptors = subject_data.load_residuals_SPM()
np.testing.assert_array_equal(
res_array.shape, (55, 60, 51, 1))
np.testing.assert_array_equal(
res_array.shape[3], len(res_descriptors))
res_descriptors.sort()
np.testing.assert_array_equal(
np.unique(res_descriptors),
res_descriptors)


class TestSaving(unittest.TestCase):

def test_saving_combo_signal(self):
stim_ids_dict = {"Face": 1, "House": 2}
subject_data = get_subject_session_data()
beta_array, beta_descriptors = subject_data.load_betas_SPM(
stim_ids_dict=stim_ids_dict)
subject_data.save2combo(
beta_array, beta_descriptors, data_type="signal")
assert os.path.isfile(subject_data.nifti_filename)
assert os.path.isfile(subject_data.csv_filename)

def test_saving_combo_noise(self):
subject_data = get_subject_session_data()
res_array, res_descriptors = subject_data.load_residuals_SPM()
subject_data.save2combo(
res_array, res_descriptors, data_type="noise")
assert os.path.isfile(subject_data.nifti_filename)
assert os.path.isfile(subject_data.csv_filename)


if __name__ == '__main__':
unittest.main()
Loading