auto commit actions/calculate-statistics

This commit is contained in:
Mikkel Elle Lepperød 2019-10-09 14:24:33 +02:00
parent fcf3c9bf25
commit 7c18a9f762
3 changed files with 14076 additions and 14167 deletions

View File

@ -1,6 +1,6 @@
registered: '2019-10-04T08:11:18' registered: '2019-10-04T08:11:18'
data: data:
units: units.csv units: units.csv
results: results.csv results: results.csv
notebook: 10_calculate_spatial_statistics.ipynb notebook: 10_calculate_spatial_statistics.ipynb
html: 10_calculate_spatial_statistics.html html: 10_calculate_spatial_statistics.html

View File

@ -1,482 +1,451 @@
{ {
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"%load_ext autoreload\n", "%load_ext autoreload\n",
"%autoreload 2" "%autoreload 2"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"08:27:22 [I] klustakwik KlustaKwik2 version 0.2.6\n" "17:02:20 [I] klustakwik KlustaKwik2 version 0.2.6\n"
] ]
} }
], ],
"source": [ "source": [
"import os\n", "import os\n",
"import expipe\n", "import expipe\n",
"import pathlib\n", "import pathlib\n",
"import numpy as np\n", "import numpy as np\n",
"import spatial_maps.stats as stats\n", "import spatial_maps.stats as stats\n",
"import septum_mec.analysis.data_processing as dp\n", "import septum_mec.analysis.data_processing as dp\n",
"import head_direction.head as head\n", "import head_direction.head as head\n",
"import spatial_maps as sp\n", "import spatial_maps as sp\n",
"import septum_mec.analysis.registration\n", "import septum_mec.analysis.registration\n",
"import speed_cells.speed as spd\n", "import speed_cells.speed as spd\n",
"import septum_mec.analysis.spikes as spikes\n", "import septum_mec.analysis.spikes as spikes\n",
"import re\n", "import re\n",
"import joblib\n", "import joblib\n",
"import multiprocessing\n", "import multiprocessing\n",
"import shutil\n", "import shutil\n",
"import psutil\n", "import psutil\n",
"import pandas as pd\n", "import pandas as pd\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"import septum_mec\n", "import septum_mec\n",
"import scipy.ndimage.measurements\n", "import scipy.ndimage.measurements\n",
"from distutils.dir_util import copy_tree\n", "from distutils.dir_util import copy_tree\n",
"\n", "\n",
"from tqdm import tqdm_notebook as tqdm\n", "from tqdm import tqdm_notebook as tqdm\n",
"from tqdm._tqdm_notebook import tqdm_notebook\n", "from tqdm._tqdm_notebook import tqdm_notebook\n",
"tqdm_notebook.pandas()" "tqdm_notebook.pandas()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"max_speed = 1, # m/s only used for speed score\n", "max_speed = 1, # m/s only used for speed score\n",
"min_speed = 0.02, # 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_sampling_rate = 100 # for interpolation\n",
"position_low_pass_frequency = 6 # for low pass filtering of position\n", "position_low_pass_frequency = 6 # for low pass filtering of position\n",
"\n", "\n",
"box_size = 1.0\n", "box_size = [1.0, 1.0]\n",
"bin_size = 0.02\n", "bin_size = 0.02\n",
"smoothing_low = 0.03\n", "smoothing_low = 0.03\n",
"smoothing_high = 0.06" "smoothing_high = 0.06"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"project_path = dp.project_path()\n", "project_path = dp.project_path()\n",
"\n", "\n",
"project = expipe.get_project(project_path)\n", "project = expipe.get_project(project_path)\n",
"actions = project.actions" "actions = project.actions"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/html": [ "text/html": [
"<div>\n", "<div>\n",
"<style scoped>\n", "<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n", " .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n", " vertical-align: middle;\n",
" }\n", " }\n",
"\n", "\n",
" .dataframe tbody tr th {\n", " .dataframe tbody tr th {\n",
" vertical-align: top;\n", " vertical-align: top;\n",
" }\n", " }\n",
"\n", "\n",
" .dataframe thead th {\n", " .dataframe thead th {\n",
" text-align: right;\n", " text-align: right;\n",
" }\n", " }\n",
"</style>\n", "</style>\n",
"<table border=\"1\" class=\"dataframe\">\n", "<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n", " <thead>\n",
" <tr style=\"text-align: right;\">\n", " <tr style=\"text-align: right;\">\n",
" <th></th>\n", " <th></th>\n",
" <th>action</th>\n", " <th>action</th>\n",
" <th>channel_group</th>\n", " <th>channel_group</th>\n",
" <th>unit_name</th>\n", " <th>max_depth_delta</th>\n",
" </tr>\n", " <th>max_dissimilarity</th>\n",
" </thead>\n", " <th>unit_id</th>\n",
" <tbody>\n", " <th>unit_name</th>\n",
" <tr>\n", " </tr>\n",
" <th>0</th>\n", " </thead>\n",
" <td>1834-150319-3</td>\n", " <tbody>\n",
" <td>0</td>\n", " <tr>\n",
" <td>71</td>\n", " <th>0</th>\n",
" </tr>\n", " <td>1834-010319-1</td>\n",
" <tr>\n", " <td>0</td>\n",
" <th>1</th>\n", " <td>100</td>\n",
" <td>1834-150319-3</td>\n", " <td>0.05</td>\n",
" <td>0</td>\n", " <td>8d8cecbe-e2e5-4020-9c94-9573ca55cdfc</td>\n",
" <td>75</td>\n", " <td>2</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>2</th>\n", " <th>1</th>\n",
" <td>1834-120319-4</td>\n", " <td>1834-010319-1</td>\n",
" <td>0</td>\n", " <td>0</td>\n",
" <td>85</td>\n", " <td>100</td>\n",
" </tr>\n", " <td>0.05</td>\n",
" <tr>\n", " <td>5b7fc3e8-b76d-4eed-a876-9ba184e508ac</td>\n",
" <th>3</th>\n", " <td>39</td>\n",
" <td>1834-120319-1</td>\n", " </tr>\n",
" <td>0</td>\n", " <tr>\n",
" <td>1</td>\n", " <th>2</th>\n",
" </tr>\n", " <td>1834-010319-3</td>\n",
" <tr>\n", " <td>0</td>\n",
" <th>4</th>\n", " <td>100</td>\n",
" <td>1834-120319-2</td>\n", " <td>0.05</td>\n",
" <td>0</td>\n", " <td>1b42831d-5d71-4cb1-ba85-b5019b56ca2e</td>\n",
" <td>39</td>\n", " <td>1</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " <tr>\n",
"</table>\n", " <th>3</th>\n",
"</div>" " <td>1834-010319-3</td>\n",
], " <td>0</td>\n",
"text/plain": [ " <td>100</td>\n",
" action channel_group unit_name\n", " <td>0.05</td>\n",
"0 1834-150319-3 0 71\n", " <td>270fb3b3-3a7d-4060-bc1a-bc68d2ecab1a</td>\n",
"1 1834-150319-3 0 75\n", " <td>12</td>\n",
"2 1834-120319-4 0 85\n", " </tr>\n",
"3 1834-120319-1 0 1\n", " <tr>\n",
"4 1834-120319-2 0 39" " <th>4</th>\n",
] " <td>1834-010319-3</td>\n",
}, " <td>0</td>\n",
"execution_count": 5, " <td>100</td>\n",
"metadata": {}, " <td>0.05</td>\n",
"output_type": "execute_result" " <td>6da7e1db-2d4f-4bd7-b45c-a1855aaa2fec</td>\n",
} " <td>72</td>\n",
], " </tr>\n",
"source": [ " </tbody>\n",
"identify_neurons = actions['identify-neurons']\n", "</table>\n",
"units = pd.read_csv(identify_neurons.data_path('units'))\n", "</div>"
"units.head()" ],
] "text/plain": [
}, " action channel_group max_depth_delta max_dissimilarity \\\n",
{ "0 1834-010319-1 0 100 0.05 \n",
"cell_type": "code", "1 1834-010319-1 0 100 0.05 \n",
"execution_count": 6, "2 1834-010319-3 0 100 0.05 \n",
"metadata": {}, "3 1834-010319-3 0 100 0.05 \n",
"outputs": [], "4 1834-010319-3 0 100 0.05 \n",
"source": [ "\n",
"data_loader = dp.Data(\n", " unit_id unit_name \n",
" position_sampling_rate=position_sampling_rate, \n", "0 8d8cecbe-e2e5-4020-9c94-9573ca55cdfc 2 \n",
" position_low_pass_frequency=position_low_pass_frequency,\n", "1 5b7fc3e8-b76d-4eed-a876-9ba184e508ac 39 \n",
" box_size=box_size, bin_size=bin_size\n", "2 1b42831d-5d71-4cb1-ba85-b5019b56ca2e 1 \n",
")" "3 270fb3b3-3a7d-4060-bc1a-bc68d2ecab1a 12 \n",
] "4 6da7e1db-2d4f-4bd7-b45c-a1855aaa2fec 72 "
}, ]
{ },
"cell_type": "code", "execution_count": 5,
"execution_count": 9, "metadata": {},
"metadata": {}, "output_type": "execute_result"
"outputs": [], }
"source": [ ],
"first_row = units[units['action'] == '1849-060319-3'].iloc[0]\n", "source": [
"#first_row = sessions.iloc[50]" "identify_neurons = actions['identify-neurons']\n",
] "units = pd.read_csv(identify_neurons.data_path('units'))\n",
}, "units.head()"
{ ]
"cell_type": "code", },
"execution_count": 10, {
"metadata": { "cell_type": "code",
"scrolled": false "execution_count": 6,
}, "metadata": {},
"outputs": [ "outputs": [],
{ "source": [
"name": "stderr", "data_loader = dp.Data(\n",
"output_type": "stream", " position_sampling_rate=position_sampling_rate, \n",
"text": [ " position_low_pass_frequency=position_low_pass_frequency,\n",
"/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", " box_size=box_size, bin_size=bin_size\n",
" warnings.warn(\"Instantaneous firing rate approximation contains \"\n" ")"
] ]
}, },
{ {
"data": { "cell_type": "code",
"text/plain": [ "execution_count": 7,
"average_rate 3.095328\n", "metadata": {},
"speed_score -0.063922\n", "outputs": [],
"out_field_mean_rate 1.837642\n", "source": [
"in_field_mean_rate 5.122323\n", "first_row = units[units['action'] == '1849-060319-3'].iloc[0]\n",
"max_field_mean_rate 8.882211\n", "#first_row = sessions.iloc[50]"
"max_rate 23.006163\n", ]
"sparsity 0.468122\n", },
"selectivity 7.306812\n", {
"interspike_interval_cv 3.970863\n", "cell_type": "code",
"burst_event_ratio 0.397921\n", "execution_count": null,
"bursty_spike_ratio 0.676486\n", "metadata": {
"gridness -0.459487\n", "scrolled": false
"border_score 0.078474\n", },
"information_rate 0.965845\n", "outputs": [],
"head_mean_ang 5.788704\n", "source": [
"head_mean_vec_len 0.043321\n", "def process(row):\n",
"spacing 0.624971\n", " action_id = row['action']\n",
"orientation 22.067900\n", " channel_id = row['channel_group']\n",
"dtype: float64" " unit_id = row['unit_name']\n",
] " \n",
}, " # common values for all units == faster calculations\n",
"execution_count": 10, " x, y, t, speed = map(data_loader.tracking(action_id).get, ['x', 'y', 't', 'v'])\n",
"metadata": {}, " ang, ang_t = map(data_loader.head_direction(action_id).get, ['a', 't'])\n",
"output_type": "execute_result" " 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",
"source": [ " prob_dist = data_loader.prob_dist(action_id)\n",
"def process(row):\n", " \n",
" action_id = row['action']\n", " smooth_low_occupancy_map = sp.maps.smooth_map(occupancy_map, bin_size=bin_size_, smoothing=smoothing_low)\n",
" channel_id = row['channel_group']\n", " smooth_high_occupancy_map = sp.maps.smooth_map(occupancy_map, bin_size=bin_size_, smoothing=smoothing_high)\n",
" unit_id = row['unit_name']\n", " \n",
" \n", " spike_times = data_loader.spike_train(action_id, channel_id, unit_id)\n",
" # common values for all units == faster calculations\n", "\n",
" x, y, t, speed = map(data_loader.tracking(action_id).get, ['x', 'y', 't', 'v'])\n", " # common\n",
" ang, ang_t = map(data_loader.head_direction(action_id).get, ['a', 't'])\n", " spike_map = sp.maps._spike_map(x, y, t, spike_times, xbins, ybins)\n",
" occupancy_map = data_loader.occupancy(action_id)\n", "\n",
" xbins, ybins = data_loader.spatial_bins\n", " smooth_low_spike_map = sp.maps.smooth_map(spike_map, bin_size=bin_size_, smoothing=smoothing_low)\n",
" box_size_, bin_size_ = data_loader.box_size_, data_loader.bin_size_\n", " smooth_high_spike_map = sp.maps.smooth_map(spike_map, bin_size=bin_size_, smoothing=smoothing_high)\n",
" prob_dist = data_loader.prob_dist(action_id)\n", "\n",
" \n", " smooth_low_rate_map = smooth_low_spike_map / smooth_low_occupancy_map\n",
" smooth_low_occupancy_map = sp.maps.smooth_map(occupancy_map, bin_size=bin_size_, smoothing=smoothing_low)\n", " smooth_high_rate_map = smooth_high_spike_map / smooth_high_occupancy_map\n",
" smooth_high_occupancy_map = sp.maps.smooth_map(occupancy_map, bin_size=bin_size_, smoothing=smoothing_high)\n", "\n",
" \n", " # find fields with laplace\n",
" spike_times = data_loader.spike_train(action_id, channel_id, unit_id)\n", " fields_laplace = sp.separate_fields_by_laplace(smooth_high_rate_map)\n",
"\n", " fields = fields_laplace.copy() # to be cleaned by Ismakov\n",
" # common\n", " fields_areas = scipy.ndimage.measurements.sum(\n",
" spike_map = sp.maps._spike_map(x, y, t, spike_times, xbins, ybins)\n", " np.ones_like(fields), fields, index=np.arange(fields.max() + 1))\n",
"\n", " fields_area = fields_areas[fields]\n",
" smooth_low_spike_map = sp.maps.smooth_map(spike_map, bin_size=bin_size_, smoothing=smoothing_low)\n", " fields[fields_area < 9.0] = 0\n",
" smooth_high_spike_map = sp.maps.smooth_map(spike_map, bin_size=bin_size_, smoothing=smoothing_high)\n", "\n",
"\n", " # find fields with Ismakov-method\n",
" smooth_low_rate_map = smooth_low_spike_map / smooth_low_occupancy_map\n", " fields_ismakov, radius = sp.separate_fields_by_distance(smooth_high_rate_map)\n",
" smooth_high_rate_map = smooth_high_spike_map / smooth_high_occupancy_map\n", " fields_ismakov_real = fields_ismakov * bin_size\n",
"\n", " approved_fields = []\n",
" # find fields with laplace\n", "\n",
" fields_laplace = sp.separate_fields_by_laplace(smooth_high_rate_map)\n", " # remove fields not found by both methods\n",
" fields = fields_laplace.copy() # to be cleaned by Ismakov\n", " for point in fields_ismakov:\n",
" fields_areas = scipy.ndimage.measurements.sum(\n", " field_id = fields[tuple(point)]\n",
" np.ones_like(fields), fields, index=np.arange(fields.max() + 1))\n", " approved_fields.append(field_id)\n",
" fields_area = fields_areas[fields]\n", "\n",
" fields[fields_area < 9.0] = 0\n", " for field_id in np.arange(1, fields.max() + 1):\n",
"\n", " if not field_id in approved_fields:\n",
" # find fields with Ismakov-method\n", " fields[fields == field_id] = 0\n",
" fields_ismakov, radius = sp.separate_fields_by_distance(smooth_high_rate_map)\n", "\n",
" fields_ismakov_real = fields_ismakov * bin_size\n", " # varying statistics\n",
" approved_fields = []\n", " average_rate = len(spike_times) / (t.max() - t.min())\n",
"\n", "\n",
" # remove fields not found by both methods\n", " max_rate = smooth_low_rate_map.max()\n",
" for point in fields_ismakov:\n", "\n",
" field_id = fields[tuple(point)]\n", " out_field_mean_rate = smooth_low_rate_map[np.where(fields == 0)].mean()\n",
" approved_fields.append(field_id)\n", " in_field_mean_rate = smooth_low_rate_map[np.where(fields != 0)].mean()\n",
"\n", " max_field_mean_rate = smooth_low_rate_map[np.where(fields == 1)].mean()\n",
" for field_id in np.arange(1, fields.max() + 1):\n", "\n",
" if not field_id in approved_fields:\n", " interspike_interval = np.diff(spike_times)\n",
" fields[fields == field_id] = 0\n", " interspike_interval_cv = interspike_interval.std() / interspike_interval.mean()\n",
"\n", "\n",
" # varying statistics\n", " autocorrelogram = sp.autocorrelation(smooth_high_rate_map)\n",
" average_rate = len(spike_times) / (t.max() - t.min())\n", " peaks = sp.fields.find_peaks(autocorrelogram)\n",
"\n", " real_peaks = peaks * bin_size\n",
" max_rate = smooth_low_rate_map.max()\n", " autocorrelogram_box_size = box_size * autocorrelogram.shape[0] / smooth_high_rate_map.shape[0]\n",
"\n", " spacing, orientation = sp.spacing_and_orientation(real_peaks, autocorrelogram_box_size)\n",
" out_field_mean_rate = smooth_low_rate_map[np.where(fields == 0)].mean()\n", " orientation *= 180 / np.pi\n",
" in_field_mean_rate = smooth_low_rate_map[np.where(fields != 0)].mean()\n", "\n",
" max_field_mean_rate = smooth_low_rate_map[np.where(fields == 1)].mean()\n", " selectivity = stats.selectivity(smooth_low_rate_map, prob_dist)\n",
"\n", "\n",
" interspike_interval = np.diff(spike_times)\n", " sparsity = stats.sparsity(smooth_low_rate_map, prob_dist)\n",
" interspike_interval_cv = interspike_interval.std() / interspike_interval.mean()\n", "\n",
"\n", " gridness = sp.gridness(smooth_high_rate_map)\n",
" autocorrelogram = sp.autocorrelation(smooth_high_rate_map)\n", "\n",
" peaks = sp.fields.find_peaks(autocorrelogram)\n", " border_score = sp.border_score(smooth_high_rate_map, fields_laplace)\n",
" real_peaks = peaks * bin_size\n", "\n",
" autocorrelogram_box_size = box_size * autocorrelogram.shape[0] / smooth_high_rate_map.shape[0]\n", " information_rate = stats.information_rate(smooth_high_rate_map, prob_dist)\n",
" spacing, orientation = sp.spacing_and_orientation(real_peaks, autocorrelogram_box_size)\n", "\n",
" orientation *= 180 / np.pi\n", " single_spikes, bursts, bursty_spikes = spikes.find_bursts(spike_times, threshold=0.01)\n",
"\n", " burst_event_ratio = np.sum(bursts) / (np.sum(single_spikes) + np.sum(bursts))\n",
" selectivity = stats.selectivity(smooth_low_rate_map, prob_dist)\n", " bursty_spike_ratio = np.sum(bursty_spikes) / (np.sum(bursty_spikes) + np.sum(single_spikes))\n",
"\n", " mean_spikes_per_burst = np.sum(bursty_spikes) / np.sum(bursts)\n",
" sparsity = stats.sparsity(smooth_low_rate_map, prob_dist)\n", "\n",
"\n", " speed_score = spd.speed_correlation(\n",
" gridness = sp.gridness(smooth_high_rate_map)\n", " speed, t, spike_times, min_speed=min_speed, max_speed=max_speed)\n",
"\n", "\n",
" border_score = sp.border_score(smooth_high_rate_map, fields_laplace)\n", " ang_bin, ang_rate = head.head_direction_rate(spike_times, ang, ang_t)\n",
"\n", "\n",
" information_rate = stats.information_rate(smooth_high_rate_map, prob_dist)\n", " head_mean_ang, head_mean_vec_len = head.head_direction_score(ang_bin, ang_rate)\n",
"\n", "\n",
" single_spikes, bursts, bursty_spikes = spikes.find_bursts(spike_times, threshold=0.01)\n", " result = pd.Series({\n",
" burst_event_ratio = np.sum(bursts) / (np.sum(single_spikes) + np.sum(bursts))\n", " 'average_rate': average_rate,\n",
" bursty_spike_ratio = np.sum(bursty_spikes) / (np.sum(bursty_spikes) + np.sum(single_spikes))\n", " 'speed_score': speed_score,\n",
" mean_spikes_per_burst = np.sum(bursty_spikes) / np.sum(bursts)\n", " 'out_field_mean_rate': out_field_mean_rate,\n",
"\n", " 'in_field_mean_rate': in_field_mean_rate,\n",
" speed_score = spd.speed_correlation(\n", " 'max_field_mean_rate': max_field_mean_rate,\n",
" speed, t, spike_times, min_speed=min_speed, max_speed=max_speed)\n", " 'max_rate': max_rate,\n",
"\n", " 'sparsity': sparsity,\n",
" ang_bin, ang_rate = head.head_direction_rate(spike_times, ang, ang_t)\n", " 'selectivity': selectivity,\n",
"\n", " 'interspike_interval_cv': float(interspike_interval_cv),\n",
" head_mean_ang, head_mean_vec_len = head.head_direction_score(ang_bin, ang_rate)\n", " 'burst_event_ratio': burst_event_ratio,\n",
"\n", " 'bursty_spike_ratio': bursty_spike_ratio,\n",
" result = pd.Series({\n", " 'gridness': gridness,\n",
" 'average_rate': average_rate,\n", " 'border_score': border_score,\n",
" 'speed_score': speed_score,\n", " 'information_rate': information_rate,\n",
" 'out_field_mean_rate': out_field_mean_rate,\n", " 'head_mean_ang': head_mean_ang,\n",
" 'in_field_mean_rate': in_field_mean_rate,\n", " 'head_mean_vec_len': head_mean_vec_len,\n",
" 'max_field_mean_rate': max_field_mean_rate,\n", " 'spacing': spacing,\n",
" 'max_rate': max_rate,\n", " 'orientation': orientation\n",
" 'sparsity': sparsity,\n", " })\n",
" 'selectivity': selectivity,\n", " return result\n",
" 'interspike_interval_cv': float(interspike_interval_cv),\n", " \n",
" 'burst_event_ratio': burst_event_ratio,\n", "process(first_row)"
" 'bursty_spike_ratio': bursty_spike_ratio,\n", ]
" 'gridness': gridness,\n", },
" 'border_score': border_score,\n", {
" 'information_rate': information_rate,\n", "cell_type": "code",
" 'head_mean_ang': head_mean_ang,\n", "execution_count": null,
" 'head_mean_vec_len': head_mean_vec_len,\n", "metadata": {
" 'spacing': spacing,\n", "scrolled": false
" 'orientation': orientation\n", },
" })\n", "outputs": [],
" return result\n", "source": [
" \n", "results = units.merge(\n",
"process(first_row)" " units.progress_apply(process, axis=1), \n",
] " left_index=True, right_index=True)"
}, ]
{ },
"cell_type": "code", {
"execution_count": null, "cell_type": "code",
"metadata": { "execution_count": null,
"scrolled": false "metadata": {},
}, "outputs": [],
"outputs": [ "source": [
{ "output_path = pathlib.Path(\"output\") / \"calculate-statistics\"\n",
"data": { "output_path.mkdir(exist_ok=True)"
"application/vnd.jupyter.widget-view+json": { ]
"model_id": "837fde7fe486422bac67341ff512a4e1", },
"version_major": 2, {
"version_minor": 0 "cell_type": "code",
}, "execution_count": null,
"text/plain": [ "metadata": {},
"HBox(children=(IntProgress(value=0, max=1281), HTML(value='')))" "outputs": [],
] "source": [
}, "units.to_csv(output_path / \"units.csv\", index=False)\n",
"metadata": {}, "results.to_csv(output_path / \"results.csv\", index=False)"
"output_type": "display_data" ]
}, },
{ {
"name": "stderr", "cell_type": "markdown",
"output_type": "stream", "metadata": {},
"text": [ "source": [
"/home/mikkel/apps/expipe-project/spatial-maps/spatial_maps/stats.py:13: RuntimeWarning: invalid value encountered in log2\n", "# Store results in Expipe action"
" 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: 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", "cell_type": "code",
" return (np.nansum(np.ravel(tmp_rate_map * np.log2(tmp_rate_map/avg_rate) *\n", "execution_count": 14,
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:56: RuntimeWarning: Mean of empty slice.\n", "metadata": {},
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/numpy/core/_methods.py:85: RuntimeWarning: invalid value encountered in double_scalars\n", "outputs": [],
" ret = ret.dtype.type(ret / rcount)\n", "source": [
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:57: RuntimeWarning: Mean of empty slice.\n", "statistics_action = project.require_action(\"calculate-statistics\")"
"/home/mikkel/.virtualenvs/expipe/lib/python3.6/site-packages/ipykernel_launcher.py:82: RuntimeWarning: invalid value encountered in long_scalars\n" ]
] },
} {
], "cell_type": "code",
"source": [ "execution_count": 15,
"results = units.merge(\n", "metadata": {},
" units.progress_apply(process, axis=1), \n", "outputs": [
" left_index=True, right_index=True)" {
] "data": {
}, "text/plain": [
{ "['/media/storage/expipe/septum-mec/actions/calculate-statistics/data/results.csv',\n",
"cell_type": "code", " '/media/storage/expipe/septum-mec/actions/calculate-statistics/data/sessions.csv',\n",
"execution_count": null, " '/media/storage/expipe/septum-mec/actions/calculate-statistics/data/units.csv']"
"metadata": {}, ]
"outputs": [], },
"source": [ "execution_count": 15,
"output_path = pathlib.Path(\"output\") / \"calculate-statistics\"\n", "metadata": {},
"output_path.mkdir(exist_ok=True)" "output_type": "execute_result"
] }
}, ],
{ "source": [
"cell_type": "code", "statistics_action.data[\"units\"] = \"units.csv\"\n",
"execution_count": null, "statistics_action.data[\"results\"] = \"results.csv\"\n",
"metadata": {}, "copy_tree(output_path, str(statistics_action.data_path()))"
"outputs": [], ]
"source": [ },
"units.to_csv(output_path / \"units.csv\", index=False)\n", {
"results.to_csv(output_path / \"results.csv\", index=False)" "cell_type": "code",
] "execution_count": 16,
}, "metadata": {},
{ "outputs": [],
"cell_type": "markdown", "source": [
"metadata": {}, "septum_mec.analysis.registration.store_notebook(statistics_action, \"10_calculate_spatial_statistics.ipynb\")"
"source": [ ]
"# Store results in Expipe action" },
] {
}, "cell_type": "code",
{ "execution_count": null,
"cell_type": "code", "metadata": {},
"execution_count": null, "outputs": [],
"metadata": {}, "source": []
"outputs": [], }
"source": [ ],
"statistics_action = project.require_action(\"calculate-statistics\")" "metadata": {
] "kernelspec": {
}, "display_name": "Python 3",
{ "language": "python",
"cell_type": "code", "name": "python3"
"execution_count": null, },
"metadata": {}, "language_info": {
"outputs": [], "codemirror_mode": {
"source": [ "name": "ipython",
"statistics_action.data[\"units\"] = \"units.csv\"\n", "version": 3
"statistics_action.data[\"results\"] = \"results.csv\"\n", },
"copy_tree(output_path, str(statistics_action.data_path()))" "file_extension": ".py",
] "mimetype": "text/x-python",
}, "name": "python",
{ "nbconvert_exporter": "python",
"cell_type": "code", "pygments_lexer": "ipython3",
"execution_count": null, "version": "3.6.8"
"metadata": {}, }
"outputs": [], },
"source": [ "nbformat": 4,
"septum_mec.analysis.registration.store_notebook(statistics_action, \"10_calculate_spatial_statistics.ipynb\")" "nbformat_minor": 2
] }
},
{
"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
}