Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ Input-Ouput
NWBFile


.. currentmodule:: pynapple.io

.. rubric:: Neo Reader / LFP

.. autosummary::
:toctree: generated/
:nosignatures:
:recursive:

NeoReader
NeoSignalInterface


.. currentmodule:: pynapple.io

.. rubric:: Numpy files
Expand Down
48 changes: 47 additions & 1 deletion doc/user_guide/02_input_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kernelspec:

# Input-output & lazy-loading

Pynapple provides loaders for [NWB format](https://pynwb.readthedocs.io/en/stable/index.html#).
Pynapple provides multiple ways to load data. The two main formats are NWB and NPZ. In addition, raw LFP data can be loaded through the NEO library.

Each pynapple objects can be saved as a [`npz`](https://numpy.org/devdocs/reference/generated/numpy.savez.html) with a special structure and loaded as a `npz`.

Expand Down Expand Up @@ -42,6 +42,8 @@ import pynapple as nap
import os
import requests, math
import tqdm
import matplotlib.pyplot as plt
import numpy as np

nwb_path = 'A2929-200711.nwb'

Expand Down Expand Up @@ -133,6 +135,50 @@ z = data['z']
print(type(z.d))
```

## LFP loading & NEO compatibility

Raw LFP data can be loaded with pynapple through the NEO library.
Internally, pynapple uses the NEO raw IO classes to read the data and convert them to one of the pynapple time series object.
This is done through the class [`nap.NeoReader`](pynapple.io.neo.NeoReader).

See here the [list of supported formats](https://neo.readthedocs.io/en/stable/rawiolist.html).


Here is a minimal working example :

```{code-cell} ipython3
:tags: [hide-cell]
import urllib
distantfile = "https://web.gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/plexon/File_plexon_3.plx"
urllib.request.urlretrieve(distantfile, "File_plexon_3.plx")
```

```{code-cell} ipython3
:tags: [hide-output]
data = nap.NeoReader("File_plexon_3.plx", format="PlexonIO");
```
```{code-cell} ipython3
print(data)
```

```{code-cell} ipython3
lfp = data['TsdFrame 0: V']
spikes = data['TsGroup']
```

```{code-cell} ipython3
fig = plt.figure()
ax1 = fig.add_subplot(2, 1, 1)
ax2 = fig.add_subplot(2, 1, 2)
ax1.plot(lfp.t, lfp.d[:])
ax1.set_xlabel("Time (s)")
colors = plt.cm.jet(np.linspace(0, 1, len(spikes)))
ax2.eventplot([spikes[i].t for i in spikes.keys()], colors=colors)
ax2.set_xlabel("Time (s)")
plt.tight_layout()
plt.show()
```

## Saving as NPZ

Pynapple objects have [`save`](pynapple.Tsd.save) methods to save them as npz files.
Expand Down
2 changes: 2 additions & 0 deletions pynapple/io/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .folder import Folder
from .interface_npz import NPZFile
from .interface_nwb import NWBFile
from .interface_neo import NeoReader, NeoSignalInterface
from .misc import append_NWB_LFP, load_eeg, load_file, load_folder, load_session

Loading
Loading