Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
8080f2f
Adding Autodocing
dw42CSCE Feb 11, 2025
b975613
Fixing gitignore
dw42CSCE Feb 11, 2025
8c27b37
testing commit
dw42CSCE Feb 11, 2025
dccae35
test
dw42CSCE Feb 11, 2025
cf6001e
Making page deploy
dw42CSCE Feb 11, 2025
2f15fbb
testing build docs
dw42CSCE Feb 11, 2025
42503d0
testing build docs
dw42CSCE Feb 11, 2025
08d2d5f
Merge branch '2-add-continuous-integration'
dw42CSCE Feb 11, 2025
e7157eb
Trying to figure out the function doc
dw42CSCE Feb 11, 2025
2f3c943
Still testing autodocing
dw42CSCE Feb 12, 2025
da4f0ab
Fixed maybe?
dw42CSCE Feb 12, 2025
f4577e3
Fixing pages display
dw42CSCE Feb 12, 2025
460beef
fixing?
dw42CSCE Feb 12, 2025
2c599f2
Check
dw42CSCE Feb 12, 2025
be8ea4a
forgot jekyll
dw42CSCE Feb 12, 2025
a84860b
test
dw42CSCE Feb 12, 2025
d7edd1c
Testing autodoc
dw42CSCE Feb 12, 2025
1eeb7b0
last test
dw42CSCE Feb 12, 2025
976f10f
last test
dw42CSCE Feb 12, 2025
a566c60
?
dw42CSCE Feb 12, 2025
e80e16c
?
dw42CSCE Feb 12, 2025
ae260cc
Fixing Dependencies
dw42CSCE Feb 12, 2025
40eae07
fixing dependencies
dw42CSCE Feb 12, 2025
a7a6334
fixing dependencies
dw42CSCE Feb 12, 2025
2584642
testing
dw42CSCE Feb 12, 2025
a9f99b7
check
dw42CSCE Feb 12, 2025
3ecf2a1
Test
dw42CSCE Feb 12, 2025
87fc395
Test
dw42CSCE Feb 12, 2025
1c53d0f
Testing
dw42CSCE Feb 12, 2025
4c41158
test
dw42CSCE Feb 12, 2025
83be695
test
dw42CSCE Feb 12, 2025
987407a
Add generated Sphinx documentation
dw42CSCE Feb 12, 2025
a284a32
testing ading new functions
dw42CSCE Feb 12, 2025
8e635aa
fixing?
dw42CSCE Feb 12, 2025
1bff093
Fixed not updating
dw42CSCE Feb 12, 2025
61ab8d5
Add generated Sphinx documentation
dw42CSCE Feb 12, 2025
d1f6222
Fixed
dw42CSCE Feb 12, 2025
d1b210d
Merge branch 'main' of https://github.com/dw42CSCE/contourusv
dw42CSCE Feb 12, 2025
d4d57ee
Fixing main maybe?
dw42CSCE Feb 12, 2025
4c0877c
Add generated Sphinx documentation
dw42CSCE Feb 12, 2025
a5f5576
t
dw42CSCE Feb 12, 2025
730001e
Merge branch 'main' of https://github.com/dw42CSCE/contourusv
dw42CSCE Feb 12, 2025
a00d5ce
Fixing main
dw42CSCE Feb 12, 2025
8f7b510
Fixing main
dw42CSCE Feb 12, 2025
5244ed6
Done for the night
dw42CSCE Feb 12, 2025
486bb4a
Done for the night
dw42CSCE Feb 12, 2025
946e83f
Fixed Main I think
dw42CSCE Feb 12, 2025
9b2f8fd
Messing with preprocessing
dw42CSCE Feb 17, 2025
a6a5970
Adding Changes
dw42CSCE Feb 21, 2025
471f30e
Add generated Sphinx documentation
dw42CSCE Feb 12, 2025
1d537d8
Fixing main maybe?
dw42CSCE Feb 12, 2025
bd68bcc
t
dw42CSCE Feb 12, 2025
8820ac1
Add generated Sphinx documentation
dw42CSCE Feb 12, 2025
d410340
Fixing main
dw42CSCE Feb 12, 2025
9f880be
Fixing main
dw42CSCE Feb 12, 2025
4fd96d7
Done for the night
dw42CSCE Feb 12, 2025
835bc75
Done for the night
dw42CSCE Feb 12, 2025
db1d8cc
Fixed Main I think
dw42CSCE Feb 12, 2025
9121db1
Add generated Sphinx documentation
dw42CSCE Feb 12, 2025
7478f06
Changing to push to gh pages
dw42CSCE Feb 16, 2025
cb53903
Fixing branching error
dw42CSCE Feb 16, 2025
d476a10
Another attempted fix
dw42CSCE Feb 17, 2025
509d2a2
Changing git add
dw42CSCE Feb 17, 2025
32c7bcf
Fixing
dw42CSCE Feb 17, 2025
ec672b1
Fixing
dw42CSCE Feb 17, 2025
34155df
Still working
dw42CSCE Feb 17, 2025
c40fba7
Still working
dw42CSCE Feb 17, 2025
37a2beb
Still working
dw42CSCE Feb 17, 2025
ddf7551
Fixing
dw42CSCE Feb 17, 2025
94d1d86
Fixing
dw42CSCE Feb 17, 2025
2612ba9
Fixing
dw42CSCE Feb 17, 2025
50c162a
adding docs
dw42CSCE Feb 17, 2025
7a85535
Commiting docs to main, then removing
dw42CSCE Feb 17, 2025
3f8bad0
Commiting docs to main, then removing
dw42CSCE Feb 17, 2025
c3dec18
Fixed I think. Testing
dw42CSCE Feb 17, 2025
9d1d1ac
Adding docs
dw42CSCE Feb 17, 2025
31ceee7
Remove docs folder from main branch
dw42CSCE Feb 17, 2025
ecb7e7f
test
dw42CSCE Feb 27, 2025
6f3e76c
Implementing Adaptive Thresh pt1
dw42CSCE Feb 27, 2025
076506d
Implementing Adaptive Thresh pt2
dw42CSCE Feb 27, 2025
7367b0b
Adding adaptive threshholding pt3
dw42CSCE Mar 1, 2025
1a9bdc1
Almost done
dw42CSCE Mar 2, 2025
71ab93c
Fixing
dw42CSCE Mar 2, 2025
06478c2
Adding Auto eval pt1
dw42CSCE Mar 3, 2025
0ff3b6c
Adding NMF
dw42CSCE Mar 10, 2025
c6fc1df
added fragmented NMF
dw42CSCE Mar 15, 2025
c8d5399
Adding improvements
dw42CSCE Mar 31, 2025
3a20227
Merge branch 'TryNR'
dw42CSCE Apr 1, 2025
bad36b7
Fixing Autodoccing
dw42CSCE Apr 1, 2025
d7a4c65
Fixing Autodoccing
dw42CSCE Apr 1, 2025
a57eb47
Fixing Autodoccing
dw42CSCE Apr 1, 2025
5c3c78b
Fixing autodoccing
dw42CSCE Apr 1, 2025
13b1568
Updated modules.rst
dw42CSCE Apr 1, 2025
10e07bc
Remove docs folder from main branch
dw42CSCE Apr 1, 2025
4da5e8b
Final Commit for Poster
dw42CSCE Apr 5, 2025
1ce4368
Fixing autodoccing
dw42CSCE Apr 5, 2025
3e2661f
Fixing autodoccing
dw42CSCE Apr 5, 2025
5d4fb46
Updated docs
dw42CSCE Apr 5, 2025
59812ce
Remove docs folder from main branch
dw42CSCE Apr 5, 2025
c05bc7b
argh
dw42CSCE Apr 5, 2025
376f573
Merge branch 'main' of https://github.com/dw42CSCE/contourusv
dw42CSCE Apr 5, 2025
103fb7f
Argh
dw42CSCE Apr 5, 2025
7d03f1d
Argh 2
dw42CSCE Apr 5, 2025
881af6f
Argh 2
dw42CSCE Apr 5, 2025
f728145
Argh 2
dw42CSCE Apr 5, 2025
fa7a0a6
Updated docs
dw42CSCE Apr 5, 2025
30189e5
Remove docs folder from main branch
dw42CSCE Apr 5, 2025
7162dde
Argh 2
dw42CSCE Apr 5, 2025
797973d
Merge branch 'main' of https://github.com/dw42CSCE/contourusv
dw42CSCE Apr 5, 2025
ae5f192
Updated docs
dw42CSCE Apr 5, 2025
0c158a1
Remove docs folder from main branch
dw42CSCE Apr 5, 2025
3e07f27
lol
dw42CSCE Apr 5, 2025
d4e4daa
Merge branch 'main' of https://github.com/dw42CSCE/contourusv
dw42CSCE Apr 5, 2025
30daebe
argh
dw42CSCE Apr 5, 2025
169e4c4
Updated docs
dw42CSCE Apr 5, 2025
8d607ef
Remove docs folder from main branch
dw42CSCE Apr 5, 2025
e0a572d
Argh
dw42CSCE Apr 5, 2025
92ff512
Merge branch 'main' of https://github.com/dw42CSCE/contourusv
dw42CSCE Apr 5, 2025
8327c07
Updated docs
dw42CSCE Apr 5, 2025
a170b28
Remove docs folder from main branch
dw42CSCE Apr 5, 2025
606163d
Commit
dw42CSCE Apr 5, 2025
77a7ee5
Merge branch 'main' of https://github.com/dw42CSCE/contourusv
dw42CSCE Apr 5, 2025
cfb4176
maybe
dw42CSCE Apr 5, 2025
fe80b49
test commit
dw42CSCE Apr 5, 2025
c7c7494
Adding check for no NMF w/ Otsu
dw42CSCE Apr 6, 2025
a7334fc
Adding params for processing
dw42CSCE Apr 7, 2025
48f9662
Adding fixes
dw42CSCE Jul 17, 2025
9c8c40c
Adding Changes
dw42CSCE Jul 21, 2025
19747cb
Adding final changes
dw42CSCE Jul 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "monthly"

