diff --git a/notebooks/43_Decoding_SortedSpikes.ipynb b/notebooks/43_Decoding_SortedSpikes.ipynb index b779bfac1..1adbe3ba2 100644 --- a/notebooks/43_Decoding_SortedSpikes.ipynb +++ b/notebooks/43_Decoding_SortedSpikes.ipynb @@ -16,14 +16,12 @@ "- `decoding_interval`\n", "\n", "This time, instead of extracting waveform features, we can proceed directly from the SpikeSortingOutput table to specify which units we want to decode. The rest of the decoding process is the same as before.\n", - "\n", - "\n", - "## SortedSpikesGroup" + "\n" ] }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -35,20 +33,158 @@ ") # load config for database connection info" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## SortedSpikesGroup\n", + "\n", + "`SortedSpikesGroup` is a child table of `SpikeSortingOutput` in the spikesorting pipeline. It allows us to group the spikesorting results from multiple \n", + "sources (e.g. multiple terode groups or intervals) into a single entry. Here we will group together the spiking of multiple tetrode groups to use for decoding.\n", + "\n", + "\n", + "This table allows us filter units by their annotation labels from curation (e.g only include units labeled \"good\", exclude units labeld \"noise\") by defining parameters from `UnitSelectionParams`. When accessing data through `SortedSpikesGroup` the table will include only units with at least one label in `include_labels` and no labels in `exclude_labels`. We can look at those here:\n" + ] + }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "[2024-01-29 10:31:51,696][INFO]: Connecting root@localhost:3306\n", - "[2024-01-29 10:31:51,746][INFO]: Connected root@localhost:3306\n", - "[10:31:52][WARNING] Spyglass: Please update position_tools to >= 0.1.0\n" + "[2024-02-02 12:06:04,725][INFO]: Connecting sambray@lmf-db.cin.ucsf.edu:3306\n", + "[2024-02-02 12:06:04,762][INFO]: Connected sambray@lmf-db.cin.ucsf.edu:3306\n", + "[12:06:05][WARNING] Spyglass: Please update position_tools to >= 0.1.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'unit_filter_params_name': 'default_exclusion', 'include_labels': [], 'exclude_labels': ['noise', 'mua']}\n" ] }, + { + "data": { + "text/html": [ + "\n", + " \n", + " \n", + " \n", + " \n", + "
\n", + " \n", + " \n", + " \n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "
\n", + "

unit_filter_params_name

\n", + " \n", + "
\n", + "

include_labels

\n", + " \n", + "
\n", + "

exclude_labels

\n", + " \n", + "
all_units=BLOB==BLOB=
default_exclusion=BLOB==BLOB=
exclude_noise=BLOB==BLOB=
\n", + " \n", + "

Total: 3

