Skip to content

Port NDR reader framework from MATLAB to Python#1

Merged
stevevanhooser merged 2 commits intomainfrom
claude/port-ndr-matlab-python-EdA1N
Mar 17, 2026
Merged

Port NDR reader framework from MATLAB to Python#1
stevevanhooser merged 2 commits intomainfrom
claude/port-ndr-matlab-python-EdA1N

Conversation

@stevevanhooser
Copy link
Copy Markdown
Contributor

Summary

This PR implements a comprehensive Python port of the NDR (Neuroscience Data Reader) MATLAB library, establishing the core reader framework and format-specific handlers for reading neural data files.

Key Changes

Core Reader Framework

  • ndr/reader/base.py: Abstract base class for all format-specific readers with concrete utility methods for channel validation, type conversion, and time/sample conversions
  • ndr/reader_wrapper.py: High-level Reader class providing unified interface to format-specific readers with dynamic loader based on data format type

Format-Specific Readers

  • ndr/reader/intan_rhd.py: Complete reader for Intan RHD2000 format with channel mapping, header parsing, and data block handling
  • ndr/reader/axon_abf.py: Reader for Axon ABF format (pyabf-based)
  • ndr/reader/ced_smr.py: Reader for CED Spike2 SMR format (neo-based)
  • ndr/reader/neo.py: Generic neo library wrapper for multiple formats
  • Stub readers: tdt_sev.py, bjg.py, dabrowska.py, spikegadgets_rec.py, whitematter.py for future implementation

Intan RHD Format Handler

  • ndr/format/intan/read_Intan_RHD2000_header.py: Binary header parsing with Qt QString support
  • ndr/format/intan/read_Intan_RHD2000_datafile.py: Data block structure calculation and file I/O

Utility Modules

  • Time utilities: ndr/time/clocktype.py, ndr/time/fun/samples2times.py, ndr/time/fun/times2samples.py for time/sample conversions
  • String utilities: ndr/string/channelstring2channels.py, ndr/string/str2intseq.py, ndr/string/intseq2str.py for channel specification parsing
  • Data utilities: ndr/data/colvec.py, ndr/data/rowvec.py for array reshaping
  • Core utilities: ndr/fun/ndrpath.py, ndr/fun/ndrresource.py, ndr/fun/bitDepth.py, ndr/fun/getDataTypeString.py
  • File utilities: ndr/file/textfile2char.py

Configuration & Resources

  • ndr/resource/ndr_reader_types.json: Registry mapping format identifiers to reader class implementations
  • ndr/globals.py: Global path and configuration management
  • ndr/known_readers.py: Public API for discovering available readers

Testing & Documentation

  • Unit tests: tests/test_reader_base.py, tests/test_readers.py with comprehensive coverage of static methods and channel type conversions
  • Symmetry test framework: tests/symmetry/ with artifact generation and validation for MATLAB/Python parity
  • Bridge documentation: ndr_matlab_python_bridge.yaml files documenting MATLAB-to-Python mapping contracts
  • Developer guides: PYTHON_PORTING_GUIDE.md, ndr_xlang_principles.md, symmetry_tests.md for cross-language development

Project Configuration

  • pyproject.toml: Package metadata, dependencies (numpy, pydantic, vhlab-toolbox-python), and optional dev dependencies
  • README.md: Updated with comprehensive overview of NDR architecture and capabilities

Implementation Details

  • Lead-Follow Architecture: Python implementation faithfully mirrors MATLAB source of truth with explicit bridge contracts via YAML files
  • Semantic Parity: 1-based indexing for user-facing APIs, 0-based for internal data structures
  • Dynamic Reader Loading: Format-specific readers loaded at runtime via importlib based on JSON registry
  • Extensible Design: Abstract base class enables straight

https://claude.ai/code/session_01QGdJXLDUuQGSiDw8ZggEMU

claude added 2 commits March 17, 2026 00:05
- Create repo structure mirroring MATLAB +namespace paths
- Port ndr.reader.base abstract base class with all method signatures
- Port ndr.reader wrapper (reader_wrapper.py) with read(), delegation
- Implement Intan RHD format reader with binary file parsing
- Implement Axon ABF reader (pyabf backend)
- Implement CED SMR reader (neo backend)
- Add stub readers: BJG, Dabrowska, Neo, SpikeGadgets, TDT, WhiteMatter
- Port utility packages: time (clocktype, samples2times, times2samples),
  data (colvec, rowvec), string (channelstring2channels, str2intseq),
  file (textfile2char), fun (ndrpath, ndrresource, bitDepth)
- Port globals, known_readers with ndr_reader_types.json resource
- Create bridge YAML files for reader and format/intan packages
- Create developer notes: porting guide, xlang principles, bridge spec,
  symmetry test docs
- Create symmetry test framework (make_artifacts, read_artifacts)
- Add 50 unit tests covering base class, Intan static methods,
  channel strings, time functions, known readers, and wrapper
- All tests pass, black formatted, ruff clean

https://claude.ai/code/session_01QGdJXLDUuQGSiDw8ZggEMU
- Lint job: black --check and ruff check
- Test job: pytest across Python 3.10, 3.11, 3.12 with fail-fast disabled

https://claude.ai/code/session_01QGdJXLDUuQGSiDw8ZggEMU
@stevevanhooser stevevanhooser merged commit af13e6a into main Mar 17, 2026
4 checks passed
@stevevanhooser stevevanhooser deleted the claude/port-ndr-matlab-python-EdA1N branch March 17, 2026 00:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants