Generated banner for Nwb Conversion
Generated logo for Nwb Conversion

Nwb Conversion

K-DenseCommunityCreated by K-Dense Inc.

  • Skill
  • Workflow
  • Science and research
  • MIT
  • Low risk
  • Has scripts

From the author

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.
— the description by K-Dense Inc.

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured workflow for converting single-channel two-photon TIFF imaging and timestamped behavioral position CSV data into the Neurodata Without Borders (NWB) format. It emphasizes data integrity by requiring explicit metadata, performing evidence-based clock synchronization, and executing rigorous post-conversion validation using NWB Inspector and schema checks. The workflow is designed for researchers who need to standardize their acquisition data while maintaining strict provenance and temporal accuracy.

What it does

  • Converts grayscale two-photon TIFF files into NWB Imaging series.
  • Integrates behavioral position CSV data into NWB SpatialSeries.
  • Performs affine clock synchronization between imaging and behavioral streams.
  • Validates output files against NWB schema and Inspector rules.
  • Conducts round-trip checks to verify data and metadata integrity.
  • Generates a comprehensive validation report alongside the NWB file.

When to use it

  • When you need to convert planar, single-channel two-photon TIFF data to NWB.
  • When you have timestamped behavioral position data that requires synchronization with imaging.
  • When you need to ensure your converted data meets NWB schema and quality standards.
  • When you require a documented, reproducible conversion process with provenance tracking.

Advantages

  • Ensures temporal alignment through explicit, evidence-based clock mapping.
  • Provides automated schema and quality validation for every conversion.
  • Maintains strict metadata requirements to prevent data ambiguity.
  • Includes round-trip verification to confirm pixel and timestamp accuracy.

Usage examples

“Convert my two-photon imaging session using the provided template.”
The agent will guide you through populating the session JSON, verifying your TIFF and CSV inputs, and executing the conversion script to produce a validated NWB file.
“How do I synchronize my behavior CSV with my imaging timestamps?”
The agent will explain how to provide either shared clock evidence or matched pulse pairs in your configuration to enable the affine clock transformation.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/k-dense-ai/nwb-conversion/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip nwb-conversion.zip -d .agents/skills

Documentation by K-Dense Inc.

Validated NWB conversion

Supported streams

The executable workflow covers two explicit input streams in one session:

InputNWB representationTested constraints
Two-photon grayscale multi-page TIFF + frame timestamps CSVAcquisition TwoPhotonSeries named Imaging through NeuroConvOne channel, one plane, one 2D image per page, fixed shape and dtype
Calibrated position CSV (time_s,x,y)Behavior Position / SpatialSeries through PyNWBCoordinates in m, cm or mm; converted to meters without temporal resampling

Other acquisition readers require their own format-specific tests. In particular, this helper does not decode SpikeGLX, Open Ephys, multichannel TIFF, volumetric TIFF, compressed video, or pixel-to-world calibration. Do not rename an arbitrary numeric table to a supported stream.

Install the tested environment

uv venv --python 3.12 nwb-env
uv pip install --python nwb-env/bin/python 'neuroconv[tiff]==0.10.2' pynwb==4.2.0 \
  nwbinspector==0.7.2 roiextractors==0.10.0 tifffile==2026.9.20 \
  zarr==2.18.7 hdmf-zarr==0.11.3

Keep both Zarr pins even for an HDF5-only conversion: NeuroConv 0.10.2 imports its backend configuration modules at startup, and the tested unconstrained Zarr 3.4.0 installation failed on zarr.codec_registry. The pinned environment ran the real conversion, PyNWB validation and Inspector successfully on macOS ARM64. The dependency resolver supplies NumPy and HDF5 support. These are compatibility pins, not claims that Zarr 2 and hdmf-zarr 0.11.3 are the latest releases. Current interface checks and the tested dependency exception are recorded in references/upstream-review.md.

