Skip to content

Commit f2b00e2

Browse files
committed
add python
1 parent 6b4f6dd commit f2b00e2

16 files changed

Lines changed: 789 additions & 0 deletions

.github/workflows/python.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Python CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v3
10+
- name: Set up Python 3.10
11+
uses: actions/setup-python@v4
12+
with:
13+
python-version: "3.10"
14+
15+
- name: Install dependencies
16+
run: |
17+
python -m pip install --upgrade pip
18+
pip install -r requirements.txt
19+
# Install local package
20+
pip install -e .
21+
22+
- name: Run tests
23+
run: |
24+
pytest python/tests

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
*.mex
2+
*egg-info*
3+
*.pyc
4+
dist/*
5+
python/dist/*

MANIFEST.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include requirements.txt
2+
include README.md
3+
include license.txt
4+
global-include *.txt

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![View COSBOS: COlor-Sensor-Based Occupancy Sensing on File Exchange](https://www.mathworks.com/matlabcentral/images/matlab-file-exchange.svg)](https://www.mathworks.com/matlabcentral/fileexchange/48428-cosbos-color-sensor-based-occupancy-sensing)
44
[![Octave application](https://github.com/wq2012/COSBOS/actions/workflows/octave.yml/badge.svg)](https://github.com/wq2012/COSBOS/actions/workflows/octave.yml)
5+
[![Python CI](https://github.com/wq2012/COSBOS/actions/workflows/python.yml/badge.svg)](https://github.com/wq2012/COSBOS/actions/workflows/python.yml)
56

67
![logo](resources/logo.png)
78

@@ -89,6 +90,51 @@ run_tests;
8990
```
9091
This verifies LTM recovery accuracy, MEX script correctness, and model performance.
9192

93+
## Python Package
94+
95+
COSBOS is also available as a Python package `cosbos`. It provides pure Python implementations of the core algorithms (Reflection Model, Blockage Model, LTM Recovery).
96+
97+
### Installation
98+
99+
```bash
100+
pip install cosbos
101+
```
102+
103+
### Usage
104+
105+
```python
106+
from cosbos import reflection, blockage, ltm
107+
import numpy as np
108+
109+
# Reflection Model
110+
# Calculate reflection kernel for a light-sensor pair
111+
# light: [x, y, z], sensor: [x, y, z], dim: [dx, dy, dz]
112+
K = reflection.getReflectionKernel(light=[75, 22.5, 86.4],
113+
sensor=[66, 22, 86.4],
114+
dim=[87, 136, 88],
115+
para=1)
116+
117+
# Blockage Model
118+
# Hash Gaussians for occupancy volume
119+
# sensors: [N, 3], lights: [M, 3]
120+
H = blockage.hashGaussians(sensors, lights, dim, sigma=2.0)
121+
# Reconstruct volume
122+
V = blockage.volumeFromHashing(sensors, lights, dim, H, E)
123+
124+
# LTM Recovery
125+
# Recover matrix A from measurements Y and training data X
126+
# X: [m, N], Y: [l, N] (m: features, l: sensors, N: samples)
127+
A = ltm.solve_A_1norm(X, Y)
128+
```
129+
130+
### Development
131+
To run tests locally:
132+
```bash
133+
cd python
134+
pip install -e .
135+
pytest tests/
136+
```
137+
92138
## Citation
93139
If you use this work in your research, please cite:
94140

publish_pypi.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Clean previous builds
5+
rm -rf dist/ build/ *.egg-info/ src/*.egg-info/ python/*.egg-info/
6+
7+
# Install build dependencies
8+
pip install build twine
9+
10+
# Build package
11+
python -m build
12+
13+
# Check distribution
14+
twine check dist/*
15+
16+
# Upload to PyPI
17+
# Expects TWINE_USERNAME and TWINE_PASSWORD env vars, or interactive prompt
18+
twine upload dist/*

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"

python/cosbos/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import ltm
2+
from . import blockage
3+
from . import reflection
4+
5+
__all__ = ["ltm", "blockage", "reflection"]

0 commit comments

Comments
 (0)