facetpy 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- facetpy-2.0.0/PKG-INFO +376 -0
- facetpy-2.0.0/README.md +326 -0
- facetpy-2.0.0/pyproject.toml +88 -0
- facetpy-2.0.0/src/facet/__init__.py +333 -0
- facetpy-2.0.0/src/facet/build.py +40 -0
- facetpy-2.0.0/src/facet/config.py +238 -0
- facetpy-2.0.0/src/facet/console/__init__.py +40 -0
- facetpy-2.0.0/src/facet/console/base.py +230 -0
- facetpy-2.0.0/src/facet/console/manager.py +54 -0
- facetpy-2.0.0/src/facet/console/modern.py +1448 -0
- facetpy-2.0.0/src/facet/console/progress.py +135 -0
- facetpy-2.0.0/src/facet/core/__init__.py +54 -0
- facetpy-2.0.0/src/facet/core/channel_sequential.py +257 -0
- facetpy-2.0.0/src/facet/core/context.py +671 -0
- facetpy-2.0.0/src/facet/core/parallel.py +396 -0
- facetpy-2.0.0/src/facet/core/pipeline.py +1024 -0
- facetpy-2.0.0/src/facet/core/processor.py +364 -0
- facetpy-2.0.0/src/facet/core/registry.py +223 -0
- facetpy-2.0.0/src/facet/correction/__init__.py +59 -0
- facetpy-2.0.0/src/facet/correction/aas.py +699 -0
- facetpy-2.0.0/src/facet/correction/anc.py +533 -0
- facetpy-2.0.0/src/facet/correction/farm.py +199 -0
- facetpy-2.0.0/src/facet/correction/pca.py +386 -0
- facetpy-2.0.0/src/facet/correction/volume.py +243 -0
- facetpy-2.0.0/src/facet/correction/weighted.py +426 -0
- facetpy-2.0.0/src/facet/evaluation/__init__.py +36 -0
- facetpy-2.0.0/src/facet/evaluation/metrics.py +2213 -0
- facetpy-2.0.0/src/facet/evaluation/visualization.py +340 -0
- facetpy-2.0.0/src/facet/helpers/__init__.py +10 -0
- facetpy-2.0.0/src/facet/helpers/alignsubsample.py +120 -0
- facetpy-2.0.0/src/facet/helpers/bcg_detector.py +708 -0
- facetpy-2.0.0/src/facet/helpers/crosscorr.py +34 -0
- facetpy-2.0.0/src/facet/helpers/eeg_metadata_mapper.py +58 -0
- facetpy-2.0.0/src/facet/helpers/fastranc.c +34 -0
- facetpy-2.0.0/src/facet/helpers/fastranc.py +65 -0
- facetpy-2.0.0/src/facet/helpers/interactive.py +566 -0
- facetpy-2.0.0/src/facet/helpers/moosmann.py +109 -0
- facetpy-2.0.0/src/facet/helpers/plotting.py +16 -0
- facetpy-2.0.0/src/facet/helpers/profiler.py +35 -0
- facetpy-2.0.0/src/facet/helpers/utils.py +22 -0
- facetpy-2.0.0/src/facet/io/__init__.py +40 -0
- facetpy-2.0.0/src/facet/io/exporters.py +458 -0
- facetpy-2.0.0/src/facet/io/loaders.py +459 -0
- facetpy-2.0.0/src/facet/logging_config.py +189 -0
- facetpy-2.0.0/src/facet/misc/__init__.py +28 -0
- facetpy-2.0.0/src/facet/misc/eeg_generator.py +1200 -0
- facetpy-2.0.0/src/facet/pipelines.py +149 -0
- facetpy-2.0.0/src/facet/preprocessing/__init__.py +64 -0
- facetpy-2.0.0/src/facet/preprocessing/acquisition.py +225 -0
- facetpy-2.0.0/src/facet/preprocessing/alignment.py +638 -0
- facetpy-2.0.0/src/facet/preprocessing/diagnostics.py +173 -0
- facetpy-2.0.0/src/facet/preprocessing/filtering.py +404 -0
- facetpy-2.0.0/src/facet/preprocessing/prefilter.py +351 -0
- facetpy-2.0.0/src/facet/preprocessing/resampling.py +320 -0
- facetpy-2.0.0/src/facet/preprocessing/transforms.py +1461 -0
- facetpy-2.0.0/src/facet/preprocessing/trigger_detection.py +892 -0
- facetpy-2.0.0/src/facet/preprocessing/trigger_explorer.py +1034 -0
- facetpy-2.0.0/src/facet/resources/__init__.py +0 -0
- facetpy-2.0.0/src/facet/resources/i18n/__init__.py +0 -0
- facetpy-2.0.0/src/facet/resources/i18n/translations_en.py +14 -0
facetpy-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: facetpy
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: A flexible artifact correction and evaluation toolbox to correct eeg data
|
|
5
|
+
License: GPL-3.0-only
|
|
6
|
+
Keywords: eeg,fmri,artifact-correction,mne,neuroscience
|
|
7
|
+
Author: Janik Michael Mueller
|
|
8
|
+
Author-email: janik.michael.mueller@gmail.com
|
|
9
|
+
Requires-Python: >=3.11,<4.0
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
|
|
20
|
+
Provides-Extra: all
|
|
21
|
+
Provides-Extra: deeplearning
|
|
22
|
+
Provides-Extra: docs
|
|
23
|
+
Provides-Extra: gui
|
|
24
|
+
Provides-Extra: notebooks
|
|
25
|
+
Requires-Dist: defusedxml (>=0.7.1,<0.8.0)
|
|
26
|
+
Requires-Dist: edfio (>=0.4.11,<0.5.0)
|
|
27
|
+
Requires-Dist: eeglabio (>=0.1.3,<0.2.0)
|
|
28
|
+
Requires-Dist: ipython (>=7.23.1,<9) ; extra == "notebooks"
|
|
29
|
+
Requires-Dist: loguru (==0.7.2)
|
|
30
|
+
Requires-Dist: matplotlib (>=3.10.3,<4.0.0)
|
|
31
|
+
Requires-Dist: mne (==1.10.2)
|
|
32
|
+
Requires-Dist: mne-bids (==0.17)
|
|
33
|
+
Requires-Dist: myst-parser (>=3.0.1,<4.0.0) ; extra == "docs" or extra == "all"
|
|
34
|
+
Requires-Dist: neurokit2 (>=0.2.7,<0.3.0)
|
|
35
|
+
Requires-Dist: notebook (>=7.1.2,<8.0.0) ; extra == "notebooks" or extra == "all"
|
|
36
|
+
Requires-Dist: numpy (==2.1.3)
|
|
37
|
+
Requires-Dist: pandas (>=2.2.3,<3.0.0)
|
|
38
|
+
Requires-Dist: pyqt6 (>=6.6.1,<7.0.0) ; extra == "gui" or extra == "all"
|
|
39
|
+
Requires-Dist: rich (>=14.2.0,<15.0.0)
|
|
40
|
+
Requires-Dist: scikit-learn (>=1.4.2,<2.0.0)
|
|
41
|
+
Requires-Dist: scipy (>=1.15.3,<2.0.0)
|
|
42
|
+
Requires-Dist: sphinx (>=7.2.6,<8.0.0) ; extra == "docs" or extra == "all"
|
|
43
|
+
Requires-Dist: sphinx-rtd-theme (>=2.0.0,<3.0.0) ; extra == "docs" or extra == "all"
|
|
44
|
+
Requires-Dist: tensorflow (>=2.19.0,<3.0.0) ; extra == "deeplearning" or extra == "all"
|
|
45
|
+
Project-URL: Documentation, https://facetpy.readthedocs.io/
|
|
46
|
+
Project-URL: Homepage, https://github.com/H0mire/facetpy
|
|
47
|
+
Project-URL: Repository, https://github.com/H0mire/facetpy
|
|
48
|
+
Description-Content-Type: text/markdown
|
|
49
|
+
|
|
50
|
+
# FACETpy — fMRI Artifact Correction and Evaluation Toolbox
|
|
51
|
+
|
|
52
|
+
<p align="center">
|
|
53
|
+
<picture>
|
|
54
|
+
<source srcset="docs/source/_static/logo_dark_theme.png" media="(prefers-color-scheme: dark)">
|
|
55
|
+
<img src="docs/source/_static/logo_light_theme.png" width="300" alt="FACETpy logo" />
|
|
56
|
+
</picture>
|
|
57
|
+
</p>
|
|
58
|
+
|
|
59
|
+
[](https://facetpy.readthedocs.io/en/latest/?badge=latest)
|
|
60
|
+
|
|
61
|
+
A Python toolbox for correcting fMRI-induced EEG artifacts using Averaged
|
|
62
|
+
Artifact Subtraction (AAS) and other advanced methods. Built on
|
|
63
|
+
[MNE-Python](https://mne.tools), it provides a modular pipeline
|
|
64
|
+
architecture that lets researchers process, evaluate, and compare correction
|
|
65
|
+
results with minimal code.
|
|
66
|
+
|
|
67
|
+
**Key features**
|
|
68
|
+
|
|
69
|
+
- Load EEG from EDF, GDF, and BIDS formats
|
|
70
|
+
- Artifact correction: AAS, PCA, Adaptive Noise Cancellation (ANC)
|
|
71
|
+
- Full evaluation suite: SNR, RMS, Median Artifact, FFT-based metrics
|
|
72
|
+
- One-call results: `result.print_metrics()`, `result.print_summary()`
|
|
73
|
+
- Batch processing across subjects/sessions with `Pipeline.map()`
|
|
74
|
+
- Generate synthetic EEG for algorithm testing
|
|
75
|
+
- Rich progress display in the terminal
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
## Quick start
|
|
79
|
+
|
|
80
|
+
Quick installation (requires Python 3.11/3.12/3.13):
|
|
81
|
+
|
|
82
|
+
Unix (macOS/Linux):
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
curl -fsSL https://raw.githubusercontent.com/H0mire/facetpy/main/scripts/bootstrap.sh | sh
|
|
86
|
+
cd facetpy
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Windows (PowerShell):
|
|
90
|
+
|
|
91
|
+
```powershell
|
|
92
|
+
git clone https://github.com/H0mire/facetpy.git
|
|
93
|
+
Set-Location facetpy
|
|
94
|
+
poetry install --no-interaction
|
|
95
|
+
```
|
|
96
|
+
<p align="center">
|
|
97
|
+
<img src="docs/source/_static/run_example.png" alt="FACETpy example run" width="700" />
|
|
98
|
+
</p>
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from facet import (
|
|
103
|
+
Pipeline, Loader, EDFExporter,
|
|
104
|
+
TriggerDetector, UpSample, DownSample, AASCorrection,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
pipeline = Pipeline([
|
|
108
|
+
Loader(path="data.edf", preload=True),
|
|
109
|
+
TriggerDetector(regex=r"\b1\b"),
|
|
110
|
+
UpSample(factor=10),
|
|
111
|
+
AASCorrection(window_size=30),
|
|
112
|
+
DownSample(factor=10),
|
|
113
|
+
EDFExporter(path="corrected.edf", overwrite=True),
|
|
114
|
+
], name="Quickstart")
|
|
115
|
+
|
|
116
|
+
result = pipeline.run()
|
|
117
|
+
result.print_summary() # Done in 4.2s snr=18.3 rms_ratio=0.14
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Installation
|
|
122
|
+
|
|
123
|
+
Requires **Python 3.11, 3.12, or 3.13** and [Poetry](https://python-poetry.org) >= 1.8.
|
|
124
|
+
Conda is optional, not required.
|
|
125
|
+
|
|
126
|
+
### Option A (PyPI): install from package index
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pip install facetpy
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The package name on PyPI is `facetpy`; import it in Python as `facet`.
|
|
133
|
+
|
|
134
|
+
### Option B (Unix recommended): bootstrap script
|
|
135
|
+
```bash
|
|
136
|
+
curl -fsSL https://raw.githubusercontent.com/H0mire/facetpy/main/scripts/bootstrap.sh | sh
|
|
137
|
+
cd facetpy
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
This bootstrap script:
|
|
141
|
+
- clones the FACETpy repository into `./facetpy`
|
|
142
|
+
- runs `./scripts/install.sh` inside that clone
|
|
143
|
+
|
|
144
|
+
### Option C (Unix): clone first, then run local installer
|
|
145
|
+
```bash
|
|
146
|
+
git clone https://github.com/H0mire/facetpy.git
|
|
147
|
+
cd facetpy
|
|
148
|
+
./scripts/install.sh
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The script:
|
|
152
|
+
- checks for Python 3.11/3.12/3.13
|
|
153
|
+
- checks whether Poetry is installed
|
|
154
|
+
- asks whether Poetry should be installed if missing
|
|
155
|
+
- runs `poetry install --no-interaction`
|
|
156
|
+
|
|
157
|
+
### Option D (Windows PowerShell): manual install
|
|
158
|
+
|
|
159
|
+
```powershell
|
|
160
|
+
git clone https://github.com/H0mire/facetpy.git
|
|
161
|
+
Set-Location facetpy
|
|
162
|
+
poetry install --no-interaction
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Use Option B/C inside WSL or Git Bash if you want to run the `.sh` installer scripts.
|
|
166
|
+
|
|
167
|
+
### Option E: system Python + Poetry (manual)
|
|
168
|
+
|
|
169
|
+
Unix (macOS/Linux):
|
|
170
|
+
```bash
|
|
171
|
+
# 1 — verify Python
|
|
172
|
+
python3 --version
|
|
173
|
+
|
|
174
|
+
# 2 — install Poetry (pick one)
|
|
175
|
+
pipx install poetry
|
|
176
|
+
# or: python3 -m pip install --user poetry
|
|
177
|
+
|
|
178
|
+
# 3 — install FACETpy and dependencies
|
|
179
|
+
poetry install --no-interaction
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Windows (PowerShell):
|
|
183
|
+
|
|
184
|
+
```powershell
|
|
185
|
+
# 1 — verify Python
|
|
186
|
+
py --version
|
|
187
|
+
|
|
188
|
+
# 2 — install Poetry (pick one)
|
|
189
|
+
pipx install poetry
|
|
190
|
+
# or: py -m pip install --user poetry
|
|
191
|
+
|
|
192
|
+
# 3 — install FACETpy and dependencies
|
|
193
|
+
poetry install --no-interaction
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### Option F (optional): Conda workflow
|
|
197
|
+
|
|
198
|
+
Unix (macOS/Linux):
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
conda create -n facetpy python=3.13 -y
|
|
202
|
+
conda activate facetpy
|
|
203
|
+
conda install -c conda-forge poetry -y
|
|
204
|
+
poetry install --no-interaction
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Windows (PowerShell):
|
|
208
|
+
|
|
209
|
+
```powershell
|
|
210
|
+
conda create -n facetpy python=3.13 -y
|
|
211
|
+
conda activate facetpy
|
|
212
|
+
conda install -c conda-forge poetry -y
|
|
213
|
+
poetry install --no-interaction
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Optional extras:
|
|
217
|
+
```text
|
|
218
|
+
poetry install -E deeplearning # TensorFlow-based models
|
|
219
|
+
poetry install -E notebooks # Jupyter notebook support
|
|
220
|
+
poetry install -E gui # PyQt6 GUI components
|
|
221
|
+
poetry install -E docs # Sphinx documentation toolchain
|
|
222
|
+
poetry install -E all # everything above
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Run commands with `poetry run ...` (for example, `poetry run python examples/quickstart.py`).
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
### Build the C extension (optional)
|
|
229
|
+
|
|
230
|
+
The fast Adaptive Noise Cancellation (ANC) step uses a compiled C extension.
|
|
231
|
+
Build it once after installing:
|
|
232
|
+
|
|
233
|
+
```bash
|
|
234
|
+
poetry run build-fastranc
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
If the extension is absent, ANC is skipped automatically and the rest of the
|
|
238
|
+
toolbox works normally.
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
## Running the examples
|
|
242
|
+
|
|
243
|
+
All examples are in the `examples/` folder and use the bundled
|
|
244
|
+
`NiazyFMRI.edf` dataset. Run them from the project root:
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
# Recommended order for new users:
|
|
248
|
+
poetry run python examples/quickstart.py # minimal pipeline
|
|
249
|
+
poetry run python examples/evaluation.py # metrics & comparison
|
|
250
|
+
poetry run python examples/advanced_workflows.py # conditional, parallel, factory
|
|
251
|
+
poetry run python examples/batch_processing.py # multiple files at once
|
|
252
|
+
poetry run python examples/inline_steps.py # custom steps & pipe operator
|
|
253
|
+
poetry run python examples/complete_pipeline_example.py # full clinical pipeline
|
|
254
|
+
poetry run python examples/eeg_generation_visualization_example.py # synthetic EEG
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
## Testing
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Run the full test suite
|
|
262
|
+
poetry run pytest
|
|
263
|
+
|
|
264
|
+
# Only fast unit tests (skip slow integration tests)
|
|
265
|
+
poetry run pytest -m "not slow"
|
|
266
|
+
|
|
267
|
+
# A single test file
|
|
268
|
+
poetry run pytest tests/test_core_pipeline.py -v
|
|
269
|
+
|
|
270
|
+
# With coverage report
|
|
271
|
+
poetry run pytest --cov=facet --cov-report=html
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
Open the coverage report:
|
|
275
|
+
|
|
276
|
+
Unix (macOS/Linux):
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
open htmlcov/index.html
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Windows (PowerShell):
|
|
283
|
+
|
|
284
|
+
```powershell
|
|
285
|
+
start htmlcov/index.html
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
## Documentation
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
# Install docs dependencies
|
|
293
|
+
poetry install -E docs
|
|
294
|
+
|
|
295
|
+
# Build HTML docs
|
|
296
|
+
poetry run sphinx-build -b html docs/source docs/build
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Open docs locally:
|
|
301
|
+
|
|
302
|
+
Unix (macOS/Linux):
|
|
303
|
+
|
|
304
|
+
```bash
|
|
305
|
+
open docs/build/index.html
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
Windows (PowerShell):
|
|
309
|
+
|
|
310
|
+
```powershell
|
|
311
|
+
start docs/build/index.html
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
Full online documentation: https://facetpy.readthedocs.io/
|
|
315
|
+
|
|
316
|
+
For comprehensive build instructions, theme configuration, and contribution guidelines see [`docs/README.md`](docs/README.md).
|
|
317
|
+
For PyPI release steps, see [`RELEASING.md`](RELEASING.md).
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
## Project structure
|
|
321
|
+
|
|
322
|
+
```
|
|
323
|
+
src/facet/
|
|
324
|
+
├── core/ Pipeline, Processor, ProcessingContext, BatchResult
|
|
325
|
+
├── io/ Loader, BIDSLoader, EDFExporter, BIDSExporter
|
|
326
|
+
├── preprocessing/ Filters, Resample, TriggerDetector, Alignment, Transforms
|
|
327
|
+
├── correction/ AASCorrection, PCACorrection, ANCCorrection
|
|
328
|
+
├── evaluation/ SNRCalculator, RMSCalculator, MetricsReport, RawPlotter
|
|
329
|
+
├── misc/ EEGGenerator (synthetic data)
|
|
330
|
+
└── pipelines.py create_standard_pipeline() factory
|
|
331
|
+
|
|
332
|
+
examples/
|
|
333
|
+
├── quickstart.py minimal pipeline
|
|
334
|
+
├── evaluation.py metrics & comparison
|
|
335
|
+
├── advanced_workflows.py conditional, parallel, factory
|
|
336
|
+
├── batch_processing.py multiple files
|
|
337
|
+
├── inline_steps.py custom steps & pipe operator
|
|
338
|
+
├── complete_pipeline_example.py full clinical pipeline
|
|
339
|
+
└── eeg_generation_visualization_example.py synthetic EEG
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
## VS Code Tasks
|
|
344
|
+
|
|
345
|
+
Tasks are defined in `.vscode/tasks.json` and can be run via **Ctrl+Shift+P** → **Tasks: Run Task**.
|
|
346
|
+
|
|
347
|
+
| Task | Shortcut | Description |
|
|
348
|
+
|---|---|---|
|
|
349
|
+
| **Test: Run All** | default test task | Full test suite with coverage report |
|
|
350
|
+
| **Test: Run Current File** | | Run pytest on the file open in the editor |
|
|
351
|
+
| **Test: Unit Only** | | Only tests marked `@pytest.mark.unit` |
|
|
352
|
+
| **Test: Integration Only** | | Only tests marked `@pytest.mark.integration` |
|
|
353
|
+
| **Test: Skip Slow** | | All tests except those marked `@pytest.mark.slow` |
|
|
354
|
+
| **Test: Show Coverage Report** | | Open `htmlcov/index.html` in the browser |
|
|
355
|
+
| **Lint: Check (Ruff)** | | Check `src/` and `tests/` for lint errors |
|
|
356
|
+
| **Lint: Fix (Ruff)** | | Auto-fix lint errors in place |
|
|
357
|
+
| **Format: Check (Ruff)** | | Verify formatting without changing files |
|
|
358
|
+
| **Format: Apply (Ruff)** | | Apply ruff formatting to `src/` and `tests/` |
|
|
359
|
+
| **Build: FastRANC C Extension** | | Compile the FastRANC C extension |
|
|
360
|
+
| **Build: Install Dependencies** | | `poetry install` |
|
|
361
|
+
| **Build: Install All Extras** | | `poetry install -E all` |
|
|
362
|
+
| **Build: Update Dependencies** | | `poetry update` |
|
|
363
|
+
| **Docs: Build HTML** | | Build Sphinx documentation |
|
|
364
|
+
| **Docs: Open in Browser** | | Open the built docs in the browser |
|
|
365
|
+
| **Docs: Build & Open** | | Build docs and open immediately |
|
|
366
|
+
| **Run: Current Python File** | | Execute the file open in the editor |
|
|
367
|
+
| **Review: Uncommitted Changes (Codex)** | | Codex AI review of all local changes |
|
|
368
|
+
| **Review: Against Branch (Codex)** | | Codex AI review against a selected base branch (prompts for branch) |
|
|
369
|
+
| **QA: Full Check (Lint + Format + Test)** | | Lint + format check + full test suite in sequence |
|
|
370
|
+
|
|
371
|
+
## License
|
|
372
|
+
|
|
373
|
+
GPLv3 — see `LICENSE` for details.
|
|
374
|
+
|
|
375
|
+
Author: Janik Michael Mueller
|
|
376
|
+
|
facetpy-2.0.0/README.md
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
# FACETpy — fMRI Artifact Correction and Evaluation Toolbox
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<picture>
|
|
5
|
+
<source srcset="docs/source/_static/logo_dark_theme.png" media="(prefers-color-scheme: dark)">
|
|
6
|
+
<img src="docs/source/_static/logo_light_theme.png" width="300" alt="FACETpy logo" />
|
|
7
|
+
</picture>
|
|
8
|
+
</p>
|
|
9
|
+
|
|
10
|
+
[](https://facetpy.readthedocs.io/en/latest/?badge=latest)
|
|
11
|
+
|
|
12
|
+
A Python toolbox for correcting fMRI-induced EEG artifacts using Averaged
|
|
13
|
+
Artifact Subtraction (AAS) and other advanced methods. Built on
|
|
14
|
+
[MNE-Python](https://mne.tools), it provides a modular pipeline
|
|
15
|
+
architecture that lets researchers process, evaluate, and compare correction
|
|
16
|
+
results with minimal code.
|
|
17
|
+
|
|
18
|
+
**Key features**
|
|
19
|
+
|
|
20
|
+
- Load EEG from EDF, GDF, and BIDS formats
|
|
21
|
+
- Artifact correction: AAS, PCA, Adaptive Noise Cancellation (ANC)
|
|
22
|
+
- Full evaluation suite: SNR, RMS, Median Artifact, FFT-based metrics
|
|
23
|
+
- One-call results: `result.print_metrics()`, `result.print_summary()`
|
|
24
|
+
- Batch processing across subjects/sessions with `Pipeline.map()`
|
|
25
|
+
- Generate synthetic EEG for algorithm testing
|
|
26
|
+
- Rich progress display in the terminal
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Quick start
|
|
30
|
+
|
|
31
|
+
Quick installation (requires Python 3.11/3.12/3.13):
|
|
32
|
+
|
|
33
|
+
Unix (macOS/Linux):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
curl -fsSL https://raw.githubusercontent.com/H0mire/facetpy/main/scripts/bootstrap.sh | sh
|
|
37
|
+
cd facetpy
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Windows (PowerShell):
|
|
41
|
+
|
|
42
|
+
```powershell
|
|
43
|
+
git clone https://github.com/H0mire/facetpy.git
|
|
44
|
+
Set-Location facetpy
|
|
45
|
+
poetry install --no-interaction
|
|
46
|
+
```
|
|
47
|
+
<p align="center">
|
|
48
|
+
<img src="docs/source/_static/run_example.png" alt="FACETpy example run" width="700" />
|
|
49
|
+
</p>
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
from facet import (
|
|
54
|
+
Pipeline, Loader, EDFExporter,
|
|
55
|
+
TriggerDetector, UpSample, DownSample, AASCorrection,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
pipeline = Pipeline([
|
|
59
|
+
Loader(path="data.edf", preload=True),
|
|
60
|
+
TriggerDetector(regex=r"\b1\b"),
|
|
61
|
+
UpSample(factor=10),
|
|
62
|
+
AASCorrection(window_size=30),
|
|
63
|
+
DownSample(factor=10),
|
|
64
|
+
EDFExporter(path="corrected.edf", overwrite=True),
|
|
65
|
+
], name="Quickstart")
|
|
66
|
+
|
|
67
|
+
result = pipeline.run()
|
|
68
|
+
result.print_summary() # Done in 4.2s snr=18.3 rms_ratio=0.14
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
Requires **Python 3.11, 3.12, or 3.13** and [Poetry](https://python-poetry.org) >= 1.8.
|
|
75
|
+
Conda is optional, not required.
|
|
76
|
+
|
|
77
|
+
### Option A (PyPI): install from package index
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install facetpy
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The package name on PyPI is `facetpy`; import it in Python as `facet`.
|
|
84
|
+
|
|
85
|
+
### Option B (Unix recommended): bootstrap script
|
|
86
|
+
```bash
|
|
87
|
+
curl -fsSL https://raw.githubusercontent.com/H0mire/facetpy/main/scripts/bootstrap.sh | sh
|
|
88
|
+
cd facetpy
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
This bootstrap script:
|
|
92
|
+
- clones the FACETpy repository into `./facetpy`
|
|
93
|
+
- runs `./scripts/install.sh` inside that clone
|
|
94
|
+
|
|
95
|
+
### Option C (Unix): clone first, then run local installer
|
|
96
|
+
```bash
|
|
97
|
+
git clone https://github.com/H0mire/facetpy.git
|
|
98
|
+
cd facetpy
|
|
99
|
+
./scripts/install.sh
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The script:
|
|
103
|
+
- checks for Python 3.11/3.12/3.13
|
|
104
|
+
- checks whether Poetry is installed
|
|
105
|
+
- asks whether Poetry should be installed if missing
|
|
106
|
+
- runs `poetry install --no-interaction`
|
|
107
|
+
|
|
108
|
+
### Option D (Windows PowerShell): manual install
|
|
109
|
+
|
|
110
|
+
```powershell
|
|
111
|
+
git clone https://github.com/H0mire/facetpy.git
|
|
112
|
+
Set-Location facetpy
|
|
113
|
+
poetry install --no-interaction
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Use Option B/C inside WSL or Git Bash if you want to run the `.sh` installer scripts.
|
|
117
|
+
|
|
118
|
+
### Option E: system Python + Poetry (manual)
|
|
119
|
+
|
|
120
|
+
Unix (macOS/Linux):
|
|
121
|
+
```bash
|
|
122
|
+
# 1 — verify Python
|
|
123
|
+
python3 --version
|
|
124
|
+
|
|
125
|
+
# 2 — install Poetry (pick one)
|
|
126
|
+
pipx install poetry
|
|
127
|
+
# or: python3 -m pip install --user poetry
|
|
128
|
+
|
|
129
|
+
# 3 — install FACETpy and dependencies
|
|
130
|
+
poetry install --no-interaction
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Windows (PowerShell):
|
|
134
|
+
|
|
135
|
+
```powershell
|
|
136
|
+
# 1 — verify Python
|
|
137
|
+
py --version
|
|
138
|
+
|
|
139
|
+
# 2 — install Poetry (pick one)
|
|
140
|
+
pipx install poetry
|
|
141
|
+
# or: py -m pip install --user poetry
|
|
142
|
+
|
|
143
|
+
# 3 — install FACETpy and dependencies
|
|
144
|
+
poetry install --no-interaction
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Option F (optional): Conda workflow
|
|
148
|
+
|
|
149
|
+
Unix (macOS/Linux):
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
conda create -n facetpy python=3.13 -y
|
|
153
|
+
conda activate facetpy
|
|
154
|
+
conda install -c conda-forge poetry -y
|
|
155
|
+
poetry install --no-interaction
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Windows (PowerShell):
|
|
159
|
+
|
|
160
|
+
```powershell
|
|
161
|
+
conda create -n facetpy python=3.13 -y
|
|
162
|
+
conda activate facetpy
|
|
163
|
+
conda install -c conda-forge poetry -y
|
|
164
|
+
poetry install --no-interaction
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Optional extras:
|
|
168
|
+
```text
|
|
169
|
+
poetry install -E deeplearning # TensorFlow-based models
|
|
170
|
+
poetry install -E notebooks # Jupyter notebook support
|
|
171
|
+
poetry install -E gui # PyQt6 GUI components
|
|
172
|
+
poetry install -E docs # Sphinx documentation toolchain
|
|
173
|
+
poetry install -E all # everything above
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Run commands with `poetry run ...` (for example, `poetry run python examples/quickstart.py`).
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
### Build the C extension (optional)
|
|
180
|
+
|
|
181
|
+
The fast Adaptive Noise Cancellation (ANC) step uses a compiled C extension.
|
|
182
|
+
Build it once after installing:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
poetry run build-fastranc
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
If the extension is absent, ANC is skipped automatically and the rest of the
|
|
189
|
+
toolbox works normally.
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
## Running the examples
|
|
193
|
+
|
|
194
|
+
All examples are in the `examples/` folder and use the bundled
|
|
195
|
+
`NiazyFMRI.edf` dataset. Run them from the project root:
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
# Recommended order for new users:
|
|
199
|
+
poetry run python examples/quickstart.py # minimal pipeline
|
|
200
|
+
poetry run python examples/evaluation.py # metrics & comparison
|
|
201
|
+
poetry run python examples/advanced_workflows.py # conditional, parallel, factory
|
|
202
|
+
poetry run python examples/batch_processing.py # multiple files at once
|
|
203
|
+
poetry run python examples/inline_steps.py # custom steps & pipe operator
|
|
204
|
+
poetry run python examples/complete_pipeline_example.py # full clinical pipeline
|
|
205
|
+
poetry run python examples/eeg_generation_visualization_example.py # synthetic EEG
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
## Testing
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Run the full test suite
|
|
213
|
+
poetry run pytest
|
|
214
|
+
|
|
215
|
+
# Only fast unit tests (skip slow integration tests)
|
|
216
|
+
poetry run pytest -m "not slow"
|
|
217
|
+
|
|
218
|
+
# A single test file
|
|
219
|
+
poetry run pytest tests/test_core_pipeline.py -v
|
|
220
|
+
|
|
221
|
+
# With coverage report
|
|
222
|
+
poetry run pytest --cov=facet --cov-report=html
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Open the coverage report:
|
|
226
|
+
|
|
227
|
+
Unix (macOS/Linux):
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
open htmlcov/index.html
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Windows (PowerShell):
|
|
234
|
+
|
|
235
|
+
```powershell
|
|
236
|
+
start htmlcov/index.html
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
## Documentation
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
# Install docs dependencies
|
|
244
|
+
poetry install -E docs
|
|
245
|
+
|
|
246
|
+
# Build HTML docs
|
|
247
|
+
poetry run sphinx-build -b html docs/source docs/build
|
|
248
|
+
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Open docs locally:
|
|
252
|
+
|
|
253
|
+
Unix (macOS/Linux):
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
open docs/build/index.html
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
Windows (PowerShell):
|
|
260
|
+
|
|
261
|
+
```powershell
|
|
262
|
+
start docs/build/index.html
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
Full online documentation: https://facetpy.readthedocs.io/
|
|
266
|
+
|
|
267
|
+
For comprehensive build instructions, theme configuration, and contribution guidelines see [`docs/README.md`](docs/README.md).
|
|
268
|
+
For PyPI release steps, see [`RELEASING.md`](RELEASING.md).
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
## Project structure
|
|
272
|
+
|
|
273
|
+
```
|
|
274
|
+
src/facet/
|
|
275
|
+
├── core/ Pipeline, Processor, ProcessingContext, BatchResult
|
|
276
|
+
├── io/ Loader, BIDSLoader, EDFExporter, BIDSExporter
|
|
277
|
+
├── preprocessing/ Filters, Resample, TriggerDetector, Alignment, Transforms
|
|
278
|
+
├── correction/ AASCorrection, PCACorrection, ANCCorrection
|
|
279
|
+
├── evaluation/ SNRCalculator, RMSCalculator, MetricsReport, RawPlotter
|
|
280
|
+
├── misc/ EEGGenerator (synthetic data)
|
|
281
|
+
└── pipelines.py create_standard_pipeline() factory
|
|
282
|
+
|
|
283
|
+
examples/
|
|
284
|
+
├── quickstart.py minimal pipeline
|
|
285
|
+
├── evaluation.py metrics & comparison
|
|
286
|
+
├── advanced_workflows.py conditional, parallel, factory
|
|
287
|
+
├── batch_processing.py multiple files
|
|
288
|
+
├── inline_steps.py custom steps & pipe operator
|
|
289
|
+
├── complete_pipeline_example.py full clinical pipeline
|
|
290
|
+
└── eeg_generation_visualization_example.py synthetic EEG
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
## VS Code Tasks
|
|
295
|
+
|
|
296
|
+
Tasks are defined in `.vscode/tasks.json` and can be run via **Ctrl+Shift+P** → **Tasks: Run Task**.
|
|
297
|
+
|
|
298
|
+
| Task | Shortcut | Description |
|
|
299
|
+
|---|---|---|
|
|
300
|
+
| **Test: Run All** | default test task | Full test suite with coverage report |
|
|
301
|
+
| **Test: Run Current File** | | Run pytest on the file open in the editor |
|
|
302
|
+
| **Test: Unit Only** | | Only tests marked `@pytest.mark.unit` |
|
|
303
|
+
| **Test: Integration Only** | | Only tests marked `@pytest.mark.integration` |
|
|
304
|
+
| **Test: Skip Slow** | | All tests except those marked `@pytest.mark.slow` |
|
|
305
|
+
| **Test: Show Coverage Report** | | Open `htmlcov/index.html` in the browser |
|
|
306
|
+
| **Lint: Check (Ruff)** | | Check `src/` and `tests/` for lint errors |
|
|
307
|
+
| **Lint: Fix (Ruff)** | | Auto-fix lint errors in place |
|
|
308
|
+
| **Format: Check (Ruff)** | | Verify formatting without changing files |
|
|
309
|
+
| **Format: Apply (Ruff)** | | Apply ruff formatting to `src/` and `tests/` |
|
|
310
|
+
| **Build: FastRANC C Extension** | | Compile the FastRANC C extension |
|
|
311
|
+
| **Build: Install Dependencies** | | `poetry install` |
|
|
312
|
+
| **Build: Install All Extras** | | `poetry install -E all` |
|
|
313
|
+
| **Build: Update Dependencies** | | `poetry update` |
|
|
314
|
+
| **Docs: Build HTML** | | Build Sphinx documentation |
|
|
315
|
+
| **Docs: Open in Browser** | | Open the built docs in the browser |
|
|
316
|
+
| **Docs: Build & Open** | | Build docs and open immediately |
|
|
317
|
+
| **Run: Current Python File** | | Execute the file open in the editor |
|
|
318
|
+
| **Review: Uncommitted Changes (Codex)** | | Codex AI review of all local changes |
|
|
319
|
+
| **Review: Against Branch (Codex)** | | Codex AI review against a selected base branch (prompts for branch) |
|
|
320
|
+
| **QA: Full Check (Lint + Format + Test)** | | Lint + format check + full test suite in sequence |
|
|
321
|
+
|
|
322
|
+
## License
|
|
323
|
+
|
|
324
|
+
GPLv3 — see `LICENSE` for details.
|
|
325
|
+
|
|
326
|
+
Author: Janik Michael Mueller
|