Metadata-Version: 2.5
Name: ndx-brainstem
Version: 0.2.0
Summary: BrainSTEM experimental metadata in NWB
Project-URL: Homepage, https://github.com/brainstem-org/ndx-brainstem
Project-URL: Bug Tracker, https://github.com/brainstem-org/ndx-brainstem/issues
Project-URL: Changelog, https://github.com/brainstem-org/ndx-brainstem/blob/main/CHANGELOG.md
Author-email: BrainSTEM Team <petersen.peter@gmail.com>
License-Expression: MIT
License-File: LICENSE.txt
Keywords: NWB,NeurodataWithoutBorders,ndx-extension,nwb-extension
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Requires-Dist: hdmf>=4.2.0
Requires-Dist: ndx-anatomical-localization<0.2,>=0.1
Requires-Dist: pynwb>=3.1.3
Description-Content-Type: text/markdown

# ndx-brainstem

An [NWB](https://www.nwb.org) extension that stores [BrainSTEM](https://www.brainstem.org) experimental metadata inside an NWB file: the BrainSTEM records the file was made from, with every field, and the links between them.

Files are written by [brainstem-nwb](https://github.com/brainstem-org/brainstem-nwb) (`brainstem-nwb export --extension brainstem`). Core NWB fields (Subject, Devices, electrode groups, epochs and the text fields) describe the experiment for every NWB reader. This extension adds the structured detail behind them, so nothing BrainSTEM records is lost.

**Status:** pre-release (0.2.0). The schema may change before 1.0.

## Installation

```bash
pip install ndx-brainstem
```

## What a file contains

`/general/brainstem` (`BrainstemMetadata`, a `LabMetaData`) holds:

- **Provenance attributes:** export format version and scope, export time, the checksum of the source export (`source_sha256`) and of the file's content (`content_sha256`), the BrainSTEM project, session, subject and unit ids, and the exporter and mapping versions.
- **One `BrainstemTable` per kind of record**, for example `procedures`, `materials`, `interfaces`, `acquisitions`, `manipulations`, `behaviors`, `specimen_sets`, `specimens`, `logs`, `log_entries`, `regions`, `catalog`, `lab_resources` and `people`. Each row is one BrainSTEM record. The spec fixes no table names; the writer's current list is in brainstem-nwb's [extensions documentation](https://github.com/brainstem-org/brainstem-nwb/blob/main/docs/extensions.md).
- **`schemas`** (`BrainstemSchemaTable`): every BrainSTEM JSON schema the tables name, with its stable URL (published versions never change) and, when embedded, the schema itself.

### `BrainstemTable` columns

| Column | Type | Contents |
|---|---|---|
| `brainstem_id`, `brainstem_model` | required text | The record's BrainSTEM id and model label (e.g. `modules.procedure`) |
| one per BrainSTEM field | text | Strings as stored. Other values (numbers, booleans, JSON objects such as `type_json`) are JSON text. An empty string means no value |
| one per link field | ragged `DynamicTableRegion` | Rows of another `BrainstemTable`, or of `/intervals/epochs` |
| `details_schema`, `coordinates_schema` | text | `<Family>/<Type>@<version>` of the record's typed details or coordinates, e.g. `Procedure/VirusInjection@3.0.0` |
| `unresolved_links` | text | JSON `{field: [ids]}` of links to records not in the file |
| writer-defined | text or `DynamicTableRegion` | Columns the writer adds beyond the fields, such as `nwb_device` (the NWB device a row became), `nwb_epochs` (rows of `/intervals/epochs`), `log` and `catalog_entry` (links to the parent log or catalog entry). A field whose name a `DynamicTable` reserves is written as `record_<field>`; a `*_time` field also gets an ISO 8601 copy named `<field>_iso` |

The table attribute `brainstem_models` lists the model labels of the table's rows.

## Reading

```python
from pynwb import NWBHDF5IO

with NWBHDF5IO("sub-X_ses-Y.nwb", "r") as io:
    nwbfile = io.read()
    brainstem = nwbfile.lab_meta_data["brainstem"]
    procedures = brainstem.brainstem_tables["procedures"].to_dataframe()
```

NWB stores the extension's schema in every file, so pynwb (and MatNWB) can read these files without installing this package.

## Installation (development)

```bash
pip install -e . --group dev   # pip 25.1 or newer; or: pip install -e . && pip install pytest
python src/spec/create_extension_spec.py   # regenerate spec/*.yaml after changing the spec
pytest
```

This extension was created with [ndx-template](https://github.com/nwb-extensions/ndx-template).
