Skip to content

Commit

Permalink
Updated SRRF in notebooks to use Liquid Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomsaraiva committed Aug 11, 2023
1 parent 3ee4205 commit 709d0d8
Show file tree
Hide file tree
Showing 2 changed files with 235 additions and 158 deletions.
110 changes: 72 additions & 38 deletions notebooks/ExampleDataSRRFandQC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,34 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [],
"cellView": "form",
"id": "I1MA0bmmCeZM"
"id": "vU0pbqWAf_Y-"
},
"outputs": [],
"source": [
"#@title Fix OpenCL if needed in Google Colab\n",
"import sys\n",
"\n",
"IN_COLAB = 'google.colab' in sys.modules\n",
"if IN_COLAB:\n",
" !sudo apt-get update -qq\n",
" !sudo apt-get purge -qq *nvidia* -y\n",
" !sudo DEBIAN_FRONTEND=noninteractive apt-get install -qq nvidia-driver-530 -y\n",
" exit(0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "I1MA0bmmCeZM",
"tags": []
},
"outputs": [],
"source": [
"#@title Install NanoPyx, import necessary libraries and connect to Google Drive\n",
"!pip install -q \"nanopyx[jupyter]\"\n",
"#!pip install -q \"nanopyx[jupyter]\"\n",
"import io\n",
"import os\n",
"import sys\n",
Expand Down Expand Up @@ -99,9 +119,9 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [],
"cellView": "form",
"id": "uo6ZDQ__CeZN"
"id": "uo6ZDQ__CeZN",
"tags": []
},
"outputs": [],
"source": [
Expand All @@ -127,7 +147,7 @@
" dataset_original = skimage.io.imread(gui_data[\"data_source\"].value)\n",
" display(stackview.slice(dataset_original, continuous_update=True,\n",
" colormap=gui_data[\"cmaps\"].value))\n",
" \n",
"\n",
" # enable button\n",
" gui_data[\"load_data\"].disabled = False\n",
" gui_data[\"load_data\"].description = \"Load data\"\n",
Expand Down Expand Up @@ -155,31 +175,32 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "GaMd1LizrBnZ"
},
"source": [
"# SRRF Parameters:\n",
"\n",
"- **Ring Radius:** Radius of the ring used to calculate the radiality (in pixels).\n",
"- **Magnification:** Desired magnification for the generated radiality image.\n",
"- **SRRF order:** Flag for types of SRRF temporal correlations. Order = -1: pairwise product sum; Order = 0: maximum intensity projection; Order = 1: mean; Order = 2,3 or 4: autocorrelation function of order 2, 3 or 4.\n",
"- **Frames-per-timepoint:** How many frames of the original image stack are used to calculated a single SRRF frame. For example, given an input image with 500 frames, if using 100 frames per timepoint, SRRF will generate an image stack with 5 super-resolved frames. "
],
"metadata": {
"id": "GaMd1LizrBnZ"
}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [],
"cellView": "form",
"id": "USD3dlBzCeZO"
"id": "USD3dlBzCeZO",
"tags": []
},
"outputs": [],
"source": [
"#@title Create SRRF GUI\n",
"gui_srrf = EasyGui(\"srrf\")\n",
"from nanopyx.methods.srrf import SRRF\n",
"from nanopyx.methods.SRRF_workflow import SRRF\n",
"from nanopyx.core.transform.sr_temporal_correlations import calculate_SRRF_temporal_correlations\n",
"\n",
"def run_srrf(b):\n",
" clear_output()\n",
Expand All @@ -192,16 +213,29 @@
" # disable button while running\n",
" gui_srrf[\"run\"].disabled = True\n",
" gui_srrf[\"run\"].description = \"Running...\"\n",
" srrf = SRRF(magnification, ring_radius)\n",
" if frames_per_timepoint == 0:\n",
" frames_per_timepoint = dataset_original.shape[0]\n",
" elif frames_per_timepoint > dataset_original.shape[0]:\n",
" frames_per_timepoint = dataset_original.shape[0]\n",
"\n",
" output= []\n",
"\n",
" for i in range(dataset_original.shape[0] // frames_per_timepoint):\n",
" block = dataset_original[i*frames_per_timepoint:(i+1)*frames_per_timepoint]\n",
" srrf_generator = SRRF(block, magnification=magnification, ringRadius=ring_radius,\n",
" radialityPositivityConstraint=True,\n",
" doIntensityWeighting=True)\n",
" result = srrf_generator.calculate()\n",
" output.append(calculate_SRRF_temporal_correlations(result[0], srrf_order))\n",
"\n",
" global dataset_srrf\n",
" dataset_srrf = srrf.calculate(dataset_original, frames_per_timepoint, srrf_order)\n",
" dataset_srrf = np.array(output)\n",
" # enable button again\n",
" gui_srrf[\"run\"].disabled = False\n",
" gui_srrf[\"run\"].description = \"Run\"\n",
" display(stackview.curtain(dataset_srrf[0], dataset_srrf[1],\n",
" display(stackview.slice(dataset_srrf,\n",
" continuous_update=True,\n",
" colormap=gui_data[\"cmaps\"].value,\n",
" curtain_colormap=gui_data[\"cmaps\"].value))\n",
" colormap=gui_data[\"cmaps\"].value))\n",
"\n",
"gui_srrf.add_float_slider(\"ring_radius\", description=\"Ring Radius:\", min=0.1, max=3.0, value=0.5, remember_value=True)\n",
"gui_srrf.add_int_slider(\"magnification\", description=\"Magnification:\", min=1, max=10, value=5)\n",
Expand Down Expand Up @@ -258,11 +292,11 @@
" plt.imshow(errormap)\n",
" plt.axis(\"off\")\n",
" plt.show()\n",
" \n",
"\n",
"gui_error.add_button(\"run\", description=\"Calculate\")\n",
"gui_error[\"run\"].on_click(run_error)\n",
"gui_error.show()\n",
" "
""
]
},
{
Expand All @@ -276,16 +310,16 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "aOb942lFrE2O"
},
"source": [
"# FRC Parameters:\n",
"\n",
"- **Pixel Size:** Pixel size of the image. Used to calculte resolution values.\n",
"- **Units:** Pixel size units.\n",
"- **First/Second Frame:** As FRC is calculated between two frames of the same image stack, these parameters determines which two frames are used for the calculation."
],
"metadata": {
"id": "aOb942lFrE2O"
}
]
},
{
"cell_type": "code",
Expand Down Expand Up @@ -318,7 +352,7 @@
" plt.imshow(frc_calculator_raw.plot_frc_curve())\n",
" plt.axis(\"off\")\n",
" plt.show()\n",
" \n",
"\n",
"gui_frc_1.add_int_slider(\"pixel_size\", description=\"Pixel Size:\", min=0.01, max=1000, value=100, remember_value=True)\n",
"gui_frc_1.add_dropdown(\"units\", description=\"Units: \", options=[\"nm\", \"um\", \"mm\"], value=\"nm\")\n",
"gui_frc_1.add_button(\"run\", description=\"Calculate\")\n",
Expand Down Expand Up @@ -367,7 +401,7 @@
" plt.imshow(frc_calculator.plot_frc_curve())\n",
" plt.axis(\"off\")\n",
" plt.show()\n",
" \n",
"\n",
"gui_frc.add_int_slider(\"pixel_size\", description=\"Pixel Size:\", min=0.01, max=1000, value=20, remember_value=True)\n",
"gui_frc.add_dropdown(\"units\", description=\"Units: \", options=[\"nm\", \"um\", \"mm\"], value=\"nm\")\n",
"gui_frc.add_int_slider(\"first_frame\", description=\"First Frame:\", min=0, max=dataset_srrf[0].shape[0]-1, value=0)\n",
Expand All @@ -388,16 +422,16 @@
},
{
"cell_type": "markdown",
"metadata": {
"id": "v1oShT8crIlO"
},
"source": [
"# Image Decorrelation Analysis Parameters:\n",
"\n",
"- **Pixel Size:** Pixel size of the image. Used to calculate resolution values.\n",
"- **Units:** Pixel size units.\n",
"- **Radius Min/Max:** Resolution calculation by Decorrelation Analysis is performed in the frequency space. These parameters define the range of radii to be used in the calculation. "
],
"metadata": {
"id": "v1oShT8crIlO"
}
]
},
{
"cell_type": "code",
Expand Down Expand Up @@ -431,7 +465,7 @@
" plt.imshow(decorr_calculator_raw.plot_results())\n",
" plt.axis(\"off\")\n",
" plt.show()\n",
" \n",
"\n",
"gui_decorr_1.add_int_slider(\"pixel_size\", description=\"Pixel Size:\", min=0.01, max=1000, value=100, remember_value=True)\n",
"gui_decorr_1.add_dropdown(\"units\", description=\"Units: \", options=[\"nm\", \"um\", \"mm\"], value=\"nm\")\n",
"gui_decorr_1.add_float_slider(\"rmin\", description=\"Radius Min:\", min=0.0, max=0.5, value=0.0)\n",
Expand All @@ -454,9 +488,9 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [],
"cellView": "form",
"id": "S9i3s0lXCeZR"
"id": "S9i3s0lXCeZR",
"tags": []
},
"outputs": [],
"source": [
Expand Down Expand Up @@ -484,7 +518,7 @@
" plt.imshow(decorr_calculator.plot_results())\n",
" plt.axis(\"off\")\n",
" plt.show()\n",
" \n",
"\n",
"gui_decorr.add_int_slider(\"pixel_size\", description=\"Pixel Size:\", min=0.01, max=1000, value=100, remember_value=True)\n",
"gui_decorr.add_dropdown(\"units\", description=\"Units: \", options=[\"nm\", \"um\", \"mm\"], value=\"nm\")\n",
"gui_decorr.add_int_slider(\"first_frame\", description=\"Frame to be used:\", min=0, max=dataset_srrf[0].shape[0]-1, value=0)\n",
Expand All @@ -497,6 +531,9 @@
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
Expand All @@ -512,10 +549,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
},
"colab": {
"provenance": []
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 709d0d8

Please sign in to comment.