Workflow

  1. Inventory the actual inputs and acquisition metadata. Identify image plane/channel, optical settings, subject/session identifiers, timezone, behavior coordinate system, units and the timestamp clock for every stream. Preserve originals. Do not replace missing metadata with plausible defaults from a sample config.

  2. Copy assets/session-template.json beside the raw data and replace the explicitly synthetic values. Paths resolve from that JSON file. Read references/input-contract.md for the exact CSV and metadata contract and the pulse-pair variant. TIFF pixels are retained as acquired; a raw arbitrary-unit intensity does not become a photon count merely by changing its unit label.

  3. Establish the common timebase from acquisition evidence. Frame timestamps must already be reference-clock seconds since the timezone-aware session start. For position, provide either a documented shared clock or matched synchronization pulses. The helper fits one affine clock transform, checks its residual against a specified tolerance, and refuses extrapolation beyond the pulse range. It never estimates synchronization from coincident-looking neural/behavioral signals. Clock resets or nonlinear drift require an explicitly validated piecewise mapping.

  4. Execute the converter. Inputs must have finite, strictly increasing timestamps and matching image/timestamp counts. Explicitly declare one channel and one plane; known TIFF channel/plane metadata must agree. Grayscale pages alone cannot exclude undocumented interleaving. The acquisition samples stay intact; only coordinate units and, when evidenced, behavior timestamps are transformed.

  5. Read the .validation.json alongside the NWB file. Schema compliance, Inspector findings and data equality answer different questions. The script exits with an error for schema failures and flags critical Inspector findings for review in the report. Review all findings in context; successful validation cannot establish that anatomical labels, pulse pairing or calibration supplied by the user are correct.

  6. Deliver the NWB, validation JSON, original conversion config and an explanation of remaining metadata gaps or Inspector findings. No upload or archive submission is part of this workflow.

Execute

Run the following from the skill directory, with paths to the actual analysis files:

nwb-env/bin/python scripts/convert_session.py /path/to/session.json --output /path/to/session.nwb

nwb-env must point to the environment created above; the absolute example input paths are illustrative. The command requires a .nwb output and refuses to overwrite an existing NWB or validation report. Output contains source and converter checksums, package versions, full supplied metadata, units and clock-fit provenance in both a scratch record and the validation report. When adapting this command for large data, TIFF writes are iterative and equality checking loads one frame at a time; position CSV currently loads into memory. Round-trip checks also verify dtype, unit scaling, optical-channel links, subject metadata, position reference frame, common time origin and embedded provenance. Inspector findings requiring review appear in the CLI summary; exit zero alone does not mean the file is scientifically correct. An exception during writing or round-trip checks can leave an incomplete NWB without a report; retain the error and use a fresh output path after correcting the cause.

The real-library test converts eight non-square uint16 images with irregular frame timing plus four position samples, asserts exact pixel and timestamp round trips, and checks centimeter-to-meter conversion. A second integration test recovers a known 1000-ppm clock drift and 50-ms offset from three matched pulses. Duplicate timestamps, mismatched frame counts, absent clock evidence, nonlinear pulse disagreement and missing timezone are rejection cases. The mapping is TIFF (time,y,x) to NWB (time,x,y), explicitly checked against every transposed source page. NWB Inspector flags the short fixture with a critical orientation heuristic because width exceeds frame count; the report retains that finding and adds the exact frame/timestamp equality evidence. No transpose is performed merely to satisfy a longest-axis heuristic.

Primary references

Files

references/input-contract.md

Input contract and clock evidence

Use assets/session-template.json as a shape template only. Every experimental field is synthetic. The helper requires timezone-aware ISO 8601 session_start_time, a stable unique identifier, session description, experimenter list, lab, institution and a PyNWB Subject mapping. Keep subject IDs pseudonymous where the dataset requires it. Do not confuse wall-clock time with elapsed sample seconds or infer a timezone from the computer running the conversion.

