eeglab-plugin-biopac 1.1__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.
@@ -0,0 +1,25 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2024, Swartz Center for Computational Neuroscience
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25
+ THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: eeglab_plugin_biopac
3
+ Version: 1.1
4
+ Summary: Import BIOPAC AcqKnowledge MATLAB data files into EEGPrep (Python version of the EEGLAB biopac plugin)
5
+ Author-email: Arnaud Delorme <eeglab@sccn.ucsd.edu>
6
+ License-Expression: BSD-2-Clause
7
+ Project-URL: Repository, https://github.com/sccn/eeglab_plugin_biopac
8
+ Requires-Python: >=3.12
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: eegprep>=0.6.0
12
+ Requires-Dist: numpy
13
+ Requires-Dist: scipy
14
+ Provides-Extra: test
15
+ Requires-Dist: pytest; extra == "test"
16
+ Dynamic: license-file
17
+
18
+ # biopac: import BIOPAC MATLAB files into EEGLAB and EEGPrep
19
+
20
+ This repository holds the same plugin for the two platforms:
21
+
22
+ - **EEGLAB (MATLAB)**: the `.m` files at the root of the repository.
23
+ - **EEGPrep (Python)**: the package `eeglab_plugin_biopac`.
24
+
25
+ Both import the MATLAB (`.mat`) file that BIOPAC AcqKnowledge writes with
26
+ "Save as" and the MATLAB format. The file holds the variables `data`, `labels`,
27
+ `isi` (the sample interval) and `isi_units`. To import BIOPAC `.acq` files,
28
+ use BIOSIG in both platforms.
29
+
30
+ ## EEGLAB
31
+
32
+ Install "biopac" from the EEGLAB plugin manager (File > Manage EEGLAB extensions),
33
+ or copy this folder into the `plugins` folder of EEGLAB.
34
+
35
+ ```matlab
36
+ EEG = pop_biopac('recording.mat');
37
+ ```
38
+
39
+ Menu: File > Import data > From BIOPAC MATLAB files.
40
+
41
+ ## EEGPrep
42
+
43
+ Install "biopac" from the EEGPrep plugin manager, or with pip:
44
+
45
+ ```bash
46
+ pip install eeglab_plugin_biopac
47
+ ```
48
+
49
+ ```python
50
+ from eeglab_plugin_biopac import pop_biopac
51
+
52
+ EEG = pop_biopac("recording.mat")
53
+ ```
54
+
55
+ Menu: File > Import data > From BIOPAC MATLAB files.
56
+
57
+ ## The two versions give the same dataset
58
+
59
+ `tests/data/biopac_export_2s.mat` is a real AcqKnowledge export (see
60
+ `tests/data/README.md`). `tests/test_pop_biopac.m` checks the MATLAB function on
61
+ it. `tests/make_matlab_reference.m` saves what MATLAB returns, and
62
+ `tests/test_pop_biopac.py` checks that the Python function returns the same
63
+ sampling rate, sizes, labels, time axis and data.
64
+
65
+ ```bash
66
+ pip install -e ".[test]"
67
+ pytest
68
+ ```
69
+
70
+ ## Versions
71
+
72
+ - 1.1: `pop_biopac` returns a complete dataset (it calls `eeg_checkset`), removes
73
+ the null characters AcqKnowledge pads the labels with, and refuses an unknown
74
+ `isi_units`. First Python version.
75
+ - 1.00: first MATLAB version (2011).
76
+
77
+ ## Licence
78
+
79
+ BSD 2-Clause, the licence of EEGLAB (see `LICENSE`).
@@ -0,0 +1,62 @@
1
+ # biopac: import BIOPAC MATLAB files into EEGLAB and EEGPrep
2
+
3
+ This repository holds the same plugin for the two platforms:
4
+
5
+ - **EEGLAB (MATLAB)**: the `.m` files at the root of the repository.
6
+ - **EEGPrep (Python)**: the package `eeglab_plugin_biopac`.
7
+
8
+ Both import the MATLAB (`.mat`) file that BIOPAC AcqKnowledge writes with
9
+ "Save as" and the MATLAB format. The file holds the variables `data`, `labels`,
10
+ `isi` (the sample interval) and `isi_units`. To import BIOPAC `.acq` files,
11
+ use BIOSIG in both platforms.
12
+
13
+ ## EEGLAB
14
+
15
+ Install "biopac" from the EEGLAB plugin manager (File > Manage EEGLAB extensions),
16
+ or copy this folder into the `plugins` folder of EEGLAB.
17
+
18
+ ```matlab
19
+ EEG = pop_biopac('recording.mat');
20
+ ```
21
+
22
+ Menu: File > Import data > From BIOPAC MATLAB files.
23
+
24
+ ## EEGPrep
25
+
26
+ Install "biopac" from the EEGPrep plugin manager, or with pip:
27
+
28
+ ```bash
29
+ pip install eeglab_plugin_biopac
30
+ ```
31
+
32
+ ```python
33
+ from eeglab_plugin_biopac import pop_biopac
34
+
35
+ EEG = pop_biopac("recording.mat")
36
+ ```
37
+
38
+ Menu: File > Import data > From BIOPAC MATLAB files.
39
+
40
+ ## The two versions give the same dataset
41
+
42
+ `tests/data/biopac_export_2s.mat` is a real AcqKnowledge export (see
43
+ `tests/data/README.md`). `tests/test_pop_biopac.m` checks the MATLAB function on
44
+ it. `tests/make_matlab_reference.m` saves what MATLAB returns, and
45
+ `tests/test_pop_biopac.py` checks that the Python function returns the same
46
+ sampling rate, sizes, labels, time axis and data.
47
+
48
+ ```bash
49
+ pip install -e ".[test]"
50
+ pytest
51
+ ```
52
+
53
+ ## Versions
54
+
55
+ - 1.1: `pop_biopac` returns a complete dataset (it calls `eeg_checkset`), removes
56
+ the null characters AcqKnowledge pads the labels with, and refuses an unknown
57
+ `isi_units`. First Python version.
58
+ - 1.00: first MATLAB version (2011).
59
+
60
+ ## Licence
61
+
62
+ BSD 2-Clause, the licence of EEGLAB (see `LICENSE`).
@@ -0,0 +1,5 @@
1
+ """Import BIOPAC AcqKnowledge MATLAB exports into EEGPrep."""
2
+
3
+ from eeglab_plugin_biopac.pop_biopac import pop_biopac
4
+
5
+ __all__ = ["pop_biopac"]
@@ -0,0 +1,15 @@
1
+ {
2
+ "manifest_version": 1,
3
+ "name": "biopac",
4
+ "display_name": "BIOPAC",
5
+ "description": "Import BIOPAC AcqKnowledge MATLAB data files. Use BIOSIG to import BIOPAC .ACQ files.",
6
+ "functions": [
7
+ {
8
+ "name": "pop_biopac",
9
+ "target": "eeglab_plugin_biopac.pop_biopac:pop_biopac",
10
+ "menu": ["File", "Import data"],
11
+ "label": "From BIOPAC MATLAB files",
12
+ "kind": "import"
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,26 @@
1
+ # pop_biopac
2
+
3
+ Import a BIOPAC AcqKnowledge MATLAB (`.mat`) export.
4
+
5
+ ## Usage
6
+
7
+ ```python
8
+ EEG = pop_biopac("recording.mat")
9
+ EEG, com = pop_biopac("recording.mat", return_com=True)
10
+ ```
11
+
12
+ In the EEGPrep window: **File > Import data > From BIOPAC MATLAB files**.
13
+
14
+ ## Input
15
+
16
+ `filename` is a file saved from AcqKnowledge with "Save as" and the MATLAB
17
+ format. It holds the variables `data`, `labels`, `isi` (the sample interval)
18
+ and `isi_units` (`ms` or `s`).
19
+
20
+ ## Output
21
+
22
+ An EEG dataset with one channel per column of `data`, the channel labels of
23
+ the file and the sampling rate computed from the sample interval. The data
24
+ keep the unit of the recording. Nothing is rescaled.
25
+
26
+ BIOPAC `.acq` files are not read by this function. Use `pop_biosig` for them.
@@ -0,0 +1,48 @@
1
+ """Python port of pop_biopac.m (same repository)."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Any
7
+
8
+ import numpy as np
9
+ import scipy.io as sio
10
+ from eegprep.functions.adminfunc.eeg_checkset import eeg_checkset
11
+ from eegprep.functions.popfunc.eeg_emptyset import eeg_emptyset
12
+
13
+ # Samples per second for one sample interval (isi) of 1 in each unit AcqKnowledge writes.
14
+ _SAMPLES_PER_SECOND = {"ms": 1000.0, "s": 1.0}
15
+
16
+
17
+ def pop_biopac(filename: str | Path, *, return_com: bool = False) -> dict[str, Any] | tuple[dict[str, Any], str]:
18
+ """Import a BIOPAC AcqKnowledge MATLAB (.mat) export.
19
+
20
+ Args:
21
+ filename: File saved from AcqKnowledge with "Save as" and the MATLAB
22
+ format. It holds the variables ``data`` (samples by channels),
23
+ ``labels``, ``isi`` (sample interval) and ``isi_units``.
24
+ return_com: Also return the command that repeats this import.
25
+
26
+ Returns:
27
+ The EEG dataset, or ``(EEG, command)`` with ``return_com``.
28
+
29
+ Notes:
30
+ The data keep the unit of the recording (``units`` in the file); nothing
31
+ is rescaled. BIOPAC ``.acq`` files are read with ``pop_biosig`` instead.
32
+ """
33
+ export = sio.loadmat(str(filename))
34
+ unit = str(np.squeeze(export["isi_units"])).lower()
35
+ if unit not in _SAMPLES_PER_SECOND:
36
+ raise ValueError(f"Unknown unit {unit!r} for the sample interval (isi_units)")
37
+
38
+ EEG = eeg_emptyset()
39
+ EEG["data"] = np.ascontiguousarray(export["data"].T)
40
+ # AcqKnowledge pads the labels with null characters; MATLAB's deblank removes those and trailing blanks.
41
+ EEG["chanlocs"] = [{"labels": str(label).rstrip(" \t\r\n\x00")} for label in export["labels"]]
42
+ EEG["srate"] = _SAMPLES_PER_SECOND[unit] / float(np.squeeze(export["isi"]))
43
+ EEG["nbchan"], EEG["pnts"] = EEG["data"].shape
44
+ EEG["trials"] = 1
45
+ EEG = eeg_checkset(EEG)
46
+
47
+ command = f"EEG = pop_biopac('{filename}');"
48
+ return (EEG, command) if return_com else EEG
@@ -0,0 +1,79 @@
1
+ Metadata-Version: 2.4
2
+ Name: eeglab_plugin_biopac
3
+ Version: 1.1
4
+ Summary: Import BIOPAC AcqKnowledge MATLAB data files into EEGPrep (Python version of the EEGLAB biopac plugin)
5
+ Author-email: Arnaud Delorme <eeglab@sccn.ucsd.edu>
6
+ License-Expression: BSD-2-Clause
7
+ Project-URL: Repository, https://github.com/sccn/eeglab_plugin_biopac
8
+ Requires-Python: >=3.12
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: eegprep>=0.6.0
12
+ Requires-Dist: numpy
13
+ Requires-Dist: scipy
14
+ Provides-Extra: test
15
+ Requires-Dist: pytest; extra == "test"
16
+ Dynamic: license-file
17
+
18
+ # biopac: import BIOPAC MATLAB files into EEGLAB and EEGPrep
19
+
20
+ This repository holds the same plugin for the two platforms:
21
+
22
+ - **EEGLAB (MATLAB)**: the `.m` files at the root of the repository.
23
+ - **EEGPrep (Python)**: the package `eeglab_plugin_biopac`.
24
+
25
+ Both import the MATLAB (`.mat`) file that BIOPAC AcqKnowledge writes with
26
+ "Save as" and the MATLAB format. The file holds the variables `data`, `labels`,
27
+ `isi` (the sample interval) and `isi_units`. To import BIOPAC `.acq` files,
28
+ use BIOSIG in both platforms.
29
+
30
+ ## EEGLAB
31
+
32
+ Install "biopac" from the EEGLAB plugin manager (File > Manage EEGLAB extensions),
33
+ or copy this folder into the `plugins` folder of EEGLAB.
34
+
35
+ ```matlab
36
+ EEG = pop_biopac('recording.mat');
37
+ ```
38
+
39
+ Menu: File > Import data > From BIOPAC MATLAB files.
40
+
41
+ ## EEGPrep
42
+
43
+ Install "biopac" from the EEGPrep plugin manager, or with pip:
44
+
45
+ ```bash
46
+ pip install eeglab_plugin_biopac
47
+ ```
48
+
49
+ ```python
50
+ from eeglab_plugin_biopac import pop_biopac
51
+
52
+ EEG = pop_biopac("recording.mat")
53
+ ```
54
+
55
+ Menu: File > Import data > From BIOPAC MATLAB files.
56
+
57
+ ## The two versions give the same dataset
58
+
59
+ `tests/data/biopac_export_2s.mat` is a real AcqKnowledge export (see
60
+ `tests/data/README.md`). `tests/test_pop_biopac.m` checks the MATLAB function on
61
+ it. `tests/make_matlab_reference.m` saves what MATLAB returns, and
62
+ `tests/test_pop_biopac.py` checks that the Python function returns the same
63
+ sampling rate, sizes, labels, time axis and data.
64
+
65
+ ```bash
66
+ pip install -e ".[test]"
67
+ pytest
68
+ ```
69
+
70
+ ## Versions
71
+
72
+ - 1.1: `pop_biopac` returns a complete dataset (it calls `eeg_checkset`), removes
73
+ the null characters AcqKnowledge pads the labels with, and refuses an unknown
74
+ `isi_units`. First Python version.
75
+ - 1.00: first MATLAB version (2011).
76
+
77
+ ## Licence
78
+
79
+ BSD 2-Clause, the licence of EEGLAB (see `LICENSE`).
@@ -0,0 +1,14 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ eeglab_plugin_biopac/__init__.py
5
+ eeglab_plugin_biopac/eeglab_plugin.json
6
+ eeglab_plugin_biopac/pop_biopac.py
7
+ eeglab_plugin_biopac.egg-info/PKG-INFO
8
+ eeglab_plugin_biopac.egg-info/SOURCES.txt
9
+ eeglab_plugin_biopac.egg-info/dependency_links.txt
10
+ eeglab_plugin_biopac.egg-info/entry_points.txt
11
+ eeglab_plugin_biopac.egg-info/requires.txt
12
+ eeglab_plugin_biopac.egg-info/top_level.txt
13
+ eeglab_plugin_biopac/help/pop_biopac.md
14
+ tests/test_pop_biopac.py
@@ -0,0 +1,2 @@
1
+ [eeglab.plugins]
2
+ biopac = eeglab_plugin_biopac:eeglab_plugin.json
@@ -0,0 +1,6 @@
1
+ eegprep>=0.6.0
2
+ numpy
3
+ scipy
4
+
5
+ [test]
6
+ pytest
@@ -0,0 +1 @@
1
+ eeglab_plugin_biopac
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "eeglab_plugin_biopac"
7
+ version = "1.1"
8
+ description = "Import BIOPAC AcqKnowledge MATLAB data files into EEGPrep (Python version of the EEGLAB biopac plugin)"
9
+ readme = "README.md"
10
+ requires-python = ">=3.12"
11
+ license = "BSD-2-Clause"
12
+ license-files = ["LICENSE"]
13
+ authors = [{ name = "Arnaud Delorme", email = "eeglab@sccn.ucsd.edu" }]
14
+ dependencies = [
15
+ "eegprep>=0.6.0",
16
+ "numpy",
17
+ "scipy",
18
+ ]
19
+
20
+ [project.optional-dependencies]
21
+ test = ["pytest"]
22
+
23
+ [project.urls]
24
+ Repository = "https://github.com/sccn/eeglab_plugin_biopac"
25
+
26
+ # The manifest EEGPrep reads to add the plugin's menu and function.
27
+ [project.entry-points."eeglab.plugins"]
28
+ biopac = "eeglab_plugin_biopac:eeglab_plugin.json"
29
+
30
+ # The MATLAB plugin sits at the root of this repository: name the Python package explicitly.
31
+ [tool.setuptools]
32
+ packages = ["eeglab_plugin_biopac"]
33
+
34
+ [tool.setuptools.package-data]
35
+ eeglab_plugin_biopac = ["eeglab_plugin.json", "help/*.md"]
36
+
37
+ [tool.pytest.ini_options]
38
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,51 @@
1
+ """pop_biopac against MATLAB on a real AcqKnowledge export, and its registration in EEGPrep."""
2
+
3
+ from importlib import metadata
4
+ from pathlib import Path
5
+
6
+ import numpy as np
7
+ import pytest
8
+ import scipy.io as sio
9
+ from eegprep.extensions import ExtensionRegistry, ExtensionStatus
10
+
11
+ from eeglab_plugin_biopac import pop_biopac
12
+
13
+ DATA = Path(__file__).parent / "data"
14
+ EXPORT = DATA / "biopac_export_2s.mat"
15
+
16
+
17
+ def test_same_dataset_as_matlab():
18
+ """tests/data/matlab_reference.mat is what pop_biopac.m returns (tests/make_matlab_reference.m)."""
19
+ ref = sio.loadmat(DATA / "matlab_reference.mat", squeeze_me=True)
20
+
21
+ EEG, com = pop_biopac(EXPORT, return_com=True)
22
+
23
+ for field in ("srate", "nbchan", "pnts", "trials", "xmin", "xmax"):
24
+ assert EEG[field] == pytest.approx(ref[field], rel=0, abs=1e-12), field
25
+ assert [chan["labels"] for chan in EEG["chanlocs"]] == list(ref["labels"])
26
+ # MATLAB keeps the data in single precision (option_single)
27
+ np.testing.assert_array_equal(np.asarray(EEG["data"], dtype=np.float32), ref["data"].astype(np.float32))
28
+ np.testing.assert_allclose(EEG["times"], ref["times"], rtol=0, atol=1e-9)
29
+ assert com == f"EEG = pop_biopac('{EXPORT}');"
30
+
31
+
32
+ def test_unknown_sample_interval_unit_is_refused(tmp_path):
33
+ export = sio.loadmat(EXPORT)
34
+ export["isi_units"] = "min"
35
+ sio.savemat(tmp_path / "minutes.mat", {k: v for k, v in export.items() if not k.startswith("__")})
36
+
37
+ with pytest.raises(ValueError, match="isi_units"):
38
+ pop_biopac(tmp_path / "minutes.mat")
39
+
40
+
41
+ def test_installed_plugin_is_found_by_eegprep():
42
+ registry = ExtensionRegistry(include_bundled=False)
43
+ registry.discover()
44
+ record = registry.get("biopac")
45
+
46
+ assert record is not None and record.status == ExtensionStatus.INSTALLED, record and record.errors
47
+ assert record.spec.version == metadata.version("eeglab_plugin_biopac")
48
+ assert [(menu.path, menu.label, menu.action) for menu in record.spec.menus] == [
49
+ (("File", "Import data"), "From BIOPAC MATLAB files", "pop_biopac")
50
+ ]
51
+ assert "import" in record.spec.help_resources[0].read_text().lower()