nex5file


Namenex5file JSON
Version 0.1.3 PyPI version JSON
download
home_page
SummaryRead and write .nex and .nex5 files and edit data stored in .nex and .nex5 files.
upload_time2023-10-07 17:30:04
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords neuroexplorer nex nex5 .nex .nex5
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.

```python
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:

```python
# 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:

```python
# 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`:

```python
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:

```python
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

```python
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/](https://www.neuroexplorer.com/nex5file/) for nex5file reference documentation.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "nex5file",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "NeuroExplorer,nex,nex5,.nex,.nex5",
    "author": "",
    "author_email": "Alex Kirillov <alex@neuroexplorer.com>",
    "download_url": "",
    "platform": null,
    "description": "# nex5file\r\nPython package to read, write and edit data stored in NeuroExplorer .nex and .nex5 files\r\n\r\n## Getting Started\r\n\r\n### Install nex5file package\r\n\r\nRun this command in Windows Command Prompt:\r\n```\r\npip install -U nex5file\r\n```\r\n\r\n### Read .nex and .nex5 Files\r\n\r\n`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.\r\n\r\n```python\r\nfrom nex5file.reader import Reader\r\nfrom nex5file.filedata import FileData\r\nnexFilePath = r\"C:\\path\\to\\your\\file.nex\"\r\nreader = Reader()\r\ndata = reader.ReadNexFile(nexFilePath)\r\n```\r\n\r\nIf you need to read only some channels from a .nex or .nex5 file, use `ReadNexFileVariables` method:\r\n\r\n```python\r\n# read only two continuous channels: cont1 and cont2\r\nfrom nex5file.reader import Reader\r\nfrom nex5file.filedata import FileData\r\nnexFilePath = r\"C:\\path\\to\\your\\file.nex\"\r\nreader = Reader()\r\ndata = reader.ReadNexFileVariables(nexFilePath, ['cont1', 'cont2'])\r\n```\r\n\r\nTo retrieve channel names from a file, use `ReadNexHeadersOnly` method. Here is the code to read only continuous channels:\r\n\r\n```python\r\n# read only all continuous channels\r\nfrom nex5file.reader import Reader\r\nfrom nex5file.filedata import FileData\r\nreader = Reader()\r\ndata = reader.ReadNexHeadersOnly(r\"C:\\path\\to\\your\\file.nex\")\r\ncontNames = data.ContinuousNames()\r\ndata_cont = reader.ReadNexFileVariables(r\"C:\\path\\to\\your\\file.nex\", contNames)\r\n```\r\n\r\n### Access Data in a FileData Object\r\n\r\nRetrieving 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.\r\n\r\nThe syntax for accessing data is similar to `nex` package syntax. Many method names in `nex5file` package are the same as in `nex` package.\r\n\r\nHere is a script to get continuous channels information using `nex`:\r\n\r\n```python\r\nimport nex\r\ndoc = nex.OpenDocument(nexFilePath)\r\n# print continuous channel name, sampling rates and continuous values\r\nfor name in doc.ContinuousNames():\r\n    rate = doc[name].SamplingRate()\r\n    values = doc[name].ContinuousValues()\r\n    print(name, rate, values)\r\n```\r\n\r\nHere is the same functionality using `nex5file` package:\r\n\r\n```python\r\nfrom nex5file.reader import Reader\r\nfrom nex5file.filedata import FileData\r\n\r\nreader = Reader()\r\ndata = reader.ReadNexFile(nexFilePath)\r\n# print continuous channel names, sampling rates and continuous values\r\nfor name in data.ContinuousNames():\r\n    rate = data[name].SamplingRate()\r\n    values = doc[name].ContinuousValues()\r\n    print(name, rate, values)\r\n```\r\n\r\n### Modify Data in a FileData Object\r\n\r\nYou can use the following `FileData` methods to modify data:\r\n\r\n- `DeleteVariable`\r\n- `AddEvent`\r\n- `AddNeuron`\r\n- `AddIntervalAsPairsStartEnd`\r\n- `AddMarker`\r\n- `AddContVarWithFloatsSingleFragment`\r\n- `AddContSingleFragmentValuesInt16`\r\n- `AddContVarWithFloatsAllTimestamps`\r\n- `AddWaveVarWithFloats`\r\n\r\n### Write .nex and .nex5 Files\r\n\r\nUse `WriteNexFile` method of `nex5file.writer.Writer` class\r\n\r\n```python\r\nfrom nex5file.writer import Writer\r\nfrom nex5file.filedata import FileData\r\nimport numpy as np\r\n\r\nfreq = 100000\r\ndata = FileData(freq)\r\n\r\neName = \"event 001\"\r\neventTs = [1, 2, 3.5]\r\ndata.AddEvent(eName, np.array(eventTs))\r\n\r\nnName = \"neuron 002\"\r\nneuronTs = [0.001, 2.54, 8.99]\r\ndata.AddNeuron(nName, np.array(neuronTs))\r\n\r\nnexFilePath = r\"C:\\path\\to\\your\\file.nex\"\r\nwriter = Writer()\r\nwriter.WriteNexFile(data, nexFilePath)\r\n```\r\n\r\nSee [www.neuroexplorer.com/nex5file/](https://www.neuroexplorer.com/nex5file/) for nex5file reference documentation.\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Read and write .nex and .nex5 files and edit data stored in .nex and .nex5 files.",
    "version": "0.1.3",
    "project_urls": {
        "documentation": "https://www.neuroexplorer.com/nex5file/",
        "homepage": "https://github.com/NeuroExplorer/nex5file",
        "repository": "https://github.com/NeuroExplorer/nex5file"
    },
    "split_keywords": [
        "neuroexplorer",
        "nex",
        "nex5",
        ".nex",
        ".nex5"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6af667230f7155cd124a7c971ecef5eb7d28fb6490f1c3746b6398e3da84bf10",
                "md5": "ae3d4329bce4bbc8d23bc13da01de9c1",
                "sha256": "d937dd4f347d7fc1c1996f8a53520024586ffc5b414dabf85c7e76266bbaa393"
            },
            "downloads": -1,
            "filename": "nex5file-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ae3d4329bce4bbc8d23bc13da01de9c1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 20874,
            "upload_time": "2023-10-07T17:30:04",
            "upload_time_iso_8601": "2023-10-07T17:30:04.597341Z",
            "url": "https://files.pythonhosted.org/packages/6a/f6/67230f7155cd124a7c971ecef5eb7d28fb6490f1c3746b6398e3da84bf10/nex5file-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-07 17:30:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NeuroExplorer",
    "github_project": "nex5file",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nex5file"
}
        
Elapsed time: 0.12636s