Skip to content

Commit

Permalink
Get examples working
Browse files Browse the repository at this point in the history
  • Loading branch information
apdavison committed Oct 3, 2022
1 parent 5a2e34a commit a54a8b8
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 13 deletions.
3 changes: 2 additions & 1 deletion doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Table of Contents
rawiolist
releases
authors
governance
governance
auto_examples/index
20 changes: 18 additions & 2 deletions doc/source/rawio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ The :mod:`neo.rawio` API is less flexible than :mod:`neo.io` and has some limita

For an intuitive comparison of :mod:`neo.io` and :mod:`neo.rawio` see:

- :file:`example/read_file_neo_io.py`
- :file:`example/read_file_neo_rawio.py`
- :doc:`auto_examples/read_files_neo_io`
- :doc:`auto_examples/read_files_neo_rawio`


One benefit of the :mod:`neo.rawio` API is that a developer
Expand All @@ -61,6 +61,22 @@ objects or of the :mod:`quantities` package.
Basic usage
===========

.. Download example files
.. ipython:: python
:suppress:
import os.path
from urllib.request import urlretrieve
url_repo = 'https://web.gin.g-node.org/NeuralEnsemble/ephy_testing_data/raw/master/'
for distantfile in ('plexon/File_plexon_2.plx', 'plexon/File_plexon_3.plx', 'blackrock/FileSpec2.3001.nev', 'blackrock/FileSpec2.3001.ns5'):
localfile = f'../examples/{distantfile.split("/")[1]}'
if not os.path.exists(localfile):
urlretrieve(url_repo + distantfile, localfile)
First create a reader from a class:

.. ipython::
Expand Down
59 changes: 59 additions & 0 deletions examples/convert_to_nwb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Converting to NWB using Neo
===========================
"""

from urllib.request import urlretrieve
from urllib.parse import quote
from neo.io import get_io


dataset_url = "https://object.cscs.ch/v1/AUTH_63ea6845b1d34ad7a43c8158d9572867/hbp-d000017_PatchClamp-GranuleCells_pub"

folder = "GrC_Subject15_180116"

#filenames = ["180116_0004 IV -70.abf", "180116_0005 CC step.abf", "180116_0006 EPSP.abf"]
filenames = ["180116_0005 CC step.abf"]

for filename in filenames:
datafile_url = f"{dataset_url}/{folder}/{quote(filename)}"
local_file = urlretrieve(datafile_url, filename)


reader = get_io("180116_0005 CC step.abf")
data = reader.read()

global_metadata = {
"session_start_time": data[0].rec_datetime,
"identifier": data[0].file_origin,
"session_id": "180116_0005",
"institution": "University of Pavia",
"lab": "D'Angelo Lab",
"related_publications": "https://doi.org/10.1038/s42003-020-0953-x"
}

#data[0].annotate(**global_metadata)

signal_metadata = {
"nwb_group": "acquisition",
"nwb_neurodata_type": ("pynwb.icephys", "PatchClampSeries"),
"nwb_electrode": {
"name": "patch clamp electrode",
"description": "The patch-clamp pipettes were pulled from borosilicate glass capillaries "
"(Hilgenberg, Malsfeld, Germany) and filled with intracellular solution "
"(K-gluconate based solution)",
"device": {
"name": "patch clamp electrode"
}
},
"nwb:gain": 1.0
}

for segment in data[0].segments:
signal = segment.analogsignals[0]
signal.annotate(**signal_metadata)

from neo.io import NWBIO
writer = NWBIO("GrC_Subject15_180116.nwb", mode="w", **global_metadata)
writer.write(data)
4 changes: 3 additions & 1 deletion examples/generated_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
This is an example for creating simple plots from various Neo structures.
Creating simple plots from various Neo structures
=================================================
It includes a function that generates toy data.
"""

Expand Down
4 changes: 3 additions & 1 deletion examples/imageseq.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
docstring needed here
ImageSequences
==============
"""

from neo.core import ImageSequence
Expand Down
4 changes: 3 additions & 1 deletion examples/plot_with_matplotlib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
This is an example for plotting a Neo object with matplotlib.
Plotting a Neo object with matplotlib
=====================================
"""

import urllib
Expand Down
4 changes: 3 additions & 1 deletion examples/read_files_neo_io.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
This is an example for reading files with neo.io
Reading files with neo.io
=========================
"""

import urllib
Expand Down
8 changes: 5 additions & 3 deletions examples/read_files_neo_rawio.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
This is an example for reading files with neo.rawio
Reading files with neo.rawio
============================
compare with read_files_neo_io.py
"""

Expand Down Expand Up @@ -52,12 +54,12 @@
float_waveforms = reader.rescale_waveforms_to_float(raw_waveforms, dtype='float32', spike_channel_index=0)
print(float_waveforms.shape, float_waveforms.dtype, float_waveforms[0, 0, :4])

# Read event timestamps and times (take anotehr file)
# Read event timestamps and times (take another file)
distantfile = url_repo + 'plexon/File_plexon_2.plx'
localfile = './File_plexon_2.plx'
urllib.request.urlretrieve(distantfile, localfile)

# Count event per channel
# Count events per channel
reader = PlexonRawIO(filename='File_plexon_2.plx')
reader.parse_header()
nb_event_channel = reader.event_channels_count()
Expand Down
3 changes: 2 additions & 1 deletion examples/read_proxy_with_lazy_load.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
This is an example demonstrate the lazy load and proxy objects.
Demonstration of lazy load and proxy objects
============================================
"""

Expand Down
4 changes: 3 additions & 1 deletion examples/roi_demo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""
Example of working with RegionOfInterest objects
Working with RegionOfInterest objects
=====================================
"""

import matplotlib.pyplot as plt
Expand Down
2 changes: 1 addition & 1 deletion neo/io/asciisignalio.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ def read_segment(self, lazy=False):
else:
ana_sig = AnalogSignal(signal * self.units, sampling_rate=sampling_rate,
t_start=t_start,
channel_index=self.usecols or np.arange(signal.shape[1]),
name='multichannel')
ana_sig.array_annotate(channel_index=self.usecols or np.arange(signal.shape[1]))
seg.analogsignals.append(ana_sig)
else:
if self.timecolumn is not None and self.timecolumn < 0:
Expand Down

0 comments on commit a54a8b8

Please sign in to comment.