Commit c6037f4b authored by Martinez-Carvajal German's avatar Martinez-Carvajal German
Browse files

I am deleting this script beacuse we are not

using the erosion_dilation method for pore
size distribution (PSD) anymore
parent bd682414
def create_pSD_graph(Folder, File, Res):
""" Creates the pore size distribution graph from raddi and cum_volumes,
inputs: Radii (in pix) and cumulated volums (in pix) are the outputs of the erosion-dilation
computation of the pore size distribution using the program PoreSizeDistriution_(ErosionDiltation)_Jython.py
input res = resolution in mm/vox """
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from os import chdir
# Importing data
global Data
Data = pd.read_csv(File, sep = ';')
# Radii
Radii_vox = Data["Radius (vox)"]
Radii_vox = np.array(Radii_vox)
Diameters_mm = Radii_vox*2*Res # in mm
# Cumulated Volume distribution (in voxels)
Cum_Volumes_vox = Data["Cumul Volume (vox)"]
Cum_Volumes_vox = np.array(Cum_Volumes_vox)
# Adding a little detail for the cumulative distributions
# The curve must show fractio = 0 for void sizes < than Res
Diameters_mm = np.insert(Diameters_mm ,1,Diameters_mm[1])
Cum_Volumes_vox= np.insert(Cum_Volumes_vox,1,0)
# Total Volume (in voxels)
Volume_Total_vox= np.max(Cum_Volumes_vox)
# Cumulated Volume distribution (in cm3)
Cum_Volumes_cm3 = Cum_Volumes_vox*(Res)**3*(1/1000)
# Total Volume (in cm3)
Volume_Total_cm3 = np.max(Cum_Volumes_cm3)
# Cummulated Volume Fractions
Cum_Volume_Fractions = Cum_Volumes_vox/Volume_Total_vox
# Computing volume distribution back from the cummulated distribution
# in voxels
Volumes_vox = [ Cum_Volumes_vox[i]-Cum_Volumes_vox[i-1] for i in range (1,len(Cum_Volumes_vox)) ]
Volumes_vox = np.concatenate (([0],Volumes_vox))
# checking
print(np.sum(Volumes_vox),Volume_Total_vox)
check = np.sum(Volumes_vox) == Volume_Total_vox
assert check
# in cm3
Volumes_cm3 = Volumes_vox*(Res)**3*(1/1000)
#checking
print(np.sum(Volumes_cm3),Volume_Total_cm3)
check = abs(np.sum(Volumes_cm3) - Volume_Total_cm3) < 0.0001**3
assert check
# in volume fraction
Volume_Fractions = np.array(Volumes_vox/Volume_Total_vox)
# Plotting void size distributions in volume fractions (Format : paper)
plt.close('all')
global fig
fig = plt.figure(1)
fig.set_size_inches(9, 7)
ax1 = fig.add_subplot(111)
ax1.bar(Diameters_mm, Volume_Fractions,
color= "gray",
label = "Fraction " ,
width = 0.06 )
ax2 = ax1.twinx()
ax2.plot(Diameters_mm, Cum_Volume_Fractions,
color= "k",
lw=1,
label = "Cummulative Fraction",
linestyle = '-' )
ax1.legend(loc = 'upper left' , bbox_to_anchor =(0.0, 1.1))
ax2.legend(loc = 'upper right' , bbox_to_anchor =(1.0, 1.1))
ax1.set_xlabel('Diameter (mm)' )
ax1.set_ylabel("Fraction (% v/v)")
ax2.set_ylabel("Cumumative Fraction (% v/v)")
ax1.set_xlim(0)
ax1.set_ylim(0)
ax2.set_ylim(0,1)
# Saving figure
chdir(Folder)
title = "Pore_Size_Distribution_ErosionDilation_in_vol_fraction"
fig.savefig(title +'.png', dpi = 300)
# Plotting void size distributions in volume fractions (Format : paper)
fig = plt.figure(2)
fig.set_size_inches(9, 7)
ax1 = fig.add_subplot(111)
ax1.bar(Diameters_mm, Volumes_cm3,
color= "gray",
label = "Volume " ,
width = 0.06 )
ax2 = ax1.twinx()
ax2.plot(Diameters_mm, Cum_Volumes_cm3,
color= "k",
lw=1,
label = "Cummulative Volume",
linestyle = '-' )
ax1.legend(loc = 'upper left' , bbox_to_anchor =(0.0, 1.1))
ax2.legend(loc = 'upper right' , bbox_to_anchor =(1.0, 1.1))
ax1.set_xlabel('Diameter (mm)' )
ax1.set_ylabel("Volume (cm3)")
ax2.set_ylabel("Cumumative Volume (cm3)")
ax1.set_xlim(0)
ax1.set_ylim(0)
ax2.set_ylim(0)
# Saving figure
chdir(Folder)
title = "Pore_Size_Distribution_ErosionDilation_in_volumes"
fig.savefig(title +'.png', dpi = 300)
# Saving data
global Result
Result = pd.DataFrame({'Diameter(mm)':Diameters_mm})
Result['Vol_cm3'] = Volumes_cm3
Result['Vol_Frac'] = Volume_Fractions
Result['Vol_Cum_cm3'] = Cum_Volumes_cm3
Result['Vol_Cum_Frac'] = Cum_Volume_Fractions
Result.to_csv('Pore_size_distribution.csv', sep = ';')
print('Finished!')
# MAIN
# Calling the function for a second example
Folder = "/home/german.martinez-carvajal/Desktop/2018/Pore_Size_Distribution/COP01/Normal_Resolution_35MIC"
File = Folder + '/Cumul_distribution.csv'
Res = 0.035 # mm/vox
create_pSD_graph(Folder, File, Res)
# Calling the function for a first example
Folder = "/home/german.martinez-carvajal/Desktop/2018/Pore_Size_Distribution/COP01/Low_Resolution_70MIC"
File = Folder + '/Cumul_distribution_Jython.csv'
Res = 0.070 # mm/vox
create_pSD_graph(Folder, File, Res)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment