Skip to content

Commit 5052176

Browse files
committed
Compostion and phase fraction calculations added
1 parent 44a81ff commit 5052176

File tree

6 files changed

+430
-156
lines changed

6 files changed

+430
-156
lines changed

compositionspace/datautils.py

+6
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ def get_big_slices(self):
274274
filestring = os.path.join(prefix, filestring)
275275
filestrings.append(filestring)
276276

277+
#pbar = tqdm(os.listdir(self.params["input_path"]), desc="Reading files")##
278+
#for filename in pbar:
277279
hdf = h5py.File(filestring, "w")
278280
group1 = hdf.create_group("group_xyz_Da_spec")
279281
group1.attrs["columns"] = ["x","y","z","Da","spec"]
@@ -503,11 +505,14 @@ def calculate_voxel_composition(self, fileindex=0, outfilename="output_vox_ratio
503505
dic_ratios = {}
504506
for spec_name in spec_names:
505507
dic_ratios["{}".format(spec_name)] = []
508+
for spec_name in spec_names:
509+
dic_ratios["{}_atoms".format(spec_name)] = []
506510

507511
dic_ratios["Total_no"]=[]
508512
dic_ratios["file_name"]=[]
509513
dic_ratios["vox"] = []
510514

515+
511516
ratios = []
512517
f_count = 0
513518
pbar = tqdm(files, desc="Calculating voxel composition")
@@ -519,6 +524,7 @@ def calculate_voxel_composition(self, fileindex=0, outfilename="output_vox_ratio
519524
for spec in (spec_names):
520525
ratio = (len(np.argwhere(arr==spec)))/N_x
521526
dic_ratios["{}".format(spec)].append(ratio)
527+
dic_ratios["{}_atoms".format(spec)].append(len(np.argwhere(arr==spec))) ## AS 27.10.2024 added for compostion calculations
522528

523529
dic_ratios["file_name"].append(filename)
524530
dic_ratios["vox"].append(f_count)

compositionspace/postprocessing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def DBSCAN_clustering(self, voxel_centroid_phases_files, cluster_id,
123123
pointsToVTK(OutFile,x,y,z, data = {"label" : label} )
124124

125125
if save == True:
126-
OutFile = os.path.join(self.params["output_path"], f"Output_DBSCAN_segmentation_phase{cluster_id}")
126+
OutFile = os.path.join(self.params["output_path"], f"Output_DBSCAN_segmentation_phase{cluster_id}.h5")
127127
with h5py.File(OutFile, "w") as hdfw:
128128
G = hdfw.create_group(f"{cluster_id}")
129129
G.attrs["columns"] = Phase_columns

compositionspace/segmentation.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,17 @@ def get_composition_cluster_files(self, vox_ratio_file, vox_file, n_components):
169169
group_name = list(list(hdfr.attrs.values())[1])
170170

171171
ratios = pd.DataFrame(data=ratios, columns=ratios_columns)
172-
173-
X_train=ratios.drop(['Total_no','vox'], axis=1)
172+
173+
col_rm = []
174+
for i in ratios_columns:
175+
if "atoms" in i:
176+
col_rm.append(i)
177+
col_rm.append('Total_no')
178+
col_rm.append('vox')
179+
180+
#X_train=ratios.drop(['Total_no','vox'], axis=1)
181+
X_train=ratios.drop(col_rm, axis=1)
182+
174183

175184
gm = get_model(ml_params=ml_params)
176185
gm.fit(X_train)

tests/20230303_Workflow.ipynb

+404-150
Large diffs are not rendered by default.

tests/experiment_params.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ output_path: output
33
n_big_slices: 10
44
voxel_size: 2
55
bics_clusters: 10
6-
n_phases: 2
6+
n_phases: 3
77
ml_models:
88
name: GaussianMixture
99
GaussianMixture:
10-
n_components: 2
10+
n_components: 3
1111
max_iter: 100000
1212
verbose: 0
1313
RandomForest:
1414
max_depth: 0
1515
n_estimators: 0
1616
DBScan:
1717
eps: 5
18-
min_samples: 25
18+
min_samples: 29

tests/read.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
25.10.2024
2+
1. I added some calculation phase composition and error functionalities
3+
for nikita polins dataset(Fe doped Sm Co alloy)
4+
5+
2. Interesesting to see that Fe and Cu are equally imporatnat for phase assignment

0 commit comments

Comments
 (0)