.. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_create_bids_folder.py: ========================================== Creating BIDS-compatible folders and files ========================================== The Brain Imaging Data Structure (BIDS) has standard conventions for file names and folder hierarchy. MNE-BIDS comes with convenience functions if you wish to create these files/folders on your own. .. note:: You may automatically convert Raw objects to BIDS-compatible files with `write_raw_bids`. This example is for manually creating files/folders. .. code-block:: default # Authors: Chris Holdgraf # License: BSD (3-clause) We'll import the relevant functions from the write module .. code-block:: default from mne_bids import make_bids_folders, make_bids_basename Creating file names for BIDS ---------------------------- BIDS requires a specific ordering and structure for metadata fields in file paths, the function `make_bids_basename` allows you to specify many such 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. .. code-block:: default bids_basename = make_bids_basename(subject='test', session='two', task='mytask', suffix='data.csv') print(bids_basename) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none sub-test_ses-two_task-mytask_data.csv 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. .. code-block:: default bids_basename = make_bids_basename(subject='test', task='mytask') print(bids_basename) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none sub-test_task-mytask Creating folders ---------------- You can also use MNE-BIDS to create folder hierarchies. .. code-block:: default path_folder = make_bids_folders('sub_01', session='mysession', kind='meg', output_path='path/to/project', make_dir=False) print(path_folder) # Note that passing `make_dir=True` will create the folder hierarchy, ignoring # errors if the folder already exists. .. rst-class:: sphx-glr-script-out Out: .. code-block:: none path/to/project/sub-sub_01/ses-mysession/meg .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.002 seconds) .. _sphx_glr_download_auto_examples_create_bids_folder.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download :download:`Download Python source code: create_bids_folder.py ` .. container:: sphx-glr-download :download:`Download Jupyter notebook: create_bids_folder.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_