\n", + " " + ], + "text/plain": [ + "*unit_filter_p include_la exclude_la\n", + "+------------+ +--------+ +--------+\n", + "all_units =BLOB= =BLOB= \n", + "default_exclus =BLOB= =BLOB= \n", + "exclude_noise =BLOB= =BLOB= \n", + " (Total: 3)" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from spyglass.spikesorting.analysis.v1.group import UnitSelectionParams\n", + "UnitSelectionParams().insert_default()\n", + "\n", + "# look at the filter set we'll use here\n", + "unit_filter_params_name = \"default_exclusion\"\n", + "print((UnitSelectionParams()\n", + " & {\"unit_filter_params_name\":unit_filter_params_name}).fetch1())\n", + "# look at full table\n", + "UnitSelectionParams()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we can make our sorted spikes group with this unit selection parameter" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ { "data": { "text/html": [ @@ -132,113 +268,40 @@ "

curation_id

\n", " \n", " \n", - " 08a302b6-5505-40fa-b4d5-62162f8eef58\n", - "485a4ddf-332d-35b5-3ad4-0561736c1844\n", - "449b64e3-db0b-437e-a1b9-0d29928aa2dd\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "45f6b9a1-eef3-46eb-866d-d0999afebda6\n", - "00ca508ee-af4c-4a89-8181-d48bd209bfd4\n", - "6acb99b8-6a0c-eb83-1141-5f603c5895e0\n", - "328da21c-1d9c-41e2-9800-76b3484b707b\n", - "clusterless_thresholder\n", - "default_clusterless\n", + " 642242ff-5f0e-45a2-bcc1-ca681f37b4a3\n", + "75286bf3-f876-4550-f235-321f2a7badef\n", + "01c5b8e9-933d-4f1e-9a5d-c494276edb3a\n", + "mountainsort4\n", + "franklab_tetrode_hippocampus_30KHz\n", "mediumnwb20230802_.nwb\n", - "686d9951-1c0f-4d5e-9f5c-09e6fd8bdd4c\n", - "0209dc048-6fae-4315-b293-c06fff29f947\n", - "f7237e18-4e73-4aee-805b-90735e9147de\n", - "aff78f2f-2ba0-412a-95cc-447c3a2f4683\n", - "clusterless_thresholder\n", - "default_clusterless\n", + "0a6611b3-c593-4900-a715-66bb1396940e\n", + "1a4b5a94d-ba41-4634-92d0-1d31c9daa913\n", + "143dff79-3779-c0d2-46fe-7c5040404219\n", + "a8a1d29d-ffdf-4370-8b3d-909fef57f9d4\n", + "mountainsort4\n", + "franklab_tetrode_hippocampus_30KHz\n", "mediumnwb20230802_.nwb\n", - "719e8a86-fcf1-4ffc-8c1f-ea912f67ad5d\n", - "021a9a593-f6f3-4b82-99d7-8fc46556eff3\n", - "7e3fa66e-727e-1541-819a-b01309bb30ae\n", - "2402805a-04f9-4a88-9ccf-071376c8de19\n", - "clusterless_thresholder\n", - "default_clusterless\n", + "3d782852-a56b-4a9d-89ca-be9e1a15c957\n", + "1874775be-df0f-4850-8f88-59ba1bbead89\n", + "a900c1c8-909d-e583-c377-e98c4f0deebf\n", + "747f4eea-6df3-422b-941e-b5aaad7ec607\n", + "mountainsort4\n", + "franklab_tetrode_hippocampus_30KHz\n", "mediumnwb20230802_.nwb\n", - "d581b117-160e-4311-b096-7781a4de4394\n", - "0406a20e3-5a9f-4fec-b046-a6561f72461e\n", - "6d039a63-17ad-0b78-4b1e-f02d5f3dbbc5\n", - "f1427e00-2974-4301-b2ac-b4dc29277c51\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "0e848c38-9105-4ea4-b6ba-dbdd5b46a088\n", - "04131c51b-c56d-41fa-b046-46635fc17fd9\n", - "e0e9133a-7a4e-1321-a43a-e8afcb2f25da\n", - "9e332d82-1daf-4e92-bb50-12e4f9430875\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "9ed11db5-c42e-491a-8caf-7d9a37a65f13\n", - "04c5a629a-71d9-481d-ab11-a4cb0fc16087\n", - "9959b614-2318-f597-6651-a3a82124d28a\n", - "3a2c3eed-413a-452a-83c8-0e4648141bde\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "2b9fbf14-74a0-4294-a805-26702340aac9\n", - "04d629c07-1931-4e1f-a3a8-cbf1b72161e3\n", - "c0eb6455-fc41-c200-b62e-e3ca81b9a3f7\n", - "f07bc0b0-de6b-4424-8ef9-766213aaca26\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "5c68f0f0-f577-4905-8a09-e4d171d0a22d\n", - "0554a9a3c-0461-48be-8435-123eed59c228\n", - "912e250e-56d8-ee33-4525-c844d810971b\n", - "7f128981-6868-4976-ba20-248655dcac21\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "f4b9301f-bc91-455b-9474-c801093f3856\n", - "07bb007f2-26d3-463f-b7dc-7bd4d271725e\n", - "d7d2c97a-0e6e-d1b8-735c-d55dc66a30e1\n", - "a9b7cec0-1256-49cf-abf0-8c45fd155379\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "74270cba-36ee-4afb-ab50-2a6cc948e68c\n", - "080e1f37f-48a7-4087-bd37-7a37b6a2c160\n", - "abb92dce-4410-8f17-a501-a4104bda0dcf\n", - "3c40ebdc-0b61-4105-9971-e1348bd49bc7\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "0f91197e-bebb-4dc6-ad41-5bf89c3eed28\n", - "08848c4a8-a2f2-4f3d-82cd-51b13b8bae3c\n", - "74e10781-1228-4075-0870-af224024ffdc\n", - "257c077b-8f3b-4abb-a631-6b8084d6a1ea\n", - "clusterless_thresholder\n", - "default_clusterless\n", - "mediumnwb20230802_.nwb\n", - "e289e03d-32ad-461a-a1cc-c88537343149\n", - "0 \n", + "9cf9e3cd-7115-4b59-a718-3633725d4738\n", + "1 \n", " \n", - "

...

\n", - "

Total: 23

\n", + " \n", + "

Total: 3

\n", " " ], "text/plain": [ "*sorting_id *merge_id recording_id sorter sorter_param_n nwb_file_name interval_list_ curation_id \n", "+------------+ +------------+ +------------+ +------------+ +------------+ +------------+ +------------+ +------------+\n", - "08a302b6-5505- 485a4ddf-332d- 449b64e3-db0b- clusterless_th default_cluste mediumnwb20230 45f6b9a1-eef3- 0 \n", - "0ca508ee-af4c- 6acb99b8-6a0c- 328da21c-1d9c- clusterless_th default_cluste mediumnwb20230 686d9951-1c0f- 0 \n", - "209dc048-6fae- f7237e18-4e73- aff78f2f-2ba0- clusterless_th default_cluste mediumnwb20230 719e8a86-fcf1- 0 \n", - "21a9a593-f6f3- 7e3fa66e-727e- 2402805a-04f9- clusterless_th default_cluste mediumnwb20230 d581b117-160e- 0 \n", - "406a20e3-5a9f- 6d039a63-17ad- f1427e00-2974- clusterless_th default_cluste mediumnwb20230 0e848c38-9105- 0 \n", - "4131c51b-c56d- e0e9133a-7a4e- 9e332d82-1daf- clusterless_th default_cluste mediumnwb20230 9ed11db5-c42e- 0 \n", - "4c5a629a-71d9- 9959b614-2318- 3a2c3eed-413a- clusterless_th default_cluste mediumnwb20230 2b9fbf14-74a0- 0 \n", - "4d629c07-1931- c0eb6455-fc41- f07bc0b0-de6b- clusterless_th default_cluste mediumnwb20230 5c68f0f0-f577- 0 \n", - "554a9a3c-0461- 912e250e-56d8- 7f128981-6868- clusterless_th default_cluste mediumnwb20230 f4b9301f-bc91- 0 \n", - "7bb007f2-26d3- d7d2c97a-0e6e- a9b7cec0-1256- clusterless_th default_cluste mediumnwb20230 74270cba-36ee- 0 \n", - "80e1f37f-48a7- abb92dce-4410- 3c40ebdc-0b61- clusterless_th default_cluste mediumnwb20230 0f91197e-bebb- 0 \n", - "8848c4a8-a2f2- 74e10781-1228- 257c077b-8f3b- clusterless_th default_cluste mediumnwb20230 e289e03d-32ad- 0 \n", - " ...\n", - " (Total: 23)" + "642242ff-5f0e- 75286bf3-f876- 01c5b8e9-933d- mountainsort4 franklab_tetro mediumnwb20230 0a6611b3-c593- 1 \n", + "a4b5a94d-ba41- 143dff79-3779- a8a1d29d-ffdf- mountainsort4 franklab_tetro mediumnwb20230 3d782852-a56b- 1 \n", + "874775be-df0f- a900c1c8-909d- 747f4eea-6df3- mountainsort4 franklab_tetro mediumnwb20230 9cf9e3cd-7115- 1 \n", + " (Total: 3)" ] }, "execution_count": 2, @@ -250,67 +313,20 @@ "from spyglass.spikesorting.spikesorting_merge import SpikeSortingOutput\n", "import spyglass.spikesorting.v1 as sgs\n", "\n", - "\n", "nwb_copy_file_name = \"mediumnwb20230802_.nwb\"\n", "\n", "sorter_keys = {\n", " \"nwb_file_name\": nwb_copy_file_name,\n", - " \"sorter\": \"clusterless_thresholder\",\n", - " \"sorter_param_name\": \"default_clusterless\",\n", + " \"sorter\": \"mountainsort4\",\n", + " \"curation_id\": 1\n", "}\n", - "\n", + "# check the set of sorting's we'll use\n", "(sgs.SpikeSortingSelection & sorter_keys) * SpikeSortingOutput.CurationV1" ] }, { "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([UUID('485a4ddf-332d-35b5-3ad4-0561736c1844'),\n", - " UUID('6acb99b8-6a0c-eb83-1141-5f603c5895e0'),\n", - " UUID('f7237e18-4e73-4aee-805b-90735e9147de'),\n", - " UUID('7e3fa66e-727e-1541-819a-b01309bb30ae'),\n", - " UUID('6d039a63-17ad-0b78-4b1e-f02d5f3dbbc5'),\n", - " UUID('e0e9133a-7a4e-1321-a43a-e8afcb2f25da'),\n", - " UUID('9959b614-2318-f597-6651-a3a82124d28a'),\n", - " UUID('c0eb6455-fc41-c200-b62e-e3ca81b9a3f7'),\n", - " UUID('912e250e-56d8-ee33-4525-c844d810971b'),\n", - " UUID('d7d2c97a-0e6e-d1b8-735c-d55dc66a30e1'),\n", - " UUID('abb92dce-4410-8f17-a501-a4104bda0dcf'),\n", - " UUID('74e10781-1228-4075-0870-af224024ffdc'),\n", - " UUID('8bbddc0f-d6ae-6260-9400-f884a6e25ae8'),\n", - " UUID('614d796c-0b95-6364-aaa0-b6cb1e7bbb83'),\n", - " UUID('b332482b-e430-169d-8ac0-0a73ce968ed7'),\n", - " UUID('86897349-ff68-ac72-02eb-739dd88936e6'),\n", - " UUID('4a712103-c223-864f-82e0-6c23de79cc14'),\n", - " UUID('cf858380-e8a3-49de-c2a9-1a277e307a68'),\n", - " UUID('cc4ee561-f974-f8e5-0ea4-83185263ac67'),\n", - " UUID('4a72c253-b3ca-8c13-e615-736a7ebff35c'),\n", - " UUID('b92a94d8-ee1e-2097-a81f-5c1e1556ed24'),\n", - " UUID('5c53bd33-d57c-fbba-e0fb-55e0bcb85d03'),\n", - " UUID('0751a1e1-a406-7f87-ae6f-ce4ffc60621c')], dtype=object)" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "spikesorting_merge_ids = (\n", - " (sgs.SpikeSortingSelection & sorter_keys) * SpikeSortingOutput.CurationV1\n", - ").fetch(\"merge_id\")\n", - "\n", - "spikesorting_merge_ids" - ] - }, - { - "cell_type": "code", - "execution_count": 4, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -372,85 +388,44 @@ "
\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", - "

merge_id

\n", - " \n", + "

nwb_file_name

\n", + " name of the NWB file\n", "
\n", - "

spikesorting_merge_id

\n", + "

unit_filter_params_name

\n", " \n", "
\n", - "

unit_group_name

\n", - " Name of unit group\n", + "

sorted_spikes_group_name

\n", + " \n", "
39b22078-84fa-d3aa-8ca9-2368603d6a470751a1e1-a406-7f87-ae6f-ce4ffc60621call units
7bc69ef8-ae89-f30f-c236-56a87a49ed63485a4ddf-332d-35b5-3ad4-0561736c1844all units
2f6295c6-ad14-dde0-6b14-ee29bc2ed8494a712103-c223-864f-82e0-6c23de79cc14all units
7fa3c0ad-36a8-c14c-d84a-890c6002a4574a72c253-b3ca-8c13-e615-736a7ebff35call units
4b025478-ab06-8e65-ef09-7e32be5a624c5c53bd33-d57c-fbba-e0fb-55e0bcb85d03all units
9658d944-1f1f-d467-1f56-bcc32d63e6e8614d796c-0b95-6364-aaa0-b6cb1e7bbb83all units
76cb7574-a687-37c9-1045-8e4e5d13a0b06acb99b8-6a0c-eb83-1141-5f603c5895e0all units
87af74fa-a77e-f29b-99f7-f5720aa4816f6d039a63-17ad-0b78-4b1e-f02d5f3dbbc5all units
3cccfce5-dad9-61c5-7eee-1c708183710074e10781-1228-4075-0870-af224024ffdcall units
bbddf25f-d810-f586-e3b8-cb96350fbbde7e3fa66e-727e-1541-819a-b01309bb30aeall units
7887e5db-da1d-d261-d58a-a5175759396586897349-ff68-ac72-02eb-739dd88936e6all units
1b7ba376-89f9-e0ac-9104-fbd1bd984e418bbddc0f-d6ae-6260-9400-f884a6e25ae8all units
mediumnwb20230802_.nwball_unitstest_group
\n", - "

...

\n", - "

Total: 23

\n", + " \n", + "

Total: 1

\n", " " ], "text/plain": [ - "*merge_id spikesorting_m unit_group_nam\n", + "*nwb_file_name *unit_filter_p *sorted_spikes\n", "+------------+ +------------+ +------------+\n", - "39b22078-84fa- 0751a1e1-a406- all units \n", - "7bc69ef8-ae89- 485a4ddf-332d- all units \n", - "2f6295c6-ad14- 4a712103-c223- all units \n", - "7fa3c0ad-36a8- 4a72c253-b3ca- all units \n", - "4b025478-ab06- 5c53bd33-d57c- all units \n", - "9658d944-1f1f- 614d796c-0b95- all units \n", - "76cb7574-a687- 6acb99b8-6a0c- all units \n", - "87af74fa-a77e- 6d039a63-17ad- all units \n", - "3cccfce5-dad9- 74e10781-1228- all units \n", - "bbddf25f-d810- 7e3fa66e-727e- all units \n", - "7887e5db-da1d- 86897349-ff68- all units \n", - "1b7ba376-89f9- 8bbddc0f-d6ae- all units \n", - " ...\n", - " (Total: 23)" + "mediumnwb20230 all_units test_group \n", + " (Total: 1)" ] }, - "execution_count": 4, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "from spyglass.spikesorting.unit_inclusion_merge import (\n", - " ImportedUnitInclusionV1,\n", - " UnitInclusionOutput,\n", - ")\n", + "from spyglass.decoding.v1.sorted_spikes import SortedSpikesGroup\n", "\n", - "ImportedUnitInclusionV1().insert_all_units(spikesorting_merge_ids)\n", - "\n", - "UnitInclusionOutput.ImportedUnitInclusionV1() & [\n", - " {\"spikesorting_merge_id\": id} for id in spikesorting_merge_ids\n", - "]" + "SortedSpikesGroup()" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -515,42 +490,53 @@ "

nwb_file_name

\n", " name of the NWB file\n", "
\n", + "

unit_filter_params_name

\n", + " \n", + "
\n", "

sorted_spikes_group_name

\n", " \n", "
\n", " mediumnwb20230802_.nwb\n", + "all_units\n", + "test_groupmediumnwb20230802_.nwb\n", + "default_exclusion\n", "test_group \n", " \n", " \n", - "

Total: 1

\n", + "

Total: 2

\n", " " ], "text/plain": [ - "*nwb_file_name *sorted_spikes\n", - "+------------+ +------------+\n", - "mediumnwb20230 test_group \n", - " (Total: 1)" + "*nwb_file_name *unit_filter_p *sorted_spikes\n", + "+------------+ +------------+ +------------+\n", + "mediumnwb20230 all_units test_group \n", + "mediumnwb20230 default_exclus test_group \n", + " (Total: 2)" ] }, - "execution_count": 5, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "from spyglass.spikesorting.analysis.v1.group import SortedSpikesGroup\n", - "\n", - "unit_inclusion_merge_ids = (\n", - " UnitInclusionOutput.ImportedUnitInclusionV1\n", - " & [{\"spikesorting_merge_id\": id} for id in spikesorting_merge_ids]\n", + "# get the merge_ids for the selected sortings\n", + "spikesorting_merge_ids = (\n", + " (sgs.SpikeSortingSelection & sorter_keys) * SpikeSortingOutput.CurationV1\n", ").fetch(\"merge_id\")\n", "\n", + "# create a new sorted spikes group\n", + "unit_filter_params_name = \"default_exclusion\"\n", "SortedSpikesGroup().create_group(\n", " group_name=\"test_group\",\n", " nwb_file_name=nwb_copy_file_name,\n", - " unit_inclusion_merge_ids=unit_inclusion_merge_ids,\n", + " keys=[\n", + " {\"spikesorting_merge_id\": merge_id}\n", + " for merge_id in spikesorting_merge_ids\n", + " ],\n", + " unit_filter_params_name=unit_filter_params_name,\n", ")\n", - "\n", + "# check the new group\n", "SortedSpikesGroup & {\n", " \"nwb_file_name\": nwb_copy_file_name,\n", " \"sorted_spikes_group_name\": \"test_group\",\n", @@ -559,7 +545,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -624,70 +610,50 @@ "

nwb_file_name

\n", " name of the NWB file\n", "
\n", + "

unit_filter_params_name

\n", + " \n", + "
\n", "

sorted_spikes_group_name

\n", " \n", "
\n", - "

unit_inclusion_merge_id

\n", + "

spikesorting_merge_id

\n", " \n", "
\n", " mediumnwb20230802_.nwb\n", + "default_exclusion\n", "test_group\n", - "0363fb94-c5de-d653-ed33-1807fa523790mediumnwb20230802_.nwb\n", - "test_group\n", - "12da7476-bb70-a4ee-0558-99ca5bcc0958mediumnwb20230802_.nwb\n", - "test_group\n", - "151976b9-9dc6-74f6-65d3-23ce96d006d1mediumnwb20230802_.nwb\n", - "test_group\n", - "1b7ba376-89f9-e0ac-9104-fbd1bd984e41mediumnwb20230802_.nwb\n", - "test_group\n", - "2f6295c6-ad14-dde0-6b14-ee29bc2ed849mediumnwb20230802_.nwb\n", - "test_group\n", - "357a0267-874e-04f0-410e-9711f29e1236mediumnwb20230802_.nwb\n", - "test_group\n", - "39b22078-84fa-d3aa-8ca9-2368603d6a47mediumnwb20230802_.nwb\n", + "143dff79-3779-c0d2-46fe-7c5040404219mediumnwb20230802_.nwb\n", + "default_exclusion\n", "test_group\n", - "3cccfce5-dad9-61c5-7eee-1c7081837100mediumnwb20230802_.nwb\n", + "75286bf3-f876-4550-f235-321f2a7badefmediumnwb20230802_.nwb\n", + "default_exclusion\n", "test_group\n", - "4b025478-ab06-8e65-ef09-7e32be5a624cmediumnwb20230802_.nwb\n", - "test_group\n", - "7591b69d-a902-9058-7597-04632de9e08cmediumnwb20230802_.nwb\n", - "test_group\n", - "76cb7574-a687-37c9-1045-8e4e5d13a0b0mediumnwb20230802_.nwb\n", - "test_group\n", - "7887e5db-da1d-d261-d58a-a51757593965 \n", + "a900c1c8-909d-e583-c377-e98c4f0deebf \n", " \n", - "

...

\n", - "

Total: 23

\n", + " \n", + "

Total: 3

\n", " " ], "text/plain": [ - "*nwb_file_name *sorted_spikes *unit_inclusio\n", - "+------------+ +------------+ +------------+\n", - "mediumnwb20230 test_group 0363fb94-c5de-\n", - "mediumnwb20230 test_group 12da7476-bb70-\n", - "mediumnwb20230 test_group 151976b9-9dc6-\n", - "mediumnwb20230 test_group 1b7ba376-89f9-\n", - "mediumnwb20230 test_group 2f6295c6-ad14-\n", - "mediumnwb20230 test_group 357a0267-874e-\n", - "mediumnwb20230 test_group 39b22078-84fa-\n", - "mediumnwb20230 test_group 3cccfce5-dad9-\n", - "mediumnwb20230 test_group 4b025478-ab06-\n", - "mediumnwb20230 test_group 7591b69d-a902-\n", - "mediumnwb20230 test_group 76cb7574-a687-\n", - "mediumnwb20230 test_group 7887e5db-da1d-\n", - " ...\n", - " (Total: 23)" + "*nwb_file_name *unit_filter_p *sorted_spikes *spikesorting_\n", + "+------------+ +------------+ +------------+ +------------+\n", + "mediumnwb20230 default_exclus test_group 143dff79-3779-\n", + "mediumnwb20230 default_exclus test_group 75286bf3-f876-\n", + "mediumnwb20230 default_exclus test_group a900c1c8-909d-\n", + " (Total: 3)" ] }, - "execution_count": 6, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "SortedSpikesGroup.Units & {\n", + "# look at the sortings within the group we just made\n", + "SortedSpikesGroup.SortGroup & {\n", " \"nwb_file_name\": nwb_copy_file_name,\n", " \"sorted_spikes_group_name\": \"test_group\",\n", + " \"unit_filter_params_name\": unit_filter_params_name,\n", "}" ] }, @@ -702,7 +668,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -777,18 +743,30 @@ "=BLOB=\n", "=BLOB=contfrag_clusterless_0.5.13\n", "=BLOB=\n", + "=BLOB=contfrag_clusterless_6track\n", + "=BLOB=\n", "=BLOB=contfrag_sorted\n", "=BLOB=\n", "=BLOB=contfrag_sorted_0.5.13\n", "=BLOB=\n", - "=BLOB=nonlocal_clusterless_0.5.13\n", + "=BLOB=j1620210710_contfrag_clusterless_1D\n", + "=BLOB=\n", + "=BLOB=j1620210710_test_contfrag_clusterless\n", + "=BLOB=\n", + "=BLOB=MS2220180629_contfrag_sorted\n", + "=BLOB=\n", + "=BLOB=ms_lineartrack_2023_contfrag_sorted\n", + "=BLOB=\n", + "=BLOB=ms_lineartrack_contfrag_clusterless\n", "=BLOB=\n", - "=BLOB=nonlocal_sorted_0.5.13\n", + "=BLOB=ms_lineartrack_contfrag_sorted\n", + "=BLOB=\n", + "=BLOB=ms_wtrack_2023_contfrag_sorted\n", "=BLOB=\n", "=BLOB= \n", " \n", - " \n", - "

Total: 6

\n", + "

...

\n", + "

Total: 15

\n", " " ], "text/plain": [ @@ -796,14 +774,21 @@ "+------------+ +--------+ +--------+\n", "contfrag_clust =BLOB= =BLOB= \n", "contfrag_clust =BLOB= =BLOB= \n", + "contfrag_clust =BLOB= =BLOB= \n", "contfrag_sorte =BLOB= =BLOB= \n", "contfrag_sorte =BLOB= =BLOB= \n", - "nonlocal_clust =BLOB= =BLOB= \n", - "nonlocal_sorte =BLOB= =BLOB= \n", - " (Total: 6)" + "j1620210710_co =BLOB= =BLOB= \n", + "j1620210710_te =BLOB= =BLOB= \n", + "MS2220180629_c =BLOB= =BLOB= \n", + "ms_lineartrack =BLOB= =BLOB= \n", + "ms_lineartrack =BLOB= =BLOB= \n", + "ms_lineartrack =BLOB= =BLOB= \n", + "ms_wtrack_2023 =BLOB= =BLOB= \n", + " ...\n", + " (Total: 15)" ] }, - "execution_count": 7, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -845,121 +830,13 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "\n", - " \n", - " \n", - " \n", - " \n", - "
\n", - " \n", - " \n", - " \n", - "
\n", - "

nwb_file_name

\n", - " name of the NWB file\n", - "
\n", - "

sorted_spikes_group_name

\n", - " \n", - "
\n", - "

position_group_name

\n", - " \n", - "
\n", - "

decoding_param_name

\n", - " a name for this set of parameters\n", - "
\n", - "

encoding_interval

\n", - " descriptive name of this interval list\n", - "
\n", - "

decoding_interval

\n", - " descriptive name of this interval list\n", - "
\n", - "

estimate_decoding_params

\n", - " whether to estimate the decoding parameters\n", - "
\n", - " \n", - "

Total: 0

\n", - " " - ], - "text/plain": [ - "*nwb_file_name *sorted_spikes *position_grou *decoding_para *encoding_inte *decoding_inte *estimate_deco\n", - "+------------+ +------------+ +------------+ +------------+ +------------+ +------------+ +------------+\n", - "\n", - " (Total: 0)" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from spyglass.decoding.v1.sorted_spikes import SortedSpikesDecodingSelection\n", - "\n", - "SortedSpikesDecodingSelection()" - ] - }, - { - "cell_type": "code", - "execution_count": 9, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "selection_key = {\n", " \"sorted_spikes_group_name\": \"test_group\",\n", + " \"unit_filter_params_name\": \"default_exclusion\",\n", " \"position_group_name\": \"test_group\",\n", " \"decoding_param_name\": \"contfrag_sorted\",\n", " \"nwb_file_name\": \"mediumnwb20230802_.nwb\",\n", @@ -968,6 +845,7 @@ " \"estimate_decoding_params\": False,\n", "}\n", "\n", + "from spyglass.decoding import SortedSpikesDecodingSelection\n", "SortedSpikesDecodingSelection.insert1(\n", " selection_key,\n", " skip_duplicates=True,\n", @@ -976,49 +854,26 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "[10:31:56][WARNING] Spyglass: Upsampled position data, frame indices are invalid. Setting add_frame_ind=False\n", - "[2024-01-29 10:31:56,808][WARNING]: Skipped checksum for file with hash: 0cd40383-03e0-44ec-5dac-36c66063796a, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_FUSH604NQA.nwb\n", - "[2024-01-29 10:31:57,259][WARNING]: Skipped checksum for file with hash: 148d9058-e6dc-e959-4c4d-75db9aa0b6e4, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_EF6N6XI3AH.nwb\n", - "[2024-01-29 10:31:57,603][WARNING]: Skipped checksum for file with hash: b4b6404f-aaf8-c4cc-9abe-ceea56e103f3, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_O7ZZ0F1XN7.nwb\n", - "[2024-01-29 10:31:57,956][WARNING]: Skipped checksum for file with hash: 4357905c-c6b9-3990-4d62-740a54cfc667, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_X84BYVM2B0.nwb\n", - "[2024-01-29 10:31:58,309][WARNING]: Skipped checksum for file with hash: ff81d274-17f7-702d-a2b4-92ac43c29316, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_Y2YF504C5D.nwb\n", - "[2024-01-29 10:31:58,659][WARNING]: Skipped checksum for file with hash: 8993754e-7dbe-94a1-403d-8c55aa9c6c42, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_JN4A4GSLZB.nwb\n", - "[2024-01-29 10:31:59,000][WARNING]: Skipped checksum for file with hash: 7d05460d-7366-27c9-2ba7-de2ad5d402f2, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_4JXWFJ3JRI.nwb\n", - "[2024-01-29 10:31:59,337][WARNING]: Skipped checksum for file with hash: 6629fd95-636a-4ad4-c9af-cee507de2130, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_AMBBKQ9RIY.nwb\n", - "[2024-01-29 10:31:59,692][WARNING]: Skipped checksum for file with hash: fa76d419-77a4-697a-325d-5c2ddbe517f9, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_0R6AWXMC6G.nwb\n", - "[2024-01-29 10:32:00,029][WARNING]: Skipped checksum for file with hash: f64f34ee-e72d-e566-a048-65f2ea31708a, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_USMRXAAV8I.nwb\n", - "[2024-01-29 10:32:00,379][WARNING]: Skipped checksum for file with hash: e282a8e5-844b-20f6-345c-cded12e761a9, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_DUNM1TZUGR.nwb\n", - "[2024-01-29 10:32:00,716][WARNING]: Skipped checksum for file with hash: d740eb7d-ce29-e140-06a2-c56655e0842a, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_L92EE1VRPB.nwb\n", - "[2024-01-29 10:32:01,067][WARNING]: Skipped checksum for file with hash: e43f95ff-9779-b980-00a3-99e104864462, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_AKOI7OTASI.nwb\n", - "[2024-01-29 10:32:01,401][WARNING]: Skipped checksum for file with hash: 6d04cbdb-e1e4-f44f-7274-0e1ab0356d75, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_W1MLF0Q86S.nwb\n", - "[2024-01-29 10:32:01,738][WARNING]: Skipped checksum for file with hash: 9e24661c-b021-6ad4-f224-89e331334f18, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_T2DBO3EMZ8.nwb\n", - "[2024-01-29 10:32:02,064][WARNING]: Skipped checksum for file with hash: 1f386cd3-89da-0233-03ff-76ba94e91a3a, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_TX2ZX3DAP4.nwb\n", - "[2024-01-29 10:32:02,430][WARNING]: Skipped checksum for file with hash: fde8b240-6adc-86f0-6391-f3f6fad72ee9, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_HWU3E4EKP4.nwb\n", - "[2024-01-29 10:32:02,773][WARNING]: Skipped checksum for file with hash: 6d13e338-41bd-b011-beb5-4de53d9d467b, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_JA2OA12RPN.nwb\n", - "[2024-01-29 10:32:03,111][WARNING]: Skipped checksum for file with hash: c202eb9e-ca43-0a72-4086-57a5bb6eb937, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_5TY04H3B5T.nwb\n", - "[2024-01-29 10:32:03,473][WARNING]: Skipped checksum for file with hash: 26f7bdc7-da8d-6ad5-3f4a-554ceb48755e, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_0TKF5589B7.nwb\n", - "[2024-01-29 10:32:03,811][WARNING]: Skipped checksum for file with hash: 023c874f-8114-3ef6-7fcf-813844787d5f, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_L7HDY9IDHO.nwb\n", - "[2024-01-29 10:32:04,158][WARNING]: Skipped checksum for file with hash: ce4cb0c3-3dd0-70fd-8ea0-98a8b84592d9, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_7UIA2ILMG6.nwb\n", - "[2024-01-29 10:32:04,515][WARNING]: Skipped checksum for file with hash: c592e63b-4db1-40be-632e-0180e6fa02d7, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_SGAU9PX7US.nwb\n", - "[2024-01-29 10:32:04,856][WARNING]: Skipped checksum for file with hash: 4c1103ac-eaca-b282-e5ff-aa2194e65a43, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_2R6VQ8EDL4.nwb\n" + "[12:19:30][WARNING] Spyglass: Upsampled position data, frame indices are invalid. Setting add_frame_ind=False\n", + "No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)\n" ] }, { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "fee69aed1a5443f0a31f87cd8c158eaa", + "model_id": "90545a744afe4ddfb30e59e070c29cdd", "version_major": 2, "version_minor": 0 }, "text/plain": [ - "Encoding models: 0%| | 0/23 [00:00nwb_file_name

\n", " name of the NWB file\n", "
\n", + "

unit_filter_params_name

\n", + " \n", + "
\n", "

sorted_spikes_group_name

\n", " \n", "
\n", @@ -1150,8 +998,9 @@ "

estimate_decoding_params

\n", " whether to estimate the decoding parameters\n", "
\n", - " 650316f6-e19b-6195-5aea-0f46bc503fa3\n", + " 42e9e7f9-a6f2-9242-63ce-94228bc72743\n", "mediumnwb20230802_.nwb\n", + "default_exclusion\n", "test_group\n", "test_group\n", "contfrag_sorted\n", @@ -1164,13 +1013,13 @@ " " ], "text/plain": [ - "*merge_id nwb_file_name sorted_spikes_ position_group decoding_param encoding_inter decoding_inter estimate_decod\n", - "+------------+ +------------+ +------------+ +------------+ +------------+ +------------+ +------------+ +------------+\n", - "650316f6-e19b- mediumnwb20230 test_group test_group contfrag_sorte pos 0 valid ti test decoding 0 \n", + "*merge_id nwb_file_name unit_filter_pa sorted_spikes_ position_group decoding_param encoding_inter decoding_inter estimate_decod\n", + "+------------+ +------------+ +------------+ +------------+ +------------+ +------------+ +------------+ +------------+ +------------+\n", + "42e9e7f9-a6f2- mediumnwb20230 default_exclus test_group test_group contfrag_sorte pos 0 valid ti test decoding 0 \n", " (Total: 1)" ] }, - "execution_count": 11, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -1190,20 +1039,9 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 6, "metadata": {}, "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "[2024-01-29 10:34:07,530][WARNING]: Skipped checksum for file with hash: 559cd050-31a1-1595-43a0-e86ff97adc73, and path: /Users/edeno/Documents/GitHub/spyglass/DATA/analysis/mediumnwb20230802/mediumnwb20230802_23fc2a6a-8c13-4256-bf78-8d2314a04709.nc\n", - "/Users/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/xarray/namedarray/core.py:487: UserWarning: Duplicate dimension names present: dimensions {'states'} appear more than once in dims=('states', 'states'). We do not yet support duplicate dimension names, but we do allow initial construction of the object. We recommend you rename the dims immediately to become distinct, as most xarray functionality is likely to fail silently if you do not. To rename the dimensions you will need to set the ``.dims`` attribute of each variable, ``e.g. var.dims=('x0', 'x1')``.\n", - " warnings.warn(\n", - "/Users/edeno/miniconda3/envs/spyglass/lib/python3.9/site-packages/xarray/namedarray/core.py:487: UserWarning: Duplicate dimension names present: dimensions {'states'} appear more than once in dims=('states', 'states'). We do not yet support duplicate dimension names, but we do allow initial construction of the object. We recommend you rename the dims immediately to become distinct, as most xarray functionality is likely to fail silently if you do not. To rename the dimensions you will need to set the ``.dims`` attribute of each variable, ``e.g. var.dims=('x0', 'x1')``.\n", - " warnings.warn(\n" - ] - }, { "data": { "text/html": [ @@ -1571,8 +1409,8 @@ " fill: currentColor;\n", "}\n", "
<xarray.Dataset>\n",
-       "Dimensions:                      (state_ind: 26668, dim_0: 26668, time: 3750,\n",
-       "                                  states: 2, intervals: 1, state_bins: 26668)\n",
+       "Dimensions:                      (state_ind: 25752, dim_0: 25752, time: 5001,\n",
+       "                                  states: 2, intervals: 1, state_bins: 25752)\n",
        "Coordinates:\n",
        "  * state_ind                    (state_ind) int32 0 0 0 0 0 0 0 ... 1 1 1 1 1 1\n",
        "  * time                         (time) float64 1.626e+09 ... 1.626e+09\n",
@@ -1581,8 +1419,8 @@
        "    encoding_groups              (states) int32 ...\n",
        "  * state_bins                   (state_bins) object MultiIndex\n",
        "  * state                        (state_bins) object 'Continuous' ... 'Fragme...\n",
-       "  * x_position                   (state_bins) float64 29.02 29.02 ... 262.7\n",
-       "  * y_position                   (state_bins) float64 0.5211 2.516 ... 224.0\n",
+       "  * x_position                   (state_bins) float64 29.02 29.02 ... 258.8\n",
+       "  * y_position                   (state_bins) float64 5.828 7.811 ... 224.0\n",
        "Dimensions without coordinates: dim_0, intervals\n",
        "Data variables:\n",
        "    initial_conditions           (dim_0) float64 ...\n",
@@ -1590,54 +1428,54 @@
        "    acausal_posterior            (intervals, time, state_bins) float32 ...\n",
        "    acausal_state_probabilities  (intervals, time, states) float64 ...\n",
        "Attributes:\n",
-       "    marginal_log_likelihoods:  -22323.148
  • marginal_log_likelihoods :
    -39514.59
  • " ], "text/plain": [ "\n", - "Dimensions: (state_ind: 26668, dim_0: 26668, time: 3750,\n", - " states: 2, intervals: 1, state_bins: 26668)\n", + "Dimensions: (state_ind: 25752, dim_0: 25752, time: 5001,\n", + " states: 2, intervals: 1, state_bins: 25752)\n", "Coordinates:\n", " * state_ind (state_ind) int32 0 0 0 0 0 0 0 ... 1 1 1 1 1 1\n", " * time (time) float64 1.626e+09 ... 1.626e+09\n", @@ -1646,8 +1484,8 @@ " encoding_groups (states) int32 ...\n", " * state_bins (state_bins) object MultiIndex\n", " * state (state_bins) object 'Continuous' ... 'Fragme...\n", - " * x_position (state_bins) float64 29.02 29.02 ... 262.7\n", - " * y_position (state_bins) float64 0.5211 2.516 ... 224.0\n", + " * x_position (state_bins) float64 29.02 29.02 ... 258.8\n", + " * y_position (state_bins) float64 5.828 7.811 ... 224.0\n", "Dimensions without coordinates: dim_0, intervals\n", "Data variables:\n", " initial_conditions (dim_0) float64 ...\n", @@ -1655,18 +1493,26 @@ " acausal_posterior (intervals, time, state_bins) float32 ...\n", " acausal_state_probabilities (intervals, time, states) float64 ...\n", "Attributes:\n", - " marginal_log_likelihoods: -22323.148" + " marginal_log_likelihoods: -39514.59" ] }, - "execution_count": 12, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ + "\n", "results = (SortedSpikesDecodingV1 & selection_key).fetch_results()\n", "results" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -1685,7 +1531,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.18" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/notebooks/py_scripts/43_Decoding_SortedSpikes.py b/notebooks/py_scripts/43_Decoding_SortedSpikes.py index 650299d0a..e6dc22bf2 100644 --- a/notebooks/py_scripts/43_Decoding_SortedSpikes.py +++ b/notebooks/py_scripts/43_Decoding_SortedSpikes.py @@ -5,7 +5,7 @@ # extension: .py # format_name: light # format_version: '1.5' -# jupytext_version: 1.16.0 +# jupytext_version: 1.15.2 # kernelspec: # display_name: spyglass # language: python @@ -26,7 +26,6 @@ # This time, instead of extracting waveform features, we can proceed directly from the SpikeSortingOutput table to specify which units we want to decode. The rest of the decoding process is the same as before. # # -# ## SortedSpikesGroup # + from pathlib import Path @@ -35,64 +34,79 @@ dj.config.load( Path("../dj_local_conf.json").absolute() ) # load config for database connection info +# - + +# ## SortedSpikesGroup +# +# `SortedSpikesGroup` is a child table of `SpikeSortingOutput` in the spikesorting pipeline. It allows us to group the spikesorting results from multiple +# sources (e.g. multiple terode groups or intervals) into a single entry. Here we will group together the spiking of multiple tetrode groups to use for decoding. +# +# +# This table allows us filter units by their annotation labels from curation (e.g only include units labeled "good", exclude units labeld "noise") by defining parameters from `UnitSelectionParams`. When accessing data through `SortedSpikesGroup` the table will include only units with at least one label in `include_labels` and no labels in `exclude_labels`. We can look at those here: +# + +# + +from spyglass.spikesorting.analysis.v1.group import UnitSelectionParams +UnitSelectionParams().insert_default() + +# look at the filter set we'll use here +unit_filter_params_name = "default_exclusion" +print((UnitSelectionParams() + & {"unit_filter_params_name":unit_filter_params_name}).fetch1()) +# look at full table +UnitSelectionParams() +# - + +# Now we can make our sorted spikes group with this unit selection parameter # + from spyglass.spikesorting.spikesorting_merge import SpikeSortingOutput import spyglass.spikesorting.v1 as sgs - nwb_copy_file_name = "mediumnwb20230802_.nwb" sorter_keys = { "nwb_file_name": nwb_copy_file_name, - "sorter": "clusterless_thresholder", - "sorter_param_name": "default_clusterless", + "sorter": "mountainsort4", + "curation_id": 1 } - +# check the set of sorting's we'll use (sgs.SpikeSortingSelection & sorter_keys) * SpikeSortingOutput.CurationV1 # + -spikesorting_merge_ids = ( - (sgs.SpikeSortingSelection & sorter_keys) * SpikeSortingOutput.CurationV1 -).fetch("merge_id") - -spikesorting_merge_ids - -# + -from spyglass.spikesorting.unit_inclusion_merge import ( - ImportedUnitInclusionV1, - UnitInclusionOutput, -) - -ImportedUnitInclusionV1().insert_all_units(spikesorting_merge_ids) +from spyglass.decoding.v1.sorted_spikes import SortedSpikesGroup -UnitInclusionOutput.ImportedUnitInclusionV1() & [ - {"spikesorting_merge_id": id} for id in spikesorting_merge_ids -] +SortedSpikesGroup() # + -from spyglass.spikesorting.analysis.v1.group import SortedSpikesGroup - -unit_inclusion_merge_ids = ( - UnitInclusionOutput.ImportedUnitInclusionV1 - & [{"spikesorting_merge_id": id} for id in spikesorting_merge_ids] +# get the merge_ids for the selected sortings +spikesorting_merge_ids = ( + (sgs.SpikeSortingSelection & sorter_keys) * SpikeSortingOutput.CurationV1 ).fetch("merge_id") +# create a new sorted spikes group +unit_filter_params_name = "default_exclusion" SortedSpikesGroup().create_group( group_name="test_group", nwb_file_name=nwb_copy_file_name, - unit_inclusion_merge_ids=unit_inclusion_merge_ids, + keys=[ + {"spikesorting_merge_id": merge_id} + for merge_id in spikesorting_merge_ids + ], + unit_filter_params_name=unit_filter_params_name, ) - +# check the new group SortedSpikesGroup & { "nwb_file_name": nwb_copy_file_name, "sorted_spikes_group_name": "test_group", } # - -SortedSpikesGroup.Units & { +# look at the sortings within the group we just made +SortedSpikesGroup.SortGroup & { "nwb_file_name": nwb_copy_file_name, "sorted_spikes_group_name": "test_group", + "unit_filter_params_name": unit_filter_params_name, } # ## Model parameters @@ -124,14 +138,10 @@ # # Now we can decode the position using the sorted spikes using the `SortedSpikesDecodingSelection` table. Here we assume that `PositionGroup` has been specified as in the clusterless decoding tutorial. -# + -from spyglass.decoding.v1.sorted_spikes import SortedSpikesDecodingSelection - -SortedSpikesDecodingSelection() - # + selection_key = { "sorted_spikes_group_name": "test_group", + "unit_filter_params_name": "default_exclusion", "position_group_name": "test_group", "decoding_param_name": "contfrag_sorted", "nwb_file_name": "mediumnwb20230802_.nwb", @@ -140,6 +150,7 @@ "estimate_decoding_params": False, } +from spyglass.decoding import SortedSpikesDecodingSelection SortedSpikesDecodingSelection.insert1( selection_key, skip_duplicates=True, @@ -161,5 +172,10 @@ # We can load the results as before: +# + + results = (SortedSpikesDecodingV1 & selection_key).fetch_results() results +# - + +