Memory-mapped file handling and streaming API
This PR introduces memory-mapped file handling and a streaming API to enable efficient processing of large IMC files without loading the entire dataset into memory.
Key Changes:
- Core Library: Replaced std::vector file buffering with a MemoryMappedFile implementation to significantly reduce memory usage.
- Python Bindings:
- Added iter_channel_numpy() to the imctermite class. This generator yields data in chunks as NumPy arrays, supporting both "scaled" (physical units) and "raw" (native integer) modes.
- Added type stubs (.pyi) and package data for improved IDE support.
- Performance: Implemented efficient memcpy transfer from C++ buffers to NumPy arrays.
- Fixes: Improved text encoding/codepage handling for Windows.
- Documentation: Added usage_numpy_chunks.py and usage_timerange.py to demonstrate new functionality.
- CI: Added Windows target to CI tests.
Performance Improvements:
Benchmarks comparing the new memory-mapped implementation against the baseline show significant improvements in both memory efficiency and load times:
- Memory Usage: Reduced memory footprint by ~50% for large files.
- 100MB file: Overhead reduced from ~204MB to ~101MB.
- Small file: Overhead reduced from ~1.3MB to ~92KB.
- Loading Speed: File loading is approximately 5x faster for large files.
- 100MB file: Load time decreased from ~1.25s to ~0.24s.
- Small file: Load time decreased from ~2.6ms to ~0.2ms.
NOTE: This PR is based on #37
Closes #33 Closes #9
I just realized the new numpy dependency was not correctly handled and that makes the PR a major change. So I took the opportunity to modernize the Python packaging infrastructure and CI workflows to follow current best practices and support Python 3.10-3.13.
Changes
Packaging
- Migrated package metadata from
setup.cfgtopyproject.toml(PEP 621) - Replaced deprecated
setup.pycommands withpython -m build - Added numpy as explicit dependency (>=1.26.0)
- Version bumped to 3.0.0
- Simplified
setup.pyto minimal Cython extension builder
CI/CD
- Updated GitHub Actions from v2 → v4
- Replaced
ubuntu-24.04withubuntu-latestfor better maintainability - Removed obsolete
cibuildwheel==2.1.2version pinning - Configured cibuildwheel via
pyproject.tomlwith proper platform targeting - Streamlined dependency installation in test workflows
Documentation
- Added Python version support badge to README
- Enhanced test documentation with pip editable install instructions
- Added note about numpy dependency requirement
Build System
- Updated makefiles to use
python3consistently - Simplified build targets using modern pip commands
Testing
All existing tests pass. CI workflows validated on Ubuntu and Windows with Python 3.10-3.13.
Hi @mario-fink,
I guess the changes I made are a bit overwhelming. To get an artifact via the CI I've merged the branches ( #37, #38 and #39) in my repository together (https://github.com/jgoedeke/IMCtermite/tree/build) this is the corresponding action run: https://github.com/jgoedeke/IMCtermite/actions/runs/21626413617.
Is there something I can do to support the review process?
Hi @jgoedeke ,
first of all, thank you for your amazing contributions to the project! I'm excited to see you adding valuable features to the package and continuing its growth.
However, I'm having a hard time finding a time slot to review your work, but I'll try to get it done a.s.a.p. .