{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "17:02:17 [I] klustakwik KlustaKwik2 version 0.2.6\n" ] } ], "source": [ "import os\n", "import expipe\n", "import pathlib\n", "import numpy as np\n", "import spatial_maps.stats as stats\n", "import septum_mec.analysis.data_processing as dp\n", "import head_direction.head as head\n", "import spatial_maps as sp\n", "import septum_mec.analysis.registration\n", "import speed_cells.speed as spd\n", "import septum_mec.analysis.spikes as spikes\n", "import re\n", "import joblib\n", "import multiprocessing\n", "import shutil\n", "import psutil\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import septum_mec\n", "import scipy.ndimage.measurements\n", "from distutils.dir_util import copy_tree\n", "\n", "from tqdm import tqdm_notebook as tqdm\n", "from tqdm._tqdm_notebook import tqdm_notebook\n", "tqdm_notebook.pandas()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "max_speed = 1, # m/s only used for speed score\n", "min_speed = 0.02, # m/s only used for speed score\n", "position_sampling_rate = 100 # for interpolation\n", "position_low_pass_frequency = 6 # for low pass filtering of position\n", "\n", "box_size = [1.0, 1.0]\n", "bin_size = 0.02\n", "smoothing_low = 0.03\n", "smoothing_high = 0.06\n", "\n", "stim_mask = True\n", "baseline_duration = 600" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "project_path = dp.project_path()\n", "\n", "project = expipe.get_project(project_path)\n", "actions = project.actions" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
actionchannel_groupmax_depth_deltamax_dissimilarityunit_idunit_idnumunit_name
01834-010319-101000.05ae0353a9-a406-409e-8ff7-2e940b8af03f3272
11834-010319-101000.057f514d43-17ba-4d88-a390-20eec8bc137832839
21834-010319-301000.05c977aa51-06cc-4d54-9430-a94ad422a03b3291
31834-010319-301000.05bd96a67d-ee7d-4cb6-90ab-a5fa751891b933012
41834-010319-401000.05abc01041-2971-4f62-bf06-5132cf3567373327
\n", "
" ], "text/plain": [ " action channel_group max_depth_delta max_dissimilarity \\\n", "0 1834-010319-1 0 100 0.05 \n", "1 1834-010319-1 0 100 0.05 \n", "2 1834-010319-3 0 100 0.05 \n", "3 1834-010319-3 0 100 0.05 \n", "4 1834-010319-4 0 100 0.05 \n", "\n", " unit_id unit_idnum unit_name \n", "0 ae0353a9-a406-409e-8ff7-2e940b8af03f 327 2 \n", "1 7f514d43-17ba-4d88-a390-20eec8bc1378 328 39 \n", "2 c977aa51-06cc-4d54-9430-a94ad422a03b 329 1 \n", "3 bd96a67d-ee7d-4cb6-90ab-a5fa751891b9 330 12 \n", "4 abc01041-2971-4f62-bf06-5132cf356737 332 7 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "identify_neurons = actions['identify-neurons']\n", "units = pd.read_csv(identify_neurons.data_path('units'))\n", "units.head()" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXIAAAD7CAYAAAB37B+tAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxp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UnH+PvItRMTjbLwzB+BXmVnmZwARcRC4LTMPRcQbgRPAOvAkcGNmvtDmfOO4YA1XAt8Efj748Jcy8+vtTbe9iNgL3AusAJcBnwV+RqH9MGQNv6HWftgD3AUEG3/u/wT0KbQfJmHILxARy8BSZh5qe5ZJRcTNwPXAnwcPHQeOZub3IuLfgWvZ+EH1jrXFGg4AxzOzytXD7weeyczrI+KVwE8G/1XaD1ut4V+otR/eC5CZb4mIQ8C/svHGjEr7YWyeWnmxK4CXRsRDEfGdwdsrq3gauG7T/QPAw4Pbp4Cr5z7R5LZaw+GIeCQi7omIfUM+b6f4BnDr4PYScJZ6+2HYGsrsh8z8L+DDg7uvB56l3n4YmyF/seeB24F3sfHXsa9GRIm/uWTm/cDapoeWMvP825KeAy6f/1ST2WINjwKfzMy3Ab8EPtPKYGPKzD9l5nOD0N0HHKXYfhiyhlL7ASAzz0bEV4A7ga9SbD9MwpC/2GngPzNzPTNPA88Ar2l5pqY2n//bx8ZRSTUPZuZj528DV7Y5zDgi4nXAd4H/yMyvUXA/bLGGcvsBIDM/APwtG+fLX7LpQyX2w7gM+YvdwOC3OUbEa4GXA79tdaLmnhicHwS4Bvh+i7M09e2I+PvB7XcAj2335LZFxKuBh4BPZea9g4dL7Ycha6i2H66PiE8P7j7Pxv9M/6fSfphEiVMGc3YPcCIifsDGT7dv2O73yOxwnwDuiogO0GPjr8nVfAS4MyLWgN/x/+c9d6pbgFcAt0bE+fPMNwGfL7QftlrDPwOfK7QfHgC+HBGPAHuBj7PxZ1/99bAlr+yUpOI8tSJJxRlySSrOkEtScYZckooz5JJUnCGXpOIMuSQVZ8glqbj/A6ohRpd2pMWOAAAAAElFTkSuQmCC\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "%matplotlib inline\n", "units.groupby('action').count().unit_name.hist()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "data_loader = dp.Data(\n", " position_sampling_rate=position_sampling_rate, \n", " position_low_pass_frequency=position_low_pass_frequency,\n", " box_size=box_size, bin_size=bin_size, stim_mask=stim_mask, baseline_duration=baseline_duration\n", ")" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "first_row = units[units['action'] == '1849-060319-3'].iloc[0]\n", "#first_row = sessions.iloc[50]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/elephant/statistics.py:835: UserWarning: Instantaneous firing rate approximation contains negative values, possibly caused due to machine precision errors.\n", " warnings.warn(\"Instantaneous firing rate approximation contains \"\n" ] }, { "data": { "text/plain": [ "average_rate 3.168492\n", "speed_score -0.068927\n", "out_field_mean_rate 1.857990\n", "in_field_mean_rate 5.257561\n", "max_field_mean_rate 8.882211\n", "max_rate 23.006163\n", "sparsity 0.466751\n", "selectivity 7.153172\n", "interspike_interval_cv 3.807699\n", "burst_event_ratio 0.398230\n", "bursty_spike_ratio 0.678064\n", "gridness -0.466923\n", "border_score 0.029328\n", "information_rate 1.009215\n", "information_specificity 0.317256\n", "head_mean_ang 5.438033\n", "head_mean_vec_len 0.040874\n", "spacing 0.628784\n", "orientation 20.224859\n", "dtype: float64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def process(row):\n", " action_id = row['action']\n", " channel_id = row['channel_group']\n", " unit_id = row['unit_name']\n", " \n", " # common values for all units == faster calculations\n", " x, y, t, speed = map(data_loader.tracking(action_id).get, ['x', 'y', 't', 'v'])\n", " ang, ang_t = map(data_loader.head_direction(action_id).get, ['a', 't'])\n", " \n", " occupancy_map = data_loader.occupancy(action_id)\n", " xbins, ybins = data_loader.spatial_bins\n", " box_size_, bin_size_ = data_loader.box_size_, data_loader.bin_size_\n", " prob_dist = data_loader.prob_dist(action_id)\n", " \n", " smooth_low_occupancy_map = sp.maps.smooth_map(\n", " occupancy_map, bin_size=bin_size_, smoothing=smoothing_low)\n", " smooth_high_occupancy_map = sp.maps.smooth_map(\n", " occupancy_map, bin_size=bin_size_, smoothing=smoothing_high)\n", " \n", " spike_times = data_loader.spike_train(action_id, channel_id, unit_id)\n", " if len(spike_times) == 0:\n", " result = pd.Series({\n", " 'average_rate': np.nan,\n", " 'speed_score': np.nan,\n", " 'out_field_mean_rate': np.nan,\n", " 'in_field_mean_rate': np.nan,\n", " 'max_field_mean_rate': np.nan,\n", " 'max_rate': np.nan,\n", " 'sparsity': np.nan,\n", " 'selectivity': np.nan,\n", " 'interspike_interval_cv': np.nan,\n", " 'burst_event_ratio': np.nan,\n", " 'bursty_spike_ratio': np.nan,\n", " 'gridness': np.nan,\n", " 'border_score': np.nan,\n", " 'information_rate': np.nan,\n", " 'information_specificity': np.nan,\n", " 'head_mean_ang': np.nan,\n", " 'head_mean_vec_len': np.nan,\n", " 'spacing': np.nan,\n", " 'orientation': np.nan\n", " })\n", " return result\n", "\n", " # common\n", " spike_map = sp.maps._spike_map(x, y, t, spike_times, xbins, ybins)\n", "\n", " smooth_low_spike_map = sp.maps.smooth_map(spike_map, bin_size=bin_size_, smoothing=smoothing_low)\n", " smooth_high_spike_map = sp.maps.smooth_map(spike_map, bin_size=bin_size_, smoothing=smoothing_high)\n", "\n", " smooth_low_rate_map = smooth_low_spike_map / smooth_low_occupancy_map\n", " smooth_high_rate_map = smooth_high_spike_map / smooth_high_occupancy_map\n", "\n", " # find fields with laplace\n", " fields_laplace = sp.separate_fields_by_laplace(smooth_high_rate_map)\n", " fields = fields_laplace.copy() # to be cleaned by Ismakov\n", " fields_areas = scipy.ndimage.measurements.sum(\n", " np.ones_like(fields), fields, index=np.arange(fields.max() + 1))\n", " fields_area = fields_areas[fields]\n", " fields[fields_area < 9.0] = 0\n", "\n", " # find fields with Ismakov-method\n", " fields_ismakov, radius = sp.separate_fields_by_distance(smooth_high_rate_map)\n", " fields_ismakov_real = fields_ismakov * bin_size\n", " approved_fields = []\n", "\n", " # remove fields not found by both methods\n", " for point in fields_ismakov:\n", " field_id = fields[tuple(point)]\n", " approved_fields.append(field_id)\n", "\n", " for field_id in np.arange(1, fields.max() + 1):\n", " if not field_id in approved_fields:\n", " fields[fields == field_id] = 0\n", "\n", " # varying statistics\n", " average_rate = len(spike_times) / (t.max() - t.min())\n", "\n", " max_rate = smooth_low_rate_map.max()\n", "\n", " out_field_mean_rate = smooth_low_rate_map[np.where(fields == 0)].mean()\n", " in_field_mean_rate = smooth_low_rate_map[np.where(fields != 0)].mean()\n", " max_field_mean_rate = smooth_low_rate_map[np.where(fields == 1)].mean()\n", "\n", " interspike_interval = np.diff(spike_times)\n", " interspike_interval_cv = interspike_interval.std() / interspike_interval.mean()\n", "\n", " autocorrelogram = sp.autocorrelation(smooth_high_rate_map)\n", " peaks = sp.fields.find_peaks(autocorrelogram)\n", " real_peaks = peaks * bin_size\n", " autocorrelogram_box_size = box_size[0] * autocorrelogram.shape[0] / smooth_high_rate_map.shape[0]\n", " spacing, orientation = sp.spacing_and_orientation(real_peaks, autocorrelogram_box_size)\n", " orientation *= 180 / np.pi\n", "\n", " selectivity = stats.selectivity(smooth_low_rate_map, prob_dist)\n", "\n", " sparsity = stats.sparsity(smooth_low_rate_map, prob_dist)\n", "\n", " gridness = sp.gridness(smooth_high_rate_map)\n", "\n", " border_score = sp.border_score(smooth_high_rate_map, fields_laplace)\n", "\n", " information_rate = stats.information_rate(smooth_high_rate_map, prob_dist)\n", " \n", " information_spec = stats.information_specificity(smooth_high_rate_map, prob_dist)\n", "\n", " single_spikes, bursts, bursty_spikes = spikes.find_bursts(spike_times, threshold=0.01)\n", " burst_event_ratio = np.sum(bursts) / (np.sum(single_spikes) + np.sum(bursts))\n", " bursty_spike_ratio = np.sum(bursty_spikes) / (np.sum(bursty_spikes) + np.sum(single_spikes))\n", " mean_spikes_per_burst = np.sum(bursty_spikes) / np.sum(bursts)\n", "\n", " speed_score = spd.speed_correlation(\n", " speed, t, spike_times, min_speed=min_speed, max_speed=max_speed)\n", "\n", " ang_bin, ang_rate = head.head_direction_rate(spike_times, ang, ang_t)\n", "\n", " head_mean_ang, head_mean_vec_len = head.head_direction_score(ang_bin, ang_rate)\n", "\n", " result = pd.Series({\n", " 'average_rate': average_rate,\n", " 'speed_score': speed_score,\n", " 'out_field_mean_rate': out_field_mean_rate,\n", " 'in_field_mean_rate': in_field_mean_rate,\n", " 'max_field_mean_rate': max_field_mean_rate,\n", " 'max_rate': max_rate,\n", " 'sparsity': sparsity,\n", " 'selectivity': selectivity,\n", " 'interspike_interval_cv': float(interspike_interval_cv),\n", " 'burst_event_ratio': burst_event_ratio,\n", " 'bursty_spike_ratio': bursty_spike_ratio,\n", " 'gridness': gridness,\n", " 'border_score': border_score,\n", " 'information_rate': information_rate,\n", " 'information_specificity': information_spec,\n", " 'head_mean_ang': head_mean_ang,\n", " 'head_mean_vec_len': head_mean_vec_len,\n", " 'spacing': spacing,\n", " 'orientation': orientation\n", " })\n", " return result\n", " \n", "process(first_row)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "2372ae1b2bea435dbc5bbfe2453747a6", "version_major": 2, "version_minor": 0 }, "text/plain": [ "HBox(children=(IntProgress(value=0, max=1284), HTML(value='')))" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "/home/mikkel/apps/expipe-project/spatial-maps/spatial_maps/stats.py:13: RuntimeWarning: invalid value encountered in log2\n", " return (np.nansum(np.ravel(tmp_rate_map * np.log2(tmp_rate_map/avg_rate) *\n", "/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:110: RuntimeWarning: invalid value encountered in long_scalars\n", "/home/mikkel/apps/expipe-project/spatial-maps/spatial_maps/stats.py:13: RuntimeWarning: divide by zero encountered in log2\n", " return (np.nansum(np.ravel(tmp_rate_map * np.log2(tmp_rate_map/avg_rate) *\n", "/home/mikkel/apps/expipe-project/spatial-maps/spatial_maps/stats.py:13: RuntimeWarning: invalid value encountered in multiply\n", " return (np.nansum(np.ravel(tmp_rate_map * np.log2(tmp_rate_map/avg_rate) *\n" ] } ], "source": [ "results = units.merge(\n", " units.progress_apply(process, axis=1), \n", " left_index=True, right_index=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%debug" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "output_path = pathlib.Path(\"output\") / \"calculate-statistics\"\n", "output_path.mkdir(exist_ok=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "results.to_csv(output_path / \"results.csv\", index=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Store results in Expipe action" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "statistics_action = project.require_action(\"calculate-statistics\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "statistics_action.data[\"results\"] = \"results.csv\"\n", "copy_tree(output_path, str(statistics_action.data_path()))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "statistics_action.modules['parameters'] = {\n", " 'max_speed': max_speed,\n", " 'min_speed': min_speed,\n", " 'position_sampling_rate': position_sampling_rate,\n", " 'position_low_pass_frequency': position_low_pass_frequency,\n", " 'box_size': box_size,\n", " 'bin_size': bin_size,\n", " 'smoothing_low': smoothing_low,\n", " 'smoothing_high': smoothing_high,\n", " 'stim_mask': stim_mask,\n", " 'baseline_duration': baseline_duration\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "septum_mec.analysis.registration.store_notebook(statistics_action, \"10_calculate_spatial_statistics.ipynb\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }