Skip to content

Commit 1726281

Browse files
committed
Update Sphinx documentation
0 parents  commit 1726281

File tree

108 files changed

+10389
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+10389
-0
lines changed

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
# Maintain dependencies for GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
schedule:
7+
interval: "monthly"
8+
9+
# Maintain dependencies for Composer
10+
- package-ecosystem: "pip"
11+
directory: "/"
12+
schedule:
13+
interval: "monthly"

.github/workflows/build_docs.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Build Sphinx Documentation
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- 2-add-continuous-integration
10+
- main
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest # You can also use `windows-latest` or `macos-latest` if needed
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v5
19+
20+
- name: Set up Python
21+
uses: actions/setup-python@v6
22+
with:
23+
python-version: '3.10' # Set your preferred Python version
24+
25+
- name: Add contourusv to PYTHONPATH
26+
run: echo "PYTHONPATH=$PYTHONPATH:$(pwd)/contourusv" >> $GITHUB_ENV
27+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install sphinx sphinx_rtd_theme opencv-python numpy pandas tqdm scipy matplotlib codecarbon scikit-learn
32+
33+
34+
- name: Build the documentation
35+
run: |
36+
37+
# Create a new branch for the documentation
38+
git checkout --orphan gh-pages
39+
# Generate reStructuredText files from the source code
40+
sphinx-apidoc -o sphinx/ contourusv/ -f
41+
42+
rm -rf docs/
43+
44+
# Ensure the docs directory exists
45+
mkdir -p docs
46+
47+
# Build the HTML documentation
48+
sphinx-build -b html sphinx/ docs/
49+
pwd
50+
ls
51+
52+
# Add a .nojekyll file to bypass Jekyll processing on GitHub Pages
53+
touch ./docs/.nojekyll
54+
55+
- name: Commit and push generated docs
56+
run: |
57+
ls
58+
git config --global user.email "[email protected]"
59+
git config --global user.name "Dallas Wade"
60+
git config --global pull.rebase false # Or true, or --ff-only based on your preference
61+
62+
# Ensure docs/ is staged properly
63+
git add docs/
64+
git status # Debugging: See if anything is staged
65+
git commit -m "Update Sphinx documentation" || echo "No changes to commit."
66+
67+
# Push the changes
68+
git push origin gh-pages --force
69+

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
contourusv/__pycache__
2+
venv
3+
contourusv/output/
4+
contourusv/Experiments/
5+
contourusv/test.ipynb

