Real-time laser beam profiler with Gaussian fitting for GenICam cameras
Project description
pyBeamprofiler
Real-time laser beam profiler with Gaussian fitting for GenICam cameras.
Features
- Real-time Gaussian fitting — 1D projections (230+ fps), 2D with rotation (50+ fps), linecut (300+ fps)
- Browser-based GUI — Dash web interface with live heatmap, fits, dark/light theme, 30+ color scales, and camera controls
- Multiple width definitions — Gaussian (1/e²), FWHM, D4σ (ISO 11146)
- GenICam hardware support — FLIR (Spinnaker) and Basler (Pylon) via Harvesters; auto-discovered features grouped by SFNC category
- Jupyter support — Live streaming with
bp.setting()interactive widgets - Simulated camera — Gaussian beam with noise, no hardware needed
- Auto-configuration — Pixel size detection for 40+ sensor models
Quick Start
pip install pybeamprofiler
# Run the browser GUI with a simulated camera (no hardware needed)
pybeamprofiler --camera simulated
# Or connect to real hardware
pybeamprofiler --camera flir # FLIR / Spinnaker
pybeamprofiler --camera basler # Basler / Pylon
The browser opens automatically at http://127.0.0.1:8050. Press Ctrl+C in the terminal to stop the server and exit.
Installation
pip install pybeamprofiler
For real hardware (FLIR or Basler), also install the corresponding SDK and set the CTI path:
| Vendor | SDK | GENICAM_GENTL64_PATH |
|---|---|---|
| FLIR | Spinnaker | /usr/local/lib/spinnaker-gentl (macOS/Linux) |
| Basler (macOS) | Pylon | /Library/Frameworks/pylon.framework/Libraries/gentlproducer/gtl |
| Basler (Linux) | Pylon | /opt/pylon/lib64/gentlproducer/gtl |
| Basler (Windows) | Pylon | C:\Program Files\Basler\pylon\Runtime\x64 |
export GENICAM_GENTL64_PATH=/path/to/cti/files
Note: GenICam cameras allow only one application to connect at a time — close Spinnaker GUI / Pylon Viewer first.
Usage
Command line
pybeamprofiler --camera simulated # simulated camera
pybeamprofiler --camera flir # FLIR / Spinnaker
pybeamprofiler --camera basler # Basler / Pylon
pybeamprofiler --file beam.png # static image
pybeamprofiler --fit 2d --definition fwhm
pybeamprofiler --help # all options
Press Ctrl+C in the terminal to stop streaming and exit.
Python API
from pybeamprofiler import BeamProfiler, print_camera_info
print_camera_info() # list connected cameras
bp = BeamProfiler(camera="simulated")
bp.plot() # open browser GUI
bp.plot(num_img=1) # single shot
print(f"Width X: {bp.width_x:.1f} μm, Y: {bp.width_y:.1f} μm")
print(f"Center: ({bp.center_x:.1f}, {bp.center_y:.1f}) px")
# Change settings
bp.setting(exposure_time=0.05, Gain=10.0)
# In Jupyter: open interactive control panel
bp.setting()
See the API docs for fitting methods (1d, 2d, linecut), width definitions (gaussian, fwhm, d4s), ROI control, and more.
Troubleshooting
- Camera not found — verify SDK install,
GENICAM_GENTL64_PATH, and runprint_camera_info(). - Access denied — close other camera software (Spinnaker GUI, Pylon Viewer).
- Jupyter camera stuck — restart the kernel to release the hardware lock.
- Basler USB3 — pass the USB3 CTI explicitly:
BaslerCamera(cti_file="/path/to/ProducerU3V.cti").
For Developers
Setup
git clone https://github.com/acechenx/pybeamprofiler.git
cd pybeamprofiler
uv sync --extra dev
uv run pre-commit install
Code quality
uv run ruff check src tests
uv run ruff format src tests
uv run ty check src tests
Testing
uv run pytest # all tests + coverage
uv run pytest --cov-report=html # HTML coverage report
uv run pytest tests/test_profiler.py # single file
Current suite: 588 tests, 97% coverage.
Architecture
beamprofiler.py—BeamProfilerclass, fitting algorithms, CLI entry pointcamera.py— abstractCamerabase class + Jupyter widget buildergen_camera.py—HarvesterCamerafor GenICam devicesflir.py/basler.py— vendor-specific subclassessimulated.py—SimulatedCamera(no hardware)dash_app.py— browser GUI with live updates, settings panel, pattern-matching callbacksutils.py— camera discovery helpersconstants.py— shared constants
Contributing
- Fork and create a feature branch
- Add tests for new functionality
- Ensure
uv run pytest,uv run ruff check, anduv run ty checkpass - Submit a pull request
Performance notes
- 2D fits use adaptive downsampling + Levenberg-Marquardt warm starts
- Projection profiles are cached between
analyze()and figure rendering - In the current Dash implementation, live updates perform
bp.camera.get_image(timeout=0.1)andbp.analyze(img)synchronously while holding athreading.Lockto reduce segfault risk in the Harvesters C library
Supported sensors
Auto-detected pixel sizes (40+ models) — Sony IMX174, IMX183, IMX226, IMX249, IMX250, IMX252, IMX253, IMX255, IMX264, IMX265, IMX273, IMX287, IMX290, IMX291, IMX304, IMX392, IMX412, IMX477, IMX485, IMX530, IMX531, IMX540, IMX541, IMX542, IMX547, and direct Basler model lookups (acA4024-8gm, acA4024-29um, acA1920-155um, acA2440-75um, acA3800-14um).
License
MIT — see LICENSE.
Author
C.-A. Chen (acechen@cirx.org)
Acknowledgments
- Built on Harvesters, Plotly/Dash
- Inspired by LaseView (old freeware), ptomato/Beams, jordens/bullseye
- FLIR and Basler cameras loaned from Atom Computing for testing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pybeamprofiler-0.2.1.tar.gz.
File metadata
- Download URL: pybeamprofiler-0.2.1.tar.gz
- Upload date:
- Size: 228.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c1490cbcfe52fd8999ca24a4fae79a9dea4aa8c4b576ab2f44e03cf34439ff6
|
|
| MD5 |
1e6833b1ee41901868c07a5953ca15d3
|
|
| BLAKE2b-256 |
7bd6af1ead06800af2f1f027d96a99a7ee36d33fa5009001ffbd364d35072d7e
|
Provenance
The following attestation bundles were made for pybeamprofiler-0.2.1.tar.gz:
Publisher:
ci.yml on AceChenX/pybeamprofiler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybeamprofiler-0.2.1.tar.gz -
Subject digest:
1c1490cbcfe52fd8999ca24a4fae79a9dea4aa8c4b576ab2f44e03cf34439ff6 - Sigstore transparency entry: 1355625561
- Sigstore integration time:
-
Permalink:
AceChenX/pybeamprofiler@4ebcd2da636c20ad7a8cd2079254aa007175bcbe -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/AceChenX
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@4ebcd2da636c20ad7a8cd2079254aa007175bcbe -
Trigger Event:
release
-
Statement type:
File details
Details for the file pybeamprofiler-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pybeamprofiler-0.2.1-py3-none-any.whl
- Upload date:
- Size: 58.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb6c4223c956ecc0369f42ff909c6f591dd0acdce1bbb9e41aba29f484ea6aa0
|
|
| MD5 |
eede3a6d8e78fcaf7371894c3bb7305d
|
|
| BLAKE2b-256 |
0b8d1eef48ca8e120ffe46b4d45337d0a99aef4ecc51a0d986b3c39cb23432cd
|
Provenance
The following attestation bundles were made for pybeamprofiler-0.2.1-py3-none-any.whl:
Publisher:
ci.yml on AceChenX/pybeamprofiler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pybeamprofiler-0.2.1-py3-none-any.whl -
Subject digest:
bb6c4223c956ecc0369f42ff909c6f591dd0acdce1bbb9e41aba29f484ea6aa0 - Sigstore transparency entry: 1355625609
- Sigstore integration time:
-
Permalink:
AceChenX/pybeamprofiler@4ebcd2da636c20ad7a8cd2079254aa007175bcbe -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/AceChenX
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@4ebcd2da636c20ad7a8cd2079254aa007175bcbe -
Trigger Event:
release
-
Statement type: