예제 #1
0
def test_convolve(collection):
    rt = collection.variables['RT']
    transform.Convolve(collection, 'RT', output='reaction_time')
    rt_conv = collection.variables['reaction_time']

    assert rt_conv.values.shape[0] == \
        rt.get_duration() * collection.sampling_rate

    transform.ToDense(collection, 'RT', output='rt_dense')
    transform.Convolve(collection, 'rt_dense', output='dense_convolved')

    dense_conv = collection.variables['reaction_time']

    assert dense_conv.values.shape[0] == \
        rt.get_duration() * collection.sampling_rate

    # Test adapative oversampling computation
    with mock.patch('bids.analysis.transformations.compute.hrf') as mocked:
        transform.Convolve(collection, 'RT', output='rt_mock')
        mocked.compute_regressor.assert_called_with(
            mock.ANY, 'spm', mock.ANY, fir_delays=None, min_onset=0,
            oversampling=1.0)

    with mock.patch('bids.analysis.transformations.compute.hrf') as mocked:
        transform.Convolve(collection, 'rt_dense', output='rt_mock')
        mocked.compute_regressor.assert_called_with(
            mock.ANY, 'spm', mock.ANY, fir_delays=None, min_onset=0,
            oversampling=3.0)

    with mock.patch('bids.analysis.transformations.compute.hrf') as mocked:
        collection.sampling_rate = 0.5
        transform.Convolve(collection, 'RT', output='rt_mock')
        mocked.compute_regressor.assert_called_with(
            mock.ANY, 'spm', mock.ANY, fir_delays=None, min_onset=0,
            oversampling=2.0)
예제 #2
0
def test_convolve_impulse():
    # Smoke test impulse convolution
    data = pd.DataFrame({
        'onset': [10, 20],
        'duration': [0, 0],
        'amplitude': [1, 1]
    })
    run_info = [RunInfo({'subject': '01'}, 20, 2, 'dummy.nii.gz', 10)]
    var = SparseRunVariable(
        name='var', data=data, run_info=run_info, source='events')
    coll = BIDSRunVariableCollection([var])
    transform.ToDense(coll, 'var', output='var_dense')
    transform.Convolve(coll, 'var', output='var_hrf')
    transform.Convolve(coll, 'var_dense', output='var_dense_hrf')
예제 #3
0
def test_convolve(collection):
    rt = collection.variables['RT']
    transform.Convolve(collection, 'RT', output='reaction_time')
    rt_conv = collection.variables['reaction_time']

    assert rt_conv.values.shape[0] == \
        rt.get_duration() * collection.sampling_rate

    transform.ToDense(collection, 'RT', output='rt_dense')
    transform.Convolve(collection, 'rt_dense', output='dense_convolved')

    dense_conv = collection.variables['reaction_time']

    assert dense_conv.values.shape[0] == \
        rt.get_duration() * collection.sampling_rate

    # Test adapative oversampling computation
    # Events are 3s duration events every 4s, so resolution demanded by the data is 1Hz
    # To resolve 1Hz frequencies, we must sample at >=2Hz
    args = (mock.ANY, 'spm', mock.ANY)
    kwargs = dict(fir_delays=None, min_onset=0)
    with mock.patch('bids.analysis.transformations.compute.hrf') as mocked:
        # Sampling rate is 10Hz, no oversampling needed
        transform.Convolve(collection, 'RT', output='rt_mock')
        mocked.compute_regressor.assert_called_with(*args,
                                                    oversampling=1.0,
                                                    **kwargs)

    with mock.patch('bids.analysis.transformations.compute.hrf') as mocked:
        # Sampling rate is 10Hz, no oversampling needed
        transform.Convolve(collection, 'rt_dense', output='rt_mock')
        mocked.compute_regressor.assert_called_with(*args,
                                                    oversampling=1.0,
                                                    **kwargs)

    with mock.patch('bids.analysis.transformations.compute.hrf') as mocked:
        # Slow sampling rate, oversample (4x) to 2Hz
        collection.sampling_rate = 0.5
        transform.Convolve(collection, 'RT', output='rt_mock')
        mocked.compute_regressor.assert_called_with(*args,
                                                    oversampling=4.0,
                                                    **kwargs)

    with mock.patch('bids.analysis.transformations.compute.hrf') as mocked:
        # Dense variable is already sampled at 10Hz, no oversampling needed
        collection.sampling_rate = 0.5
        transform.Convolve(collection, 'rt_dense', output='rt_mock')
        mocked.compute_regressor.assert_called_with(*args,
                                                    oversampling=1.0,
                                                    **kwargs)

    with mock.patch('bids.analysis.transformations.compute.hrf') as mocked:
        # Onset requires 10Hz resolution, oversample (2x) to 20Hz
        collection.sampling_rate = 10
        collection['RT'].onset[0] += 0.1
        transform.Convolve(collection, 'RT', output='rt_mock')
        mocked.compute_regressor.assert_called_with(*args,
                                                    oversampling=2.0,
                                                    **kwargs)