NWB Conversion Skill

NWB Conversion Skill

Guides an AI agent in converting two-photon imaging TIFFs and behavioural position CSVs into validated Neurodata Without Borders files, with clock alignment and round-trip checks.

Skill files5 files

assets/

references/

scripts/

SKILL.md113 lines
1
---
2
name: nwb-conversion
3
description: Converts neuroscience acquisition data to Neurodata Without Borders files with NeuroConv and PyNWB, preserves metadata and timebases, checks evidence-based clock alignment, and produces schema validation, NWB Inspector findings and round-trip checks. Use for NWB conversion and synchronization of planar single-channel two-photon TIFF imaging plus timestamped behavioral position CSV; this skill does not perform spike sorting or claim tested support for arbitrary acquisition formats.
4
license: MIT
5
compatibility: Requires Python 3.12 with neuroconv[tiff] 0.10.2, PyNWB 4.2.0, NWB Inspector 0.7.2, roiextractors 0.10.0, tifffile 2026.9.20, zarr 2.18.7 and hdmf-zarr 0.11.3. Local HDF5 file access is required. Network is needed only for installation; no credentials.
6
metadata:
7
version: "1.1"
8
skill-author: K-Dense Inc.
9
last-reviewed: "2026-10-01"
10
upstream-neuroconv: "0.10.2"
11
upstream-pynwb: "4.2.0"
12
upstream-nwbinspector: "0.7.2"
13
---
14
15
# Validated NWB conversion
16
17
## Supported streams
18
19
The executable workflow covers two explicit input streams in one session:
20
21
| Input | NWB representation | Tested constraints |
22
| --- | --- | --- |
23
| Two-photon grayscale multi-page TIFF + frame timestamps CSV | Acquisition `TwoPhotonSeries` named `Imaging` through NeuroConv | One channel, one plane, one 2D image per page, fixed shape and dtype |
24
| Calibrated position CSV (`time_s,x,y`) | Behavior `Position` / `SpatialSeries` through PyNWB | Coordinates in m, cm or mm; converted to meters without temporal resampling |
25
26
Other acquisition readers require their own format-specific tests. In particular, this helper does
27
not decode SpikeGLX, Open Ephys, multichannel TIFF, volumetric TIFF, compressed video, or pixel-to-world
28
calibration. Do not rename an arbitrary numeric table to a supported stream.
29
30
## Install the tested environment
31
32
```bash
33
uv venv --python 3.12 nwb-env
34
uv pip install --python nwb-env/bin/python 'neuroconv[tiff]==0.10.2' pynwb==4.2.0 \
35
nwbinspector==0.7.2 roiextractors==0.10.0 tifffile==2026.9.20 \
36
zarr==2.18.7 hdmf-zarr==0.11.3
37
```
38
39
Keep both Zarr pins even for an HDF5-only conversion: NeuroConv 0.10.2 imports its backend
40
configuration modules at startup, and the tested unconstrained Zarr 3.4.0 installation failed on
41
`zarr.codec_registry`. The pinned environment ran the real conversion, PyNWB validation and
42
Inspector successfully on macOS ARM64. The dependency resolver supplies NumPy and HDF5 support.
43
These are compatibility pins, not claims that Zarr 2 and hdmf-zarr 0.11.3 are the latest releases.
44
Current interface checks and the tested dependency exception are recorded in
45
[references/upstream-review.md](references/upstream-review.md).
46
47
## Workflow
48
49
1. Inventory the actual inputs and acquisition metadata. Identify image plane/channel, optical
50
settings, subject/session identifiers, timezone, behavior coordinate system, units and the
51
timestamp clock for every stream. Preserve originals. Do not replace missing metadata with
52
plausible defaults from a sample config.
53
2. Copy [assets/session-template.json](assets/session-template.json) beside the raw data and
54
replace the explicitly synthetic values. Paths resolve from that JSON file. Read
55
[references/input-contract.md](references/input-contract.md) for the exact CSV and metadata
56
contract and the pulse-pair variant. TIFF pixels are retained as acquired; a raw arbitrary-unit
57
intensity does not become a photon count merely by changing its unit label.
58
3. Establish the common timebase from acquisition evidence. Frame timestamps must already be
59
reference-clock seconds since the timezone-aware session start. For position, provide either
60
a documented shared clock or matched synchronization pulses. The helper fits one affine clock
61
transform, checks its residual against a specified tolerance, and refuses extrapolation beyond
62
the pulse range. It never estimates synchronization from coincident-looking neural/behavioral
63
signals. Clock resets or nonlinear drift require an explicitly validated piecewise mapping.
64
4. Execute the converter. Inputs must have finite, strictly increasing timestamps and matching
65
image/timestamp counts. Explicitly declare one channel and one plane; known TIFF channel/plane
66
metadata must agree. Grayscale pages alone cannot exclude undocumented interleaving.
67
The acquisition samples stay intact; only coordinate units and, when
68
evidenced, behavior timestamps are transformed.
69
5. Read the `.validation.json` alongside the NWB file. Schema compliance, Inspector findings and
70
data equality answer different questions. The script exits with an error for schema failures
71
and flags critical Inspector findings for review in the report. Review all findings in context;
72
successful validation cannot establish that anatomical labels, pulse pairing or calibration
73
supplied by the user are correct.
74
6. Deliver the NWB, validation JSON, original conversion config and an explanation of remaining
75
metadata gaps or Inspector findings. No upload or archive submission is part of this workflow.
76
77
## Execute
78
79
Run the following from the skill directory, with paths to the actual analysis files:
80
81
```bash
82
nwb-env/bin/python scripts/convert_session.py /path/to/session.json --output /path/to/session.nwb
83
```
84
85
`nwb-env` must point to the environment created above; the absolute example input paths are
86
illustrative. The command requires a `.nwb` output and refuses to overwrite an existing NWB or
87
validation report. Output contains source and converter checksums,
88
package versions, full supplied metadata, units and clock-fit provenance in both a scratch record
89
and the validation report. When adapting this command for large data, TIFF writes are iterative
90
and equality checking loads one frame at a time; position CSV currently loads into memory.
91
Round-trip checks also verify dtype, unit scaling, optical-channel links, subject metadata,
92
position reference frame, common time origin and embedded provenance. Inspector findings requiring
93
review appear in the CLI summary; exit zero alone does not mean the file is scientifically correct.
94
An exception during writing or round-trip checks can leave an incomplete NWB without a report;
95
retain the error and use a fresh output path after correcting the cause.
96
97
The real-library test converts eight non-square uint16 images with irregular frame timing plus
98
four position samples, asserts exact pixel and timestamp round trips, and checks centimeter-to-meter
99
conversion. A second integration test recovers a known 1000-ppm clock drift and 50-ms offset from
100
three matched pulses. Duplicate timestamps, mismatched frame counts, absent clock evidence,
101
nonlinear pulse disagreement and missing timezone are rejection cases. The mapping is
102
TIFF `(time,y,x)` to NWB `(time,x,y)`, explicitly checked against every transposed source page. NWB Inspector flags the short fixture
103
with a critical orientation heuristic because width exceeds frame count; the report retains that
104
finding and adds the exact frame/timestamp equality evidence. No transpose is performed merely to
105
satisfy a longest-axis heuristic.
106
107
## Primary references
108
109
- [NeuroConv TIFF conversion](https://neuroconv.readthedocs.io/en/stable/conversion_examples_gallery/imaging/tiff.html)
110
- [NeuroConv temporal alignment](https://neuroconv.readthedocs.io/en/stable/user_guide/temporal_alignment.html)
111
- [PyNWB](https://github.com/NeurodataWithoutBorders/pynwb)
112
- [NWB Inspector and its relation to schema validation](https://github.com/NeurodataWithoutBorders/nwbinspector)
113

© K-Dense Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 6,373 prompts

More by @OpenSourceBuffGuy

See all
Website Clone Architect prompt image

Website Clone Architect

Reverse-engineers a website section by section, writes component specs, and hands them to parallel builder agents in git worktrees to rebuild it.

agent-skill, orchestrator, parallel-agents, multi-agent, plan-then-execute, web-development, frontend, codebase-analysis, scaffolding, css, html, nextjs, typescript, git, mcp, claude-code, for-developers, for-designers, long-form, advanced, technical-spec, task-decomposition, structured-output, design-systems, ui-ux, tool-use, checklist, report, vibe-coding

Italian Terrace Cafe Candid Portrait prompt image

Italian Terrace Cafe Candid Portrait

Generates a photorealistic candid shot of a woman in a white corset dress laughing at a sunny hotel terrace cafe, written as detailed JSON.

image-prompt, json-prompt, structured-output, photorealistic, portrait, woman, candid, fashion, cottagecore, natural-light, golden-hour, bokeh, summer, travel, cityscape, mountains, medium-shot, vibrant-colors, for-photographers, nano-banana, fashion-shoot, luxury

Night Street Photo With Leashed Cat prompt image

Night Street Photo With Leashed Cat

Generates a flash-lit night street photo of a blonde woman in a retro track jacket walking a hissing tabby cat on a leash.

image-prompt, json-prompt, nano-banana, structured-output, portrait, woman, animals, pet-portrait, night-scene, street-photography, candid, editorial, fashion, dramatic-lighting, photorealistic, vertical-format, medium-shot, graffiti, for-photographers, for-content-creators

1 view

Reviews

Loading reviews…

Discussion

Loading comments…