Skip to content

Commit

Permalink
Merge pull request #154 from pynapple-org/new_doc
Browse files Browse the repository at this point in the history
Cleaning
  • Loading branch information
gviejo authored Aug 8, 2023
2 parents 49b8b95 + 8e72445 commit 35ed2ab
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 132 deletions.
56 changes: 17 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,7 @@ $ pip install pynapple
$ pip install spyder
$ spyder
```
<!-- > **Warning**
> note for **Windows** users: on a multi-user Windows, make sure you open the conda prompt with *administrative access*: `run as administrator`; otherwise directory paths for some dependencies may be missing from the PYTHONPATH environment variable. The most common is the error in importing PyQt5. In case of such errors, right click on your conda prompt and select `run as administrator`, activate your pynapple environment, and install the said package again (e.g. pip install PyQt) so that the paths are properly saved by Windows.

> **Warning**
> note for **Mac** users with M1/M2 chips: PyQt5 may fail to install. In the Application folder, make a copy of the Terminal app (or any other console you're using), and call the second one, for exampe, 'Terminal-Rosetta'. Right click->Get Info and click on 'Open using Rosetta'. Open this terminal and enter the following instructions (you need to install virtualenv before)
``` {.sourceCode .shell}
$ /usr/bin/python3 -m venv pynapple
$ (pynapple) pip install --upgrade pip
$ (pynapple) pip install pynapple
```
Open python and try:
``` py
import pynapple as nap
nap.load_session()
```
The data loader should open in a new window. -->

Basic Usage
-----------
Expand All @@ -105,45 +90,38 @@ $ python
You'll find an example of the package below. Click [here](https://www.dropbox.com/s/su4oaje57g3kit9/A2929-200711.zip?dl=1) to download the example dataset. The folder includes a NWB file containing the data (See this [notebook](https://github.com/pynapple-org/pynapple/blob/main/docs/notebooks/pynapple-io-notebook.ipynb) for more information on the creation of the NWB file).

``` py
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

import pynapple as nap
from matplotlib.pyplot import *

data_directory = '/your/path/to/A2929-200711'
# LOADING DATA FROM NWB
data = nap.load_file("A2929-200711.nwb")

# LOADING DATA
data = nap.load_session(data_directory, 'neurosuite')
spikes = data["units"]
head_direction = data["ry"]
wake_ep = data["position_time_support"]

# COMPUTING TUNING CURVES
tuning_curves = nap.compute_1d_tuning_curves(
spikes, head_direction, 120, minmax=(0, 2 * np.pi)
)

spikes = data.spikes
position = data.position
wake_ep = data.epochs['wake']

# COMPUTING TUNING CURVES
tuning_curves = nap.compute_1d_tuning_curves(group = spikes,
feature = position['ry'],
ep = position['ry'].time_support,
nb_bins = 120,
minmax=(0, 2*np.pi) )



# PLOT
figure()
plt.figure()
for i in spikes:
subplot(6,7,i+1, projection = 'polar')
plot(tuning_curves[i])


show()
plt.subplot(3, 5, i + 1, projection="polar")
plt.plot(tuning_curves[i])
plt.xticks([0, np.pi / 2, np.pi, 3 * np.pi / 2])

plt.show()
```
Shown below, the final figure from the example code displays the firing rate of 15 neurons as a function of the direction of the head of the animal in the horizontal plane.

<!-- ![pic1](readme_figure.png) -->
<p align="center">
<img width="90%" src="readme_figure.png">
<img width="80%" src="readme_figure.png">
</p>


Expand Down
56 changes: 17 additions & 39 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,7 @@ $ pip install pynapple
$ pip install spyder
$ spyder
```
<!-- > **Warning**
> note for **Windows** users: on a multi-user Windows, make sure you open the conda prompt with *administrative access*: `run as administrator`; otherwise directory paths for some dependencies may be missing from the PYTHONPATH environment variable. The most common is the error in importing PyQt5. In case of such errors, right click on your conda prompt and select `run as administrator`, activate your pynapple environment, and install the said package again (e.g. pip install PyQt) so that the paths are properly saved by Windows.

