Skip to content

Commit cfe2d88

Browse files
author
Caitlin Lewis
committed
add neuro example for line collection cmapping
1 parent df9ed25 commit cfe2d88

File tree

1 file changed

+299
-4
lines changed

1 file changed

+299
-4
lines changed

lines.ipynb

Lines changed: 299 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
},
2121
{
2222
"cell_type": "code",
23-
"execution_count": 1,
23+
"execution_count": 2,
2424
"id": "177e0cc3-870c-4570-bf59-af3528ba94bf",
2525
"metadata": {},
2626
"outputs": [],
@@ -563,7 +563,7 @@
563563
"plot = fpl.Plot()\n",
564564
"\n",
565565
"# highest values, lowest values, mid-high values, mid values\n",
566-
"cmap_values = cmap_values = [\n",
566+
"cmap_values = [\n",
567567
" 0, 1, 1, 2,\n",
568568
" 0, 0, 1, 1,\n",
569569
" 2, 2, 3, 3,\n",
@@ -648,6 +648,289 @@
648648
"sc.close()"
649649
]
650650
},
651+
{
652+
"cell_type": "markdown",
653+
"id": "54374981-9a79-4887-a297-8a5012ebb4b7",
654+
"metadata": {},
655+
"source": [
656+
"## neuro data example"
657+
]
658+
},
659+
{
660+
"cell_type": "code",
661+
"execution_count": 48,
662+
"id": "6901f4b7-d1f8-4747-b8b0-de078ae4c825",
663+
"metadata": {
664+
"tags": []
665+
},
666+
"outputs": [],
667+
"source": [
668+
"# load in movie \n",
669+
"movie = np.load('/home/clewis7/repos/fastplotlib-scipy2023/data/rcm.npy')\n",
670+
"\n",
671+
"# load in identified nuerons\n",
672+
"contours = np.load('/home/clewis7/repos/fastplotlib-scipy2023/data/contours.npy', allow_pickle=True)"
673+
]
674+
},
675+
{
676+
"cell_type": "markdown",
677+
"id": "606c769a-9c63-4c3f-ace7-a5f4721b5ee5",
678+
"metadata": {},
679+
"source": [
680+
"### labeling good and bad components"
681+
]
682+
},
683+
{
684+
"cell_type": "code",
685+
"execution_count": 50,
686+
"id": "6a9005e6-2c6b-4561-8890-0a576273e609",
687+
"metadata": {
688+
"tags": []
689+
},
690+
"outputs": [],
691+
"source": [
692+
"# indices of good components\n",
693+
"good_ixs = np.load('/home/clewis7/repos/fastplotlib-scipy2023/data/good_ixs.npy')"
694+
]
695+
},
696+
{
697+
"cell_type": "code",
698+
"execution_count": 51,
699+
"id": "7c8eaeac-3f4a-45aa-8a85-ad319c25143d",
700+
"metadata": {
701+
"tags": []
702+
},
703+
"outputs": [],
704+
"source": [
705+
"# initialize colors and set good components as green\n",
706+
"colors = np.tile([255, 0, 0, 1], 155).reshape(155, 4)\n",
707+
"colors[good_ixs] = [0, 255, 0, 1]"
708+
]
709+
},
710+
{
711+
"cell_type": "code",
712+
"execution_count": 52,
713+
"id": "162a1602-2201-45be-bcc2-6fd7550cf0e4",
714+
"metadata": {
715+
"tags": []
716+
},
717+
"outputs": [
718+
{
719+
"data": {
720+
"application/vnd.jupyter.widget-view+json": {
721+
"model_id": "8990b15d33c440c786e26fbd356002d2",
722+
"version_major": 2,
723+
"version_minor": 0
724+
},
725+
"text/plain": [
726+
"RFBOutputContext()"
727+
]
728+
},
729+
"metadata": {},
730+
"output_type": "display_data"
731+
},
732+
{
733+
"name": "stderr",
734+
"output_type": "stream",
735+
"text": [
736+
"/home/clewis7/repos/fastplotlib/fastplotlib/graphics/_features/_base.py:34: UserWarning: converting float64 array to float32\n",
737+
" warn(f\"converting {array.dtype} array to float32\")\n",
738+
"/home/clewis7/repos/fastplotlib/fastplotlib/graphics/_features/_base.py:31: UserWarning: converting int64 array to int32\n",
739+
" warn(f\"converting {array.dtype} array to int32\")\n"
740+
]
741+
}
742+
],
743+
"source": [
744+
"# for the image data and contours\n",
745+
"cnmf_iw = fpl.ImageWidget(movie, vmin_vmax_sliders=True, cmap=\"gnuplot2\")\n",
746+
"\n",
747+
"# add contours to the plot within the widget\n",
748+
"contours_graphic = cnmf_iw.gridplot[0,0].add_line_collection(\n",
749+
" contours, \n",
750+
" colors=colors, \n",
751+
" thickness=1.1, \n",
752+
" name=\"contours\"\n",
753+
")\n",
754+
"\n",
755+
"# stack the plots and show them in sidecar\n",
756+
"sc = Sidecar(title=\"good/bad comps\")\n",
757+
"\n",
758+
"with sc:\n",
759+
" display(cnmf_iw.show())"
760+
]
761+
},
762+
{
763+
"cell_type": "code",
764+
"execution_count": 53,
765+
"id": "2e34929f-55dd-43d5-8736-8253ad11d96e",
766+
"metadata": {
767+
"tags": []
768+
},
769+
"outputs": [],
770+
"source": [
771+
"cnmf_iw.vmin_vmax_sliders[0].value = (-5, 15)"
772+
]
773+
},
774+
{
775+
"cell_type": "code",
776+
"execution_count": 54,
777+
"id": "60ec0022-857e-46e7-abd3-17bf852bd6e6",
778+
"metadata": {
779+
"tags": []
780+
},
781+
"outputs": [],
782+
"source": [
783+
"cnmf_iw.gridplot.close()\n",
784+
"sc.close()"
785+
]
786+
},
787+
{
788+
"cell_type": "markdown",
789+
"id": "7a254ed4-370c-4b5a-8c55-8b9603af7816",
790+
"metadata": {},
791+
"source": [
792+
"### mapping eval metrics to cmap"
793+
]
794+
},
795+
{
796+
"cell_type": "markdown",
797+
"id": "2516bb91-04f3-4c65-ba17-7f1cc1c7188f",
798+
"metadata": {},
799+
"source": [
800+
"#### cnn thresholds"
801+
]
802+
},
803+
{
804+
"cell_type": "code",
805+
"execution_count": 55,
806+
"id": "b1319e04-e1b6-4c11-a887-314dba7d60fb",
807+
"metadata": {
808+
"tags": []
809+
},
810+
"outputs": [],
811+
"source": [
812+
"# load in CNN predictions\n",
813+
"cnn_preds = np.load('/home/clewis7/repos/fastplotlib-scipy2023/data/cnn_preds.npy')"
814+
]
815+
},
816+
{
817+
"cell_type": "code",
818+
"execution_count": 56,
819+
"id": "8f532d3f-aed5-4dd5-b433-0a76f429022a",
820+
"metadata": {
821+
"tags": []
822+
},
823+
"outputs": [
824+
{
825+
"data": {
826+
"application/vnd.jupyter.widget-view+json": {
827+
"model_id": "952f12e9654a4e968ab42a80e0e32e9f",
828+
"version_major": 2,
829+
"version_minor": 0
830+
},
831+
"text/plain": [
832+
"RFBOutputContext()"
833+
]
834+
},
835+
"metadata": {},
836+
"output_type": "display_data"
837+
}
838+
],
839+
"source": [
840+
"# for the image data and contours\n",
841+
"cnmf_iw = fpl.ImageWidget(movie, vmin_vmax_sliders=True, cmap=\"gnuplot2\")\n",
842+
"\n",
843+
"# add contours to the plot within the widget\n",
844+
"contours_graphic = cnmf_iw.gridplot[0,0].add_line_collection(\n",
845+
" contours, \n",
846+
" cmap_values=cnn_preds,\n",
847+
" cmap=\"Wistia\",\n",
848+
" thickness=1.1, \n",
849+
" name=\"contours\"\n",
850+
")\n",
851+
"\n",
852+
"# stack the plots and show them in sidecar\n",
853+
"sc = Sidecar(title=\"eval metrics\")\n",
854+
"\n",
855+
"with sc:\n",
856+
" display(cnmf_iw.show())"
857+
]
858+
},
859+
{
860+
"cell_type": "code",
861+
"execution_count": 57,
862+
"id": "bc7672ba-237f-46b7-9374-538babe1fdbd",
863+
"metadata": {
864+
"tags": []
865+
},
866+
"outputs": [],
867+
"source": [
868+
"cnmf_iw.vmin_vmax_sliders[0].value = (-5, 15)"
869+
]
870+
},
871+
{
872+
"cell_type": "markdown",
873+
"id": "f60c6fb2-1d73-4d8b-ac5d-3d37a216d071",
874+
"metadata": {},
875+
"source": [
876+
"#### r_values"
877+
]
878+
},
879+
{
880+
"cell_type": "code",
881+
"execution_count": 58,
882+
"id": "be53bd85-9d4a-415c-b70b-c38160472aa0",
883+
"metadata": {
884+
"tags": []
885+
},
886+
"outputs": [],
887+
"source": [
888+
"# load in r_vals\n",
889+
"r_vals = np.load('/home/clewis7/repos/fastplotlib-scipy2023/data/r_vals.npy')\n",
890+
"\n",
891+
"# remap cmap values and cmap\n",
892+
"contours_graphic.cmap_values = r_vals\n",
893+
"contours_graphic.cmap = \"cool\""
894+
]
895+
},
896+
{
897+
"cell_type": "markdown",
898+
"id": "90e7e79a-2879-454a-9293-e8abda55808e",
899+
"metadata": {},
900+
"source": [
901+
"#### SNR comps"
902+
]
903+
},
904+
{
905+
"cell_type": "code",
906+
"execution_count": 59,
907+
"id": "3dbd7a7e-da52-4c95-a66e-020feb447080",
908+
"metadata": {
909+
"tags": []
910+
},
911+
"outputs": [],
912+
"source": [
913+
"# load in SNR comps\n",
914+
"snr_comps = np.load('/home/clewis7/repos/fastplotlib-scipy2023/data/SNR_comps.npy')\n",
915+
"\n",
916+
"# remap cmap values and cmap\n",
917+
"contours_graphic.cmap_values = snr_comps\n",
918+
"contours_graphic.cmap = \"spring\""
919+
]
920+
},
921+
{
922+
"cell_type": "code",
923+
"execution_count": 60,
924+
"id": "32ed59ef-d956-4e83-b12f-8c496e1579e4",
925+
"metadata": {
926+
"tags": []
927+
},
928+
"outputs": [],
929+
"source": [
930+
"cnmf_iw.gridplot.close()\n",
931+
"sc.close()"
932+
]
933+
},
651934
{
652935
"cell_type": "markdown",
653936
"id": "a1a34cfd-3746-489e-aeff-7373d538ab8b",
@@ -718,12 +1001,24 @@
7181001
},
7191002
{
7201003
"cell_type": "code",
721-
"execution_count": 35,
1004+
"execution_count": 33,
7221005
"id": "7a3b8014-a89e-4138-98ac-ed3cbf1f0d51",
7231006
"metadata": {
7241007
"tags": []
7251008
},
726-
"outputs": [],
1009+
"outputs": [
1010+
{
1011+
"ename": "NameError",
1012+
"evalue": "name 'plot' is not defined",
1013+
"output_type": "error",
1014+
"traceback": [
1015+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
1016+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
1017+
"Cell \u001b[0;32mIn[33], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mplot\u001b[49m\u001b[38;5;241m.\u001b[39mclose()\n\u001b[1;32m 2\u001b[0m sc\u001b[38;5;241m.\u001b[39mclose()\n",
1018+
"\u001b[0;31mNameError\u001b[0m: name 'plot' is not defined"
1019+
]
1020+
}
1021+
],
7271022
"source": [
7281023
"plot.close()\n",
7291024
"sc.close()"

0 commit comments

Comments
 (0)