Skip to content

lmascelli/pycode

Repository files navigation

Spike-rs

Introduction

The goal of this project is to provide a fast library for the computational part of the analysis, like the conversion of the ADC data, the spikes detection and any sort of operation with data that requires iterating through them. The core of the library is written in Rust but it’s then wrapped in a Python module to be easily used in an analisys workflow.

At the moment no GUI is provided with the library but a collection of example scripts will be provided to be modified as needed.

Structure of the project

The library itself it’s composed of three components:

  • spike-rs: written in Rust, a modern and safe alternative to C/C++ that provide the same performance but also avoids some common mistakes and provides nice compilation errors. Almost all the code is build just on standard library.
  • c_pycode: written in pure C, it’s responsible for all the operations on I/O with the stored data. It’s linked with the hdf5 library.
  • pycode: That’s the actual python library that wraps the C and Rust functions. For the creation of the Python wrapper an external dependency PyO3 is being used.

Build instruction

Requirements

To build the library you’ll need:

  • the rust toolchain installed: Rust download
  • a C compiler compatible with the hdf5 library (usually MSVC on Windows and gcc on Linux)
  • hdf5 library: hdf5 download (unzip it in a folder: you’ll need that path later)
  • a python interpreter
  • the LLVM suite is also needed for the automatic traslation of the C part of the library to a Rust module via bindgen

Windows Installing the Rust toolchain should be enough to get bot the rust and the c tools needed. There are several python distribution like WinPython]] or Anaconda. Choose the one you prefer. LLVM can be downloaded from the official site https://releases.llvm.org/

Linux Depending on you distro you can install the rust toolchain and LLVM with your package manager or by using the install script from the rust project. Usually both the c compiler and a python environment are already bundle in the linux installation.

Set the environment variables

To compile the library the path of the hdf5 binaries and include files are needed. So you’ll need to set those environment variables:

  • HDF5_LIB_DIR: path of the lib directory of the downloaded hdf5 library
  • HDF5_INCLUDE_DIR: path of the include directory of the downloaded hdf5 library

    For testing purpose there is a build.ps1 PowerShell script that can be modified and already has those variables defined. You can update their value with the correct path for your machine and use it for building the library.

Setup a virtual environment (optional)

For the integration of python and rust code i’ve used a tool provided by the same mainteiners of PyO3, maturin, that makes easy to build and publish a mix of python and rust code. Those steps are not mandatory but i suggest you to use this tool too because it’s a matter of a couple of commands and you’ll have a ready to install python wheel or a virtual environment where to test the code.

Once you have a python interpreter installed lets create a virtual environment with maturin and all the needed libraries to use pycode. In a shell run

(I suppose you’re using PowerShell as shell, if it’s not the case change the command that differ for your shell or use PowerShell)

python -m venv .venv
 .venv/Scripts/Activate.ps1
 pip install maturin numpy matplotlib scipy cmake

With maturin installed and the virtual environment enabled build the python library is easy as:

maturin develop

this will build the debug version of the native library and install it in your virtual environment.

To create the optimized release version of the library and create a wheel installable in any compatible python environment run:

maturin build --release 

About

a tool for spike detection in cellular recordings

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published