Metadata-Version: 2.4
Name: pylossless
Version: 0.3.0
Summary: Lossless EEG Processing Pipeline Built on MNE and Dash
Home-page: https://github.com/lina-usc/pylossless
Author: Scott Huberty
Author-email: seh33@uw.edu
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=2.2.6
Requires-Dist: mne>=1.7
Requires-Dist: mne_bids>=0.14
Requires-Dist: pandas
Requires-Dist: xarray
Requires-Dist: scipy>=1.7.1
Requires-Dist: mne_icalabel>=0.6.0
Requires-Dist: pyyaml
Requires-Dist: scikit-learn
Requires-Dist: torch
Requires-Dist: edfio
Provides-Extra: dash
Requires-Dist: gunicorn>=19.8.1; extra == "dash"
Requires-Dist: dash>=1.0.0; extra == "dash"
Requires-Dist: plotly>=5.4.0; extra == "dash"
Requires-Dist: dash-extensions>=0.1.7; extra == "dash"
Requires-Dist: colorlover>=0.2.1; extra == "dash"
Requires-Dist: dash_bootstrap_components; extra == "dash"
Provides-Extra: test
Requires-Dist: amica-python; extra == "test"
Requires-Dist: codespell; extra == "test"
Requires-Dist: dash[testing]; extra == "test"
Requires-Dist: numpydoc; extra == "test"
Requires-Dist: pre-commit; extra == "test"
Requires-Dist: pytest; extra == "test"
Requires-Dist: pytest-cov; extra == "test"
Requires-Dist: pydocstyle; extra == "test"
Requires-Dist: ruff; extra == "test"
Requires-Dist: selenium; extra == "test"
Requires-Dist: tomli; python_version < "3.11" and extra == "test"
Requires-Dist: torch; extra == "test"
Requires-Dist: edfio; extra == "test"
Requires-Dist: openneuro-py>=2025.2.0; extra == "test"
Provides-Extra: doc
Requires-Dist: sphinx>=6; extra == "doc"
Requires-Dist: shibuya; extra == "doc"
Requires-Dist: sphinx-design; extra == "doc"
Requires-Dist: sphinx-gallery; extra == "doc"
Requires-Dist: sphinxemoji; extra == "doc"
Requires-Dist: numpydoc; extra == "doc"
Dynamic: author
Dynamic: author-email
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

[![codecov](https://codecov.io/github/lina-usc/pylossless/branch/main/graph/badge.svg?token=SVAD8HTJNG)](https://codecov.io/github/lina-usc/pylossless)

[![Documentation Status](https://readthedocs.org/projects/pylossless/badge/?version=latest)](https://pylossless.readthedocs.io/en/latest/?badge=latest)

![logo](https://github.com/scott-huberty/wip_pipeline-figures/blob/main/logo/Logo_neutral.png)


## Introduction to the Lossless Pipeline

This EEG processing pipeline is especially useful for the following scenarios:

- You want to keep your EEG data in a continuous state, allowing you the flexibility to
  epoch your data at a later stage.
- You are part of a research team or community that shares a common dataset, and you
  want to process the data once in a way that can be used for multiple analyses (i.e.,
  one analysis can segment the cleaned data into 10-second epochs and filter the data
  betweeen 1-30Hz, while another analysis can use 1-second epochs with no filter, etc.)
- You want to be able to do a hands on review of the pre-processing results for each file.

## 📘 Installation and usage instructions

The development version can be installed from GitHub with
```bash
$ git clone git@github.com:lina-usc/pylossless.git
$ pip install --editable ./pylossless
```

for an editable installation, or simply with 
```bash
$ pip install git+https://github.com/lina-usc/pylossless.git
```
for a static version. 

Please find the full documentation at
[**pylossless.readthedocs.io**](https://pylossless.readthedocs.io/en/latest/index.html).


## ▶️ Running the pyLossless Pipeline
Below is a minimal example that runs the pipeline one of MNE's sample files.  
```python
from pathlib import Path
import pylossless as ll 
import mne
import mne_bids
fname = mne.datasets.sample.data_path() / 'MEG' / 'sample' /  'sample_audvis_raw.fif'
raw = mne.io.read_raw_fif(fname, preload=True).pick("eeg")

config = ll.config.Config()
config.load_default()

pipeline = ll.LosslessPipeline(config=config)
pipeline.run_with_raw(raw)
```

Once it is completed, You can see what channels and times were flagged:
```python
print(pipeline.flags['ch']
print(pipeline.flags['epoch']
```

Once you are ready, you can save your file in its lossless state:
```python
bpath = mne_bids.BIDSPath(root=Path.cwd(), subject="sample", task="audvis")
pipeline.save(pipeline.get_derivative_path(bids_path), overwrite=True)
```

To get a **cleaned** version, you can use a `RejectionPolicy` object to apply
these annotations to your raw object. This is a lossy operation:
```python
rejection_policy = ll.RejectionPolicy()
cleaned_raw = rejection_policy.apply(pipeline)
```

## 👩‍💻 Dashboard Review
[![Open in Colab](https://camo.githubusercontent.com/84f0493939e0c4de4e6dbe113251b4bfb5353e57134ffd9fcab6b8714514d4d1/68747470733a2f2f636f6c61622e72657365617263682e676f6f676c652e636f6d2f6173736574732f636f6c61622d62616467652e737667)](https://colab.research.google.com/github/lina-usc/pylossless/blob/main/notebooks/qc_example.ipynb)

![QCR Dashboard](https://raw.githubusercontent.com/scott-huberty/wip_pipeline-figures/main/dashboard.png)

After running the Lossless pipeline, you can launch the Quality Control
Review (QC) dashboard to review the pipeline's decisions on each file!
You can flag additional channels, times and components, and edit flags
made by the pipeline.

First install the dashboard requirements
```bash
$ cd ./path/to/pylossless/on/your/computer
$ pip install --editable .[dash]
```

```bash
$ pylossless_qc
```

## ▶️ Example HPC Environment Setup

If you are a Canadian researcher working on an HPC system such as [Narval](https://docs.alliancecan.ca/wiki/Narval/en):

```bash
module load python/3.10

# Build the virtualenv in your homedir
cd ~
virtualenv --no-download eeg-env
source eeg-env/bin/activate

pip install --no-index mne
pip install --no-index pandas
pip install --no-index xarray
pip install --no-index pyyaml
pip install --no-index sklearn
pip install mne_bids
pip install edfio
pip install openneuro-py

pip install mne-icalabel

pip install --no-deps pylossless

# Verify that the package has installed correct with an import
python -c 'import pylossless'
```