# Maintain dependencies for Composer
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "monthly"
69 changes: 69 additions & 0 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build Sphinx Documentation

on:
push:
branches:
- main
pull_request:
branches:
- 2-add-continuous-integration
- main

jobs:
build:
runs-on: ubuntu-latest # You can also use `windows-latest` or `macos-latest` if needed

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10' # Set your preferred Python version

- name: Add contourusv to PYTHONPATH
run: echo "PYTHONPATH=$PYTHONPATH:$(pwd)/contourusv" >> $GITHUB_ENV

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install sphinx sphinx_rtd_theme opencv-python numpy pandas tqdm scipy matplotlib codecarbon scikit-learn


- name: Build the documentation
run: |

# Create a new branch for the documentation
git checkout --orphan gh-pages
# Generate reStructuredText files from the source code
sphinx-apidoc -o sphinx/ contourusv/ -f

rm -rf docs/

# Ensure the docs directory exists
mkdir -p docs

# Build the HTML documentation
sphinx-build -b html sphinx/ docs/
pwd
ls

# Add a .nojekyll file to bypass Jekyll processing on GitHub Pages
touch ./docs/.nojekyll

- name: Commit and push generated docs
run: |
ls
git config --global user.email "[email protected]"
git config --global user.name "Dallas Wade"
git config --global pull.rebase false # Or true, or --ff-only based on your preference

