From 086d7ff2bab58506e00b2e282434632df59d9321 Mon Sep 17 00:00:00 2001 From: "Marco A. Lopez-Sanchez" Date: Fri, 17 May 2024 16:33:42 +0200 Subject: [PATCH] update stereology analysis template --- ...ynb => stereology_analysis_template.ipynb} | 112 +++++++++--------- 1 file changed, 54 insertions(+), 58 deletions(-) rename grain_size_tools/{stereology_analysis.ipynb => stereology_analysis_template.ipynb} (98%) diff --git a/grain_size_tools/stereology_analysis.ipynb b/grain_size_tools/stereology_analysis_template.ipynb similarity index 98% rename from grain_size_tools/stereology_analysis.ipynb rename to grain_size_tools/stereology_analysis_template.ipynb index 486be40..2a7bc34 100644 --- a/grain_size_tools/stereology_analysis.ipynb +++ b/grain_size_tools/stereology_analysis_template.ipynb @@ -7,8 +7,6 @@ "source": [ "# Stereology Analysis Template\n", "\n", - "Last update: 2024-05-14\n", - "\n", "> **INFO** \n", "> This is the template for using the stereology module. The specific documentation can be found at the following link: \n", "> https://github.com/marcoalopez/GrainSizeTools/wiki/3.-Using-the-stereology-module \n", @@ -58,7 +56,7 @@ "id": "85ec740e", "metadata": {}, "source": [ - "## Load the data" + "## Data reading" ] }, { @@ -68,7 +66,7 @@ "metadata": {}, "outputs": [], "source": [ - "# specify your file(s) to be analysed here\n", + "# specify the file(s) to be analysed here\n", "dataset = pd.read_csv('DATA\\data_set.txt', sep='\\t')" ] }, @@ -308,7 +306,7 @@ } ], "source": [ - "# estimate Equivalent Circular Diameters based on areas\n", + "# estimate Equivalent Circular Diameters based on areas (if neccesary)\n", "dataset['diameters'] = 2 * np.sqrt(dataset['Area'] / np.pi)\n", "\n", "# display a view of the dataset \n", @@ -320,9 +318,7 @@ "id": "c847e718-36c1-46f0-bf6b-7881dcb6b86e", "metadata": {}, "source": [ - "# Using the Saltykov method\n", - "\n", - "TODO" + "# Saltykov method" ] }, { @@ -335,12 +331,10 @@ "name": "stdout", "output_type": "stream", "text": [ - "=======================================\n", + "=================================================\n", "volume fraction (up to 50 microns) = 41.65 %\n", - "=======================================\n", - "=======================================\n", - "bin size = 14.24\n", - "=======================================\n" + "=================================================\n", + "bin size = 14.24\n" ] }, { @@ -363,7 +357,7 @@ "id": "458148cc-b7c4-431b-8006-27a11d0a544a", "metadata": {}, "source": [ - "## Using the two-step method" + "## The two-step method" ] }, { @@ -396,7 +390,7 @@ } ], "source": [ - "_ = stereology.calc_shape(dataset['diameters'])" + "_ = stereology.two_step(dataset['diameters'])" ] }, { @@ -404,9 +398,7 @@ "id": "473f283f", "metadata": {}, "source": [ - "### Estimate volume fractions from a lognormal distribution\n", - "\n", - "#### Generate a lognormal distribution using the calculated optimal values" + "## Estimation of volume fractions from a calculated lognormal distribution" ] }, { @@ -414,70 +406,74 @@ "execution_count": 6, "id": "effea92e", "metadata": {}, - "outputs": [], - "source": [ - "# import lognorm from Scipy\n", - "from scipy.stats import lognorm\n", - "\n", - "# set calculated variables\n", - "geo_mean = 36.05\n", - "sigma = np.log(1.63)\n", - "\n", - "# Calculate the lognormal distribution\n", - "dist = lognorm(s=sigma, scale=geo_mean)" - ] - }, - { - "cell_type": "markdown", - "id": "5dba15b3", - "metadata": {}, - "source": [ - "#### Examples of volume fractions representing a particular range of grain sizes using the cumulative distribution function (CDF) of the lognormal distribution" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "c6f5648c", - "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Volume fraction of grains below 50 microns: 74.8 %\n" + "Volume fraction occupied by grains between 0 and 50 microns: 22.7 %\n" ] + }, + { + "data": { + "text/plain": [ + "0.22693747883065515" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "# Calculate the CDF value at 50 microns in percentage\n", - "volume_fraction_below_50 = dist.cdf(50)\n", - "print(f\"Volume fraction of grains below 50 microns: {100 * volume_fraction_below_50:.1f} %\")" + "# lognormal parameters\n", + "geomean = 36.05\n", + "std = np.log(1.63)\n", + "\n", + "# set min and max grain size in the population\n", + "min_size = 0\n", + "max_size = dataset['diameters'].max()\n", + "\n", + "\n", + "# get the volume fraction of a specific grain size\n", + "stereology.calc_volume_fraction(lognorm_params=(geomean, std),\n", + " total_size_range=(min_size, max_size),\n", + " interest_size_range=(0, 50))" ] }, { "cell_type": "code", - "execution_count": 8, - "id": "bdf1a171", + "execution_count": 7, + "id": "3b2d4bec", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Volume fraction of grains between 15 and 35 microns: 0.44\n" + "Volume fraction occupied by grains between 10 and 80 microns: 60.3 %\n" ] + }, + { + "data": { + "text/plain": [ + "0.6030751209186476" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ - "# Calculate the volume fraction between 15 and 35 microns \n", - "volume_fraction_15_to_35 = dist.cdf(35) - dist.cdf(15)\n", - "print(f\"Volume fraction of grains between 15 and 35 microns: {volume_fraction_15_to_35:.2f}\")" + "stereology.calc_volume_fraction(lognorm_params=(geomean, std),\n", + " total_size_range=(min_size, max_size),\n", + " interest_size_range=(10, 80))" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "id": "38f0bf26", "metadata": {}, "outputs": [ @@ -485,8 +481,8 @@ "name": "stdout", "output_type": "stream", "text": [ - "Notebook last run in 2024-05-14 using:\n", - "Python 3.11.5 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:16:22) [MSC v.1916 64 bit (AMD64)]\n" + "Notebook last run in 2024-05-17 using:\n", + "Python 3.10.13 | packaged by Anaconda, Inc. | (main, Sep 11 2023, 13:24:38) [MSC v.1916 64 bit (AMD64)]\n" ] } ], @@ -517,7 +513,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.5" + "version": "3.10.13" } }, "nbformat": 4,