Skip to main content

Read and write .nex and .nex5 files and edit data stored in .nex and .nex5 files.

Project description

nex5file

Python package to read, write and edit data stored in NeuroExplorer .nex and .nex5 files

Getting Started

Install nex5file package

Run this command in Windows Command Prompt:

pip install -U nex5file

Read .nex and .nex5 Files

ReadNexFile method of nex5file.reader.Reader class reads and parses contents of a .nex or a .nex5 file and returns an instance of nex5file.filedata.FileData object. This method reads all the data in the file.

from nex5file.reader import Reader
from nex5file.filedata import FileData
nexFilePath = r"C:\path\to\your\file.nex"
reader = Reader()
data = reader.ReadNexFile(nexFilePath)

If you need to read only some channels from a .nex or .nex5 file, use ReadNexFileVariables method:

# read only two continuous channels: cont1 and cont2
from nex5file.reader import Reader
from nex5file.filedata import FileData
nexFilePath = r"C:\path\to\your\file.nex"
reader = Reader()
data = reader.ReadNexFileVariables(nexFilePath, ['cont1', 'cont2'])

To retrieve channel names from a file, use ReadNexHeadersOnly method. Here is the code to read only continuous channels:

# read only all continuous channels
from nex5file.reader import Reader
from nex5file.filedata import FileData
reader = Reader()
data = reader.ReadNexHeadersOnly(r"C:\path\to\your\file.nex")
contNames = data.ContinuousNames()
data_cont = reader.ReadNexFileVariables(r"C:\path\to\your\file.nex", contNames)

Access Data in a FileData Object

Retrieving information fromm FileData object is similar to retrieving values using nex package. The difference is that nex package requires NeuroExplorer to be installed and running, while nex5file package if pure Python.

The syntax for accessing data is similar to nex package syntax. Many method names in nex5file package are the same as in nex package.

Here is a script to get continuous channels information using nex:

import nex
doc = nex.OpenDocument(nexFilePath)
# print continuous channel name, sampling rates and continuous values
for name in doc.ContinuousNames():
    rate = doc[name].SamplingRate()
    values = doc[name].ContinuousValues()
    print(name, rate, values)

Here is the same functionality using nex5file package:

from nex5file.reader import Reader
from nex5file.filedata import FileData

reader = Reader()
data = reader.ReadNexFile(nexFilePath)
# print continuous channel names, sampling rates and continuous values
for name in data.ContinuousNames():
    rate = data[name].SamplingRate()
    values = doc[name].ContinuousValues()
    print(name, rate, values)

Modify Data in a FileData Object

You can use the following FileData methods to modify data:

  • DeleteVariable
  • AddEvent
  • AddNeuron
  • AddIntervalAsPairsStartEnd
  • AddMarker
  • AddContVarWithFloatsSingleFragment
  • AddContSingleFragmentValuesInt16
  • AddContVarWithFloatsAllTimestamps
  • AddWaveVarWithFloats

Write .nex and .nex5 Files

Use WriteNexFile method of nex5file.writer.Writer class

from nex5file.writer import Writer
from nex5file.filedata import FileData
import numpy as np

freq = 100000
data = FileData(freq)

eName = "event 001"
eventTs = [1, 2, 3.5]
data.AddEvent(eName, np.array(eventTs))

nName = "neuron 002"
neuronTs = [0.001, 2.54, 8.99]
data.AddNeuron(nName, np.array(neuronTs))

nexFilePath = r"C:\path\to\your\file.nex"
writer = Writer()
writer.WriteNexFile(data, nexFilePath)

See www.neuroexplorer.com/nex5file/ for nex5file reference documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

nex5file-0.1.3-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file nex5file-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: nex5file-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for nex5file-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d937dd4f347d7fc1c1996f8a53520024586ffc5b414dabf85c7e76266bbaa393
MD5 ae3d4329bce4bbc8d23bc13da01de9c1
BLAKE2b-256 6af667230f7155cd124a7c971ecef5eb7d28fb6490f1c3746b6398e3da84bf10

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page