|
@@ -0,0 +1,152 @@
|
|
|
+{
|
|
|
+ "cells": [
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "id": "723581d7",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ "# Conversion\n",
|
|
|
+ "This Notebook converts the dataset for the unitary events tutorial from .h5 to.nix format"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 1,
|
|
|
+ "id": "6c6d2774",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "import neo\n",
|
|
|
+ "from neo.core import Block, Segment, Group, AnalogSignal\n",
|
|
|
+ "import numpy as np\n",
|
|
|
+ "import quantities as pq\n",
|
|
|
+ "\n",
|
|
|
+ "import random\n",
|
|
|
+ "import string\n",
|
|
|
+ "import matplotlib.pyplot as plt\n",
|
|
|
+ "import elephant.unitary_event_analysis as ue\n",
|
|
|
+ "# Fix random seed to guarantee fixed output\n",
|
|
|
+ "random.seed(1224)"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "id": "26914203",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ "## Download data"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 2,
|
|
|
+ "id": "8c798f2b",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stdout",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ " % Total % Received % Xferd Average Speed Time Time Time Current\n",
|
|
|
+ " Dload Upload Total Spent Left Speed\n",
|
|
|
+ "100 369 100 369 0 0 7096 0 --:--:-- --:--:-- --:--:-- 7096\n",
|
|
|
+ "100 289k 0 289k 0 0 255k 0 --:--:-- 0:00:01 --:--:-- 1562k\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "!curl https://web.gin.g-node.org/INM-6/elephant-data/raw/master/dataset-1/dataset-1.h5 --output dataset-1.h5 --location"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "id": "903fc908",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ "## Load Data"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 3,
|
|
|
+ "id": "870b8b77",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [
|
|
|
+ {
|
|
|
+ "name": "stderr",
|
|
|
+ "output_type": "stream",
|
|
|
+ "text": [
|
|
|
+ "/home/kern/miniconda3/envs/elephant/lib/python3.9/site-packages/neo/io/hdf5io.py:63: FutureWarning: NeoHdf5IO will be removed in the next release of Neo. If you still have data in this format, we recommend saving it using NixIO which is also based on HDF5.\n",
|
|
|
+ " warn(warning_msg, FutureWarning)\n",
|
|
|
+ "/home/kern/miniconda3/envs/elephant/lib/python3.9/site-packages/numpy/core/shape_base.py:121: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.\n",
|
|
|
+ " ary = asanyarray(ary)\n"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "source": [
|
|
|
+ "block = neo.io.NeoHdf5IO(\"./dataset-1.h5\")\n",
|
|
|
+ "sts1 = block.read_block().segments[0].spiketrains\n",
|
|
|
+ "sts2 = block.read_block().segments[1].spiketrains\n",
|
|
|
+ "spiketrains = np.vstack((sts1,sts2)).T"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 4,
|
|
|
+ "id": "c52a2a89",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "# create empty block\n",
|
|
|
+ "blk = Block()\n",
|
|
|
+ "# add segments and spike trains\n",
|
|
|
+ "for ind in range (len(sts1)):\n",
|
|
|
+ " seg = Segment(name='segment %d' % ind, index=ind)\n",
|
|
|
+ " seg.spiketrains.append(sts1[ind])\n",
|
|
|
+ " seg.spiketrains.append(sts2[ind])\n",
|
|
|
+ " blk.segments.append(seg)\n"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "id": "28a2e17f",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
+ "## Save as .nix"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": 5,
|
|
|
+ "id": "2a06477e",
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "filename = 'dataset-1.nix'\n",
|
|
|
+ "with neo.io.NixIO(filename, 'ow') as io:\n",
|
|
|
+ " io.write_block(blk)"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "metadata": {
|
|
|
+ "kernelspec": {
|
|
|
+ "display_name": "elephant_old",
|
|
|
+ "language": "python",
|
|
|
+ "name": "elephant_old"
|
|
|
+ },
|
|
|
+ "language_info": {
|
|
|
+ "codemirror_mode": {
|
|
|
+ "name": "ipython",
|
|
|
+ "version": 3
|
|
|
+ },
|
|
|
+ "file_extension": ".py",
|
|
|
+ "mimetype": "text/x-python",
|
|
|
+ "name": "python",
|
|
|
+ "nbconvert_exporter": "python",
|
|
|
+ "pygments_lexer": "ipython3",
|
|
|
+ "version": "3.9.6"
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "nbformat": 4,
|
|
|
+ "nbformat_minor": 5
|
|
|
+}
|