osl_ephys.utils.study#

Classes#

Study

Class for simple file finding and looping.

Module Contents#

class osl_ephys.utils.study.Study(studydir)[source]#

Class for simple file finding and looping.

Parameters:

studydir (str) – The study directory with wildcards.

studydir[source]#

The study directory with wildcards.

Type:

str

fieldnames[source]#

The wildcards in the study directory, i.e., the field names in between {braces}.

Type:

list

globdir[source]#

The study directory with wildcards replaced with *.

Type:

str

match_files[source]#

The files that match the globdir.

Type:

list

match_values[source]#

The values of the field names (i.e., wildcards) for each file.

Type:

list

fields[source]#

The field names and values for each file.

Type:

dict

Notes

This class is a simple wrapper around glob and parse. It works something like this:

>>> studydir = '/path/to/study/{subject}/{session}/{subject}_{task}.fif'
>>> study = Study(studydir)

Get all files in the study directory:

>>> study.get()

Get all files for a particular subject:

>>> study.get(subject='sub-01')

Get all files for a particular subject and session:

>>> study.get(subject='sub-01', session='ses-01')

The fieldnames that are not specified in get are replaced with wildcards (*).

studydir[source]#
fieldnames[source]#
globdir[source]#
match_files[source]#
match_values = [][source]#
fields[source]#
refresh()[source]#

Refresh the study directory.

get(check_exist=True, **kwargs)[source]#

Get files from the study directory that match the fieldnames.

Parameters:
  • check_exist (bool) – Whether to check if the files exist.

  • **kwargs (dict) – The field names and values to match.

Returns:

out – The files that match the field names and values.

Return type:

list

Notes

Example using Study and Study.get():

>>> studydir = '/path/to/study/{subject}/{session}/{subject}_{task}.fif'
>>> study = Study(studydir)

Get all files in the study directory:

>>> study.get()

Get all files for a particular subject:

>>> study.get(subject='sub-01')

Get all files for a particular subject and session:

>>> study.get(subject='sub-01', session='ses-01')

The fieldnames that are not specified in get are replaced with wildcards (*).