Created
December 21, 2019 12:33
-
-
Save mhhennig/989c0e4948cae7684d6498b74142a239 to your computer and use it in GitHub Desktop.
bug in metrics calc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Using temp dir:/disk/scratch/mhennig/tmp\n" | |
] | |
}, | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/disk/scratch/mhennig/miniconda3/envs/spikesorting/lib/python3.7/site-packages/networkx/classes/reportviews.py:95: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working\n", | |
" from collections import Mapping, Set, Iterable\n" | |
] | |
} | |
], | |
"source": [ | |
"%load_ext autoreload\n", | |
"%autoreload 2\n", | |
"\n", | |
"import matplotlib.pyplot as plt\n", | |
"import numpy as np\n", | |
"import time\n", | |
"import sys, os\n", | |
"import pickle\n", | |
"from pathlib import Path\n", | |
"import pandas as pd\n", | |
"\n", | |
"sys.path.insert(0, '../../spikeinterface/spikeextractors/')\n", | |
"sys.path.insert(0, '../../spikeinterface/spiketoolkit/')\n", | |
"sys.path.insert(0, '../../spikeinterface/spikesorters/')\n", | |
"sys.path.insert(0, '../../spikeinterface/spikewidgets/')\n", | |
"sys.path.insert(0, '../../spikeinterface/spikemetrics/')\n", | |
"sys.path.insert(0, '../../spikeinterface/spikecomparison/')\n", | |
"\n", | |
"os.environ[\"TMPDIR\"] = \"/disk/scratch/mhennig/tmp\"\n", | |
"\n", | |
"import spikeextractors as se\n", | |
"import spiketoolkit as st\n", | |
"import spikesorters as ss\n", | |
"import spikecomparison as sc\n", | |
"import spikewidgets as sw\n", | |
"\n", | |
"import tempfile\n", | |
"print('Using temp dir:'+tempfile.gettempdir())\n", | |
"\n", | |
"\n", | |
"%matplotlib inline" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Could not load plane information. Assuming probe is in yz plane\n" | |
] | |
} | |
], | |
"source": [ | |
"p = Path('/disk/scratch/mhennig/spikeinterface/paper/MEArec/')\n", | |
"study_folder = p / 'study_mearec_SqMEA1015um/'\n", | |
"\n", | |
"mearec_filename = p / 'recordings_50cells_SqMEA-10-15um_60.0_10.0uV_27-03-2019_13-31-005.h5'\n", | |
"\n", | |
"# SX_gt = se.MEArecSortingExtractor(mearec_filename)\n", | |
"RX = se.MEArecRecordingExtractor(mearec_filename)\n", | |
"SX = se.KiloSortSortingExtractor(study_folder/'sorter_folders/rec0/kilosort2/')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"mc = st.validation.MetricCalculator(SX, recording=RX, apply_filter=False, verbose=True,\n", | |
" sampling_frequency=RX.get_sampling_frequency())\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"spike_times.shape (26103, 1)\n", | |
"spike_times_amps.shape (26103, 1)\n", | |
"spike_clusters.shape (26103, 1)\n", | |
"spike_clusters_amps.shape (17839,)\n", | |
"spike_clusters_pca.shape (17839,)\n" | |
] | |
}, | |
{ | |
"ename": "IndexError", | |
"evalue": "index 19850 is out of bounds for axis 0 with size 17839", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-5-09372d0116f2>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# fails:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mmc\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcompute_all_metric_data\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;31m# works:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m#mc.compute_all_metric_data(max_spikes_for_pca=10000, max_spikes_per_unit=10000)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/disk/scratch/mhennig/spikeinterface/spiketoolkit/spiketoolkit/validation/metric_calculator.py\u001b[0m in \u001b[0;36mcompute_all_metric_data\u001b[0;34m(self, recording, n_comp, ms_before, ms_after, dtype, max_spikes_per_unit, amp_method, amp_peak, amp_frames_before, amp_frames_after, recompute_info, max_spikes_for_pca, apply_filter, freq_min, freq_max, save_features_props, seed)\u001b[0m\n\u001b[1;32m 410\u001b[0m \u001b[0mrecompute_info\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrecompute_info\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 411\u001b[0m \u001b[0msave_features_props\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msave_features_props\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 412\u001b[0;31m \u001b[0mseed\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mseed\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 413\u001b[0m )\n\u001b[1;32m 414\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/disk/scratch/mhennig/spikeinterface/spiketoolkit/spiketoolkit/validation/validation_tools.py\u001b[0m in \u001b[0;36mget_all_metric_data\u001b[0;34m(recording, sorting, n_comp, ms_before, ms_after, dtype, amp_method, amp_peak, amp_frames_before, amp_frames_after, max_spikes_per_unit, max_spikes_for_pca, recompute_info, save_features_props, verbose, seed)\u001b[0m\n\u001b[1;32m 245\u001b[0m \u001b[0mrecompute_info\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mrecompute_info\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 246\u001b[0m \u001b[0msave_features_props\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msave_features_props\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 247\u001b[0;31m verbose=verbose, seed=seed)\n\u001b[0m\u001b[1;32m 248\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 249\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqueeze\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecording\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mframe_to_time\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mspike_times\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msqueeze\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrecording\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mframe_to_time\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mspike_times_amps\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;31m \u001b[0m\u001b[0;31m\\\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/disk/scratch/mhennig/spikeinterface/spiketoolkit/spiketoolkit/postprocessing/postprocessing_tools.py\u001b[0m in \u001b[0;36m_get_quality_metric_data\u001b[0;34m(recording, sorting, n_comp, ms_before, ms_after, dtype, amp_method, amp_peak, amp_frames_before, amp_frames_after, max_spikes_per_unit, max_spikes_for_pca, recompute_info, save_features_props, verbose, seed)\u001b[0m\n\u001b[1;32m 1073\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'spike_clusters_amps.shape'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mspike_clusters_amps\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1074\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'spike_clusters_pca.shape'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mspike_clusters_pca\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1075\u001b[0;31m \u001b[0mspike_clusters_amps\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mspike_clusters_amps\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0msorting_idxs_amps\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnewaxis\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1076\u001b[0m \u001b[0mspike_clusters_pca\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mspike_clusters_pca\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0msorting_idxs_pca\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnewaxis\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mint\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1077\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;31mIndexError\u001b[0m: index 19850 is out of bounds for axis 0 with size 17839" | |
] | |
} | |
], | |
"source": [ | |
"# fails:\n", | |
"mc.compute_all_metric_data()\n", | |
"\n", | |
"# works:\n", | |
"#mc.compute_all_metric_data(max_spikes_for_pca=10000, max_spikes_per_unit=10000)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [conda env:spikesorting]", | |
"language": "python", | |
"name": "conda-env-spikesorting-py" | |
}, | |
"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.7.2" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment