Skip to main content
Ctrl+K
nwb2bids  documentation - Home nwb2bids  documentation - Home
  • User Guide
  • Tutorials
  • Conversion Gallery
  • Developer Guide
  • API
  • GitHub
  • User Guide
  • Tutorials
  • Conversion Gallery
  • Developer Guide
  • API
  • GitHub
  • Conversion Gallery

Conversion Gallery#

This section provides an in-depth look at how nwb2bids extracts metadata from NWB files and organizes it into BIDS-compliant sidecar files.

For each type of metadata, we’ll show:

  1. How to express the intended data fields of the NWB neurodata type using PyNWB.

  2. What the corresponding extracted BIDS sidecar file contains.

This should help clarify the mapping between NWB and BIDS fields which nwb2bids handles.

Note

We’ll use the same example data from the Tutorials section to demonstrate the fine-grain file contents, so be sure to have those files generated before proceeding.

Dataset Description#

The dataset_description.json file at the root of the BIDS dataset contains high-level metadata about the entire dataset. Unless you are converting a dataset that has already been uploaded to DANDI (and thus may contain several high-level metadata fields not found in any individual files), this information must be provided via the additional metadata feature (see Tutorial 5 - Additional metadata).

A typical dataset_description.json file might look like:

{
    "Name": "`nwb2bids` Conversion Gallery Example",
    "BIDSVersion": "1.10.1",
    "HEDVersion": "8.3.0",
    "Description": "An example dataset description!",
    "DatasetType": "raw",
    "Authors": ["Baker, Cody"],
    "License": "CC-BY-4.0",
    "GeneratedBy": [
        {
            "Name": "nwb2bids",
            "Version": "0.9.1",
            "Description": "Tool to reorganize NWB files into a BIDS directory layout.",
            "CodeURL": "https://github.com/con/nwb2bids"
        }
    ]
}

Hint

If you are using the nwb2bids.DatasetConverter.from_remote_dandiset() method, this file should be autopopulated for you with as much metadata as could be inferred from the DANDI API.

Subjects & Sessions#

In a single NWB file (which can typically represent a single ‘session’), subject-level metadata is attached as a singular Subject object. In BIDS, information about all subjects in the dataset is collected in the top-level participants.tsv and participants.json files, while session-level metadata goes into per-subject sessions.tsv and sessions.json sidecar files.

NWB Session:

nwbfile = pynwb.file.NWBFile(
   session_id="A",
   session_start_time=datetime.datetime(1970, 1, 1, tzinfo=dateutil.tz.tzutc()),
   session_description="An example NWB file containing ecephys neurodata types - for use in the nwb2bids tutorials.",
   identifier=uuid.uuid4().hex,
)

NWB Subject:

subject = pynwb.file.Subject(
   subject_id="001",
   sex="M",
   species="Mus musculus",
)
nwbfile.subject = subject

BIDS Sessions:

The sessions.tsv file contains a row for each session of a subject:

session_id
ses-A

BIDS Participants:

The participants.tsv file contains a row for each subject:

participant_idspeciessex
sub-001Mus musculusM

Note

The column order in all TSV files is strictly enforced by BIDS validation, and nwb2bids will make every effort to produce valid files based on input data.

And the corresponding participants.json file provides detailed descriptions of each column:

{
    "participant_id": "A unique identifier for this participant.",
    "species": "The species should be the proper Latin binomial species name from the NCBI Taxonomy (for example, Mus musculus).",
    "sex": "String value indicating phenotypical sex, one of \"male\", \"female\", \"other\".\n\tFor \"male\", use one of these values: male, m, M, MALE, Male.\n\tFor \"female\", use one of these values: female, f, F, FEMALE, Female.\n\tFor \"other\", use one of these values: other, o, O, OTHER, Other."
}

Mapping:

NWB Field

BIDS Field

subject.subject_id

participant_id (with sub- prefix)

subject.species

species

subject.sex

sex

session_id

session_id (with ses- prefix)

session_start_time

acq_time

General Metadata#

NWB files can contain a number of high-level metadata fields that describe the overall experiment, acquisition parameters, and other details that don’t neatly belong to specific neurodata types. These fields are typically set on the top-level pynwb.NWBFile object, though there are a few that belong to particular subfields such as pynwb.DeviceModel.

NWB file metadata:

general_metadata_nwbfile = pynwb.NWBFile(
    session_id="B",
    session_start_time=datetime.datetime(1970, 1, 2, tzinfo=dateutil.tz.tzutc()),
    session_description="An example NWB file used for demonstration of general metadata mapping.",
    identifier=uuid.uuid4().hex,
    institution="My Institution",
    pharmacology="carprofen, 5 mg/kg, given peri-operatively and maintained during recording sessions to manage pain from the craniotomy/implant without sedation.",
    protocol="Mice were placed in a running wheel and allowed to run freely while neural activity was recorded. Mice were trained to stop running in response to air puffs.",
    slices="After the experiment, brains were extracted and sliced into 5 micron sections from primary motor cortex were fixed in epoxy resin for subsequent icephys study.",
)
general_metadata_device = pynwb.file.DeviceModel(
    name="GeneralMetadataDevice",
    description="This is an example device used for demonstration of general metadata mapping.",
    manufacturer="imec",
    model_number="NP2014",
)
general_metadata_nwbfile.add_device_model(general_metadata_device)

BIDS general metadata:

Depending on the modality, the ecephys.json or icephys.json file contains metadata such as:

{
     "InstitutionName": "My Institution",
     "InstitutionAddress": "123 Institution Rd, My City, My State, My Country",
     "InstitutionalDepartmentName": "My Department",
     "PowerLineFrequency": "60",  // In Hz
     "Manufacturer": "imec",
     "ManufacturersModelName": "NP",
     "ManufacturersModelVersion": "2014",
     "RecordingSetupName": "MyLabsRig",
     "SamplingFrequency": 30000.0,  // In Hz
     "DeviceSerialNumber": "ABC123",
     "SoftwareName": "RecordingSoftware",
     "SoftwareVersions": "1.0.0",
     "RecordingDuration": "7200",  // In seconds
     "RecordingType": "continuous",
     "SoftwareFilters": {"Anti-aliasing filter": {"half-amplitude cutoff (Hz)": 500, "Roll-off": "6dB/Octave"}},
     "HardwareFilters": {"Highpass RC filter": {"Half amplitude cutoff (Hz)": 0.0159, "Roll-off": "6dB/Octave"}},
     "BodyPart": "BRAIN",
     "BodyPartDetails": "primary motor cortex",
     "BodyPartDetailsOntology": "http://purl.obolibrary.org/obo/UBERON_0001384"
}
{
     "PharmaceuticalName": "carprofen",
     "PharmaceuticalDoseAmount": 5,
     "PharmaceuticalDoseUnits": "mg/kg",
     "PharmaceuticalDoseRegimen": "Given peri-operatively and maintained during recording sessions to manage pain from the craniotomy/implant without sedation.",
     "PharmaceuticalDoseTime": "0",  // In seconds
     "SampleEnvironment": "in-vivo",
     "SupplementarySignals": "Running wheel velocity.",
     "TaskName": "My Running Task",
     "TaskDescription": "Mice were placed in a running wheel and allowed to run freely while neural activity was recorded.",
     "Instructions": "Mice were trained to stop running in response to air puffs."
}
{
     "SampleEnvironment": "ex-vivo",
     "SampleEmbedding": "Epoxy resin",
     "SliceThickness": "5",  // In microns
     "SampleExtractionProtocol": "Aliquot of primary motor cortex extracted from brain and embedded in epoxy resin."
}

Mapping:

Currently, only one electrical series per NWB file is supported for automated metadata extraction. Additional sidecar files should be copied and modified to correspond to additional electrical series within the same NWB files. The use of acq-[label] suffixes in the other sidecar filenames is recommended to avoid confusion between series.

