-
Notifications
You must be signed in to change notification settings - Fork 0
added Brainflow SpO2 example #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,15 @@ | ||||||||||||||||||||||||
| # Porting an algorithm from C++ to Python | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Table of Contents | ||||||||||||||||||||||||
| - [Why?](#why?) | ||||||||||||||||||||||||
| - [Why?](#why) | ||||||||||||||||||||||||
| - [How it works](#how-it-works) | ||||||||||||||||||||||||
| - [Requirements](#Requirements) | ||||||||||||||||||||||||
| - [Creating python-env with pybind11](#Creating-python-env-with-pybind11) | ||||||||||||||||||||||||
| - [Using venv (recommended)](#Using-venv) | ||||||||||||||||||||||||
| - [Using anaconda](#Using-anaconda) | ||||||||||||||||||||||||
| - [Examples](#Examples) | ||||||||||||||||||||||||
| - [Rounder](#Rounder) | ||||||||||||||||||||||||
| - [EmotiBitPacket](#EmotiBitPacket) | ||||||||||||||||||||||||
| - [Adapting this to your C++ code](#Adapting-this-to-your-C++-code) | ||||||||||||||||||||||||
| - [Requirements](#requirements) | ||||||||||||||||||||||||
| - [Setting up Python virtual environment](#setting-up-python-virtual-environment) | ||||||||||||||||||||||||
| - [Adapting this to your C++ code](#adapting-this-to-your-c-code) | ||||||||||||||||||||||||
| - [Examples](#examples) | ||||||||||||||||||||||||
| - [Rounder](#rounder) | ||||||||||||||||||||||||
| - [EmotiBitPacket](#emotibitpacket) | ||||||||||||||||||||||||
| - [Brainflow SpO2 Algorithm](#brainflow-spo2-algorithm) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Why? | ||||||||||||||||||||||||
| The goal of this project is to allow users to take an algorithm written in C++ and translate it into runnable Python code. | ||||||||||||||||||||||||
|
|
@@ -37,62 +36,51 @@ PYBIND11_MODULE(EmotiBitPacket, m) { | |||||||||||||||||||||||
| - Build the files created in the previous step to create the `.pyd` file | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Requirements | ||||||||||||||||||||||||
| ### Creating python-env with pybind11 | ||||||||||||||||||||||||
| #### Using venv | ||||||||||||||||||||||||
| ### Setting up Python Virtual Environment | ||||||||||||||||||||||||
| - Open a new command prompt window | ||||||||||||||||||||||||
| - `cd` to the EmotiBit_Plugins repository | ||||||||||||||||||||||||
| - Run the following command `python -m venv .\py_envs\<env-name>` | ||||||||||||||||||||||||
| - replace `<env-name>` with the environment name | ||||||||||||||||||||||||
| - Activate the new environment by running the command `.\py_envs\<env-name>\Scripts\activate.bat` | ||||||||||||||||||||||||
| - You will see the prompt in the terminal change. It now shows the python environment in parenthesis. | ||||||||||||||||||||||||
| - Run the following command to install bypind11. `pip install pybind11==2.13.5` | ||||||||||||||||||||||||
| - `cd` to `EmotiBit_Plugins/py_envs` | ||||||||||||||||||||||||
| - Run the following command `python -m venv emotibit_plugins` | ||||||||||||||||||||||||
| - This creates a new folder called `plugins` containing the virtual Python environment | ||||||||||||||||||||||||
| - Activate the new environment: | ||||||||||||||||||||||||
| - Windows (cmd): `.\emotibit_plugins\Scripts\activate.bat` | ||||||||||||||||||||||||
| - Windows (PowerShell): `.\emotibit_plugins\Scripts\Activate.ps1` | ||||||||||||||||||||||||
| - macOS/Linux (bash/zsh): `source emotibit_plugins/bin/activate` | ||||||||||||||||||||||||
| - Run the following command to install pybind11. `pip install pybind11==2.13.5` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| #### Using anaconda | ||||||||||||||||||||||||
| - Download [Anaconda](https://www.anaconda.com/download/) as shown here. | ||||||||||||||||||||||||
| - ***Do not close out of the Anaconda Powershell Prompt until completely done with an example*** | ||||||||||||||||||||||||
| - Open an Anaconda Powershell Prompt through the search feature on your machine and run the command below | ||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| cd C:\path\to\your\EmotiBit_Plugins\pyExample_alg01 | ||||||||||||||||||||||||
| conda config --set channel_priority flexible | ||||||||||||||||||||||||
| conda env update --name EmotiBit-pyenv-modern --file .\EmotiBit-pyenv-modern.yml | ||||||||||||||||||||||||
| conda activate EmotiBit-pyenv-modern | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
| ## Adapting this to your C++ code | ||||||||||||||||||||||||
| - Add pybind11 bindings to a file `bindings_<srcName>.cpp`. Refer the [pybind11 documentation](https://pybind11.readthedocs.io/en/stable/basics.html) for more information. | ||||||||||||||||||||||||
| - Create a new CMakeLists.txt file that | ||||||||||||||||||||||||
| - Builds a library from your source files | ||||||||||||||||||||||||
| - Builds the Python module (`.pyd` or `.so`) file from that library | ||||||||||||||||||||||||
| - Run the `cmake` commands from the examples below to create a build the project. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Refer to the examples below to see what `bindings.cpp` and `CMakeLists.txt` should look like. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Examples | ||||||||||||||||||||||||
| ### Rounder | ||||||||||||||||||||||||
| #### Steps to Run Example | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| - cd to `pyExample_alg01` | ||||||||||||||||||||||||
| - run the following commands | ||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| mkdir build | ||||||||||||||||||||||||
| cd build | ||||||||||||||||||||||||
| cmake .. | ||||||||||||||||||||||||
| cmake --build . --config Release | ||||||||||||||||||||||||
| cmake -B build | ||||||||||||||||||||||||
| cmake --build build --config Release | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
| - The following command runs the python example. The expected result is for the script to round the input. | ||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| python example.py -i 3.4 | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ### EmotiBitPacket | ||||||||||||||||||||||||
| #### Building the example | ||||||||||||||||||||||||
| - To make this example work, you will need to copy/clone the `EmotiBit_XPlat_Utils` repository into the `src` folder. | ||||||||||||||||||||||||
| - cd to the `src` folder. | ||||||||||||||||||||||||
| - clone using `git clone https://github.com/EmotiBit/EmotiBit_XPlat_Utils`. Checkout the following commit `393b611ee0d0c1f1cec70e243fd5b643c2e25250` | ||||||||||||||||||||||||
| - cd to `pyExample_emotibitPacket` and run the following commands | ||||||||||||||||||||||||
|
Comment on lines
72
to
76
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix directory name casing: “pyExample_EmotiBitPacket” The current path uses a lowercase/typo’d name and will fail on case-sensitive filesystems. Apply: -- cd to `pyExample_emotibitPacket` and run the following commands
+- cd to `pyExample_EmotiBitPacket` and run the following commands📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| mkdir build | ||||||||||||||||||||||||
| cd build | ||||||||||||||||||||||||
| cmake .. | ||||||||||||||||||||||||
| cmake --build . --config Release | ||||||||||||||||||||||||
| cmake -B build | ||||||||||||||||||||||||
| cmake --build build --config Release | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
| - Run the Python example script `pyExample_emotibitPacket\example.py` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ## Adapting this to your C++ code | ||||||||||||||||||||||||
| - Add pybind11 bindings to a file `bindings_<srcName>.cpp`. Refer the [pybind11 documentation](https://pybind11.readthedocs.io/en/stable/basics.html) for more information. | ||||||||||||||||||||||||
| - Create a new CMakeLists.txt file that | ||||||||||||||||||||||||
| - creates a lib from your source files | ||||||||||||||||||||||||
| - creates the pyd file from the src library | ||||||||||||||||||||||||
| - Run the cmake commands above to create a build the project. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ### Brainflow SpO2 Algorithm | ||||||||||||||||||||||||
| - Clone the EmotiBit Brainflow SpO2 Algorithm [repo](https://github.com/EmotiBit/EmotiBit_Brainflow_SpO2_Algorithm) into any directory | ||||||||||||||||||||||||
| - `cd` into the `EmotiBit Brainflow SpO2 Algorithm` folder and checkout the following commit: `7bc9dc3b02f361c37e9e917477abefe9f5468a68` | ||||||||||||||||||||||||
| - Follow the instructions under `pybind/README.md` to finish building the algorithm | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix venv name mismatch and strengthen cross‑platform install notes
Apply:
Follow-up: please standardize this venv name (“emotibit_plugins”) across CMake and the rest of the repo to avoid breakage when locating pybind11.
I can scan the repo and draft diffs to align the venv name everywhere if helpful.
📝 Committable suggestion
🧰 Tools
🪛 LanguageTool
[grammar] ~39-~39: There might be a mistake here.
Context: ....pyd` file ## Requirements ### Setting up Python Virtual Environment - Open a new...
(QB_NEW_EN)
[grammar] ~39-~39: There might be a mistake here.
Context: ...## Setting up Python Virtual Environment - Open a new command prompt window -
cd...(QB_NEW_EN)
[grammar] ~44-~44: There might be a mistake here.
Context: ...ironment - Activate the new environment: - Windows (cmd): `.\emotibit_plugins\Scrip...
(QB_NEW_EN)
🤖 Prompt for AI Agents