Skip to content

Commit 1f73e92

Browse files
edenoclaude
andcommitted
Update Python version requirement to 3.10+ and auto-fix ruff issues
- Increase minimum Python version from 3.8 to 3.10 - Update all tool configurations to target Python 3.10 - Auto-fix 124 code style issues with ruff --fix including: - Import sorting and organization - Remove unused imports and variables - Simplify code patterns (list comprehensions, conditionals) - Fix whitespace and formatting issues 61 issues remain that require manual review, mostly in notebooks and complex logic patterns that need careful consideration. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 3c9478d commit 1f73e92

27 files changed

+328
-254
lines changed

CLAUDE.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Python package that converts SpikeGadgets .rec files (electrophysiology data) to NWB 2.0+ format. The conversion includes ephys data, position tracking, video files, DIO events, and behavioral metadata, with validation for DANDI archive compatibility.
8+
9+
## Development Setup Commands
10+
11+
**Environment Setup:**
12+
13+
```bash
14+
mamba env create -f environment.yml
15+
mamba activate trodes_to_nwb
16+
pip install -e .
17+
```
18+
19+
**Testing:**
20+
21+
```bash
22+
pytest --cov=src --cov-report=xml --doctest-modules -v --pyargs trodes_to_nwb
23+
```
24+
25+
**Linting:**
26+
27+
```bash
28+
black .
29+
```
30+
31+
**Build Package:**
32+
33+
```bash
34+
python -m build
35+
twine check dist/*
36+
```
37+
38+
## Architecture
39+
40+
### Core Conversion Pipeline
41+
42+
The main conversion happens in `src/trodes_to_nwb/convert.py` with the `create_nwbs()` function which orchestrates:
43+
44+
1. **File Discovery** (`data_scanner.py`): Scans directories for .rec files and associated data files
45+
2. **Metadata Loading** (`convert_yaml.py`): Loads and validates YAML metadata files
46+
3. **Header Processing** (`convert_rec_header.py`): Extracts device configuration from .rec file headers
47+
4. **Data Conversion**: Modular converters for different data types:
48+
- `convert_ephys.py`: Raw electrophysiology data
49+
- `convert_position.py`: Position tracking and video
50+
- `convert_dios.py`: Digital I/O events
51+
- `convert_analog.py`: Analog signals
52+
- `convert_intervals.py`: Epoch and behavioral intervals
53+
- `convert_optogenetics.py`: Optogenetic stimulation data
54+
55+
### File Structure Requirements
56+
57+
Input files must follow naming convention: `{YYYYMMDD}_{animal}_{epoch}_{tag}.{extension}`
58+
59+
Required files per session:
60+
61+
- `.rec`: Main recording file
62+
- `{date}_{animal}.metadata.yml`: Session metadata
63+
- Optional: `.h264`, `.videoPositionTracking`, `.cameraHWSync`, `.stateScriptLog`
64+
65+
### Metadata System
66+
67+
- Uses YAML metadata files validated against JSON schema (`nwb_schema.json`)
68+
- Probe configurations stored in `device_metadata/probe_metadata/`
69+
- Virus metadata in `device_metadata/virus_metadata/`
70+
- See `docs/yaml_mapping.md` for complete metadata field mapping
71+
72+
### Key Data Processing
73+
74+
- Uses Neo library (`spike_gadgets_raw_io.py`) for .rec file I/O
75+
- Implements chunked data loading (`RecFileDataChunkIterator`) for memory efficiency
76+
- Parallel processing support via Dask for batch conversions
77+
- NWB validation using nwbinspector after conversion
78+
79+
## Testing
80+
81+
- Unit tests in `src/trodes_to_nwb/tests/`
82+
- Integration tests in `tests/integration-tests/`
83+
- Test data downloaded from secure UCSF Box in CI
84+
- Coverage reports uploaded to Codecov
85+
86+
## Release Process
87+
88+
1. Tag release commit (e.g. `v0.1.0`)
89+
2. Push tag to GitHub (triggers PyPI upload)
90+
3. Create GitHub release
91+
92+
## Important Notes
93+
94+
- Package supports Python >=3.8
95+
- Requires `ffmpeg` for video conversion
96+
- Uses hatch for build system with VCS-based versioning
97+
- Main branch protected, requires PR reviews

notebooks/explore_rec_file_neo.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
"# The raw data block consists of N packets.\n",
119119
"# Each packet consists of:\n",
120120
"# First byte is 0x55\n",
121-
"# Some number of bytes for each device (e.g., Controller_DIO has 1 byte, \n",
121+
"# Some number of bytes for each device (e.g., Controller_DIO has 1 byte,\n",
122122
"# ECU has 32 bytes, Multiplexed has 8 bytes, SysClock has 8 bytes)\n",
123123
"# Timestamp (uint32) which has 4 bytes\n",
124124
"# Ephys data (int16) which has 2 * num_ephy_channels bytes\n",
@@ -182,6 +182,7 @@
182182
"source": [
183183
"# read the binary part lazily\n",
184184
"import numpy as np\n",
185+
"\n",
185186
"raw_memmap = np.memmap(rec_file_path, mode='r', offset=header_size, dtype='<u1')\n",
186187
"\n",
187188
"num_packet = raw_memmap.size // packet_size\n",
@@ -325,10 +326,10 @@
325326
"for device in hconf:\n",
326327
" stream_id = device.attrib['name']\n",
327328
" print(stream_id)\n",
328-
" \n",
329+
"\n",
329330
" for channel in device:\n",
330331
" print(channel.attrib)\n",
331-
" \n",
332+
"\n",
332333
" if 'interleavedDataIDByte' in channel.attrib:\n",
333334
" # TODO LATER: deal with \"headstageSensor\" which have interleaved\n",
334335
" continue\n",

0 commit comments

Comments
 (0)