README.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# ContourUSV: Ultrasonic Vocalization Detection Pipeline
2+
3+
![Python Version](https://img.shields.io/badge/python-%3E%3D3.9-blue.svg)
4+
![License](https://img.shields.io/badge/license-MIT-green.svg)
5+
6+
ContourUSV is an automated pipeline for detecting ultrasonic vocalizations (USVs) in audio recordings. The system uses spectrogram analysis combined with advanced image processing techniques to identify and classify 22kHz and 50kHz USVs.
7+
8+
<!-- ## Features
9+
10+
- Audio preprocessing with bandpass filtering and normalization
11+
- Spectrogram generation with customizable parameters
12+
- Advanced image processing for noise reduction:
13+
- Median filtering
14+
- Otsu's thresholding
15+
- Contrast Limited Adaptive Histogram Equalization (CLAHE)
16+
- Morphological operations
17+
- Contour-based USV detection
18+
- Annotation generation from multiple file formats (HTML, Excel, CSV)
19+
- Comprehensive evaluation metrics:
20+
- Precision, Recall, F1 Score, Specificity
21+
- Carbon emissions tracking via CodeCarbon
22+
- Parallel processing support -->
23+
24+
## Installation
25+
26+
1. **Clone the repository:**
27+
```bash
28+
git clone https://github.com/yourusername/contourusv.git
29+
cd contourusv
30+
```
31+
32+
2. **Create and activate virtual environment:**
33+
```bash
34+
python -m venv venv
35+
source venv/bin/activate # Linux/MacOS
36+
venv\Scripts\activate # Windows
37+
```
38+
39+
3. **Install dependencies:**
40+
```bash
41+
pip install -e .
42+
```
43+
44+
## Data Directory Structure
45+
46+
Organize your input data using the following structure:
47+
48+
```
49+
root_path/ # Passed via --root_path argument
50+
├── EXPERIMENT_NAME/ # Passed via --experiment argument
51+
│ └── TRIAL_NAME/ # Passed via --trial argument
52+
│ ├── *.wav # Audio recordings
53+
│ ├── *.WAV # (Alternative capitalization)
54+
│ ├── *.html # HTML annotations
55+
│ ├── *.xlsx # Excel annotations
56+
│ └── *.csv # CSV annotations
57+
```
58+
59+
**Example Concrete Structure:**
60+
```
61+
/Users/username/data/
62+
└── PTSD16/
63+
└── ACQ/
64+
├── rat12_day1.wav
65+
├── rat12_day1.html
66+
├── rat13_day1.WAV
67+
└── rat13_day1.html
68+
```
69+
70+
**File Requirements:**
71+
- Audio files: Must have `.wav` or `.WAV` extension
72+
- Annotation files: Must match audio filenames and reside in same directory
73+
- Supported annotation formats:
74+
- HTML
75+
- Excel
76+
- CSV
77+
78+
## Output Structure
79+
80+
```
81+
output/
82+
├── EXPERIMENT_NAME/
83+
│ ├── TRIAL_NAME/
84+
│ │ ├── contour_detections/
85+
│ │ │ └── *.csv (detection annotations)
86+
│ │ ├── evaluation_results/
87+
│ │ │ └── Evaluation_*.csv (performance metrics)
88+
│ │ └── spectrograms/
89+
│ │ └── *.png (annotated spectrograms)
90+
│ └── ground_truth_annotations/
91+
│ └── *.csv (processed ground truth)
92+
```
93+
94+
## Usage
95+
96+
In the `src` directory execute the following command to run the detection pipeline.
97+
98+
### Basic Command
99+
```bash
100+
python main.py \
101+
--root_path /path/to/your/data \
102+
--experiment EXPERIMENT_NAME \
103+
--trial TRIAL_NAME \
104+
--file_ext ANNOTATION_FILE_EXT
105+
```
106+
107+
### Example Command
108+
```bash
109+
python main.py \
110+
--root_path /Users/username/data \
111+
--experiment PTSD16 \
112+
--trial ACQ \
113+
--file_ext .html
114+
```
115+
116+
### Required Arguments
117+
| Argument | Description | Example |
118+
|---------------|-------------------------------------------|------------------|
119+
| `--root_path` | Root directory containing experiment data | `/data/studies` |
120+
| `--experiment`| Name of the experiment | `PTSD16` |
121+
| `--trial` | Name of the trial/condition | `ACQ` |
122+
| `--file_ext` | Annotation file extension (`.html`, `.xlsx`, `.csv`) | `.html` |
123+
124+
### Optional Parameters
125+
| Parameter | Default | Description |
126+
|----------------|---------|------------------------------------------|
127+
| `--overlap` | 3 | Overlap duration between windows (seconds) |
128+
| `--winlen` | 10 | Window length for processing (seconds) |
129+
| `--freq_min` | 15 | Minimum frequency for detection (kHz) |
130+
| `--freq_max` | 115 | Maximum frequency for detection (kHz) |
131+
| `--wsize` | 2500 | Window size for processing |
132+
| `--th_perc` | 95 | Percentile threshold for noise reduction |
133+
134+
<!-- ## Pipeline Architecture
135+
136+
1. **Preprocessing**
137+
- Audio normalization and filtering
138+
- Spectrogram generation
139+
- Noise reduction using:
140+
- Median filtering
141+
- Otsu's thresholding
142+
- CLAHE contrast enhancement
143+
144+
2. **Detection**
145+
- Contour detection using OpenCV
146+
- USV classification (22kHz vs 50kHz)
147+
- Bounding box annotation
148+
- Temporal and spectral feature extraction
149+
150+
3. **Annotation Generation**
151+
- Supports multiple input formats:
152+
- HTML
153+
- Excel
154+
- CSV
155+
156+
4. **Evaluation**
157+
- Precision/Recall calculations
158+
- F1 Score and Specificity metrics
159+
- Carbon emissions tracking
160+
- Energy consumption monitoring
161+
162+
## Evaluation Metrics
163+
164+
The pipeline calculates four key performance metrics:
165+
- **Precision**: Ratio of correct USV detections to total detections
166+
- **Recall**: Ratio of detected USVs to total actual USVs
167+
- **F1 Score**: Harmonic mean of precision and recall
168+
- **Specificity**: Ability to identify true negative segments
169+
170+
Example output:
171+
```
172+
Mean Precision: 0.92 ± 0.05
173+
Mean Recall: 0.88 ± 0.07
174+
Mean F1 Score: 0.90 ± 0.04
175+
Mean Specificity: 0.95 ± 0.03
176+
```
177+
178+
## Environmental Impact Tracking
179+
180+
The pipeline integrates with CodeCarbon to monitor:
181+
- CO₂ emissions (kg)
182+
- Energy consumption (kWh)
183+
- Computational efficiency
184+
185+
Sample output:
186+
```
187+
ContourUSV_Execution_Time_(s) = 452.783
188+
ContourUSV_Carbon_Emissions_(kgCO2) = 0.127
189+
ContourUSV_Total_Energy_Consumed_(kWh) = 0.342
190+
``` -->
191+
192+
## Contributing
193+
194+
Contributions are welcome! Please follow these steps:
195+
1. Fork the repository
196+
2. Create your feature branch (`git checkout -b feature/your-feature`)
197+
3. Commit your changes (`git commit -am 'Add some feature'`)
198+
4. Push to the branch (`git push origin feature/your-feature`)
199+
5. Open a Pull Request
200+
201+
## License
202+
203+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
204+
205+
## Contact
206+
207+
Sabah Anis - [[email protected]](mailto:[email protected])

contourusv/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)