Metadata-Version: 2.4
Name: biosigio
Version: 1.1.3
Summary: A unified interface to import, convert, and serve biosignal data (EEG, EMG, MEG, iEEG) across formats, including EDF/BDF, EEGLAB, BrainVision, FIF, and a cloud-native Zarr serving store
Author-email: Seyed Yahya Shirazi <shirazi@ieee.org>
Maintainer-email: Seyed Yahya Shirazi <shirazi@ieee.org>
License: BSD 3-Clause License
        
        Copyright (c) 2024, Swartz Center for Computational Neuroscience
        All rights reserved.
        
        Redistribution and use in source and binary forms, with or without
        modification, are permitted provided that the following conditions are met:
        
        1. Redistributions of source code must retain the above copyright notice, this
           list of conditions and the following disclaimer.
        
        2. Redistributions in binary form must reproduce the above copyright notice,
           this list of conditions and the following disclaimer in the documentation
           and/or other materials provided with the distribution.
        
        3. Neither the name of the copyright holder nor the names of its
           contributors may be used to endorse or promote products derived from
           this software without specific prior written permission.
        
        THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
        AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
        IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
        DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
        FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
        DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
        SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
        CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
        OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
        OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
        
Project-URL: Homepage, https://github.com/neuromechanist/biosigio
Project-URL: Documentation, https://neuromechanist.github.io/biosigio/
Project-URL: Repository, https://github.com/neuromechanist/biosigio
Project-URL: Issues, https://github.com/neuromechanist/biosigio/issues
Project-URL: Changelog, https://github.com/neuromechanist/biosigio/releases
Keywords: biosignal,electrophysiology,eeg,emg,electromyography,meg,ieeg,eeglab,edf,bdf,brainvision,wfdb,trigno,delsys,zarr,bids,neuroscience,signal-processing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Healthcare Industry
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.20.0
Requires-Dist: pandas>=1.3.0
Requires-Dist: scipy>=1.7.0
Requires-Dist: matplotlib>=3.4.0
Requires-Dist: pyedflib>=0.1.30
Requires-Dist: wfdb>=4.0.0
Requires-Dist: pyxdf>=1.16.0
Provides-Extra: meg
Requires-Dist: mne>=1.6; extra == "meg"
Provides-Extra: arrow
Requires-Dist: pyarrow>=14; extra == "arrow"
Provides-Extra: neo
Requires-Dist: neo>=0.13; extra == "neo"
Provides-Extra: zarr
Requires-Dist: zarr>=3; extra == "zarr"
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: ruff>=0.14; extra == "dev"
Requires-Dist: ty; extra == "dev"
Requires-Dist: mne>=1.6; extra == "dev"
Requires-Dist: pyarrow>=14; extra == "dev"
Requires-Dist: neo>=0.13; extra == "dev"
Requires-Dist: zarr>=3; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.6.0; extra == "docs"
Requires-Dist: mkdocs-material>=9.5.0; extra == "docs"
Requires-Dist: mkdocstrings[python]>=1.0.0; extra == "docs"
Requires-Dist: pymdown-extensions>=10.10.0; extra == "docs"
Requires-Dist: mkdocs-jupyter>=0.25.0; extra == "docs"
Requires-Dist: mike>=2.1.0; extra == "docs"
Provides-Extra: all
Requires-Dist: biosigio[arrow,dev,docs,meg,neo,zarr]; extra == "all"
Dynamic: license-file

# biosigIO

