diff --git a/notebooks/ChannelRegistration.ipynb b/notebooks/ChannelRegistration.ipynb index b7794cb2..3479fd7a 100644 --- a/notebooks/ChannelRegistration.ipynb +++ b/notebooks/ChannelRegistration.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "3a463e61", + "id": "adc06056", "metadata": {}, "source": [ "# NanoPyx \"Codeless\" Jupyter Notebook\n", @@ -22,7 +22,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2c8eefa2", + "id": "5849fa88", "metadata": { "cellView": "form" }, @@ -45,7 +45,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b399241e", + "id": "9f1e02c2", "metadata": { "cellView": "form" }, @@ -103,7 +103,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3515d5ba", + "id": "1ecca89e", "metadata": { "cellView": "form" }, @@ -187,7 +187,7 @@ }, { "cell_type": "markdown", - "id": "28fd6b5d", + "id": "ec09efb1", "metadata": {}, "source": [ "# Channel Registration Parameters: \n", @@ -205,7 +205,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cc625efd", + "id": "b06dfc66", "metadata": { "cellView": "form" }, @@ -273,7 +273,7 @@ }, { "cell_type": "markdown", - "id": "0187c8cc", + "id": "7224e975", "metadata": {}, "source": [ "## Use the following cell only if you have a previously calculated translation mask\n", @@ -283,7 +283,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b7fa2ef3", + "id": "edb303a6", "metadata": { "cellView": "form" }, diff --git a/notebooks/DriftCorrection.ipynb b/notebooks/DriftCorrection.ipynb index da2cf2f4..4af79977 100644 --- a/notebooks/DriftCorrection.ipynb +++ b/notebooks/DriftCorrection.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "8000d90a", + "id": "e7c865cd", "metadata": {}, "source": [ "# NanoPyx \"Codeless\" Jupyter Notebook\n", @@ -22,7 +22,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8e6267d8", + "id": "e2314904", "metadata": { "cellView": "form" }, @@ -45,7 +45,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8a1ec6e4", + "id": "96f0af5a", "metadata": { "cellView": "form" }, @@ -103,7 +103,7 @@ { "cell_type": "code", "execution_count": null, - "id": "cd931d80", + "id": "1541817a", "metadata": { "cellView": "form" }, @@ -187,7 +187,7 @@ }, { "cell_type": "markdown", - "id": "c64af72e", + "id": "a6f608a3", "metadata": {}, "source": [ "# Drift Correction Parameters: \n", @@ -204,7 +204,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6e00f92e", + "id": "47c6e626", "metadata": { "cellView": "form" }, @@ -297,7 +297,7 @@ }, { "cell_type": "markdown", - "id": "4dee37ed", + "id": "f082a781", "metadata": {}, "source": [ "## Use the following cell only if you have a previously calculated drift table\n", @@ -307,7 +307,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e68d4a71", + "id": "139cbeb0", "metadata": { "cellView": "form" }, diff --git a/notebooks/ExampleDataSRRFandQC.ipynb b/notebooks/ExampleDataSRRFandQC.ipynb index e4e7395a..3e61b482 100644 --- a/notebooks/ExampleDataSRRFandQC.ipynb +++ b/notebooks/ExampleDataSRRFandQC.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "0bb114f6", + "id": "d8d514e3", "metadata": {}, "source": [ "# NanoPyx \"Codeless\" Jupyter Notebook\n", @@ -26,7 +26,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9b1d5a74", + "id": "b7db11f3", "metadata": { "cellView": "form" }, @@ -49,7 +49,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bf06f12f", + "id": "26dea83e", "metadata": { "cellView": "form" }, @@ -106,7 +106,7 @@ }, { "cell_type": "markdown", - "id": "9b40447a", + "id": "f374a5ac", "metadata": {}, "source": [ "## Next lets create the Data Loader GUI.\n", @@ -117,7 +117,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0facb763", + "id": "49736d21", "metadata": { "cellView": "form" }, @@ -201,7 +201,7 @@ }, { "cell_type": "markdown", - "id": "9c6e9ba9", + "id": "1a631b2f", "metadata": {}, "source": [ "## Now let's use SRRF to generate a super-resolution image\n", @@ -210,7 +210,7 @@ }, { "cell_type": "markdown", - "id": "5d3afd30", + "id": "45d0fda3", "metadata": {}, "source": [ "# SRRF Parameters:\n", @@ -226,7 +226,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ad5edeff", + "id": "2981320f", "metadata": { "cellView": "form" }, @@ -334,7 +334,7 @@ }, { "cell_type": "markdown", - "id": "e32a84cf", + "id": "0232bb0b", "metadata": {}, "source": [ "## Let's use NanoPyx to generate an error map of the SRRF image\n", @@ -344,7 +344,7 @@ { "cell_type": "code", "execution_count": null, - "id": "44184399", + "id": "186ff2ea", "metadata": { "cellView": "form" }, @@ -499,7 +499,7 @@ }, { "cell_type": "markdown", - "id": "c954bc0c", + "id": "162dc7db", "metadata": {}, "source": [ "## Let's compare the resolution of the raw data with the SRRF using FRC and DecorrelationAnalysis. Let's start with calculation the FRC resolution of the raw data (select frame 3 and 11).\n", @@ -508,7 +508,7 @@ }, { "cell_type": "markdown", - "id": "03d6c564", + "id": "0a8f2ad1", "metadata": {}, "source": [ "# FRC Parameters:\n", @@ -523,7 +523,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3bc9fcaf", + "id": "0104860b", "metadata": { "cellView": "form" }, @@ -583,7 +583,7 @@ }, { "cell_type": "markdown", - "id": "c064f783", + "id": "3b1cc7dd", "metadata": {}, "source": [ "## Now do the same for the SRRF image\n", @@ -593,7 +593,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a15491c4", + "id": "305ce249", "metadata": { "cellView": "form" }, @@ -653,7 +653,7 @@ }, { "cell_type": "markdown", - "id": "b070890b", + "id": "7626a919", "metadata": {}, "source": [ "## Let's do the same using Decorrelation analysis\n", @@ -662,7 +662,7 @@ }, { "cell_type": "markdown", - "id": "9cf3dcf4", + "id": "c32ac330", "metadata": {}, "source": [ "# Image Decorrelation Analysis Parameters:\n", @@ -678,7 +678,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bd63a8fe", + "id": "6efd1941", "metadata": { "cellView": "form" }, @@ -739,7 +739,7 @@ }, { "cell_type": "markdown", - "id": "adb0d906", + "id": "99af2031", "metadata": {}, "source": [ "## Now let's measure the resolution of the generated SRRF image using Decorrelation analysis\n", @@ -749,7 +749,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c467203c", + "id": "e966123f", "metadata": { "cellView": "form" }, diff --git a/notebooks/NonLocalMeansDenoising.ipynb b/notebooks/NonLocalMeansDenoising.ipynb index 784ae4c5..6de29736 100644 --- a/notebooks/NonLocalMeansDenoising.ipynb +++ b/notebooks/NonLocalMeansDenoising.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "4add2b4d", + "id": "8dc1ae65", "metadata": {}, "source": [ "# NanoPyx \"Codeless\" Jupyter Notebook\n", @@ -23,7 +23,7 @@ { "cell_type": "code", "execution_count": null, - "id": "09454d17", + "id": "3d6a85bd", "metadata": { "cellView": "form" }, @@ -46,7 +46,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ffa7c053", + "id": "4f9ba1b8", "metadata": { "cellView": "form" }, @@ -104,7 +104,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8153398f", + "id": "759776aa", "metadata": { "cellView": "form" }, @@ -188,7 +188,7 @@ }, { "cell_type": "markdown", - "id": "1b5bb6d3", + "id": "39ad63d4", "metadata": {}, "source": [ "# Use Non-local means denoising on selected data\n", @@ -205,7 +205,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0888b1fe", + "id": "b02ad033", "metadata": { "cellView": "form" }, diff --git a/notebooks/ParamSweepandeSRRF.ipynb b/notebooks/ParamSweepandeSRRF.ipynb index d1ce9e02..8df4af77 100644 --- a/notebooks/ParamSweepandeSRRF.ipynb +++ b/notebooks/ParamSweepandeSRRF.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "8047889c", + "id": "1e895ab9", "metadata": {}, "source": [ "# NanoPyx \"Codeless\" Jupyter Notebook\n", @@ -28,7 +28,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a0d63f0d", + "id": "6ef0870e", "metadata": { "cellView": "form" }, @@ -51,7 +51,7 @@ { "cell_type": "code", "execution_count": null, - "id": "43026c0e", + "id": "1265318e", "metadata": { "cellView": "form" }, @@ -109,7 +109,7 @@ { "cell_type": "code", "execution_count": null, - "id": "775998a4", + "id": "976710b8", "metadata": { "cellView": "form" }, @@ -193,7 +193,7 @@ }, { "cell_type": "markdown", - "id": "74595e53", + "id": "3f123bb1", "metadata": {}, "source": [ "# Run a parameter sweep to find the best combination of parameters\n", @@ -210,7 +210,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a5f70766", + "id": "c90098f8", "metadata": { "cellView": "form" }, @@ -275,7 +275,7 @@ { "cell_type": "code", "execution_count": null, - "id": "eb09c35a", + "id": "2525bedc", "metadata": { "cellView": "form" }, @@ -308,28 +308,17 @@ " # disable button while running\n", " gui_esrrf[\"run\"].disabled = True\n", " gui_esrrf[\"run\"].description = \"Running...\"\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[\n", - " i * frames_per_timepoint : (i + 1) * frames_per_timepoint\n", - " ]\n", - " result = eSRRF(\n", - " block,\n", - " magnification=magnification,\n", - " radius=ring_radius,\n", - " sensitivity=sensitivity,\n", - " doIntensityWeighting=True,\n", - " macro_pixel_correction=mpcorrection,\n", - " )\n", - " output.append(\n", - " calculate_eSRRF_temporal_correlations(result, esrrf_order)\n", - " )\n", + " output = eSRRF(\n", + " dataset_original,\n", + " magnification=magnification,\n", + " radius=ring_radius,\n", + " sensitivity=sensitivity,\n", + " doIntensityWeighting=True,\n", + " macro_pixel_correction=mpcorrection,\n", + " frames_per_timepoint=frames_per_timepoint,\n", + " temporal_correlation=esrrf_order,\n", + " )\n", "\n", " global dataset_esrrf\n", " dataset_esrrf = np.array(output)\n", @@ -415,7 +404,7 @@ }, { "cell_type": "markdown", - "id": "54fbdd6a", + "id": "f1ab5a3b", "metadata": {}, "source": [ "## Calculate error map for the eSRRF image\n", @@ -425,7 +414,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2fd58492", + "id": "0206ceef", "metadata": { "cellView": "form" }, @@ -580,7 +569,7 @@ }, { "cell_type": "markdown", - "id": "ee07fd90", + "id": "1a1ddddb", "metadata": {}, "source": [ "## Calculate FRC resolution of the diffraction limited image\n", @@ -596,7 +585,7 @@ { "cell_type": "code", "execution_count": null, - "id": "674861a8", + "id": "63e3ab75", "metadata": { "cellView": "form" }, @@ -656,7 +645,7 @@ }, { "cell_type": "markdown", - "id": "d4b7bb70", + "id": "a7f31be2", "metadata": {}, "source": [ "## Calculate FRC resolution of the SR image\n", @@ -672,7 +661,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9e2c0164", + "id": "d55748a5", "metadata": { "cellView": "form" }, @@ -732,7 +721,7 @@ }, { "cell_type": "markdown", - "id": "765431c5", + "id": "504ba5c7", "metadata": {}, "source": [ "## Calculate Decorrelation analysis resolution of the diffraction limited image\n", @@ -749,7 +738,7 @@ { "cell_type": "code", "execution_count": null, - "id": "abc6f7eb", + "id": "533983ae", "metadata": { "cellView": "form" }, @@ -810,7 +799,7 @@ }, { "cell_type": "markdown", - "id": "4fccd529", + "id": "e562a43d", "metadata": {}, "source": [ "## Calculate Decorrelation analysis resolution of the SR image\n", @@ -827,7 +816,7 @@ { "cell_type": "code", "execution_count": null, - "id": "02da8d00", + "id": "7ff3f203", "metadata": { "cellView": "form" }, diff --git a/notebooks/SRMetrics.ipynb b/notebooks/SRMetrics.ipynb index 3736e701..e16592a3 100644 --- a/notebooks/SRMetrics.ipynb +++ b/notebooks/SRMetrics.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "97e5fd86", + "id": "2ceb6385", "metadata": {}, "source": [ "# NanoPyx \"Codeless\" Jupyter Notebook\n", @@ -26,7 +26,7 @@ { "cell_type": "code", "execution_count": null, - "id": "951d88a7", + "id": "d91c4601", "metadata": { "cellView": "form" }, @@ -49,7 +49,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f45244bb", + "id": "d304611a", "metadata": { "cellView": "form" }, @@ -106,7 +106,7 @@ }, { "cell_type": "markdown", - "id": "3fdade62", + "id": "1929eaaa", "metadata": {}, "source": [ "## Load difraction limited image (only needed if you want to use the FRC and Decorrelation analysis on this image or if you want to perform the Error Map analysis)\n", @@ -116,7 +116,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ca1e5bec", + "id": "7d643d89", "metadata": { "cellView": "form" }, @@ -200,7 +200,7 @@ }, { "cell_type": "markdown", - "id": "664ed11e", + "id": "77554c08", "metadata": {}, "source": [ "## Load super-resolved image\n", @@ -210,7 +210,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8e442e2e", + "id": "17ff8563", "metadata": { "cellView": "form" }, @@ -294,7 +294,7 @@ }, { "cell_type": "markdown", - "id": "67256b12", + "id": "e6d69951", "metadata": {}, "source": [ "## Calculate Error Map\n", @@ -304,7 +304,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9459ed67", + "id": "a3dae658", "metadata": { "cellView": "form" }, @@ -459,7 +459,7 @@ }, { "cell_type": "markdown", - "id": "43e793e6", + "id": "352c361f", "metadata": {}, "source": [ "# Calculate FRC of the diffraction limited image\n", @@ -475,7 +475,7 @@ { "cell_type": "code", "execution_count": null, - "id": "64b5bca2", + "id": "f0ce8ec6", "metadata": { "cellView": "form" }, @@ -535,7 +535,7 @@ }, { "cell_type": "markdown", - "id": "74a8584c", + "id": "541354b7", "metadata": {}, "source": [ "# Calculate FRC of the SR image\n", @@ -551,7 +551,7 @@ { "cell_type": "code", "execution_count": null, - "id": "975eed33", + "id": "b652c0ae", "metadata": { "cellView": "form" }, @@ -611,7 +611,7 @@ }, { "cell_type": "markdown", - "id": "e4344b4a", + "id": "9683af87", "metadata": {}, "source": [ "# Calculate Decorrelation analysis of diffraction limited image\n", @@ -628,7 +628,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5924d95f", + "id": "7c187366", "metadata": { "cellView": "form" }, @@ -689,7 +689,7 @@ }, { "cell_type": "markdown", - "id": "a9ff5221", + "id": "141500cc", "metadata": {}, "source": [ "# Calculate Decorrelation analysis of SR image\n", @@ -706,7 +706,7 @@ { "cell_type": "code", "execution_count": null, - "id": "fed6f580", + "id": "e2449b79", "metadata": { "cellView": "form" }, diff --git a/notebooks/SRRFandQC.ipynb b/notebooks/SRRFandQC.ipynb index e6545c90..cf3d8026 100644 --- a/notebooks/SRRFandQC.ipynb +++ b/notebooks/SRRFandQC.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "a0c4a106", + "id": "b5b962fb", "metadata": {}, "source": [ "# NanoPyx \"Codeless\" Jupyter Notebook\n", @@ -28,7 +28,7 @@ { "cell_type": "code", "execution_count": null, - "id": "378e76be", + "id": "e60b32e5", "metadata": { "cellView": "form" }, @@ -51,7 +51,7 @@ { "cell_type": "code", "execution_count": null, - "id": "093cec67", + "id": "34acafeb", "metadata": { "cellView": "form" }, @@ -109,7 +109,7 @@ { "cell_type": "code", "execution_count": null, - "id": "303b232b", + "id": "e750a416", "metadata": { "cellView": "form" }, @@ -193,7 +193,7 @@ }, { "cell_type": "markdown", - "id": "f1ad7f42", + "id": "46429ac7", "metadata": {}, "source": [ "# Use SRRF to generate a super-resolved image\n", @@ -210,7 +210,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3c82b75d", + "id": "1c8153bf", "metadata": { "cellView": "form" }, @@ -318,7 +318,7 @@ }, { "cell_type": "markdown", - "id": "08a8cd23", + "id": "1930fceb", "metadata": {}, "source": [ "## Calculate error map for the SRRF image\n", @@ -328,7 +328,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ee868b6a", + "id": "a030e7ca", "metadata": { "cellView": "form" }, @@ -483,7 +483,7 @@ }, { "cell_type": "markdown", - "id": "b83edb6a", + "id": "625616d5", "metadata": {}, "source": [ "## Calculate FRC resolution of the diffraction limited image\n", @@ -499,7 +499,7 @@ { "cell_type": "code", "execution_count": null, - "id": "267e9345", + "id": "86e99e2d", "metadata": { "cellView": "form" }, @@ -559,7 +559,7 @@ }, { "cell_type": "markdown", - "id": "d9c9df13", + "id": "53aeaae6", "metadata": {}, "source": [ "## Calculate FRC resolution of the SR image\n", @@ -575,7 +575,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f4b3a01b", + "id": "83695311", "metadata": { "cellView": "form" }, @@ -635,7 +635,7 @@ }, { "cell_type": "markdown", - "id": "d3de6597", + "id": "848ec406", "metadata": {}, "source": [ "## Calculate Decorrelation analysis resolution of the diffraction limited image\n", @@ -652,7 +652,7 @@ { "cell_type": "code", "execution_count": null, - "id": "298b3cea", + "id": "4437b7b2", "metadata": { "cellView": "form" }, @@ -713,7 +713,7 @@ }, { "cell_type": "markdown", - "id": "aba479b1", + "id": "c4b4cd75", "metadata": {}, "source": [ "## Calculate Decorrelation analysis resolution of the SR image\n", @@ -730,7 +730,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c050dbdd", + "id": "7c1af074", "metadata": { "cellView": "form" }, diff --git a/notebooks/eSRRFandQC.ipynb b/notebooks/eSRRFandQC.ipynb index 7be611a1..3f00df8e 100644 --- a/notebooks/eSRRFandQC.ipynb +++ b/notebooks/eSRRFandQC.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "8416580c", + "id": "5f1d843d", "metadata": {}, "source": [ "# NanoPyx \"Codeless\" Jupyter Notebook\n", @@ -28,7 +28,7 @@ { "cell_type": "code", "execution_count": null, - "id": "117138df", + "id": "18d54342", "metadata": { "cellView": "form" }, @@ -51,7 +51,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f8d47fc3", + "id": "cdd9b61d", "metadata": { "cellView": "form" }, @@ -109,7 +109,7 @@ { "cell_type": "code", "execution_count": null, - "id": "16c0ffe7", + "id": "89c05f1b", "metadata": { "cellView": "form" }, @@ -193,7 +193,7 @@ }, { "cell_type": "markdown", - "id": "ac124508", + "id": "18a94a49", "metadata": {}, "source": [ "# Use eSRRF to generate a super-resolved image\n", @@ -210,7 +210,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d31adb14", + "id": "322720a0", "metadata": { "cellView": "form" }, @@ -243,28 +243,17 @@ " # disable button while running\n", " gui_esrrf[\"run\"].disabled = True\n", " gui_esrrf[\"run\"].description = \"Running...\"\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[\n", - " i * frames_per_timepoint : (i + 1) * frames_per_timepoint\n", - " ]\n", - " result = eSRRF(\n", - " block,\n", - " magnification=magnification,\n", - " radius=ring_radius,\n", - " sensitivity=sensitivity,\n", - " doIntensityWeighting=True,\n", - " macro_pixel_correction=mpcorrection,\n", - " )\n", - " output.append(\n", - " calculate_eSRRF_temporal_correlations(result, esrrf_order)\n", - " )\n", + " output = eSRRF(\n", + " dataset_original,\n", + " magnification=magnification,\n", + " radius=ring_radius,\n", + " sensitivity=sensitivity,\n", + " doIntensityWeighting=True,\n", + " macro_pixel_correction=mpcorrection,\n", + " frames_per_timepoint=frames_per_timepoint,\n", + " temporal_correlation=esrrf_order,\n", + " )\n", "\n", " global dataset_esrrf\n", " dataset_esrrf = np.array(output)\n", @@ -350,7 +339,7 @@ }, { "cell_type": "markdown", - "id": "6688cee1", + "id": "b6226154", "metadata": {}, "source": [ "## Calculate error map for the eSRRF image\n", @@ -360,7 +349,7 @@ { "cell_type": "code", "execution_count": null, - "id": "654a97c7", + "id": "a93a23e6", "metadata": { "cellView": "form" }, @@ -515,7 +504,7 @@ }, { "cell_type": "markdown", - "id": "cae6921f", + "id": "bc2d28e6", "metadata": {}, "source": [ "## Calculate FRC resolution of the diffraction limited image\n", @@ -531,7 +520,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f767f72e", + "id": "7b737a13", "metadata": { "cellView": "form" }, @@ -591,7 +580,7 @@ }, { "cell_type": "markdown", - "id": "b277a488", + "id": "e97787d3", "metadata": {}, "source": [ "## Calculate FRC resolution of the SR image\n", @@ -607,7 +596,7 @@ { "cell_type": "code", "execution_count": null, - "id": "60ed9d03", + "id": "ad9d9488", "metadata": { "cellView": "form" }, @@ -667,7 +656,7 @@ }, { "cell_type": "markdown", - "id": "e69fce14", + "id": "b30ffccc", "metadata": {}, "source": [ "## Calculate Decorrelation analysis resolution of the diffraction limited image\n", @@ -684,7 +673,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5a627d33", + "id": "ef3bf607", "metadata": { "cellView": "form" }, @@ -745,7 +734,7 @@ }, { "cell_type": "markdown", - "id": "b63fc518", + "id": "629b67d0", "metadata": {}, "source": [ "## Calculate Decorrelation analysis resolution of the SR image\n", @@ -762,7 +751,7 @@ { "cell_type": "code", "execution_count": null, - "id": "adfb20e3", + "id": "d667d440", "metadata": { "cellView": "form" }, diff --git a/setup.py b/setup.py index 442af95e..41ee8237 100644 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ ] EXTRA_LING_ARGS = [] -VERSION = "1.2.2" # sets version number for whole package +VERSION = "1.2.3" # sets version number for whole package def run_command(command: str) -> str: diff --git a/src/mako_templates/nanopyx.core.transform._le_esrrf.pyx b/src/mako_templates/nanopyx.core.transform._le_esrrf.pyx index ea8afd15..1fc91a8c 100644 --- a/src/mako_templates/nanopyx.core.transform._le_esrrf.pyx +++ b/src/mako_templates/nanopyx.core.transform._le_esrrf.pyx @@ -29,15 +29,15 @@ class eSRRF(LiquidEngine): self._designation = "eSRRF_ST" super().__init__(clear_benchmarks=clear_benchmarks, testing=testing, verbose=verbose) - def run(self, image, magnification: int = 5, grad_magnification: int = 1, radius: float = 1.5, sensitivity: float = 1, doIntensityWeighting: bool = True, run_type=None): + def run(self, image, magnification: int = 5, grad_magnification: int = 2, radius: float = 1.5, sensitivity: float = 1, doIntensityWeighting: bool = True, run_type=None): image = check_image(image) return self._run(image, magnification=magnification, grad_magnification=grad_magnification, radius=radius, sensitivity=sensitivity, doIntensityWeighting=doIntensityWeighting, run_type=run_type) - def benchmark(self, image, magnification: int = 5, grad_magnification: int = 1, radius: float = 1.5, sensitivity: float = 1, doIntensityWeighting: bool = True): + def benchmark(self, image, magnification: int = 5, grad_magnification: int = 2, radius: float = 1.5, sensitivity: float = 1, doIntensityWeighting: bool = True): image = check_image(image) return super().benchmark(image, magnification=magnification, grad_magnification=grad_magnification, radius=radius, sensitivity=sensitivity, doIntensityWeighting=doIntensityWeighting) - def _run_opencl(self, image, magnification=5, grad_magnification=1, radius=1.5, sensitivity=1, doIntensityWeighting=True, device=None, mem_div=1): + def _run_opencl(self, image, magnification=5, grad_magnification=2, radius=1.5, sensitivity=1, doIntensityWeighting=True, device=None, mem_div=1): """ @gpu """ @@ -70,8 +70,8 @@ class eSRRF(LiquidEngine): input_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(image[0:max_slices, :, :].nbytes, dc, max_slices)) output_cl = cl.Buffer(cl_ctx, mf.WRITE_ONLY, self._check_max_buffer_size(np.empty((max_slices, output_shape[1], output_shape[2]), dtype=np.float32).nbytes, dc, max_slices)) magnified_cl = cl.Buffer(cl_ctx, mf.READ_WRITE, self._check_max_buffer_size(np.empty((max_slices, output_shape[1], output_shape[2]), dtype=np.float32).nbytes, dc, max_slices)) - col_kernel_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(np.empty((2,2)).nbytes, dc, max_slices)) - row_kernel_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(np.empty((2,2)).nbytes, dc, max_slices)) + col_kernel_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(np.empty_like(kernely).nbytes, dc, max_slices)) + row_kernel_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(np.empty_like(kernelx).nbytes, dc, max_slices)) cl.enqueue_copy(cl_queue, col_kernel_cl, kernely).wait() cl.enqueue_copy(cl_queue, row_kernel_cl, kernelx).wait() col_gradients_cl = cl.Buffer(cl_ctx, mf.READ_WRITE, self._check_max_buffer_size(np.empty((max_slices, image.shape[1], image.shape[2]), dtype=np.float32).nbytes, dc, max_slices)) @@ -181,7 +181,7 @@ class eSRRF(LiquidEngine): return output_image % for sch in schedulers: - def _run_${sch}(self, image, magnification=5, grad_magnification=1, radius=1.5, sensitivity=1, doIntensityWeighting=True): + def _run_${sch}(self, image, magnification=5, grad_magnification=2, radius=1.5, sensitivity=1, doIntensityWeighting=True): """ @cpu @threaded diff --git a/src/nanopyx/core/transform/_le_esrrf.pyx b/src/nanopyx/core/transform/_le_esrrf.pyx index 20e92b38..ec511196 100644 --- a/src/nanopyx/core/transform/_le_esrrf.pyx +++ b/src/nanopyx/core/transform/_le_esrrf.pyx @@ -27,15 +27,15 @@ class eSRRF(LiquidEngine): self._designation = "eSRRF_ST" super().__init__(clear_benchmarks=clear_benchmarks, testing=testing, verbose=verbose) - def run(self, image, magnification: int = 5, grad_magnification: int = 1, radius: float = 1.5, sensitivity: float = 1, doIntensityWeighting: bool = True, run_type=None): + def run(self, image, magnification: int = 5, grad_magnification: int = 2, radius: float = 1.5, sensitivity: float = 1, doIntensityWeighting: bool = True, run_type=None): image = check_image(image) return self._run(image, magnification=magnification, grad_magnification=grad_magnification, radius=radius, sensitivity=sensitivity, doIntensityWeighting=doIntensityWeighting, run_type=run_type) - def benchmark(self, image, magnification: int = 5, grad_magnification: int = 1, radius: float = 1.5, sensitivity: float = 1, doIntensityWeighting: bool = True): + def benchmark(self, image, magnification: int = 5, grad_magnification: int = 2, radius: float = 1.5, sensitivity: float = 1, doIntensityWeighting: bool = True): image = check_image(image) return super().benchmark(image, magnification=magnification, grad_magnification=grad_magnification, radius=radius, sensitivity=sensitivity, doIntensityWeighting=doIntensityWeighting) - def _run_opencl(self, image, magnification=5, grad_magnification=1, radius=1.5, sensitivity=1, doIntensityWeighting=True, device=None, mem_div=1): + def _run_opencl(self, image, magnification=5, grad_magnification=2, radius=1.5, sensitivity=1, doIntensityWeighting=True, device=None, mem_div=1): """ @gpu """ @@ -68,8 +68,8 @@ class eSRRF(LiquidEngine): input_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(image[0:max_slices, :, :].nbytes, dc, max_slices)) output_cl = cl.Buffer(cl_ctx, mf.WRITE_ONLY, self._check_max_buffer_size(np.empty((max_slices, output_shape[1], output_shape[2]), dtype=np.float32).nbytes, dc, max_slices)) magnified_cl = cl.Buffer(cl_ctx, mf.READ_WRITE, self._check_max_buffer_size(np.empty((max_slices, output_shape[1], output_shape[2]), dtype=np.float32).nbytes, dc, max_slices)) - col_kernel_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(np.empty((2,2)).nbytes, dc, max_slices)) - row_kernel_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(np.empty((2,2)).nbytes, dc, max_slices)) + col_kernel_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(np.empty_like(kernely).nbytes, dc, max_slices)) + row_kernel_cl = cl.Buffer(cl_ctx, mf.READ_ONLY, self._check_max_buffer_size(np.empty_like(kernelx).nbytes, dc, max_slices)) cl.enqueue_copy(cl_queue, col_kernel_cl, kernely).wait() cl.enqueue_copy(cl_queue, row_kernel_cl, kernelx).wait() col_gradients_cl = cl.Buffer(cl_ctx, mf.READ_WRITE, self._check_max_buffer_size(np.empty((max_slices, image.shape[1], image.shape[2]), dtype=np.float32).nbytes, dc, max_slices)) @@ -178,7 +178,7 @@ class eSRRF(LiquidEngine): return output_image - def _run_threaded(self, image, magnification=5, grad_magnification=1, radius=1.5, sensitivity=1, doIntensityWeighting=True): + def _run_threaded(self, image, magnification=5, grad_magnification=2, radius=1.5, sensitivity=1, doIntensityWeighting=True): """ @cpu @threaded @@ -200,7 +200,7 @@ class eSRRF(LiquidEngine): radial_gradients = rgc.run(gradient_col_interp, gradient_row_interp, magnified_image, magnification=magnification, grad_magnification=grad_magnification, radius=radius, sensitivity=sensitivity, doIntensityWeighting=doIntensityWeighting, offset=0, xyoffset=-0.5, angle=np.pi/4, run_type=runtype) return radial_gradients - def _run_threaded_guided(self, image, magnification=5, grad_magnification=1, radius=1.5, sensitivity=1, doIntensityWeighting=True): + def _run_threaded_guided(self, image, magnification=5, grad_magnification=2, radius=1.5, sensitivity=1, doIntensityWeighting=True): """ @cpu @threaded @@ -222,7 +222,7 @@ class eSRRF(LiquidEngine): radial_gradients = rgc.run(gradient_col_interp, gradient_row_interp, magnified_image, magnification=magnification, grad_magnification=grad_magnification, radius=radius, sensitivity=sensitivity, doIntensityWeighting=doIntensityWeighting, offset=0, xyoffset=-0.5, angle=np.pi/4, run_type=runtype) return radial_gradients - def _run_threaded_dynamic(self, image, magnification=5, grad_magnification=1, radius=1.5, sensitivity=1, doIntensityWeighting=True): + def _run_threaded_dynamic(self, image, magnification=5, grad_magnification=2, radius=1.5, sensitivity=1, doIntensityWeighting=True): """ @cpu @threaded @@ -244,7 +244,7 @@ class eSRRF(LiquidEngine): radial_gradients = rgc.run(gradient_col_interp, gradient_row_interp, magnified_image, magnification=magnification, grad_magnification=grad_magnification, radius=radius, sensitivity=sensitivity, doIntensityWeighting=doIntensityWeighting, offset=0, xyoffset=-0.5, angle=np.pi/4, run_type=runtype) return radial_gradients - def _run_threaded_static(self, image, magnification=5, grad_magnification=1, radius=1.5, sensitivity=1, doIntensityWeighting=True): + def _run_threaded_static(self, image, magnification=5, grad_magnification=2, radius=1.5, sensitivity=1, doIntensityWeighting=True): """ @cpu @threaded diff --git a/src/nanopyx/methods/esrrf/eSRRF_workflow.py b/src/nanopyx/methods/esrrf/eSRRF_workflow.py index 01ae33e8..51de6986 100644 --- a/src/nanopyx/methods/esrrf/eSRRF_workflow.py +++ b/src/nanopyx/methods/esrrf/eSRRF_workflow.py @@ -1,6 +1,9 @@ from ..workflow import Workflow from ...core.transform import eSRRF_ST from ...core.transform.mpcorrector import macro_pixel_corrector +from ...core.transform.sr_temporal_correlations import ( + calculate_eSRRF_temporal_correlations, +) import numpy as np # TODO check correlations and error map @@ -9,9 +12,11 @@ def eSRRF( image, magnification: int = 5, - grad_magnification: int = 1, + grad_magnification: int = 2, radius: float = 1.5, sensitivity: float = 1, + frames_per_timepoint: int = 0, + temporal_correlation: str = "AVG", doIntensityWeighting: bool = True, macro_pixel_correction: bool = True, _force_run_type=None, @@ -24,6 +29,8 @@ def eSRRF( magnification (int, optional): Magnification factor (default is 5). radius (float, optional): Radius parameter for eSRRF analysis (default is 1.5). sensitivity (float, optional): Sensitivity parameter for eSRRF analysis (default is 1). + frames_per_timepoint (int, optional): Number of frames per timepoint (default is 0, which means all frames are used). + temporal_correlation (str, optional): Type of temporal correlation to calculate. Options are: AVG, VAR or TAC2 (default is "AVG"). doIntensityWeighting (bool, optional): Enable intensity weighting (default is True). macro_pixel_correction (bool, optional): Enable macro pixel correction (default is True). _force_run_type (str, optional): Force a specific run type for the analysis (default is None). @@ -45,23 +52,66 @@ def eSRRF( - Workflow: The class used to define and run analysis workflows. """ - _eSRRF = Workflow( + if frames_per_timepoint == 0: + frames_per_timepoint = image.shape[0] + elif frames_per_timepoint > image.shape[0]: + frames_per_timepoint = image.shape[0] + + number_of_timepoints = image.shape[0] // frames_per_timepoint + if image.shape[0] % frames_per_timepoint != 0: + number_of_timepoints += 1 + + output_array = np.zeros( ( - eSRRF_ST(verbose=False), - (image,), - { - "magnification": magnification, - "grad_magnification": grad_magnification, - "radius": radius, - "sensitivity": sensitivity, - "doIntensityWeighting": doIntensityWeighting, - }, - ) + number_of_timepoints, + image.shape[1] * magnification, + image.shape[2] * magnification, + ), + dtype=np.float32, ) - if macro_pixel_correction: - return macro_pixel_corrector( - np.asarray(_eSRRF.calculate(_force_run_type=_force_run_type)[0]), - magnification=magnification, + + for i in range(number_of_timepoints): + + _eSRRF = Workflow( + ( + eSRRF_ST(verbose=False), + ( + image[ + frames_per_timepoint + * i : frames_per_timepoint + * (i + 1) + ], + ), + { + "magnification": magnification, + "grad_magnification": grad_magnification, + "radius": radius, + "sensitivity": sensitivity, + "doIntensityWeighting": doIntensityWeighting, + }, + ) ) - else: - return np.asarray(_eSRRF.calculate(_force_run_type=_force_run_type)[0]) + if macro_pixel_correction: + output_array[i] = macro_pixel_corrector( + np.expand_dims( + np.asarray( + calculate_eSRRF_temporal_correlations( + _eSRRF.calculate(_force_run_type=_force_run_type)[ + 0 + ], + temporal_correlation, + ) + ), + axis=0, + ), + magnification=magnification, + ) + else: + output_array[i] = np.asarray( + calculate_eSRRF_temporal_correlations( + _eSRRF.calculate(_force_run_type=_force_run_type)[0], + temporal_correlation, + ) + ) + + return np.squeeze(output_array.astype(np.float32)) diff --git a/src/notebookchef/pantry/methods/esrrf.py b/src/notebookchef/pantry/methods/esrrf.py index 76ead076..8f3cceba 100644 --- a/src/notebookchef/pantry/methods/esrrf.py +++ b/src/notebookchef/pantry/methods/esrrf.py @@ -25,28 +25,17 @@ def run_esrrf(b): # disable button while running gui_esrrf["run"].disabled = True gui_esrrf["run"].description = "Running..." - if frames_per_timepoint == 0: - frames_per_timepoint = dataset_original.shape[0] - elif frames_per_timepoint > dataset_original.shape[0]: - frames_per_timepoint = dataset_original.shape[0] - output = [] - - for i in range(dataset_original.shape[0] // frames_per_timepoint): - block = dataset_original[ - i * frames_per_timepoint : (i + 1) * frames_per_timepoint - ] - result = eSRRF( - block, - magnification=magnification, - radius=ring_radius, - sensitivity=sensitivity, - doIntensityWeighting=True, - macro_pixel_correction=mpcorrection, - ) - output.append( - calculate_eSRRF_temporal_correlations(result, esrrf_order) - ) + output = eSRRF( + dataset_original, + magnification=magnification, + radius=ring_radius, + sensitivity=sensitivity, + doIntensityWeighting=True, + macro_pixel_correction=mpcorrection, + frames_per_timepoint=frames_per_timepoint, + temporal_correlation=esrrf_order, + ) global dataset_esrrf dataset_esrrf = np.array(output)