Skip to content

Instantly share code, notes, and snippets.

@ledochowitsch
Last active October 18, 2019 06:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ledochowitsch/1fe3d7b3ef25fedafa2dea270183c807 to your computer and use it in GitHub Desktop.
Save ledochowitsch/1fe3d7b3ef25fedafa2dea270183c807 to your computer and use it in GitHub Desktop.
oephys_visualization
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
"import h5py\n",
"import numpy as np\n",
"from matplotlib import pyplot as plt\n",
"from ipywidgets import interact\n",
"import io\n",
"import shutil\n",
"import tempfile\n",
"import urllib.request\n",
"import zipfile\n",
"from IPython.core.display import HTML\n",
"\n",
"def oephys_plot(Recording):\n",
" %matplotlib widget \n",
" h5name = Recording + '_medium.h5'\n",
" with archive.open(h5name) as h5data:\n",
" with tempfile.SpooledTemporaryFile() as tmp_file:\n",
" shutil.copyfileobj(h5data, tmp_file)\n",
" with h5py.File(tmp_file,'r') as h:\n",
" dto = 1.0 * np.array(h['dto'])\n",
" dte = 1.0 * np.array(h['dte'])\n",
" quiroga = 1.0 * np.array(h['quiroga'])\n",
" dff = np.array(h['dff']).ravel()\n",
" sptimes = np.array(h['sptimes']).ravel()\n",
" genotype = h['genotype'][()].decode(\"utf-8\") \n",
" #V = np.array(h['ephys_raw']).ravel()\n",
" ephys = np.array(h['ephys_baseline_subtracted']).ravel()\n",
" fig, ax = plt.subplots(3, 1, sharex=True, sharey=False)\n",
" fig.set_figwidth(10)\n",
" fig.suptitle(Recording, fontsize=14)\n",
" ax[0].plot(np.arange(0,dff.size*dto,dto), dff, 'g')\n",
" ax[0].set_ylabel('DF/F')\n",
" # ax[1].plot(np.arange(0,len(V)*dte,dte), 1000.0 * V, 'b')\n",
" # ax[1].set_ylabel('V [mV]')\n",
" #ax[1].set_title('Raw cell-attached electrophysiology')\n",
" ax[1].plot(np.arange(0,len(ephys)*dte,dte), 1000.0 * ephys, 'k')\n",
" ax[1].set_ylabel('V [mV]')\n",
" ax[1].axhline(y=1000.0 * quiroga, color = 'r', alpha = 0.5)\n",
" #ax[2].set_title('Post baseline-subtraction')\n",
" ax[2].eventplot(sptimes, orientation='horizontal', lineoffsets=-1, linelengths=0.5, linewidths=None, colors='r', linestyles='solid')\n",
" ax[2].set_xlabel('Time [s]')\n",
" ax[2].tick_params(labelleft=False) \n",
" display(HTML('<center><a href=' + data_dict[Recording] + '>Download the full data set ['+ Recording +'] in HDF5 format</a></center>'))\n",
"\n",
"archive = zipfile.ZipFile('oephys_medium.zip', 'r')\n",
"\n",
"\n",
"cellids = ['102978','103467','102969','104001','102525','103444','102892','103992','103932','102510','102875','103920','103988','103402','103931','102890','102960','103863','102860','103950','102511','103991','103438','103406','103852','102891','102958','102086','104002','103953','102102','102906','102959','103979','103934','103933','103986','103985','102970','102529','103856','102858','103401','102512','103971','102956','103958','103849','103400','102898']\n",
"url_list = ['https://www.dropbox.com/s/npahi5b2kg0li8s/102086.h5?dl=0', 'https://www.dropbox.com/s/v1q24t83hmv075k/102102.h5?dl=0', 'https://www.dropbox.com/s/6kafakjvfcj0k9i/102510.h5?dl=0', 'https://www.dropbox.com/s/wegiifv2glr2uym/102511.h5?dl=0', 'https://www.dropbox.com/s/lbeqfi2cn51bzr5/102512.h5?dl=0', 'https://www.dropbox.com/s/jsyhq7vu5329duj/102525.h5?dl=0', 'https://www.dropbox.com/s/58vrzxf7td85x8v/102529.h5?dl=0', 'https://www.dropbox.com/s/3b9wsf7nulxx5o4/102858.h5?dl=0', 'https://www.dropbox.com/s/u0aui5jiewfo9dx/102860.h5?dl=0', 'https://www.dropbox.com/s/oarz7pipcvxotv2/102875.h5?dl=0', 'https://www.dropbox.com/s/j3wuz64qwxlg2je/102890.h5?dl=0', 'https://www.dropbox.com/s/6n2axnjt19s21nh/102891.h5?dl=0', 'https://www.dropbox.com/s/5qh2o0gzt370ug0/102892.h5?dl=0', 'https://www.dropbox.com/s/ev6yzx3a5b7iwq9/102898.h5?dl=0', 'https://www.dropbox.com/s/sj2pul8k27kl45z/102906.h5?dl=0', 'https://www.dropbox.com/s/39i8rxr0ejc0rjr/102956.h5?dl=0', 'https://www.dropbox.com/s/8mx3fky55243vee/102958.h5?dl=0', 'https://www.dropbox.com/s/4k0lvi89u2qv4l3/102959.h5?dl=0', 'https://www.dropbox.com/s/rszu0jrafgohy8f/102960.h5?dl=0', 'https://www.dropbox.com/s/aw9gxcs4nfbs299/102969.h5?dl=0', 'https://www.dropbox.com/s/nizqswef6o3j81t/102970.h5?dl=0', 'https://www.dropbox.com/s/5h51iy0k92f1poi/102978.h5?dl=0', 'https://www.dropbox.com/s/iqw9iels8nqgyv7/103400.h5?dl=0', 'https://www.dropbox.com/s/x2f91h536j8qrk3/103401.h5?dl=0', 'https://www.dropbox.com/s/zswhxi9ck33oc18/103402.h5?dl=0', 'https://www.dropbox.com/s/99kvbfdjpf6avct/103406.h5?dl=0', 'https://www.dropbox.com/s/77yxcfth7h8ugft/103438.h5?dl=0', 'https://www.dropbox.com/s/5l49czden5ae75y/103444.h5?dl=0', 'https://www.dropbox.com/s/e9ugb1b1fhwj0bh/103467.h5?dl=0', 'https://www.dropbox.com/s/o7o5mnmqr9xpu1c/103849.h5?dl=0', 'https://www.dropbox.com/s/w0ajezbbsvy7tcc/103852.h5?dl=0', 'https://www.dropbox.com/s/tcjic1m64wmnyb0/103856.h5?dl=0', 'https://www.dropbox.com/s/m84bgaqn8sn715w/103863.h5?dl=0', 'https://www.dropbox.com/s/lbcmj0qbjy4y0ge/103920.h5?dl=0', 'https://www.dropbox.com/s/v8h7ne2fve9nly8/103931.h5?dl=0', 'https://www.dropbox.com/s/ikbb4z9lp5s6h3t/103932.h5?dl=0', 'https://www.dropbox.com/s/htz4nnr58jnqa8f/103933.h5?dl=0', 'https://www.dropbox.com/s/tp5o0fep8hw9upa/103934.h5?dl=0', 'https://www.dropbox.com/s/z8bsatb9tn9erom/103950.h5?dl=0', 'https://www.dropbox.com/s/hiq3uytvcebcs1v/103953.h5?dl=0', 'https://www.dropbox.com/s/tj0weua5u6rzww7/103958.h5?dl=0', 'https://www.dropbox.com/s/g71gg7cn171asbp/103971.h5?dl=0', 'https://www.dropbox.com/s/habsa5po24dlgn2/103979.h5?dl=0', 'https://www.dropbox.com/s/9e6bbxlaz60lmq6/103985.h5?dl=0', 'https://www.dropbox.com/s/qo8qujph9yn1vwy/103986.h5?dl=0', 'https://www.dropbox.com/s/gcavd8br3fu0j0x/103988.h5?dl=0', 'https://www.dropbox.com/s/iynuewvm3w22tpb/103991.h5?dl=0', 'https://www.dropbox.com/s/cj1fqbvp0zrv94s/103992.h5?dl=0', 'https://www.dropbox.com/s/t5gun7kdsyyjj54/104001.h5?dl=0', 'https://www.dropbox.com/s/iyh7kew5ypo3zwn/104002.h5?dl=0']\n",
"Cre_lines = {'Cux2-f': ['104001','103992','103932','103920','103988','103931','103950','103991','104002','103953','103979','103934','103933','103986','103985','103971','103958'],'Emx1-f': ['102978','103467','102969','103444','103402','102960','103438','103406','102958','102959','102970','103401','102956',\n",
"'103400'],'Emx1-s': ['102525','102892','102510','102875','102890','103863','102860','102511','103852','102891','102086','102102','102906','102529','103856','102858','102512','103849','102898']}\n",
"data_dict = {}\n",
"for url in url_list:\n",
" data_dict[url[-14:-8]] = url[:-1] + '1'\n",
" \n",
" \n",
"##Cux2-f\n",
"\n",
"display(HTML('<center><h1> Visualization of downsampled calibration dataset </h1></center>')) \n",
"display(HTML('<center><h2> Cux2-f (GCaMP6f) </h2></center>')) \n",
"interact(oephys_plot, Recording=Cre_lines['Cux2-f'])\n",
"\n",
"##Emx1-f\n",
"display(HTML('<center><h2> Emx1-f (GCaMP6f) </h2></center>'))\n",
"interact(oephys_plot, Recording=Cre_lines['Emx1-f'])\n",
"\n",
"##Emx1-s\n",
"\n",
"display(HTML('<center><h2> Emx1-s (GCaMP6s) </h2></center>'))\n",
"interact(oephys_plot, Recording=Cre_lines['Emx1-s'])\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "oephys",
"language": "python",
"name": "oephys"
},
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
wget -q -O oephys_medium.zip "https://www.dropbox.com/s/7sv8op4f28gdua6/oephys_medium.zip?dl=1"
bqplot
ipympl
ipyvolume
scipy
voila
h5py
numpy
matplotlib
ipywidgets
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment