Skip to content

Commit

Permalink
bids_fname -> bids_basename
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmainak committed Nov 3, 2018
1 parent 665fbf5 commit a9674c3
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
8 changes: 4 additions & 4 deletions examples/convert_eeg_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
# however optional. The required inputs are:
#
# * raw
# * bids_fname
# * bids_basename
# * output_path
#
# ... as you can see in the docstring:
Expand All @@ -132,8 +132,8 @@
trial_type = {'rest': 0, 'imagine left fist': 1, 'imagine right fist': 2}

# Now convert our data to be in a new BIDS dataset.
bids_fname = make_bids_basename(subject=subject_id, task=task)
write_raw_bids(raw_file, bids_fname, output_path, event_id=trial_type,
bids_basename = make_bids_basename(subject=subject_id, task=task)
write_raw_bids(raw_file, bids_basename, output_path, event_id=trial_type,
events_data=events, overwrite=True)
###############################################################################
# What does our fresh BIDS directory look like?
Expand Down Expand Up @@ -170,7 +170,7 @@
make_bids_basename(
subject='{:03}'.format(subj_idx), task=task_names[task_idx],
run=run_mapping[task_idx])
write_raw_bids(raw, bids_fname, output_path, event_id=trial_type,
write_raw_bids(raw, bids_basename, output_path, event_id=trial_type,
events_data=events, overwrite=True)

###############################################################################
Expand Down
6 changes: 3 additions & 3 deletions examples/convert_group_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
'run_%02d_raw.fif' % run)

raw = mne.io.read_raw_fif(raw_fname)
bids_fname = ('sub-%02d_ses-01_task-VisualFaces_run-%d'
% (subject_id, run))
write_raw_bids(raw, bids_fname, output_path, event_id=event_id,
bids_basename = ('sub-%02d_ses-01_task-VisualFaces_run-%d'
% (subject_id, run))
write_raw_bids(raw, bids_basename, output_path, event_id=event_id,
overwrite=True)

###############################################################################
Expand Down
4 changes: 2 additions & 2 deletions examples/convert_mne_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
# Finally, we specify the raw_file and events_data

raw = mne.io.read_raw_fif(raw_fname)
bids_fname = 'sub-01_ses-01_task-audiovisual_run-01'
write_raw_bids(raw, bids_fname, output_path, events_data=events_data,
bids_basename = 'sub-01_ses-01_task-audiovisual_run-01'
write_raw_bids(raw, bids_basename, output_path, events_data=events_data,
event_id=event_id, overwrite=True)

###############################################################################
Expand Down
14 changes: 7 additions & 7 deletions examples/create_bids_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
.. note::
You may automatically convert Raw files to a BIDS-compatible folder with
`raw_to_bids`. This example is for manually creating files/folders.
You may automatically convert Raw objects to BIDS-compatible files with
`write_raw_bids`. This example is for manually creating files/folders.
"""

# Authors: Chris Holdgraf <choldgraf@berkeley.edu>
Expand All @@ -30,16 +30,16 @@
# pieces of metadata, ensuring that they are in the correct order in the
# final file path. Omitted keys will not be included in the file path.

my_name = make_bids_basename(subject='test', session='two', task='mytask',
suffix='data.csv')
print(my_name)
bids_basename = make_bids_basename(subject='test', session='two',
task='mytask', suffix='data.csv')
print(bids_basename)

###############################################################################
# You may also omit the suffix, which will result in *only* a prefix for a
# file name. This could then prepended to many more files.

my_name = make_bids_basename(subject='test', task='mytask')
print(my_name)
bids_basename = make_bids_basename(subject='test', task='mytask')
print(bids_basename)

###############################################################################
# Creating folders
Expand Down
4 changes: 2 additions & 2 deletions mne_bids/commands/mne_bids_raw_to_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def run():

opt, args = parser.parse_args()

bids_fname = make_bids_basename(
bids_basename = make_bids_basename(
subject=opt.subject_id, session=opt.session_id, run=opt.run,
acquisition=opt.acq, task=opt.task)
raw = _read_raw(opt.raw_fname, hpi=opt.hpi, electrode=opt.electrode,
hsp=opt.hsp, config=opt.config)
write_raw_bids(raw, bids_fname, opt.output_path, event_id=opt.event_id,
write_raw_bids(raw, bids_basename, opt.output_path, event_id=opt.event_id,
events_data=opt.events_data, overwrite=opt.overwrite,
verbose=True)

Expand Down
12 changes: 6 additions & 6 deletions mne_bids/mne_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def _sidecar_json(raw, task, manufacturer, fname, kind, overwrite=False,
return fname


def write_raw_bids(raw, bids_fname, output_path, events_data=None,
def write_raw_bids(raw, bids_basename, output_path, events_data=None,
event_id=None, overwrite=False, verbose=True):
"""Walk over a folder of files and create BIDS compatible folder.
Expand All @@ -529,7 +529,7 @@ def write_raw_bids(raw, bids_fname, output_path, events_data=None,
raw : instance of mne.Raw
The raw data. It must be an instance of mne.Raw. The data should not be
loaded on disk, i.e., raw.preload must be False.
bids_fname : str
bids_basename : str
The base filename of the BIDS compatible files. Typically, this can be
generated using make_bids_basename.
Example: sub-01_ses-01_task-testing_acq-01_run-01
Expand All @@ -549,7 +549,7 @@ def write_raw_bids(raw, bids_fname, output_path, events_data=None,
output_path : str
The path of the root of the BIDS compatible folder. The session and
subject specific folders will be populated automatically by parsing
bids_fname.
bids_basename.
events_data : str | array | None
The events file. If a string, a path to the events file. If an array,
the MNE events array (shape n_events, 3). If None, events will be
Expand Down Expand Up @@ -602,12 +602,12 @@ def write_raw_bids(raw, bids_fname, output_path, events_data=None,
"raw.times should not have changed since reading"
" in from the file. It may have been cropped.")

params = _parse_bids_filename(bids_fname, verbose)
params = _parse_bids_filename(bids_basename, verbose)
subject_id, session_id = params['sub'], params['ses']
acquisition, task, run = params['acq'], params['task'], params['run']
kind = _handle_kind(raw)

bids_fname = bids_fname + '_%s%s' % (kind, ext)
bids_fname = bids_basename + '_%s%s' % (kind, ext)
data_path = make_bids_folders(subject=subject_id, session=session_id,
kind=kind, root=output_path,
overwrite=False, verbose=verbose)
Expand Down Expand Up @@ -677,7 +677,7 @@ def write_raw_bids(raw, bids_fname, output_path, events_data=None,
_mkdir_p(os.path.dirname(bids_fname))

if verbose:
print('Writing data files to %s' % bids_fname)
print('Copying data files to %s' % bids_fname)

if ext not in ALLOWED_EXTENSIONS:
raise ValueError('ext must be in %s, got %s'
Expand Down
18 changes: 9 additions & 9 deletions mne_bids/tests/test_mne_bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,36 @@ def test_fif():
raw_fname2 = op.join(data_path2, 'sample_audvis_raw.fif')
raw.save(raw_fname2)

bids_fname = bids_basename.replace(subject_id, subject_id2)
write_raw_bids(raw, bids_fname, output_path, events_data=events_fname,
bids_basename2 = bids_basename.replace(subject_id, subject_id2)
write_raw_bids(raw, bids_basename2, output_path, events_data=events_fname,
event_id=event_id, overwrite=False)
# check that the overwrite parameters work correctly for the participant
# data
# change the gender but don't force overwrite.
raw.info['subject_info'] = {'his_id': subject_id2,
'birthday': (1994, 1, 26), 'sex': 2}
with pytest.raises(OSError, match="already exists"):
write_raw_bids(raw, bids_fname, output_path,
write_raw_bids(raw, bids_basename2, output_path,
events_data=events_fname, event_id=event_id,
overwrite=False)
# now force the overwrite
write_raw_bids(raw, bids_fname, output_path, events_data=events_fname,
write_raw_bids(raw, bids_basename2, output_path, events_data=events_fname,
event_id=event_id, overwrite=True)

with pytest.raises(ValueError, match='raw_file must be'):
write_raw_bids('blah', bids_basename, output_path)

bids_fname = 'sub-01_ses-01_xyz-01_run-01'
bids_basename2 = 'sub-01_ses-01_xyz-01_run-01'
with pytest.raises(KeyError, match='Unexpected entity'):
write_raw_bids(raw, bids_fname, output_path)
write_raw_bids(raw, bids_basename2, output_path)

bids_fname = 'sub-01_run-01_task-auditory'
bids_basename2 = 'sub-01_run-01_task-auditory'
with pytest.raises(ValueError, match='ordered correctly'):
write_raw_bids(raw, bids_fname, output_path, overwrite=True)
write_raw_bids(raw, bids_basename2, output_path, overwrite=True)

del raw._filenames
with pytest.raises(ValueError, match='raw.filenames is missing'):
write_raw_bids(raw, bids_fname, output_path)
write_raw_bids(raw, bids_basename2, output_path)

cmd = ['bids-validator', output_path]
run_subprocess(cmd, shell=shell)
Expand Down

0 comments on commit a9674c3

Please sign in to comment.