pyEDFlib

repository·master·Indexed 42 days ago

https://github.com/holgern/pyedflib

A Python library for reading and writing EDF+, BDF+, EDF, and BDF files. It serves as a Python wrapper around the C-based EDFlib, providing low-level access via EdfReader and EdfWriter, as well as a high-level interface for tasks such as anonymization, channel manipulation, and signal polarity changes.

Tokens
4.5K
Snippets
26
Records
39
Agent score
52%

What's inside pyEDFlib

  1. Use pyedflib.highlevel functions for EDF/BDF manipulation

    master
    The pyedflib.highlevel module provides a set of convenient functions for common EDF (European Data Format) and BDF (BioSemi Data Format) tasks. These functions abstract away the low-level complexities of managing headers, signals, and file structures, allowing you to perform operations like reading, writing, renaming, or anonymizing files with single function calls.
  2. Use the pyEDFlib highlevel interface

    master

    The pyedflib.highlevel module provides an easy-to-use interface for common EDF/BDF file operations, including reading, writing, and modifying files without managing low-level buffers manually.

    from pyedflib import highlevel
    
    # Example usage of highlevel functions
    # (See specific records for detailed task examples)
  3. Install build dependencies via pip

    master

    To build pyEDFlib from source, you need to install several build-time dependencies using pip:

    • Cython: Required for compiling C extensions. Requires version 0.16 or higher.
    • numpy: Required for numerical operations.
    • Sphinx: Used for generating documentation.
    • numpydoc: Used to format API documentation.
    pip install Cython>=0.16
    pip install numpy
    pip install Sphinx
    pip install numpydoc
  4. Prepare the Windows build environment for pyedflib

    master

    To develop pyedflib on Windows, you must install a C compiler and configure the build environment. The primary requirement is the Microsoft Visual C++ Compiler.

    Installing Microsoft Visual C++ Compiler

    Download and install the compiler from the official Microsoft website: https://visualstudio.microsoft.com/downloads/

    Next steps

    Once the compiler is installed, proceed to installing the necessary build dependencies.

  5. Install PyEDFlib from source code

    master

    To build and install PyEDFlib from the source code, clone the repository and use pip install . within your Python virtual environment. You can also install specific optional dependency groups using the --group flag.

    Optional dependency groups:

    • test: Installs test dependencies.
    • docs: Installs documentation dependencies.
    • dev: Installs all development dependencies.
    # Clone the repository
    git clone https://github.com/holgern/pyedflib.git pyedflib
    
    # Navigate to the directory and install
    cd pyedflib
    pip install .
    
    # Install with specific groups
    pip install --group test .
    pip install --group docs .
    pip install --group dev .
    
    # Verify installation
    python -m pytest
  6. Set up pre-commit hooks for code quality

    master

    The project uses pre-commit to enforce code quality, including ruff for linting/formatting and various pre-commit-hooks (e.g., trailing whitespace, end-of-file fixer).

    To set up the hooks so they run automatically during git commit:

    1. Install the pre-commit package via pip.
    2. Install the git hooks using the pre-commit install command.

    To run all hooks manually against all files in the repository, use pre-commit run -a.

    # 1. Install pre-commit
    $ pip install pre-commit
    
    # 2. Install git hooks
    $ pre-commit install
    
    # 3. Run hooks manually on all files
    $ pre-commit run -a
  7. Install pyEDFlib

    master

    pyEDFlib requires Python >= 3.9 and the Numpy package. You can install it using several methods:

    Via pip (Binary Wheels)

    For most users, install the pre-built binary wheels:

    pip install pyEDFlib

    Via pip (From Source)

    To use the newest source code from git, download the source and run:

    pip install .

    Note: This requires a C compiler and Cython (which pip will install automatically).

    Via Conda

    Users of Anaconda can install pre-built binaries from the conda-forge channel:

    conda install -c conda-forge pyedflib
    pip install pyEDFlib
  8. Install PyEDFlib from source on Windows

    master

    When installing from source on Windows, you must have the Microsoft Visual C++ Compiler installed (available at https://visualstudio.microsoft.com/downloads/).

    Use pip install -e . to perform an editable installation from the cloned source directory.

    # Clone the repository
    git clone https://github.com/holgern/pyedflib.git pyedflib
    
    # Install Microsoft Visual C++ Compiler first
    
    # Navigate to the directory and install in editable mode
    cd pyedflib
    pip install -e .
    
    # Verify installation
    python -m pytest
  9. Run tests locally with pytest

    master

    Tests for pyedflib are implemented using pytest. You can run the test suite from the command line using the pytest command, or by calling the pyedflib.test() function within a Python environment. Note that running doctests requires Matplotlib to be installed in addition to the standard dependencies.

    $ pytest
    # Alternatively, via Python
    pyedflib.test()