Beispiel #1
0
def test_bids_naming():
    from samri.pipelines.extra_functions import get_data_selection
    from samri.pipelines.utils import bids_naming
    import pandas as pd
    import os

    bruker_data_dir = path.join(DATA_DIR, 'bruker')
    f_data_selection = get_data_selection(
        bruker_data_dir,
        match={
            'task': ['JogB', 'CogB', 'CogB2m'],
        },
    )
    s_data_selection = get_data_selection(
        bruker_data_dir,
        match={
            'acquisition': ['TurboRARE', 'TurboRARElowcov'],
        },
    )

    name = bids_naming(
        subject_session=('5706', 'ofMpF'),
        metadata=f_data_selection,
    )
    assert_and_feedback(name,
                        'sub-5706_ses-ofMpF_task-CogB_acq-EPI_cbv.nii.gz',
                        debug=f_data_selection)

    name = bids_naming(
        subject_session=('4011', 'ofMaF'),
        metadata=s_data_selection,
    )
    assert_and_feedback(name,
                        'sub-4011_ses-ofMaF_acq-TurboRARElowcov_T2w.nii.gz',
                        debug=s_data_selection)

    name = bids_naming(
        subject_session=('5704', 'ofMpF'),
        metadata=f_data_selection,
    )
    assert_and_feedback(name,
                        'sub-5704_ses-ofMpF_task-CogB_acq-EPI_cbv.nii.gz',
                        debug=f_data_selection)

    name = bids_naming(
        subject_session=('5704', 'ofMpF'),
        metadata=s_data_selection,
    )
    assert_and_feedback(name,
                        'sub-5704_ses-ofMpF_acq-TurboRARE_T2w.nii.gz',
                        debug=s_data_selection)
Beispiel #2
0
def test_bids_naming():
	from samri.pipelines.extra_functions import get_data_selection
	from samri.pipelines.utils import bids_naming
	import pandas as pd
	import os

	bruker_data_dir = path.join(DATA_DIR,'bruker')
	f_data_selection = get_data_selection(bruker_data_dir,
		match={
			'task':['JogB','CogB','CogB2m'],
			},
		)
	s_data_selection = get_data_selection(bruker_data_dir,
		match={
			'acquisition':['TurboRARE', 'TurboRARElowcov'],
			},
		)

	name = bids_naming(
			subject_session=('5706','ofMpF'),
			metadata=f_data_selection,
			)
	assert_and_feedback(name,'sub-5706_ses-ofMpF_task-CogB_acq-EPI_cbv.nii.gz', debug=f_data_selection)

	name = bids_naming(
			subject_session=('4011','ofMaF'),
			metadata=s_data_selection,
			)
	assert_and_feedback(name,'sub-4011_ses-ofMaF_acq-TurboRARElowcov_T2w.nii.gz', debug=s_data_selection)

	name = bids_naming(
			subject_session=('5704','ofMpF'),
			metadata=f_data_selection,
			)
	assert_and_feedback(name,'sub-5704_ses-ofMpF_task-CogB_acq-EPI_cbv.nii.gz', debug=f_data_selection)

	name = bids_naming(
			subject_session=('5704','ofMpF'),
			metadata=s_data_selection,
			)
	assert_and_feedback(name,'sub-5704_ses-ofMpF_acq-TurboRARE_T2w.nii.gz', debug=s_data_selection)
