Topology in neuroscience
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

739 lines
349 KiB

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Analyzing experimental data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Some imports*"
]
},
{
"cell_type": "code",
"execution_count": 97,
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"import numpy as np\n",
"import scipy\n",
"import typing\n",
"from matplotlib import pyplot as plt\n",
"import pandas as pd\n",
"%matplotlib inline\n",
"import seaborn as sns"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Spiketimes_Ntsr1Cre_2020_0003_s02_e05.npy res.pkl\n",
"Spiketimes_Ntsr1Cre_2020_0003_s02_e10.npy simple_cell_center_fp\n",
"Stiminfo_Ntsr1Cre_2020_0003_s02_e05.npy simple_cell_random_fp\n",
"Stiminfo_Ntsr1Cre_2020_0003_s02_e10.npy\n"
]
}
],
"source": [
"!ls data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### *Load squares data*"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"\n",
"squares_stim = np.load(open('data/Stiminfo_Ntsr1Cre_2020_0003_s02_e10.npy', 'rb'), allow_pickle=True).item()\n",
"squares_spikes = np.load(open('data/Spiketimes_Ntsr1Cre_2020_0003_s02_e10.npy', 'rb'), allow_pickle=True).item()"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('AsparseNoise5_60deg',\n",
" dict_keys(['ename', 'area', 'probename', 'electrode_spacing', 'monitor_offset', 'stimtimes', 'stimvals', 'opto', 'optotimes', 'ivs', 'run_spdthr', 'run_minon', 'runperiods']))"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"squares_stim['ename'], squares_stim.keys()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['grat_x_position', 'grat_y_position', 'grat_contrast'])"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"squares_stim['ivs'].keys()"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/lib/python3.10/site-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).\n",
" warnings.warn(msg, FutureWarning)\n"
]
},
{
"data": {
"text/plain": [
"<AxesSubplot:ylabel='Density'>"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAD4CAYAAAD7CAEUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAmF0lEQVR4nO3de3gcd33v8fd3d3XxTZZsybbi+w07joltxXEuDilJSuMEiktbICmQkEOb5iHpgZZDm9JDH3h6nnMoD5eW53ASEkiBljsJYMBNcEPu5GY7ji+xHSu+27It2fLduuzu9/wxI0VRZGvX0WpmV5/X8+yzu7Mzs5/Zlea785v5zZi7IyIikqtE1AFERKS4qHCIiEheVDhERCQvKhwiIpIXFQ4REclLKuoAg6G2ttanTZsWdQwRkaKyZs2aFnev6z18SBSOadOmsXr16qhjiIgUFTPb1ddwNVWJiEheVDhERCQvKhwiIpIXFQ4REcmLCoeIiORFhUNERPKiwiEiInlR4RARkbyocIiISF6GRM/xUvT953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FZdIsUslErxt/CjeNn4UR0518F+bD/L4q81s3H+cmy6dzAXVw6KOGDs5rUHc/b/c/UNAA7ATWGVmvzOz28xM23QxlHXnl+v38+DafUyqGcYnrpvNO+eMU9EQOYcxI8r5wOLJ3LZ0Gh3pDN948jU27jsWdazYyXktYmZjgY8Cfw68BPwrQSFZVZBkct6y7jy0dh/PvnaYpTPHctuV06kZXh51LJGiMXvcKO68ZhYTqir5wQu7u4/MkkBOhcPMHgKeAoYDf+ju73X3H7n7XwE
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.distplot(squares_stim['ivs']['grat_x_position'])"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(25.4911, 80.5089)"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"squares_stim['ivs']['grat_x_position'].min(), squares_stim['ivs']['grat_x_position'].max()"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(-27.5089, 27.5089)"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"squares_stim['ivs']['grat_y_position'].min(), squares_stim['ivs']['grat_y_position'].max()"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 4, 8, 11, 14, 17, 20, 26, 29, 33, 34, 35, 36, 37,\n",
" 41, 44, 45, 46, 48, 51, 58, 59, 67, 72, 77, 82, 87,\n",
" 93, 96, 101, 104, 112, 116, 120, 128, 129, 140, 141, 142, 144,\n",
" 145])"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"squares_spikes['units']"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/lib/python3.10/site-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).\n",
" warnings.warn(msg, FutureWarning)\n"
]
},
{
"data": {
"text/plain": [
"<AxesSubplot:ylabel='Density'>"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZUAAAD4CAYAAAAkRnsLAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAy7ElEQVR4nO3dd3xU95nv8c+jLtQbQhVJIDDVBsuAu+OKcRycOM7aTmJSiZPYm91sNiE3N7vOvrI33tzcTdk4dpysE9tJ3OISkpAQd3sxHUQRICMEqIIKqIGEyjz3jznYsiykEczojGae9+ul18ycc34z3xGaeTjnd36/I6qKMcYY4w8RbgcwxhgTOqyoGGOM8RsrKsYYY/zGiooxxhi/saJijDHGb6LcDuCmzMxMLSoqcjuGMcZMKFu3bm1R1azh1oV1USkqKmLLli1uxzDGmAlFRA6faZ0d/jLGGOM3VlSMMcb4jRUVY4wxfmNFxRhjjN9YUTHGGOM3VlSMMcb4jRUVY4wxfmNFxRhjjN9YUTHGGOM3YT2i3phw87uNNX5/zjsXF/r9Oc3EZXsqxhhj/MaKijHGGL+xomKMMcZvrKgYY4zxGysqxhhj/MaKijHGGL+xomKMMcZvrKgYY4zxGxv8aIwf2KBCY7xsT8UYY4zf2J6KMROQqtLcdYqa1pO0d/fRdaqf7t4BYqMjSE+IZfrkRHJT4hARt6OaMGNFxZgg1zfgofJIJzvr2tlV38au+nYONp/gRO/AiO1yU+K4ZlY2n7x4KjOyk8YprQl3VlSMCTL9Hg+1x7r54Ytvs/5AK+V1bfT2ewBIiY9mXl4Kt5WlU5QxiamZCaRPiiEhNopJMZGc6vf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{
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.distplot(squares_spikes['spiketimes'][0])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### *Load gratings data*"
]
},
{
"cell_type": "code",
"execution_count": 155,
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
},
"outputs": [],
"source": [
"gratings_stim = np.load(open('data/Stiminfo_Ntsr1Cre_2020_0003_s02_e05.npy', 'rb'), allow_pickle=True).item()\n",
"gratings_spikes = np.load(open('data/Spiketimes_Ntsr1Cre_2020_0003_s02_e05.npy', 'rb'), allow_pickle=True).item()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['ename', 'area', 'probename', 'electrode_spacing', 'monitor_offset', 'stimtimes', 'stimvals', 'optotimes', 'opto', 'optofreq', 'ivs', 'run_spdthr', 'run_minon', 'runperiods'])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gratings_stim.keys()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'oriTun12_opto'"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gratings_stim['ename']"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['grat_height', 'opto', 'optofreq'])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gratings_stim['ivs'].keys()"
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 9.55191999, -3.82510311, 1.18950616, 1. , 3.35761066,\n",
" 4.65747346, 0.05402836])"
]
},
"execution_count": 158,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gratings_spikes['RFpars'][0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pre-processing squares data"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"*Turn squares data into a better format*\n",
"\n",
"`{'squares': (x, y, c), 'firing_rates': [fr1, fr2, ...]}`"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([1.512 , 1.7124]),\n",
" array([1155.5455, 1155.7459]),\n",
" 54.692066,\n",
" 1152.682366)"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"squares_stim['stimtimes'][0], squares_stim['stimtimes'][-1], squares_spikes['spiketimes'][0][0], squares_spikes['spiketimes'][0][-1]"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [],
"source": [
"get_firing_rates = lambda i: ((squares_stim['stimtimes'][:, 0].reshape((-1, 1)) <= squares_spikes['spiketimes'][i]) * (squares_spikes['spiketimes'][i] < squares_stim['stimtimes'][:, 1].reshape((-1, 1)))).sum(axis=1) / (squares_stim['stimtimes'][:, 1] - squares_stim['stimtimes'][:, 0])"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(40, 5760)"
]
},
"execution_count": 73,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"N_UNITS = squares_spikes['spiketimes'].shape[0]\n",
"N_EXPS = squares_stim['stimtimes'].shape[0]\n",
"N_UNITS, N_EXPS"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {},
"outputs": [],
"source": [
"firing_rates = np.array([get_firing_rates(i) for i in range(N_UNITS)])"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [],
"source": [
"stim_data = np.array([((squares_stim['ivs']['grat_x_position'][i] - 25) * 100 / 60, 100 * (squares_stim['ivs']['grat_y_position'][i] / 55) + 50, round(squares_stim['ivs']['grat_contrast'][i])) for i in range(len(squares_stim['ivs']['grat_x_position']))])"
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"((40, 5760), (5760, 3))"
]
},
"execution_count": 79,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"squares_data = {'squares': stim_data, 'firing_rates': firing_rates}\n",
"firing_rates.shape, stim_data.shape"
]
},
{
"cell_type": "code",
"execution_count": 88,
"metadata": {},
"outputs": [],
"source": [
"fields_plus = [np.zeros((100, 100)) for i in range(N_UNITS)]\n",
"fields_minus = [np.zeros((100, 100)) for i in range(N_UNITS)]\n",
"r_coord = lambda x: min(max(round(x), 0), 99)\n",
"\n",
"for i in range(N_EXPS):\n",
" for j in range(N_UNITS):\n",
" if squares_data['squares'][i, 2] >= 0:\n",
" fields_plus[j][r_coord(squares_data['squares'][i, 0]), r_coord(squares_data['squares'][i, 1])] += squares_data['firing_rates'][j, i]\n",
" else:\n",
" fields_minus[j][r_coord(squares_data['squares'][i, 0]), r_coord(squares_data['squares'][i, 1])] += squares_data['firing_rates'][j, i]"
]
},
{
"cell_type": "code",
"execution_count": 89,
"metadata": {},
"outputs": [],
"source": [
"for i in range(N_UNITS):\n",
" fields_plus[i] = scipy.ndimage.gaussian_filter(fields_plus[i], sigma=4)\n",
" fields_minus[i] = scipy.ndimage.gaussian_filter(fields_minus[i], sigma=4)"
]
},
{
"cell_type": "code",
"execution_count": 94,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAESCAYAAADkJY5uAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz9eZRtW3beBf7mWnufcyLixu1el+9lvkwprZTVFahzSu6wGLYEGCgbXBYGFyWMbaECUYApg0wzimLY2FRBDVzFqIFlsJExbuhkGyMsC2PJNnLZKctOSZmSMqXs82Xm6++90Zyz915r1h9zrrXXiYh7b8R9L2/mS505RtyIe5rdrL3WXHN+85tziq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ELvnvmc35P9ZwXyd308suNTqnyRhT4p4Dnm/+/A3jh7IdU9fuB7we40T+lv/LGPwEpockmAznPHw6h3oiq+ueS/c6KxIgsemRvheztoasF9B0aAkRB+2iTWIQwJsLpiJxuICVXzuU8Yso/mmaTlGGcYJrQabKF0Z67Kvf5+xIjxIjEAP0CWS54TV/iF177m7xy/NGPX3ZM9p9+Xr/6H/nXWL2WWNwZCZsJGTOSMyQ/py9MMoRhgimdn4Ax2P0vOrSbHSuNgdwHEAibRDwZkWGy97qAxggBtI/kZWRaRbTzc/n5NQgaywHt/2kp5E6QrMRBiRvf7DphWgXGg8DmprC5Dfde+Qif+X//p8OD5ko7Jtfltn6L/Pqzw/YlJa/rK/wEf/WBYwLb47L37PP6Fb/l93Dts4n9F06Jrx4jGzuELhfk63tMhwvSMoIqcZOJ6wkZE5LUNvMo5GX
"text/plain": [
"<Figure size 432x288 with 15 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots(3, 5)\n",
"ax = ax.flatten()\n",
"# set title\n",
"fig.suptitle('Receptive fields - positive')\n",
"for i in range(len(ax)):\n",
" ax[i].imshow(fields_plus[i])"
]
},
{
"cell_type": "code",
"execution_count": 95,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAESCAYAAADkJY5uAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz9ebBtW3bWB/7GnHOtvfc559777n0vX7YvUz3qAIGQRFMYOUD0bYWhaIwxUVhFuTBBUwWyK8qmFAaEC4ehiqgwgqAzpnGY1kYgyRRCNLJRDymhNpWdXma+9jbnnL33WmvOUX+MMeda59zm3fPey5v5UntEnDjd3nvNNdecY47xjW+MIarKQQ5ykIMc5K0n4VM9gIMc5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HWePnBN4wFo5eXZeF/XVQdAAJcp9+yJkkOxro+i8TpbQqT9vDb6/RC4srbZvlsuiLtO6DHX+HcHXxfx3ASi+pvO8rjUImoTcCempW0ynd7jSnMT+y4+O3+YLdB4Xxdal5Mv7QOcX3afB/GYetSfE7rGkhe64dK/Lj5t1jEIRwgRhhDD6HFx+luLPIYjvI3u225c++tJCpzR5Iwr8o8Bzi9/fAzx/+UWq+o3ANwK8/Ytv6Xv+5Ndy+/1Pc+sH4fpP7OhePoNxghQpxyvycUdeRQDCWJDJblAFiEKJgbwOjMeBvDLN0p8V1i/sSS/chVfvoNsdlIKsV8jxMXpyRDlZkTcdeR2ZTiL765H9DSGvfZLFlE1Z2bW6e8LRJ5TrHxpYPX8XuXsGIVCevs75cyfce09k97SgCdIZrF9Sxh/7AB/9gW/h1Zd/9EOPOycnt57TL/tFv5e4K0hWO2iwBxx3E2E/IZMdcpLVDqd
"text/plain": [
"<Figure size 432x288 with 15 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots(3, 5)\n",
"ax = ax.flatten()\n",
"# set title\n",
"fig.suptitle('Receptive fields - negative')\n",
"for i in range(len(ax)):\n",
" ax[i].imshow(fields_minus[i])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Finding centers of the receptive fields"
]
},
{
"cell_type": "code",
"execution_count": 129,
"metadata": {},
"outputs": [],
"source": [
"from scipy import signal\n",
"\n",
"def gkern(kernlen=100, std=5, x=0, y=0):\n",
" \"\"\"Returns a 2D Gaussian kernel array.\"\"\"\n",
" if not x and not y:\n",
" gkern1d = signal.gaussian(kernlen, std=std).reshape(kernlen, 1)\n",
" gkern2d = np.outer(gkern1d, gkern1d)\n",
" return gkern2d\n",
" else:\n",
" return np.roll(gkern(kernlen, std, 0, 0), (x - 50, y - 50))\n",
"\n",
"\n",
"def find_center(field) -> typing.Tuple[typing.Tuple[int, int], float]:\n",
" \"\"\"\n",
" Find the center of the field and return it and the score\n",
" \"\"\"\n",
" center = np.unravel_index(np.argmax(scipy.ndimage.gaussian_filter(field, sigma=7)), field.shape)\n",
" score = np.sum(field * gkern(x=center[0], y=center[1])) / field.mean()\n",
" return center, score"
]
},
{
"cell_type": "code",
"execution_count": 130,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/tmp/ipykernel_1038211/2956312832.py:18: RuntimeWarning: invalid value encountered in double_scalars\n",
" score = np.sum(field * gkern(x=center[0], y=center[1])) / field.mean()\n"
]
}
],
"source": [
"centers_pos = [find_center(fields_plus[i]) for i in range(N_UNITS)]\n",
"centers_neg = [find_center(fields_minus[i]) for i in range(N_UNITS)]"
]
},
{
"cell_type": "code",
"execution_count": 141,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/lib/python3.10/site-packages/seaborn/distributions.py:2619: FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).\n",
" warnings.warn(msg, FutureWarning)\n"
]
},
{
"data": {
"text/plain": [
"12"
]
},
"execution_count": 141,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAD4CAYAAAD7CAEUAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAli0lEQVR4nO3de3icdZ338fc3k0xOTdomTXpuE9rSUk6llFJAXRHBlhWq6wkEQfTZisLuqusBxcvjPs/q+qwHXBYW3e7CCoKswlPcKgIiglBoKxR6pOkxadomPeZ8mMz3+WMmNYQcZtrcmUnm87quuTJzz+8393fuZPKZ+/S7zd0RERFJVFaqCxARkZFFwSEiIklRcIiISFIUHCIikhQFh4iIJCU71QUMhwkTJnhFRUWqyxARGVHWr19/yN3Lek/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W7vmFvOwhnj+NHvtvPM6/oOIjISDTbkyKeBS4AL3L3U3UuAC4FLzOwzQRcn6efZ1+vZdaiZq86ZQnlRXtL9zYyrz53K6eVFfOahV6hr1GVdREaawYLjBuBad9/VPcHddwLXx5+TDHKoqZ2nttZx5pRiFs4Yd9KvE87O4s7rzqOpPcJXH92Exs4UGVkGC44cdz/Ue2J8P0dOH+1llHJ3Vm2oJZRlXHXOlFPesT27vIjPvPN0frPpAP/z2v4hqlJEhsNgwdFxks/JKLOptoGquiaumD+R4vyh+c7w12+t5OypY/nmY5tpao8MyWuKSPAGC45zzayhj1sjcPZwFCip1xV1Ht90gPKiXBZXlg7Z62aHsvjm8jOpa2znR09tH7LXFZFgDRgc7h5y9+I+bkX
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"sns.distplot([centers_pos[i][1] for i in range(N_UNITS)])\n",
"tuning_threshold = 200\n",
"sum(centers_pos[i][1] > tuning_threshold for i in range(N_UNITS))"
]
},
{
"cell_type": "code",
"execution_count": 142,
"metadata": {},
"outputs": [],
"source": [
"tuned_units = [i for i in range(N_UNITS) if centers_pos[i][1] > tuning_threshold]"
]
},
{
"cell_type": "code",
"execution_count": 143,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAWgAAAEVCAYAAADNWX/KAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAEAAElEQVR4nOz9ebCt23YXhv3GmPNba+3mnHPPfbd59+o9PYlODY7BBIQIFJZNY8AQXClDAIWAC6zCsSqQkETCsRObuBEpJ+XETRUC0zgYA6mADUFBCIomYBeWrEg0ivQkvff0uqvX3Xua3az1fXPOkT/GGHPOb+2199nn3rP2vY7XqFpn77P2t771ffObc8wxfuM3xiAR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LT1ZeRj2O65DACGgqPFhCUnMAmKEAQEJkFAQQHhMg9YTwNkYlCysbP5UJ+unV/nBmZzQ0jHVgKAKBiGhEXIeOdHv3zb8X1+vUArOeJTm2cEENd1ZYt/pgtmaxHd3L5JqF+jfm4fAF/43fH92hCZLx/aOr4etq3TtvTCNfIkXz+270VB7/rGK0NFRN8G4NsAYBXu4X/w2m+BpKQT3JUgAHgvUuqMeimQXIBp0p92DMUIWi1BR0eQkyPIaglZBlWGBEhkyGCKUQAeM/gygTcTMKU28D5ozEAMkGBKJxVgSqBxAsYJkjJQMjAlSM56/UVm10xBFykNEYgRNAzAagk5WqIcDZAh4K/9V/+7n3qR49uP7eLkIf6xX/v7sHhaEC8yOJWqGCgXVaJQhVnHZcp6r/14+IZUAETWsYxsCoVQFoy8DCiDniOsM+J
"text/plain": [
"<Figure size 432x288 with 12 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"fig, ax = plt.subplots(3, 4)\n",
"ax = ax.flatten()\n",
"fig.suptitle('Receptive fields for tuned units')\n",
"for i in range(min(len(tuned_units), len(ax))):\n",
" ax[i].imshow(fields_plus[tuned_units[i]])\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Preprocessing grating data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.5 64-bit",
"language": "python",
"name": "python3"
},
"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.10.5"
},
"vscode": {
"interpreter": {
"hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a"
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}