> **Warning**
> note for **Mac** users with M1/M2 chips: PyQt5 may fail to install. In the Application folder, make a copy of the Terminal app (or any other console you're using), and call the second one, for exampe, 'Terminal-Rosetta'. Right click->Get Info and click on 'Open using Rosetta'. Open this terminal and enter the following instructions (you need to install virtualenv before)
``` {.sourceCode .shell}
$ /usr/bin/python3 -m venv pynapple
$ (pynapple) pip install --upgrade pip
$ (pynapple) pip install pynapple
```
Open python and try:
``` py
import pynapple as nap
nap.load_session()
```
The data loader should open in a new window. -->

Basic Usage
-----------
Expand All @@ -99,45 +84,38 @@ $ python
You'll find an example of the package below. Click [here](https://www.dropbox.com/s/su4oaje57g3kit9/A2929-200711.zip?dl=1) to download the example dataset. The folder includes a NWB file containing the data (See this [notebook](https://github.com/pynapple-org/pynapple/blob/main/docs/notebooks/pynapple-io-notebook.ipynb) for more information on the creation of the NWB file).

``` py
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

import pynapple as nap
from matplotlib.pyplot import *

data_directory = '/your/path/to/A2929-200711'
# LOADING DATA FROM NWB
data = nap.load_file("A2929-200711.nwb")

# LOADING DATA
data = nap.load_session(data_directory, 'neurosuite')
spikes = data["units"]
head_direction = data["ry"]
wake_ep = data["position_time_support"]

# COMPUTING TUNING CURVES
tuning_curves = nap.compute_1d_tuning_curves(
spikes, head_direction, 120, minmax=(0, 2 * np.pi)
)

spikes = data.spikes
position = data.position
wake_ep = data.epochs['wake']

# COMPUTING TUNING CURVES
tuning_curves = nap.compute_1d_tuning_curves(group = spikes,
feature = position['ry'],
ep = position['ry'].time_support,
nb_bins = 120,
minmax=(0, 2*np.pi) )



# PLOT
figure()
plt.figure()
for i in spikes:
subplot(6,7,i+1, projection = 'polar')
plot(tuning_curves[i])


show()
plt.subplot(3, 5, i + 1, projection="polar")
plt.plot(tuning_curves[i])
plt.xticks([0, np.pi / 2, np.pi, 3 * np.pi / 2])

plt.show()
```
Shown below, the final figure from the example code displays the firing rate of 15 neurons as a function of the direction of the head of the animal in the horizontal plane.

<!-- ![pic1](readme_figure.png) -->
<p align="center">
<img width="90%" src="readme_figure.png">
<img width="80%" src="readme_figure.png">
</p>

### Credits
Expand Down
19 changes: 7 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
"""
Minimal working example
This example is soon to be deprecated.
You can see the new example in main2.py
"""

import matplotlib.pyplot as plt
import numpy as np

import pynapple as nap

DATA_DIRECTORY = "your/path/to/MyProject/sub-A2929/ses-A2929-200711"

# LOADING DATA
data = nap.load_session(DATA_DIRECTORY, "neurosuite")
# LOADING DATA FROM NWB
data = nap.load_file("A2929-200711.nwb")

spikes = data.spikes
position = data.position
wake_ep = data.epochs["wake"]
spikes = data["units"]
head_direction = data["ry"]
wake_ep = data["position_time_support"]

# COMPUTING TUNING CURVES
tuning_curves = nap.compute_1d_tuning_curves(
spikes, position["ry"], 120, minmax=(0, 2 * np.pi)
spikes, head_direction, 120, minmax=(0, 2 * np.pi)
)


Expand All @@ -33,4 +28,4 @@
plt.plot(tuning_curves[i])
plt.xticks([0, np.pi / 2, np.pi, 3 * np.pi / 2])

plt.show()
plt.show()
37 changes: 0 additions & 37 deletions main2.py

This file was deleted.

10 changes: 6 additions & 4 deletions pynapple/io/interface_nwb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# @Author: Guillaume Viejo
# @Date: 2023-08-01 11:54:45
# @Last Modified by: Guillaume Viejo
# @Last Modified time: 2023-08-06 17:55:32
# @Last Modified by: gviejo
# @Last Modified time: 2023-08-07 21:38:08

"""
Pynapple class to interface with NWB files.
Expand Down Expand Up @@ -110,8 +110,10 @@ def _make_interval_set(obj):
data[k] = nap.IntervalSet(
start=subdf["start_time"], end=subdf["stop_time"]
)

return data
if len(data) == 1:
return data[list(data.keys())[0]]
else:
return data

else:
warnings.warn(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ classifiers = [
]
keywords = ["neuroscience"]
dependencies = [
"pandas>=1.0.3,<2.0.0",
"pandas>1.0.3,<2.0.0",
"numpy>=1.17.4",
"scipy>=1.3.2",
"numba>=0.46.0",
Expand Down

0 comments on commit 35ed2ab

Please sign in to comment.