Skip to content

Commit

Permalink
incremental updates v3
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoalopez committed Apr 6, 2020
1 parent 7278c73 commit 4991e0c
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 23 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,8 @@ pip-log.txt
*.ai
twoStep_output.csv
Saltykov_output.csv

#############
## Notebook checkpoints
#############
.ipynb_checkpoints
2 changes: 1 addition & 1 deletion DOCS/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ dataset.head()

![](https://github.com/marcoalopez/GrainSizeTools/blob/master/FIGURES/dataframe_diameters.png?raw=true)

> 👉 Note that we define the square root and pi as ``np.sqrt`` and ``np.pi``. In this case, ``np.`` stems for numerical Python, a basic package for scientific computing with Python, and the word after the dot the method or scientific variables to be applied. If you write in the console ``np.`` and then press press the TAB key, you will see a huge list of methods available. In general, the name of the methods used are equivalent to those used in MATLAB but always adding the ``np.`` first.
> 👉 Note that we define the square root and pi as ``np.sqrt`` and ``np.pi``. In this case, ``np.`` stems for Numpy or numerical Python, a basic package for scientific computing with Python, and the word after the dot the method or scientific variables to be applied. If you write in the console ``np.`` and then press press the TAB key, you will see a huge list of methods available. In general, the name of the methods used are equivalent to those used in MATLAB but always adding the ``np.`` first.


Expand Down
Binary file modified FIGURES/Jupyter_lab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 23 additions & 19 deletions grain_size_tools/GrainSizeTools_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,39 +134,47 @@ def summarize(data, avg=('amean', 'gmean', 'median', 'mode'), ci_level=0.95,
"""

# check and remove for negative values
if data[data < 0].size > 0:
if data[data <= 0].size > 0:
print('Warning: I found negative and/or zero values in your dataset!')
data = data[data > 0]
print('Negative/zero values automatically removed')
print('')

std = np.std(data)

# estimate Shapiro-Wilk test to check normality and lognormality
W, p_value = shapiro(data)
W2, p_value2 = shapiro(np.log(data))

if 'amean' in avg:
amean, __, ci, length = averages.amean(data, ci_level, method='ASTM')
if len(data) > 99:
__, __, (low_ci, high_ci), length2 = averages.amean(data, ci_level, method='mCox')
if p_value2 < 0.05:
amean, __, ci, length = averages.amean(data, ci_level, method='ASTM')
else:
__, __, (low_ci, high_ci), length2 = averages.amean(data, ci_level, method='GCI')
if len(data) > 99:
amean, __, (low_ci, high_ci), length2 = averages.amean(data, ci_level, method='mCox')
else:
amean, __, (low_ci, high_ci), length2 = averages.amean(data, ci_level, method='GCI')

# estimate coefficients of variation
lower_cvar = 100 * (amean - low_ci) / amean
upper_cvar = 100 * (high_ci - amean) / amean
# estimate coefficients of variation
lower_cvar = 100 * (amean - low_ci) / amean
upper_cvar = 100 * (high_ci - amean) / amean

print(' ')
print('============================================================================')
print('CENTRAL TENDENCY ESTIMATORS')
print('============================================================================')
print('Arithmetic mean = {:0.2f} microns' .format(amean))
print('Confidence intervals at {:0.1f} %' .format(ci_level * 100))
print('ASTM method: {:0.2f} - {:0.2f}, (±{:0.1f}%), length = {:0.3f}'
.format(ci[0], ci[1], 100 * (ci[1] - amean) / amean, length))
if len(data) > 99:
print('mCox method: {:0.2f} - {:0.2f} (-{:0.1f}%, +{:0.1f}%), length = {:0.3f}'
.format(low_ci, high_ci, lower_cvar, upper_cvar, length2))
if p_value2 < 0.05:
print('ASTM method: {:0.2f} - {:0.2f}, (±{:0.1f}%), length = {:0.3f}'
.format(ci[0], ci[1], 100 * (ci[1] - amean) / amean, length))
else:
print('GCI method: {:0.2f} - {:0.2f} (-{:0.1f}%, +{:0.1f}%), length = {:0.3f}'
.format(low_ci, high_ci, lower_cvar, upper_cvar, length2))
if len(data) > 99:
print('mCox method: {:0.2f} - {:0.2f} (-{:0.1f}%, +{:0.1f}%), length = {:0.3f}'
.format(low_ci, high_ci, lower_cvar, upper_cvar, length2))
else:
print('GCI method: {:0.2f} - {:0.2f} (-{:0.1f}%, +{:0.1f}%), length = {:0.3f}'
.format(low_ci, high_ci, lower_cvar, upper_cvar, length2))

if 'gmean' in avg:
m = 'CLT' if len(data) > 99 else 'bayes' # choose optimal method to estimate confidence intervals
Expand Down Expand Up @@ -207,10 +215,6 @@ def summarize(data, avg=('amean', 'gmean', 'median', 'mode'), ci_level=0.95,
else:
print('KDE bandwidth =', bandwidth)

# estimate Shapiro-Wilk test to check normality and lognormality
W, p_value = shapiro(data)
W2, p_value2 = shapiro(np.log(data))

print(' ')
print('============================================================================')
print('DISTRIBUTION FEATURES')
Expand Down
4 changes: 1 addition & 3 deletions grain_size_tools/notebook_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,6 @@
"============================================================================\n",
"Arithmetic mean = 22.13 microns\n",
"Confidence intervals at 95.0 %\n",
"ASTM method: 21.33 - 22.93, (±3.6%), length = 1.596\n",
"mCox method: 21.35 - 22.98 (-3.5%, +3.8%), length = 1.623\n",
"============================================================================\n",
"Geometric mean = 20.44 microns\n",
Expand Down Expand Up @@ -892,7 +891,6 @@
"Arithmetic mean = 34.79 microns\n",
"Confidence intervals at 95.0 %\n",
"ASTM method: 34.09 - 35.48, (±2.0%), length = 1.393\n",
"mCox method: 34.43 - 36.04 (-1.0%, +3.6%), length = 1.616\n",
"============================================================================\n",
"Geometric mean = 30.10 microns\n",
"Confidence interval at 95.0 %\n",
Expand Down Expand Up @@ -1033,7 +1031,7 @@
"output_type": "stream",
"text": [
"=======================================\n",
"Normalized SD = 0.16\n",
"Normalized SD = 0.165\n",
"KDE bandwidth = 0.04\n",
"=======================================\n"
]
Expand Down

0 comments on commit 4991e0c

Please sign in to comment.