[![PyPI version](https://badge.fury.io/py/biosigio.svg)](https://badge.fury.io/py/biosigio)
[![Tests](https://github.com/neuromechanist/biosigio/actions/workflows/tests.yml/badge.svg)](https://github.com/neuromechanist/biosigio/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/neuromechanist/biosigio/branch/main/graph/badge.svg?token=63EDIA9TWD)](https://codecov.io/gh/neuromechanist/biosigio)

A Python package for biosignal import/export and manipulation across modalities (EEG, EMG, iEEG, MEG, and behavioral/marker streams). biosigIO provides a unified `Recording` interface for loading data from many acquisition systems and archives (EEGLAB, Delsys Trigno, OTB, EDF/BDF, WFDB, XDF, MEG/CTF and BrainVision via MNE, and proprietary electrophysiology such as Intan/Blackrock via python-neo) and exporting it to standardized and serving formats (EDF/BDF, Parquet, Arrow, Zarr) with harmonized metadata.

The determination of the EDF/BDF format is based on the dynamic range of the data. If the data is within the range of 16-bit integers (~90dB), the EDF format is used. Otherwise, the BDF format is used. This is to ensure that the data is stored in the most efficient format possible. This determination is made automatically using SVD decomposition and/or FFT to determine the dynamic range of the data. (Alternatively, the user can override the format selection by explicitly indicating their desired format).

## Documentation

The documentation including installation instructions, examples, and API reference is available at [https://neuromechanist.github.io/biosigio/](https://neuromechanist.github.io/biosigio/).

## Features

- Import biosignal recordings from many systems and archives:
  - EEGLAB set files (supported)
  - Delsys Trigno (supported)
  - OTB Systems (supported)
  - EDF/BDF(+) (supported, including annotations)
  - WFDB (supported, including annotations)
  - XDF/Lab Streaming Layer (supported, multi-stream)
  - MEG: `.fif` and CTF `.ds` via MNE (supported; `meg` extra)
  - BrainVision `.vhdr` via MNE (supported; `meg` extra)
  - Proprietary electrophysiology via python-neo: Intan, Blackrock, Spike2, Plexon, Micromed, Neuralynx (supported; `neo` extra)
  - Generic CSV (supported with auto-detection)
  - Noraxon (planned)
  
- Smart import:
  - Automatic file format detection based on extension
  - Specialized format detection for CSV files
  - Custom importers for system-specific formats
  - Automatic annotation/event loading (WFDB, EDF+/BDF+, and EEGLAB .set) into the events table, embedded back on EDF+/BDF+ export and carried in the Parquet/Arrow/Zarr serialization formats
  - LSL timestamp preservation for XDF files (for synchronization)
  
- Export to standardized formats:
  - EDF/BDF(+) with channels.tsv metadata (automatically selects format based on signal properties, preserves annotations)

- Serialization & serving (see [docs](https://neuromechanist.github.io/biosigio/formats/serialization/)):
  - Parquet and Arrow/Feather: lossless columnar round-trip (analytics, fast IPC); requires the `arrow` extra
  - Zarr: cloud-native serving store (one store serves viewing, inference, and training), a derived downsampled copy; requires the `zarr` extra
  
- Data manipulation:
  - Channel selection
  - Metadata handling
  - Event/Annotation handling (access, add)
  - Basic signal visualization
  - Raw data access and modification

## Installation

biosigIO uses [UV](https://docs.astral.sh/uv/) for Python environment and package management.

### From PyPI (recommended)

```bash
uv pip install biosigio
```

(If your own project is uv-managed, use `uv add biosigio` to track it as a dependency.)

### From source

```bash
git clone https://github.com/neuromechanist/biosigio.git
cd biosigio
uv pip install .
```

## Usage

### Basic Example

```python
from biosigio import Recording

# Load data with automatic format detection
rec = Recording.from_file('data.csv')  # Format detected from file extension

# Load data with explicit importer
rec = Recording.from_file('data.csv', importer='trigno')

# Plot specific channels
rec.plot_signals(['EMG1', 'EMG2'])

# Export to EDF or BDF (format automatically determined)
rec.to_edf('output.edf')
```

### Generic CSV Import

```python
# Import a generic CSV file
rec = Recording.from_file('data.csv', importer='csv',
                   sample_frequency=1000,  # Required if no time column
                   has_header=True,        # Whether file has header row
                   channel_names=['EMG_L', 'EMG_R', 'ACC_X'])
```

### Channel Selection

```python
# Select specific channels
subset_emg = rec.select_channels(['EMG1', 'EMG2', 'ACC1'])

# Select all channels of a specific type
emg_only = rec.select_channels(channel_type='EMG')

# Plot selected channels
subset_emg.plot_signals()
```

### Metadata Handling

```python
# Set metadata
rec.set_metadata('subject', 'S001')
rec.set_metadata('condition', 'resting')

# Get metadata
subject = rec.get_metadata('subject')
```

## Development

### Setup

1. Clone the repository:
```bash
git clone https://github.com/neuromechanist/biosigio.git
cd biosigio
```

2. Install for development (editable install with dev dependencies):
```bash
uv sync --extra dev
```

### Running Tests

```bash
uv run pytest
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

## Acknowledgment
This project is partially supported by a Meta Reality Labs gift to @sccn and NIH 5R01NS047293.