Beispiel #3
0
def get_bids_scan(data_selection,
	bids_base="",
	ind_type="",
	selector=None,
	subject=None,
	session=None,
	extra=['acq','run'],
	):

	"""Description...

	Parameters
	----------
	bids_base : str
		Path to the bids base path.
	data_selection : pandas.DataFrame
		A `pandas.DataFrame` object as produced by `samri.preprocessing.extra_functions.get_data_selection()`.
	selector : iterable, optional
		The first method of selecting the subject and scan, this value should be a length-2 list or tuple containing the subject and sthe session to be selected.
	subject : string, optional
		This has to be defined if `selector` is not defined. The subject for which to return a scan directory.
	session : string, optional
		This has to be defined if `selector` is not defined. The session for which to return a scan directory.
	"""
	import os #for some reason the import outside the function fails
	import pandas as pd
	from samri.pipelines.utils import bids_naming

	filtered_data = []

	if selector:
		subject = selector[0]
		session = selector[1]
		filtered_data = data_selection[(data_selection["session"] == session)&(data_selection["subject"] == subject)]
	else:
		filtered_data = data_selection[data_selection.index==ind_type]

	if filtered_data.empty:
		raise Exception("SAMRIError: Does not exist: " + str(selector[0]) + str(selector[1]) + str(ind_type))
	else:
		subject = filtered_data['subject'].item()
		session = filtered_data['session'].item()
		try:
			typ = filtered_data['type'].item()
		except:
			typ = ""
		try:
			task = filtered_data['task'].item()
		except:
			task = ""
		subject_session = [subject, session]
		#scan_path = os.path.join(bids_base, 'sub-' + subject + '/', 'ses-' + session + '/', typ )

		try:
			nii_path = filtered_data['path'].item()
		except KeyError:
			nii_path = filtered_data['measurement'].item()
			nii_path += '/'+filtered_data['scan'].item()
			nii_name = bids_naming(subject_session, filtered_data,
					extra=extra,
					extension='',
					)
			scan_path = nii_path
		else:
			scan_path = os.path.dirname(nii_path)
			nii_name = os.path.basename(nii_path)

		eventfile_name = bids_naming(subject_session, filtered_data,
				extra=extra,
				extension='.tsv',
				suffix='events'
				)
		metadata_filename = bids_naming(subject_session, filtered_data,
				extra=extra,
				extension='.json',
				)

		dict_slice = filtered_data.to_dict('records')[0]

		return scan_path, typ, task, nii_path, nii_name, eventfile_name, subject_session, metadata_filename, dict_slice
Beispiel #4
0
def get_bids_scan(
    data_selection,
    bids_base="",
    ind_type="",
    selector=None,
    subject=None,
    session=None,
    extra=['acq', 'run'],
):
    """Description...

	Parameters
	----------
	bids_base : str
		Path to the bids base path.
	data_selection : pandas.DataFrame
		A `pandas.DataFrame` object as produced by `samri.preprocessing.extra_functions.get_data_selection()`.
	selector : iterable, optional
		The first method of selecting the subject and scan, this value should be a length-2 list or tuple containing the subject and sthe session to be selected.
	subject : string, optional
		This has to be defined if `selector` is not defined. The subject for which to return a scan directory.
	session : string, optional
		This has to be defined if `selector` is not defined. The session for which to return a scan directory.
	"""
    import os  #for some reason the import outside the function fails
    import pandas as pd
    from samri.pipelines.utils import bids_naming

    filtered_data = []

    if selector:
        subject = selector[0]
        session = selector[1]
        filtered_data = data_selection[(data_selection["session"] == session) &
                                       (data_selection["subject"] == subject)]
    else:
        filtered_data = data_selection[data_selection.index == ind_type]

    if filtered_data.empty:
        raise Exception("SAMRIError: Does not exist: " + str(selector[0]) +
                        str(selector[1]) + str(ind_type))
    else:
        subject = filtered_data['subject'].item()
        session = filtered_data['session'].item()
        try:
            typ = filtered_data['type'].item()
        except:
            typ = ""
        try:
            task = filtered_data['task'].item()
        except:
            task = ""
        subject_session = [subject, session]
        #scan_path = os.path.join(bids_base, 'sub-' + subject + '/', 'ses-' + session + '/', typ )

        try:
            nii_path = filtered_data['path'].item()
        except KeyError:
            nii_path = filtered_data['measurement'].item()
            nii_path += '/' + filtered_data['scan'].item()
            nii_name = bids_naming(
                subject_session,
                filtered_data,
                extra=extra,
                extension='',
            )
            scan_path = nii_path
        else:
            scan_path = os.path.dirname(nii_path)
            nii_name = os.path.basename(nii_path)

        eventfile_name = bids_naming(subject_session,
                                     filtered_data,
                                     extra=extra,
                                     extension='.tsv',
                                     suffix='events')
        metadata_filename = bids_naming(
            subject_session,
            filtered_data,
            extra=extra,
            extension='.json',
        )

        dict_slice = filtered_data.to_dict('records')[0]

        return scan_path, typ, task, nii_path, nii_name, eventfile_name, subject_session, metadata_filename, dict_slice