export_to_nwb#

export_to_nwb(
block: Block,
filepath: str | Path,
session_description: str = 'MyoGen simulation',
identifier: str | None = None,
session_start_time: datetime | None = None,
experimenter: str | list[str] | None = None,
institution: str | None = None,
lab: str | None = None,
experiment_description: str | None = None,
keywords: list[str] | None = None,
subject_id: str | None = None,
species: str = 'Homo sapiens',
age: str | None = None,
sex: str | None = None,
subject_description: str | None = None,
**kwargs,
) Path[source]#

Export a Neo Block to NWB format.

This function uses Neo’s NWBIO to write simulation data to an NWB file. The Block should contain AnalogSignals with grid annotations (created via create_grid_signal) for electrode array data.

Parameters:
  • block (Block) – Neo Block containing simulation data. Can be spike trains, EMG, or MUAP data from MyoGen simulations.

  • filepath (str or Path) – Output file path. Should end with ‘.nwb’.

  • session_description (str, default="MyoGen simulation") – Description of the simulation session.

  • identifier (str, optional) – Unique identifier for this NWB file. If None, a UUID is generated.

  • session_start_time (datetime, optional) – Start time of the session. If None, current time is used.

  • experimenter (str or list[str], optional) – Name(s) of experimenter(s).

  • institution (str, optional) – Institution where the simulation was performed.

  • lab (str, optional) – Lab where the simulation was performed.

  • experiment_description (str, optional) – Description of the experiment/simulation.

  • keywords (list[str], optional) – Keywords describing the data.

  • subject_id (str, optional) – Subject identifier (recommended for DANDI).

  • species (str, default="Homo sapiens") – Species of the subject. Use Latin binomial (e.g., “Homo sapiens”, “Mus musculus”). For simulations, defaults to human.

  • age (str, optional) – Age of subject in ISO 8601 duration format (e.g., “P30Y” for 30 years).

  • sex (str, optional) – Sex of subject. One of: “M”, “F”, “U” (unknown), “O” (other).

  • subject_description (str, optional) – Description of the subject.

  • **kwargs – Additional keyword arguments passed to NWBIO.

Returns:

Path to the created NWB file.

Return type:

Path

Examples

>>> from myogen.utils.nwb import export_to_nwb
>>>
>>> # Export spike trains to NWB
>>> export_to_nwb(
...     spike_train__Block,
...     "simulation_spikes.nwb",
...     session_description="Motor neuron pool simulation",
...     institution="My University",
... )
>>>
>>> # Export surface EMG to NWB
>>> export_to_nwb(
...     surface_emg__Block,
...     "simulation_emg.nwb",
...     session_description="Surface EMG simulation",
...     experimenter="John Doe",
... )

Notes

For electrode array data (surface EMG, MUAPs), the grid structure is preserved via electrode_positions in annotations, which map to NWB’s electrode table.

See also

create_grid_signal

Create grid-annotated AnalogSignals

validate_nwb

Validate NWB file with NWBInspector