Skip to content

Commit

Permalink
final mcorr_cnmf.ipynb for workshop
Browse files Browse the repository at this point in the history
  • Loading branch information
kushalkolar committed Nov 8, 2023
1 parent c48e180 commit 24a0bca
Showing 1 changed file with 225 additions and 31 deletions.
256 changes: 225 additions & 31 deletions notebooks/mcorr_cnmf.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
"\n",
"There is only one item in this DataFrame and it is located at index `0`. You can run a row using `df.iloc[index].caiman.run()`\n",
"\n",
"Technical notes: On Linux & Mac it will run in subprocess but on Windows it will run in the local kernel. If using the subprocess backend (only Linux & Mac) you can use `run(wait=False)` if you don't want to block the kernel while running. "
"Technical notes: On Linux & Mac it will run in subprocess but on Windows it will run in the local kernel."
]
},
{
Expand Down Expand Up @@ -567,8 +567,11 @@
},
"outputs": [],
"source": [
"viz = df.mcorr.viz(data_options=[\"input\", \"mcorr\"])\n",
"viz.show()"
"viz = df.mcorr.viz(\n",
" data_options=[\"input\", \"mcorr\"],\n",
" image_widget_kwargs={\"grid_plot_kwargs\": {\"size\": (800, 400)}},\n",
")\n",
"viz.show(sidecar=True) # show in sidecar"
]
},
{
Expand All @@ -591,6 +594,16 @@
"viz"
]
},
{
"cell_type": "markdown",
"id": "ff9587b8-c0bf-41a5-a580-bd61fb8118fd",
"metadata": {},
"source": [
"**Use tab completion to see public methods and attributes**\n",
"\n",
"``viz.<Tab>``"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -906,29 +919,28 @@
{
"cell_type": "code",
"execution_count": null,
"id": "9bc56b3d-2bec-4b60-9d05-788950b61c34",
"id": "78708874-f58f-4508-b1f5-b07cce0203f8",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from mesmerize_viz import *"
"mcorr_viz = df.mcorr.viz(\n",
" data_options=[\"input\", \"mcorr\"], \n",
" image_widget_kwargs={\"grid_plot_kwargs\": {\"size\": (1000, 500)}} # you can also pass kwargs to the ImageWidget that is created\n",
")\n",
"mcorr_viz.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "78708874-f58f-4508-b1f5-b07cce0203f8",
"metadata": {
"tags": []
},
"id": "390fe3a8-27bd-4710-b6ec-5419c13a4611",
"metadata": {},
"outputs": [],
"source": [
"mcorr_viz = df.mcorr.viz(\n",
" data_options=[\"input\", \"mcorr\"], \n",
" image_widget_kwargs={\"grid_plot_kwargs\": {\"size\": (1000, 500)}} # you can also pass kwargs to the ImageWidget that is created\n",
")\n",
"mcorr_viz.show()"
"# close when done\n",
"mcorr_viz.close()"
]
},
{
Expand Down Expand Up @@ -1057,8 +1069,8 @@
"outputs": [],
"source": [
"# make a list of rows we want to keep using the uuids\n",
"rows_keep = [df.iloc[6].uuid]\n",
"rows_keep"
"# rows_keep = [df.iloc[6].uuid]\n",
"# rows_keep"
]
},
{
Expand All @@ -1078,11 +1090,11 @@
"metadata": {},
"outputs": [],
"source": [
"for i, row in df.iterrows():\n",
" if row.uuid not in rows_keep:\n",
" df.caiman.remove_item(row.uuid)\n",
"# for i, row in df.iterrows():\n",
"# if row.uuid not in rows_keep:\n",
"# df.caiman.remove_item(row.uuid)\n",
"\n",
"df"
"# df"
]
},
{
Expand Down Expand Up @@ -1168,14 +1180,14 @@
},
"outputs": [],
"source": [
"good_mcorr_index = 0\n",
"good_mcorr_index = 6\n",
"\n",
"# add a batch item\n",
"df.caiman.add_item(\n",
" algo='cnmf', # algo is cnmf\n",
" input_movie_path=df.iloc[good_mcorr_index], # use mcorr output from a completed batch item\n",
" params=params_cnmf,\n",
" item_name=df.iloc[0][\"item_name\"], # use the same item name\n",
" item_name=df.iloc[good_mcorr_index][\"item_name\"], # use the same item name\n",
")"
]
},
Expand Down Expand Up @@ -1499,12 +1511,63 @@
"rcm[10:20].shape"
]
},
{
"cell_type": "markdown",
"id": "c6fe2ca3-0255-43fd-9ae2-c635b2d0355a",
"metadata": {},
"source": [
"# Using LazyArrays"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cf4f70d3-badc-4339-92f8-1ac0351e64b6",
"metadata": {},
"outputs": [],
"source": [
"rcm_accepted = df.iloc[index].cnmf.get_rcm(\"good\")\n",
"rcm_rejected = df.iloc[index].cnmf.get_rcm(\"bad\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "96b638ee-ce7e-4c58-a2e5-3d46b986d04a",
"metadata": {},
"outputs": [],
"source": [
"iw_max = fpl.ImageWidget(\n",
" data=[rcm_accepted.max_image, rcm_rejected.max_image],\n",
" names=[\"accepted\", \"rejected\"],\n",
" grid_plot_kwargs={\"size\": (900, 450)},\n",
" cmap=\"gnuplot2\"\n",
")\n",
"iw_max.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0517f807-bb71-4152-b1ad-ad785d4108cc",
"metadata": {},
"outputs": [],
"source": [
"iw_rcm_separated = fpl.ImageWidget(\n",
" data=[rcm_accepted, rcm_rejected],\n",
" names=[\"accepted\", \"rejected\"],\n",
" grid_plot_kwargs={\"size\": (900, 450)},\n",
" cmap=\"gnuplot2\"\n",
")\n",
"iw_rcm_separated.show()"
]
},
{
"cell_type": "markdown",
"id": "934dc203-fa0c-4c1e-b8e9-0c6dba91ef3d",
"metadata": {},
"source": [
"Get all the lazy arrays and the input movie"
"# All CNMF LazyArrays"
]
},
{
Expand Down Expand Up @@ -1534,7 +1597,11 @@
"metadata": {},
"outputs": [],
"source": [
"iw_rcm = fpl.ImageWidget([input_movie, rcm, rcb, residuals], grid_plot_kwargs={\"size\": (800, 600)}, cmap=\"gnuplot2\")\n",
"iw_rcm = fpl.ImageWidget(\n",
" data=[input_movie, rcm, rcb, residuals], \n",
" grid_plot_kwargs={\"size\": (800, 600)}, \n",
" cmap=\"gnuplot2\"\n",
")\n",
"iw_rcm.show()"
]
},
Expand Down Expand Up @@ -1599,7 +1666,7 @@
"from itertools import product\n",
"\n",
"# variants of several parameters\n",
"gSig_variants = [6, 8]\n",
"gSig_variants = [4, 6]\n",
"K_variants = [4, 8]\n",
"merge_thr_variants = [0.8, 0.95]\n",
"\n",
Expand All @@ -1621,8 +1688,8 @@
" # add param combination variant to batch\n",
" df.caiman.add_item(\n",
" algo=\"cnmf\",\n",
" item_name=df.iloc[0][\"item_name\"], # mcorr item\n",
" input_movie_path=df.iloc[0],\n",
" item_name=df.iloc[good_mcorr_index][\"item_name\"], # good mcorr item\n",
" input_movie_path=df.iloc[good_mcorr_index],\n",
" params=new_params_cnmf\n",
" )"
]
Expand Down Expand Up @@ -1735,7 +1802,7 @@
"outputs": [],
"source": [
"viz_cnmf = df.cnmf.viz()\n",
"viz_cnmf.show()"
"viz_cnmf.show(sidecar=True)"
]
},
{
Expand Down Expand Up @@ -1818,10 +1885,137 @@
{
"cell_type": "code",
"execution_count": null,
"id": "6260eba2-8c40-478e-ad90-f355d3861c8f",
"id": "bb2db848-272d-4001-92cc-369e9d2d62b6",
"metadata": {},
"outputs": [],
"source": [
"viz_cnmf.plot_heatmap[\"heatmap\"].cmap.vmax"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33758ab0-b355-450f-8edc-dc9fa5b7364f",
"metadata": {},
"outputs": [],
"source": [
"viz_cnmf.plot_heatmap[\"heatmap\"].cmap.vmax = 2_000"
]
},
{
"cell_type": "markdown",
"id": "b60a5224-9945-4f15-9ecb-99d448745942",
"metadata": {},
"source": [
"Customize contours"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7668b133-0431-464e-af1d-0ce353628e6e",
"metadata": {},
"outputs": [],
"source": [
"for subplot in viz_cnmf.image_widget.gridplot:\n",
" subplot[\"contours\"][:].thickness = 1.0"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4e238b53-9f20-44b3-ab99-94332f93b949",
"metadata": {},
"outputs": [],
"source": [
"for subplot in viz_cnmf.image_widget.gridplot:\n",
" subplot[\"contours\"].visible = False"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "61508674-8ed6-4ae2-a232-44a55bd4c646",
"metadata": {},
"outputs": [],
"source": [
"for subplot in viz_cnmf.image_widget.gridplot:\n",
" subplot[\"contours\"].visible = True"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "29abcc5a-7ecc-4e95-8532-f1a4dcc3e1f2",
"metadata": {},
"outputs": [],
"source": [
"viz_cnmf.plot_temporal[\"line\"].thickness()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "14ae170b-096c-421d-b47d-13042ab8e4cf",
"metadata": {},
"outputs": [],
"source": [
"viz_cnmf.plot_temporal[\"line\"].thickness = 1"
]
},
{
"cell_type": "markdown",
"id": "31dd4191-9781-45b4-84cb-35a62597fb6c",
"metadata": {},
"source": [
"# Visualize fewer things"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6581e60e-8827-490d-af5f-3ff8b5308680",
"metadata": {},
"outputs": [],
"source": [
"viz_simple = df.cnmf.viz(\n",
" image_data_options=[\"input\", \"rcm\"],\n",
")\n",
"viz_simple.show(sidecar=True)"
]
},
{
"cell_type": "markdown",
"id": "a5479abd-2f34-4e6e-bd64-702720e25ff4",
"metadata": {},
"source": [
"# More customization of kwargs"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20845bb1-5f27-4c60-8638-2d17a03cff99",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"viz_more_custom = df.cnmf.viz(\n",
" image_data_options=[\"input\", \"rcm\", \"rcm-max\", \"corr\"],\n",
" temporal_kwargs={\"add_residuals\": True},\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1e8f57c5-9f9e-495a-aa44-86f18c886eed",
"metadata": {},
"outputs": [],
"source": []
"source": [
"viz_more_custom.show(sidecar=True)"
]
}
],
"metadata": {
Expand All @@ -1840,7 +2034,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 24a0bca

Please sign in to comment.