NWB Field

BIDS Field

nwbfile.institution

InstitutionName

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

InstitutionAddress

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

InstitutionalDepartmentName

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

PowerLineFrequency

nwbfile.acquisition.electrical_series[0].device_model.manufacturer

Manufacturer

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

ManufacturersModelName

nwbfile.acquisition.electrical_series[0].device_model.model_number

ManufacturersModelVersion

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

RecordingSetupName

nwbfile.acquisition.electrical_series[0].rate

SamplingFrequency

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

DeviceSerialNumber

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

SoftwareName

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

SoftwareVersions

nwbfile.acquisition.electrical_series[0].data.shape[0] / nwbfile.acquisition.electrical_series[0].rate

RecordingDuration

~Not Yet Implemented~
Please directly edit the file(s)
or comment on Issue #337

RecordingType

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

EpochLength

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

SoftwareFilters

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

HardwareFilters

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

PharmaceuticalName

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

PharmaceuticalDoseAmount

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

PharmaceuticalDoseUnits

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

PharmaceuticalDoseRegimen

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

PharmaceuticalDoseTime

"BRAIN" if nwbfile.acquisition.electrical_series[0].electrode_group.location is not None

BodyPart

nwbfile.acquisition.electrical_series[0].electrode_group.location

BodyPartDetails

~Not Yet Implemented~
Please directly edit the file(s)
or comment on Issue #338

BodyPartDetailsOntology

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

SampleEnvironment

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

SampleEmbedding

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

SliceThickness

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

SampleExtractionProtocol

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

SupplementarySignals

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

TaskName

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

TaskDescription

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

Instructions

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

CogAtlasID

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

CogPOID

Ecephys Probes#

In NWB, recording hardware is represented as Device objects. In the BIDS ecephys specification, these become entries in the probes.tsv and probes.json sidecar files.

NWB Device:

probe = pynwb.file.Device(
   name="ExampleProbe",
   description="This is an example ecephys probe used for demonstration purposes.",
   manufacturer="`nwb2bids` test suite",
)

BIDS Probes:

The probes.tsv file contains a row for each probe:

probe_nametypemanufacturerdescription
ExampleProben/a`nwb2bids` test suiteThis is an example ecephys probe used for demonstration purposes.

Note

The column order in all TSV files is strictly enforced by BIDS validation, and nwb2bids will make every effort to produce valid files based on input data.

And the corresponding probes.json file provides detailed descriptions of each column:

# TODO: fix this

{}

Mapping:

NWB Field

BIDS Field

Device.name

probe_name

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

type

Device.manufacturer

manufacturer

Device.description

description

Ecephys Electrodes#

Electrodes represent the physical recording sites on a probe. In classic NWB, these may be stored in the electrodes table, which requires each electrode to also link to an ElectrodeGroup, commonly interpreted as a traditional ‘shank’ in ecephys. In BIDS, they appear in the electrodes.tsv and electrodes.json sidecar files.

Note

Certain special probes, such as Neuropixels, may overload the electrodes table to actually store information about each recording channel. In this case, a special column electrode.contact_id is used to distinguish physical contacts from recording channels.

NWB Electrode Table:

shank = pynwb.ecephys.ElectrodeGroup(
   name="ExampleShank",
   description="This is an example electrode group (shank) used for demonstration purposes.",
   location="hippocampus",
   device=probe,
)
nwbfile.add_electrode_group(shank)

for _ in range(8):
   nwbfile.add_electrode(
      imp=150_000.0,
      location="hippocampus",
      group=shank,
      filtering="HighpassFilter"
   )

BIDS Electrodes:

The electrodes.tsv file contains a row for each electrode:

nameprobe_namexyzhemisphereimpedanceshank_idlocation
e000ExampleProben/an/an/an/a150.0ExampleShankhippocampus
e001ExampleProben/an/an/an/a150.0ExampleShankhippocampus
e002ExampleProben/an/an/an/a150.0ExampleShankhippocampus
e003ExampleProben/an/an/an/a150.0ExampleShankhippocampus
e004ExampleProben/an/an/an/a150.0ExampleShankhippocampus
e005ExampleProben/an/an/an/a150.0ExampleShankhippocampus
e006ExampleProben/an/an/an/a150.0ExampleShankhippocampus
e007ExampleProben/an/an/an/a150.0ExampleShankhippocampus

You may notice many differences between the classic NWB electrode fields and the electrodes.tsv file. BIDS requires several fields that NWB does not, but their values may be set to n/a if they are not known. Additionally, NWB stores impedance values in units of Ohms, while BIDS expects kOhms - nwb2bids handles this conversion automatically.

And the corresponding electrodes.json file provides detailed descriptions of each column:

# TODO: fix this

{}

Mapping:

NWB Field (Ecephys)

BIDS Field

“e{electrode.index}”

name

electrode.group.device.name

probe_name

electrode.x

x

electrode.y

y

electrode.z

z

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

hemisphere

electrode.imp (in Ohms)

impedance (in kOhms)

electrode.group.name

shank_id

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

size

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

electrode_shape

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

material

electrode.location

location

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

pipette_solution

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

internal_pipette_diameter

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

external_pipette_diameter

Ecephys Channels#

Channels represent separate data streams recorded from the physical electrodes. In NWB, this information is often combined with the previously shown electrodes table and additional columns may be used to disambiguate physical contacts from recording channels. In BIDS, channels are described separately from electrodes via the channels.tsv and channels.json sidecar files.

BIDS Channels:

The channels.tsv file contains a row for each channel:

nameelectrode_nametypeunitssampling_frequencystream_idgain
ch000e000n/aV30000.0ExampleElectricalSeries3.02734375e-06
ch001e001n/aV30000.0ExampleElectricalSeries3.02734375e-06
ch002e002n/aV30000.0ExampleElectricalSeries3.02734375e-06
ch003e003n/aV30000.0ExampleElectricalSeries3.02734375e-06
ch004e004n/aV30000.0ExampleElectricalSeries3.02734375e-06
ch005e005n/aV30000.0ExampleElectricalSeries3.02734375e-06
ch006e006n/aV30000.0ExampleElectricalSeries3.02734375e-06
ch007e007n/aV30000.0ExampleElectricalSeries3.02734375e-06

You may notice many differences between the classic NWB electrode fields and the channels.tsv file. In particular, a number of these values are not specified in the NWB electrodes table, but are instead set on any data-containing ElectricalSeries objects that link to those electrodes. In these cases, nwb2bids will attempt to find and extract the relevant values.

And the corresponding channels.json file provides detailed descriptions of each column:

# TODO: fix this

{}

Mapping:

NWB Field (Ecephys)

BIDS Field

ch{electrode.index}

name

e{electrode.index}

electrode_name

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

type

electrical_series.units (if available; fixed to V)

units

electrical_series.rate (if available)

sampling_frequency

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

low_cutoff

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

high_cutoff

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

reference

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

notch

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

channel_label (Good or Bad)

electrical_series.name (if available)

stream_id

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

description

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

software_filter_types

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

status

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

status_description

electrical_series.conversion (if available)

gain

electrical_series.starting_time (if available)

time_offset

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

time_reference_channel

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

ground

~Not Yet Implemented~
Please directly edit the file(s)
or Request This Feature

recording_mode

previous

Generating an example dataset

next

Developer Guide

On this page
  • Dataset Description
  • Subjects & Sessions
  • General Metadata
  • Ecephys Probes
  • Ecephys Electrodes
  • Ecephys Channels
Edit on GitHub
Show Source

© Copyright 2025, Cody Baker.

Created using Sphinx 9.1.0.

Built with the PyData Sphinx Theme 0.17.0.