Skip to content

Commit 3aeef97

Browse files
authored
Sphinx documentation (#27)
* Fix of the dartsort parameter such that it uses scratch_dir * Added spikeinterface backend * Added Google style documentation for all the functions * Ruff fixes * Changes to documentation and README.md
1 parent c0cd4c2 commit 3aeef97

26 files changed

+3179
-1214
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,9 @@ testing.ipynb
181181
*.parquet
182182
scratch/
183183
.DS_Store
184-
random_testing_scripts.py
184+
random_testing_scripts.py
185+
84c48d67-3d58-4cb6-8e57-fd206e6508d6/
186+
187+
188+
#Sphinx doucmentation
189+
docs/build/

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The main branch is the trunk and features branches are squashed merge after a su
66

77
Contributer steps:
88
- [X] make sure the tests pass locally
9+
- [X] follow Google docstring format for all function and class documentation
910
- [X] use `ruff format` and `ruff check` to make sure the formatting is correct
1011
- [X] `CHANGELOG.md` documents the changes, references the PR, the date and the new version number in `./src/ephysatlas/__init__.py`
1112
- [X] create a PR from your feature branch to main

README.md

Lines changed: 8 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -5,182 +5,20 @@
55

66
This repository contains tools for computing electrophysiology features and performing region inference from neural recordings.
77

8-
## Installation
8+
## Documentation
99

10-
> **Note**: It is recommended to create and use a separate virtual environment before installation.
10+
For detailed documentation, installation instructions, usage examples, and API reference, please visit our comprehensive documentation:
11+
12+
**[📚 View Full Documentation](docs/source/index.rst)**
13+
14+
## Quick Installation
1115

12-
1. Clone the repository and navigate to the directory:
1316
```bash
1417
git clone https://github.com/int-brain-lab/ibleatools.git
1518
cd ibleatools
16-
```
17-
18-
2. Install the package in editable mode:
19-
```bash
2019
pip install -e .
2120
```
2221

23-
## Main Functions
24-
25-
The package provides functions for electrophysiology analysis:
26-
27-
### 1. Feature Computation from Probe ID (`compute_features_from_pid`)
28-
29-
This function computes various electrophysiological features from raw neural recordings using data from the IBL database with a probe ID (pid).
30-
31-
Basic usage:
32-
```python
33-
from one.api import ONE
34-
from ephysatlas.feature_computation import compute_features_from_pid
35-
36-
# Using IBL database
37-
one = ONE() # Initialize ONE client
38-
df_features = compute_features_from_pid(
39-
pid="your_probe_id",
40-
t_start=300.0, # Start time in seconds
41-
duration=3.0, # Duration in seconds
42-
one=one
43-
)
44-
```
45-
46-
The function returns a pandas DataFrame containing various electrophysiological features, which are also saved in Parquet format for efficient storage and retrieval.
47-
48-
### 2. Feature Computation from Files (`compute_features_from_file`)
49-
50-
This function computes various electrophysiological features from local .cbin files (AP and LF band data).
51-
52-
Basic usage:
53-
```python
54-
from ephysatlas.feature_computation import compute_features_from_file
55-
56-
# Using local files
57-
df_features = compute_features_from_file(
58-
ap_file="path/to/ap.cbin",
59-
lf_file="path/to/lf.cbin",
60-
t_start=300.0,
61-
duration=3.0
62-
)
63-
```
64-
65-
### 3. Legacy Function (`compute_features`) - DEPRECATED
66-
67-
> **Note**: The `compute_features` function is deprecated and will be removed in a future version. Please use `compute_features_from_pid` or `compute_features_from_file` instead.
68-
69-
This function was the original interface for computing electrophysiological features. It can work with either:
70-
- Data from the IBL database using a probe ID (pid)
71-
- Local .cbin files (AP and LF band data)
72-
73-
Basic usage:
74-
```python
75-
from one.api import ONE
76-
from ephysatlas.feature_computation import compute_features
77-
78-
# Using IBL database
79-
one = ONE() # Initialize ONE client
80-
df_features = compute_features(
81-
pid="your_probe_id",
82-
t_start=300.0, # Start time in seconds
83-
duration=3.0, # Duration in seconds
84-
one=one
85-
)
86-
87-
# Using local files
88-
df_features = compute_features(
89-
ap_file="path/to/ap.cbin",
90-
lf_file="path/to/lf.cbin",
91-
t_start=300.0,
92-
duration=3.0
93-
)
94-
```
95-
96-
The function returns a pandas DataFrame containing various electrophysiological features, which are also saved in Parquet format for efficient storage and retrieval.
97-
98-
> **Note**: Due to a known issue in PyTorch ([#132372](https://github.com/pytorch/pytorch/issues/132372)), you might encounter a SEGFAULT when running the feature computation. To resolve this, you can either:
99-
> 1. Import torch at the start of your script:
100-
> ```python
101-
> import torch # Add this at the beginning of your script
102-
> ```
103-
> 2. Set the `DYLD_LIBRARY_PATH` environment variable to point to your virtual environment's torch library:
104-
> ```bash
105-
> export DYLD_LIBRARY_PATH=/path/to/your/venv/lib/python3.x/site-packages/torch/lib
106-
> ```
107-
108-
> **Important**: This package (`ephysatlas`) is different from the `ephys_atlas` package (with underscore) from the [paper-ephys-atlas](https://github.com/int-brain-lab/paper-ephys-atlas) repository.
109-
110-
### 4. Region Inference (`infer_regions`)
111-
112-
This function uses pre-trained models to infer brain regions from the computed features. It performs inference across multiple model folds and returns both the predicted regions and their probabilities.
113-
114-
Basic usage:
115-
116-
```python
117-
from ephysatlas.regionclassifier.region_inference import infer_regions
118-
119-
# Perform region inference
120-
predicted_probas, predicted_region = infer_regions(
121-
df_inference=df_features, # DataFrame from compute_features
122-
path_model="path/to/model" # Path to the model directory
123-
)
124-
```
125-
126-
The function returns:
127-
- `predicted_probas`: Array of shape (n_folds, n_channels, n_regions) containing region probabilities
128-
- `predicted_region`: Array of shape (n_folds, n_channels) containing predicted region indices
129-
130-
## Usage through CLI
131-
132-
The CLI interface is through `main.py`, which can be run using a configuration file:
133-
134-
```bash
135-
python main.py --config config.yaml
136-
```
137-
138-
Using CLI one can do both feature computations and region inference by specifying it in the configuration.
139-
140-
> **Note**: The CLI currently uses the deprecated `compute_features` function internally. This will be updated in a future version to use the new `compute_features_from_pid` and `compute_features_from_file` functions.
141-
142-
### Configuration File
143-
144-
The configuration is managed through a YAML file. To avoid committing local changes, the actual configuration file (`config.yaml`) is ignored by git. Instead, a template file (`config_template.yaml`) is provided. To use the tool:
145-
146-
1. Copy the template file to create your local configuration:
147-
```bash
148-
cp config_template.yaml config.yaml
149-
```
150-
151-
2. Edit `config.yaml` with your specific settings:
152-
```yaml
153-
# Required parameters
154-
pid: "5246af08-0730-40f7-83de-29b5d62b9b6d" # Probe ID
155-
t_start: 300.0 # Start time in seconds
156-
duration: 3.0 # Duration in seconds
157-
158-
# Operation mode
159-
mode: "both" # Options: 'features', 'inference', or 'both'
160-
161-
# Optional parameters
162-
output_dir: "/path/to/output_dir" # Path to output directory
163-
model_path: "/path/to/model" # Path to the model directory for region inference
164-
```
165-
166-
#### Configuration Parameters
167-
168-
- **Required Parameters**:
169-
- `pid`: Probe ID for the recording
170-
- `t_start`: Start time in seconds
171-
- `duration`: Duration of the analysis in seconds
172-
173-
- **Operation Mode**:
174-
- `mode`: Specifies which operations to perform
175-
- `features`: Only compute features
176-
- `inference`: Only perform region inference
177-
- `both`: Perform both feature computation and region inference
178-
179-
- **Optional Parameters**:
180-
- `output_dir`: Path to output directory for saving results
181-
- `model_path`: Path to the model directory for region inference. If not provided, a default path will be used
182-
183-
## Output
22+
## Contributing
18423

185-
- Features are saved in Parquet format for efficient storage
186-
- Region inference results include predicted regions and their probabilities
24+
Please see our [Contributing Guide](CONTRIBUTING.md) for details on how to contribute to this project.

docs/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line, and also
5+
# from the environment for the first two.
6+
SPHINXOPTS ?=
7+
SPHINXBUILD ?= sphinx-build
8+
SOURCEDIR = source
9+
BUILDDIR = build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

docs/README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Building ibleatools Documentation
2+
3+
This directory contains the Sphinx documentation for ibleatools. This README explains how to build and serve the documentation locally for development purposes.
4+
5+
## Prerequisites
6+
7+
Before building the documentation, ensure you have the following installed:
8+
9+
1. **Python 3.10+** - The project requires Python 3.10 or higher
10+
2. **ibleatools package** - Install the package in development mode:
11+
```bash
12+
pip install -e .
13+
```
14+
3. **Sphinx and documentation dependencies** - Install the required packages:
15+
```bash
16+
pip install sphinx sphinx-rtd-theme sphinx-autodoc-typehints
17+
```
18+
19+
## Building the Documentation
20+
21+
### Quick Start
22+
23+
To build the documentation, navigate to the `docs/` directory and run:
24+
25+
```bash
26+
cd docs/
27+
make html
28+
```
29+
30+
This will generate the HTML documentation in the `build/html/` directory.
31+
32+
### Available Build Commands
33+
34+
The documentation supports several build targets:
35+
36+
- **`make html`** - Build HTML documentation (default)
37+
- **`make clean`** - Clean the build directory
38+
- **`make help`** - Show all available build options
39+
- **`make livehtml`** - Build HTML with live reload (requires `sphinx-autobuild`)
40+
41+
### Windows Users
42+
43+
If you're on Windows, use the provided batch file instead:
44+
45+
```cmd
46+
cd docs/
47+
make.bat html
48+
```
49+
50+
## Viewing the Documentation
51+
52+
After building, you can view the documentation by:
53+
54+
1. **Opening the HTML files directly:**
55+
- Navigate to `docs/build/html/`
56+
- Open `index.html` in your web browser
57+
58+
2. **Using a local web server:**
59+
```bash
60+
cd docs/build/html/
61+
python -m http.server 8000
62+
```
63+
Then open http://localhost:8000 in your browser
64+
65+
## Development Workflow
66+
67+
### Making Changes
68+
69+
1. Edit the source files in `docs/source/`
70+
2. Rebuild the documentation: `make html`
71+
3. Refresh your browser to see changes
72+
73+
### Live Reload (Optional)
74+
75+
For automatic rebuilding when files change, install `sphinx-autobuild` and use:
76+
77+
```bash
78+
pip install sphinx-autobuild
79+
make livehtml
80+
```
81+
82+
This will start a local server that automatically rebuilds and refreshes the documentation when you make changes.
83+
84+
## Documentation Structure
85+
86+
The documentation is organized as follows:
87+
88+
```
89+
docs/
90+
├── source/ # Sphinx source files
91+
│ ├── index.rst # Main documentation page
92+
│ ├── ephysatlas.rst # Package overview
93+
│ ├── features.rst # Feature computation module
94+
│ ├── plots.rst # Visualization module
95+
│ ├── reveal.rst # High-level interface
96+
│ ├── utils.rst # Utility functions
97+
│ ├── how-to/ # Tutorials and guides
98+
│ └── reference/ # API reference
99+
├── build/ # Generated documentation (git-ignored)
100+
├── Makefile # Build commands
101+
└── make.bat # Windows build commands
102+
```
103+
104+
## Troubleshooting
105+
106+
### Common Issues
107+
108+
1. **Import errors**: Ensure ibleatools is installed in development mode (`pip install -e .`)
109+
2. **Missing dependencies**: Install all required packages listed in the Prerequisites section
110+
3. **Build errors**: Check that all source files are valid RST format
111+
4. **Permission errors**: Ensure you have write permissions to the `build/` directory
112+
113+
### Cleaning Build Artifacts
114+
115+
If you encounter build issues, clean the build directory:
116+
117+
```bash
118+
make clean
119+
make html
120+
```
121+
122+
## Contributing to Documentation
123+
124+
When contributing to the documentation:
125+
126+
1. Follow the existing RST format and structure
127+
2. Use Google-style docstrings in Python code (as specified in CONTRIBUTING.md)
128+
3. Test your changes by building the documentation locally
129+
4. Ensure all links and references work correctly
130+
131+
## Online Documentation
132+
133+
The latest documentation is available online at:(This is TODO) [https://int-brain-lab.github.io/ibleatools](https://int-brain-lab.github.io/ibleatools)
134+
135+
For questions or issues with the documentation, please open an issue on the [ibleatools GitHub repository](https://github.com/int-brain-lab/ibleatools).

0 commit comments

Comments
 (0)