# Ensure docs/ is staged properly
git add docs/
git status # Debugging: See if anything is staged
git commit -m "Update Sphinx documentation" || echo "No changes to commit."

# Push the changes
git push origin gh-pages --force

6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
src/__pycache__
contourusv/__pycache__
venv
contourusv/output/
contourusv/Experiments/
contourusv/test.ipynb
Empty file added contourusv/__init__.py
Empty file.
226 changes: 226 additions & 0 deletions contourusv/contourusv.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
Metadata-Version: 2.2
Name: contourusv
Version: 0.1.0
Summary: USV Detection Pipeline
Author-email: Sabah Anis <[email protected]>
License: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy
Requires-Dist: mne
Requires-Dist: matplotlib
Requires-Dist: scipy
Requires-Dist: pandas
Requires-Dist: opencv-python
Requires-Dist: tqdm
Requires-Dist: codecarbon
Requires-Dist: seaborn
Requires-Dist: pillow

# ContourUSV: Ultrasonic Vocalization Detection Pipeline

![Python Version](https://img.shields.io/badge/python-%3E%3D3.9-blue.svg)
![License](https://img.shields.io/badge/license-MIT-green.svg)

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.

<!-- ## Features

- Audio preprocessing with bandpass filtering and normalization
- Spectrogram generation with customizable parameters
- Advanced image processing for noise reduction:
- Median filtering
- Otsu's thresholding
- Contrast Limited Adaptive Histogram Equalization (CLAHE)
- Morphological operations
- Contour-based USV detection
- Annotation generation from multiple file formats (HTML, Excel, CSV)
- Comprehensive evaluation metrics:
- Precision, Recall, F1 Score, Specificity
- Carbon emissions tracking via CodeCarbon
- Parallel processing support -->

## Installation

1. **Clone the repository:**
```bash
git clone https://github.com/yourusername/contourusv.git
cd contourusv
```

2. **Create and activate virtual environment:**
```bash
python -m venv venv
source venv/bin/activate # Linux/MacOS
venv\Scripts\activate # Windows
```

3. **Install dependencies:**
```bash
pip install -e .
```

## Data Directory Structure

Organize your input data using the following structure:

```
root_path/ # Passed via --root_path argument
├── EXPERIMENT_NAME/ # Passed via --experiment argument
│ └── TRIAL_NAME/ # Passed via --trial argument
│ ├── *.wav # Audio recordings
│ ├── *.WAV # (Alternative capitalization)
│ ├── *.html # HTML annotations
│ ├── *.xlsx # Excel annotations
│ └── *.csv # CSV annotations
```

**Example Concrete Structure:**
```
/Users/username/data/
└── PTSD16/
└── ACQ/
├── rat12_day1.wav
├── rat12_day1.html
├── rat13_day1.WAV
└── rat13_day1.html
```

**File Requirements:**
- Audio files: Must have `.wav` or `.WAV` extension
- Annotation files: Must match audio filenames and reside in same directory
- Supported annotation formats:
- HTML
- Excel
- CSV

## Output Structure

```
output/
├── EXPERIMENT_NAME/
│ ├── TRIAL_NAME/
│ │ ├── contour_detections/
│ │ │ └── *.csv (detection annotations)
│ │ ├── evaluation_results/
│ │ │ └── Evaluation_*.csv (performance metrics)
│ │ └── spectrograms/
│ │ └── *.png (annotated spectrograms)
│ └── ground_truth_annotations/
│ └── *.csv (processed ground truth)
```

## Usage

In the `src` directory execute the following command to run the detection pipeline.

### Basic Command
```bash
python main.py \
--root_path /path/to/your/data \
--experiment EXPERIMENT_NAME \
--trial TRIAL_NAME \
--file_ext ANNOTATION_FILE_EXT
```

### Example Command
```bash
python main.py \
--root_path /Users/username/data \
--experiment PTSD16 \
--trial ACQ \
--file_ext .html
```

### Required Arguments
| Argument | Description | Example |
|---------------|-------------------------------------------|------------------|
| `--root_path` | Root directory containing experiment data | `/data/studies` |
| `--experiment`| Name of the experiment | `PTSD16` |
| `--trial` | Name of the trial/condition | `ACQ` |
| `--file_ext` | Annotation file extension (`.html`, `.xlsx`, `.csv`) | `.html` |

### Optional Parameters
| Parameter | Default | Description |
|----------------|---------|------------------------------------------|
| `--overlap` | 3 | Overlap duration between windows (seconds) |
| `--winlen` | 10 | Window length for processing (seconds) |
| `--freq_min` | 15 | Minimum frequency for detection (kHz) |
| `--freq_max` | 115 | Maximum frequency for detection (kHz) |
| `--wsize` | 2500 | Window size for processing |
| `--th_perc` | 95 | Percentile threshold for noise reduction |

<!-- ## Pipeline Architecture

1. **Preprocessing**
- Audio normalization and filtering
- Spectrogram generation
- Noise reduction using:
- Median filtering
- Otsu's thresholding
- CLAHE contrast enhancement

2. **Detection**
- Contour detection using OpenCV
- USV classification (22kHz vs 50kHz)
- Bounding box annotation
- Temporal and spectral feature extraction

3. **Annotation Generation**
- Supports multiple input formats:
- HTML
- Excel
- CSV

4. **Evaluation**
- Precision/Recall calculations
- F1 Score and Specificity metrics
- Carbon emissions tracking
- Energy consumption monitoring

## Evaluation Metrics

The pipeline calculates four key performance metrics:
- **Precision**: Ratio of correct USV detections to total detections
- **Recall**: Ratio of detected USVs to total actual USVs
- **F1 Score**: Harmonic mean of precision and recall
- **Specificity**: Ability to identify true negative segments

Example output:
```
Mean Precision: 0.92 ± 0.05
Mean Recall: 0.88 ± 0.07
Mean F1 Score: 0.90 ± 0.04
Mean Specificity: 0.95 ± 0.03
```

## Environmental Impact Tracking

The pipeline integrates with CodeCarbon to monitor:
- CO₂ emissions (kg)
- Energy consumption (kWh)
- Computational efficiency

Sample output:
```
ContourUSV_Execution_Time_(s) = 452.783
ContourUSV_Carbon_Emissions_(kgCO2) = 0.127
ContourUSV_Total_Energy_Consumed_(kWh) = 0.342
``` -->

## Contributing

Contributions are welcome! Please follow these steps:
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/your-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin feature/your-feature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Contact

Sabah Anis - [[email protected]](mailto:[email protected])
13 changes: 13 additions & 0 deletions contourusv/contourusv.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
README.md
pyproject.toml
src/__init__.py
src/detection.py
src/evaluation.py
src/generate_annotation.py
src/main.py
src/preprocessing.py
src/contourusv.egg-info/PKG-INFO
src/contourusv.egg-info/SOURCES.txt
src/contourusv.egg-info/dependency_links.txt
src/contourusv.egg-info/requires.txt
src/contourusv.egg-info/top_level.txt
1 change: 1 addition & 0 deletions contourusv/contourusv.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

10 changes: 10 additions & 0 deletions contourusv/contourusv.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
numpy
mne
matplotlib
scipy
pandas
opencv-python
tqdm
codecarbon
seaborn
pillow
6 changes: 6 additions & 0 deletions contourusv/contourusv.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__init__
detection
evaluation
generate_annotation
main
preprocessing
14 changes: 9 additions & 5 deletions src/detection.py → contourusv/detection.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cv2

def detect_contours(cleaned_image, start_time, end_time, freq_min, freq_max,
file_name, annotations, call_type_defs=None):
file_name, annotations, call_type_defs=None, processing="adaptive"):
"""
Detect and classify USVs in cleaned spectrogram images.
Expand Down Expand Up @@ -34,18 +34,22 @@ def detect_contours(cleaned_image, start_time, end_time, freq_min, freq_max,
"22kHz": {"freq_min": 15,
"freq_max": 45,
"freq_span_max": 10,
"duration_min": 0.03,
"duration_min": 0.03, # .03 was original
"duration_max": 3.0},
"50kHz": {"freq_min": 40,
"freq_max": 80,
"freq_span_max": 10,
"duration_min": 0.01,
"duration_max": 0.3},

}

# Re-apply Otsu's Thresholding
ret, thresholded_image = cv2.threshold(
cleaned_image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
# Re-apply Otsu's Thresholding (Cant do if using adaptive)
if(processing == "Otsu"):
ret, thresholded_image = cv2.threshold(
cleaned_image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
else:
thresholded_image = cleaned_image

contours, _ = cv2.findContours(
thresholded_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
Expand Down
Loading
Loading