Skip to content
cortex-labPublic

About

Lightweight electrophysiological data analysis library

Topics

Resources

Code of conduct

Stars

16 stars

Watchers

10 watching

Forks

Repository files navigation

phylib

CI codecov.io

Electrophysiological data analysis library used by phy, a spike sorting visualization software, and ibllib.

Raw data through SpikeInterface

With pip install phylib[spikeinterface], dat_path in params.py can name a SpikeInterface recording instead of a flat binary file: a provenance .json (from recording.dump_to_json()) or a .zarr folder (from recording.save(format='zarr')). The recording's preprocessing chain is computed lazily, so remote data is read without being downloaded or exported. Traces are raw and unscaled, in the recording's dtype. The recording sets the sample rate and channel count, so keep sample_rate and n_channels_dat in params.py consistent with it.

Reads compute only the requested blocks and share a bounded cache. Navigation code can opt into background lookahead by calling traces.prefetch(sample) with a sample beyond the visible window, for example half a second ahead when moving forward or behind when moving backward. Each hint warms the block containing that sample; a newer hint replaces obsolete lookahead, and traces.cancel_prefetch() withdraws the hint. Out-of-range samples also withdraw the hint. Waveform extraction does not generate hints. This API requires navigation callers (such as phy) to supply hints before scrolling benefits from prefetching.

The reader serializes demand and prefetch calls to the recording, so the backend need not support concurrent reads, but it must permit reads from a worker thread when hints are used. A demand read may wait for one running prefetch; new prefetch work waits for demand reads. TemplateModel.close() closes the reader. A running backend call finishes in the background and cannot refill the cache after close. Closing is terminal for all shared views: new reads raise RuntimeError and later hints are ignored. Other reader types accept navigation hints as no-ops, so callers can use the same API.

visible = traces[start:stop]
lookahead = int(0.5 * traces.sample_rate)
traces.prefetch(stop + lookahead)  # Forward navigation; does not wait.
# On a jump or when navigation stops:
traces.cancel_prefetch()

Contribution

  • participation in phylib is governed by the project Code of Conduct
  • run all tests using pytest pytest phylib
  • PR to master
  • keep phylib/__init__.py on the next development version (for example, 2.7.1.dev0)
  • for a release, follow the steps below
  • after publishing, immediately bump phylib/__init__.py to the next .dev0 version

Release

Before merging the release PR, confirm maintainer approval and green CI. Update CHANGELOG.md with all changes since the previous release, replace the pending release date with the actual release date, and remove the .dev0 suffix from phylib/__init__.py.

Validate the final release checkout in a dedicated environment:

uv venv --python 3.12 .venv-release
uv pip install --python .venv-release -r requirements-dev.txt -e . setuptools build twine
.venv-release/bin/python -m flake8 phylib
.venv-release/bin/python -m pytest phylib

After the approved PR is merged, create an annotated tag from the merged release commit (for example, git tag -a 2.7.1 -m "phylib 2.7.1"). Build fresh artifacts from that tagged checkout into an empty output directory:

.venv-release/bin/python -m build --outdir dist/2.7.1
.venv-release/bin/python -m twine check dist/2.7.1/*

Install the wheel in a separate clean environment and verify its version and imports. Verify the downstream phy template-less waveform regression against this wheel before publishing. Upload only the artifacts just checked:

.venv-release/bin/python -m twine upload dist/2.7.1/*

Verify installation of the published version from PyPI in another clean environment. Then bump master to 2.7.2.dev0 and add an Unreleased changelog section. Substitute the appropriate version numbers for subsequent releases.

About

Lightweight electrophysiological data analysis library

Topics

Resources

Code of conduct

Stars

16 stars

Watchers

10 watching

Forks

Releases

Packages

Used by

Contributors

Languages