Skip to content

Commit

Permalink
update stereology analysis template
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoalopez committed May 17, 2024
1 parent cbaefd9 commit 086d7ff
Showing 1 changed file with 54 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -58,7 +56,7 @@
"id": "85ec740e",
"metadata": {},
"source": [
"## Load the data"
"## Data reading"
]
},
{
Expand All @@ -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')"
]
},
Expand Down Expand Up @@ -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",
Expand All @@ -320,9 +318,7 @@
"id": "c847e718-36c1-46f0-bf6b-7881dcb6b86e",
"metadata": {},
"source": [
"# Using the Saltykov method\n",
"\n",
"TODO"
"# Saltykov method"
]
},
{
Expand All @@ -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"
]
},
{
Expand All @@ -363,7 +357,7 @@
"id": "458148cc-b7c4-431b-8006-27a11d0a544a",
"metadata": {},
"source": [
"## Using the two-step method"
"## The two-step method"
]
},
{
Expand Down Expand Up @@ -396,97 +390,99 @@
}
],
"source": [
"_ = stereology.calc_shape(dataset['diameters'])"
"_ = stereology.two_step(dataset['diameters'])"
]
},
{
"cell_type": "markdown",
"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"
]
},
{
"cell_type": "code",
"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": [
{
"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"
]
}
],
Expand Down Expand Up @@ -517,7 +513,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 086d7ff

Please sign in to comment.