|
| 1 | +:html_theme.sidebar_secondary.remove: |
| 2 | + |
| 3 | +.. _tutorials: |
| 4 | + |
| 5 | +Tutorials |
| 6 | +========= |
| 7 | + |
| 8 | +**nwb2bids** comes pre-packaged with some demonstrative tools to help showcase its functionality on various types of |
| 9 | +NWB file contents. No additional requirements, knowledge, or experience are necessary to run these tutorials! |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +Tutorial 1 - Converting a single file |
| 14 | +------------------------------------- |
| 15 | + |
| 16 | +In case you don't have any NWB files handy, or perhaps you've never worked with NWB files before, you can generate a |
| 17 | +toy example through the command line interface (CLI) as follows: |
| 18 | + |
| 19 | +.. code-block:: bash |
| 20 | +
|
| 21 | + nwb2bids tutorial generate ephys |
| 22 | +
|
| 23 | +This created an NWB file with contents typical of an extracellular electrophysiology experiment in your home |
| 24 | +directory for **nwb2bids**: ``~/.nwb2bids/tutorials/ephys/nwb2bids_tutorial_ephys.nwb``. |
| 25 | + |
| 26 | +.. note:: |
| 27 | + |
| 28 | + Don't like overwhelming your home directory with lots of small files? |
| 29 | + |
| 30 | + You can control where tutorial data is generated by using the ``--output-directory`` flag (or ``-o`` for short): |
| 31 | + |
| 32 | + .. code-block:: bash |
| 33 | +
|
| 34 | + nwb2bids tutorial generate ephys --output-directory path/to/some/directory |
| 35 | +
|
| 36 | +NWB files like this contain a lot of metadata about the probes and electrode structure, which will be useful later |
| 37 | +when we compare the source file to the sidecar tables found in BIDS. You can explore these file contents through |
| 38 | +`neurosift.app <neurosift.app>`_ by following this link: TODO |
| 39 | + |
| 40 | +.. tip:: |
| 41 | + |
| 42 | + The link above actually points to a similar file published on the DANDI Archive, which should be identical to |
| 43 | + what what written on your system. You can explore and visualize your local file contents and structure |
| 44 | + in many other ways, such as the |
| 45 | + `NWB GUIDE <https://nwb-guide.readthedocs.io/en/stable/installation.html>`_, |
| 46 | + `HDFView <https://www.hdfgroup.org/download-hdfview/>`_, or the |
| 47 | + `PyNWB library <https://pynwb.readthedocs.io/en/stable/tutorials/general/plot_read_basics.html#reading-and-exploring-an-nwb-file>`_. |
| 48 | + |
| 49 | +Now that we have an NWB file, we can convert it to BIDS using the following command: |
| 50 | + |
| 51 | +.. code-block:: bash |
| 52 | +
|
| 53 | + nwb2bids convert ~/.nwb2bids/tutorials/ephys/nwb2bids_tutorial_ephys.nwb --bids-directory ~/.nwb2bids/tutorials/ephys/bids_dataset |
| 54 | +
|
| 55 | +Notice how we explicitly specified the output BIDS directory using the ``--bids-directory`` flag. We will cover the |
| 56 | +implicit (current working directory) approach in TODO: crossref to later tutorial. |
| 57 | + |
| 58 | + |
| 59 | +Tutorial 2 - Converting multiple files |
| 60 | +-------------------------------------- |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +.. tip:: |
| 65 | + |
| 66 | + Lost in the CLI? Can't remember the exact phrase to type when navigating through the command groups? No worries! |
| 67 | + Simply add the ``--help`` to any command to see detailed descriptions, expected inputs, and optional flags. |
| 68 | + |
| 69 | + You can also see a layout of the command structure by calling each level at a time, for example ``nwb2bids``, |
| 70 | + ``nwb2bids tutorial``, and so on. |
| 71 | + |
| 72 | + Try it out on ``nwb2bids tutorial generate`` to see all the types of tutorial data we can generate for you. |
| 73 | + |
| 74 | +This command assumes you are located within either an empty directory or a BIDS dataset, informing you accordingly if |
| 75 | +these conditions are not met. |
| 76 | + |
| 77 | +To specify a specific location other than your current working directory, use the ``--bids-directory`` |
| 78 | +flag (or ``-o`` for short): |
| 79 | + |
| 80 | +.. code-block:: bash |
| 81 | +
|
| 82 | + nwb2bids convert [path to NWB files] --bids-directory [path to BIDS directory] |
| 83 | +
|
| 84 | +The main input to the interface can be any combination of directories containing NWB files or individual NWB files: |
| 85 | + |
| 86 | +.. code-block:: bash |
| 87 | +
|
| 88 | + nwb2bids convert path/to/many/nwb single.nwb another.nwb |
| 89 | +
|
| 90 | +
|
| 91 | +
|
| 92 | +Application Programming Interface (API) |
| 93 | +--------------------------------------- |
| 94 | + |
| 95 | +A more advanced usage of **nwb2bids** is through its Python library. A thorough description of all publicly exposed |
| 96 | +functions and classes can be found in the :ref:`API <api>` section of the documentation. |
| 97 | + |
| 98 | +The core function is the ``convert_nwb_to_bids`` function, which can be used as follows: |
| 99 | + |
| 100 | +.. code-block:: python |
| 101 | +
|
| 102 | + import nwb2bids |
| 103 | +
|
| 104 | + nwb2bids.convert_nwb_to_bids( |
| 105 | + nwb_paths=["path/to/many/nwb", "single.nwb", "another.nwb"], |
| 106 | + bids_directory="path/to/bids/directory" # Optional, defaults to current working directory |
| 107 | + ) |
| 108 | +
|
| 109 | +Essentially, this function is direct wrapper used by the CLI and behaves in the same way. |
| 110 | + |
| 111 | +One key programmatic difference however is the ability to interact with the notifications returned by the operation: |
| 112 | + |
| 113 | +.. code-block:: python |
| 114 | +
|
| 115 | + import nwb2bids |
| 116 | +
|
| 117 | + notifications = nwb2bids.convert_nwb_to_bids( |
| 118 | + nwb_paths=["path/to/many/nwb", "single.nwb", "another.nwb"], |
| 119 | + bids_directory="path/to/bids/directory" |
| 120 | + ) |
| 121 | +
|
| 122 | + for notification in notifications: |
| 123 | + print(notification) |
| 124 | +
|
| 125 | +More examples to follow soon... |
0 commit comments