imaging.modality must explicitly equal two-photon; other or missing modalities are rejected. imaging supplies device name/description, series/plane description, indicator, anatomical location, intensity unit, excitation and emission wavelengths in nanometers, and optical-channel description. The helper implements a two-photon series; optical metadata must describe that actual acquisition. Subject fields are passed through to PyNWB and retained in the full provenance config. The optional subject.date_of_birth uses timezone-aware ISO 8601 text, converted to a datetime for PyNWB. Session and position descriptions, optical text fields, and every experimenter name must be nonempty. The position reference frame must describe the calibrated coordinates actually supplied.

Set integer imaging.num_channels: 1 and imaging.num_planes: 1 only after checking the acquisition layout. The helper rejects multiple TIFF series, color/palette samples, or explicit non-singleton channel/depth axes. Missing TIFF layout metadata does not prove a single channel or plane: a stack of interleaved grayscale pages can look identical to a time sequence. Resolve that from microscope metadata before conversion. OME multi-channel or volumetric input needs a separately tested reader.

Image timestamps CSV has exactly one column:

time_s
0.0
0.1
0.203

There must be one row per grayscale TIFF page. Dropped frames are represented by gaps in the actual timestamps, not by silently reindexing to a nominal rate. The nominal rate supplied internally to NeuroConv is only an initial reader parameter; every recorded frame receives its explicit timestamp. A reordered TIFF must be paired with correspondingly reordered acquisition timestamps before use.

Position CSV has exactly these columns:

time_s,x,y
0.0,10.0,20.0
0.2,10.3,20.2
0.4,10.8,20.1

Every CSV row must have exactly the header's number of fields. Extra values, missing fields, nonfinite values and nonincreasing time values are rejected rather than silently discarded.

position_unit is m, cm or mm; position_reference_frame describes origin and axis directions, and position_description records measurement/calibration context. Pixel inputs are rejected because a scale, lens correction and coordinate transform cannot be inferred from the CSV alone. Coordinates are converted once to meters and written with unit="meters" and default conversion 1.0.

For a real shared clock, record the acquisition evidence, for example a shared DAQ counter that actually timestamps both streams. Similar nominal sampling rates and matching file creation dates are not evidence of shared timing.

"synchronization": {
  "shared_clock_evidence": "Both vectors are acquisition DAQ counter timestamps, converted with its recorded tick rate"
}

For separate clocks, provide already matched pulse pairs; this helper does not discover correspondences or correct missing pulses. The CSV columns are device_time_s,reference_time_s. At least three distinct, increasing pairs must span the entire behavior interval. Specify the maximum acceptable residual in seconds from the experiment's timing precision requirement:

"synchronization": {
  "pulse_pairs_csv": "sync.csv",
  "max_residual_s": 0.001
}

The fitted map is reference_seconds = slope * device_seconds + offset_seconds. Evaluation centers device times at the first pulse to reduce loss of numerical precision. The report preserves that origin, the centered intercept, each pulse residual and both clocks' support intervals. All reference seconds use the explicit NWB timestamps_reference_time, equal to this converter's session_start_time; device seconds must use the same device origin in behavior and pulse CSVs. A shared clock requires a shared epoch as well as a shared tick rate. Inspect residuals and drift over the session before choosing the tolerance. A small least-squares residual from only three pulses does not rule out unobserved clock jumps between them; record pulse coverage and acquisition interruptions. Pulse extrapolation is rejected even when a linear fit is excellent. If pulses fail the model, segment on evidence or use dense event timestamps with an independently tested converter; do not loosen the tolerance just to make validation pass.

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Python

The author says: 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.

Security

What our scanner noticed· Low risk

  • Instructions that use the network
  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
K-Dense Inc.
Publisher
K-Dense (Community)
Source
K-Dense-AI/scientific-agent-skills · skills/nwb-conversion · commit a25cf9e
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE.md)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by K-Dense Inc. or K-Dense.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download nwb-conversion.zip