返回 Skills 目錄
來源:Scientific Agent Skills
🧠

NWB Conversion

🧬生物資訊

以 NeuroConv 與 PyNWB 將神經科學實驗資料轉為 NWB 格式,保留中繼資料與時間基準並做結構驗證。

安裝教學

選擇你使用的 AI coding agent,複製指令到終端機執行

一鍵安裝(需要 Node.js)
npx skills add K-Dense-AI/scientific-agent-skills --skill nwb-conversion -g -a claude-code -y
手動安裝(不使用 npx)
clone 後複製到 skills 目錄
git clone --depth 1 https://github.com/K-Dense-AI/scientific-agent-skills.git
mkdir -p ~/.claude/skills
cp -r scientific-agent-skills/skills/nwb-conversion ~/.claude/skills/nwb-conversion

Skills 會以 agent 的完整權限執行,安裝前請先閱讀原始 SKILL.md。安裝後重新啟動 agent 即可使用。

使用教學

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.

工作流程

  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. 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 refuses to overwrite an existing NWB. Output contains source 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.

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