Skip to content

Commit

Permalink
Add test w/ slight error in scan_length
Browse files Browse the repository at this point in the history
  • Loading branch information
adelavega committed Apr 7, 2021
1 parent 6b65695 commit c0551ea
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bids/variables/tests/test_collections.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from os.path import join, dirname, abspath

import pytest
import numpy as np

from bids.layout import BIDSLayout
from bids.tests import get_test_data_path
Expand All @@ -16,6 +17,14 @@ def run_coll():
return layout.get_collections('run', types=['events'], merge=True,
scan_length=480, subject=['01', '02', '04'])

@pytest.fixture(scope="module")
def run_coll_bad_length():
path = join(get_test_data_path(), 'ds005')
layout = BIDSLayout(path)
# Limit to a few subjects to reduce test running time
return layout.get_collections('run', types=['events'], merge=True,
scan_length=480.1, subject=['01', '02', '04'])


@pytest.fixture(scope="module")
def run_coll_list():
Expand Down Expand Up @@ -203,6 +212,34 @@ def test_run_variable_collection_to_df_all_dense_vars(run_coll):
n_rows = int(rows_per_var * 12 / 10)
assert df.shape == (n_rows, 18)

def test_run_variable_collection_bad_length_to_df_all_dense_vars(run_coll_bad_length):

timing_cols = {'onset', 'duration'}
entity_cols = {'subject', 'run', 'task', 'suffix', 'datatype'}
cond_names = {'PTval', 'RT', 'gain', 'loss', 'parametric gain', 'respcat',
'respnum', 'trial_type'}
md_names = {'TaskName', 'RepetitionTime', 'extension', 'SliceTiming'}
condition = {'condition'}
ampl = {'amplitude'}

unif_coll = run_coll_bad_length.to_dense(sampling_rate=10)

df = unif_coll.to_df()
rows_per_var = np.round(3 * 3 * 480.1 * 10) # subjects x runs x time x sampling rate

# Test resampling without setting sample rate (default sr == 10)
df = unif_coll.to_df(format='long')
assert df.shape == (rows_per_var * 7, 13)
cols = timing_cols | entity_cols | condition | ampl | md_names
assert set(df.columns) == cols

# Test resampling to TR
df = unif_coll.to_df(sampling_rate='TR')
n_rows = int(480 * 3 * 3 / 2) # (Note number of volumes is 480, not 480.1)
assert df.shape == (n_rows, 18)
cols = (timing_cols | entity_cols | cond_names | md_names) - {'trial_type'}
assert set(df.columns) == cols


def test_run_variable_collection_to_df_mixed_vars(run_coll):
coll = run_coll.clone()
Expand Down

0 comments on commit c0551ea

Please sign in to comment.