Skip to content

Commit 86d1728

Browse files
analyser: Added missing features in PCA plot
1 parent 56ba903 commit 86d1728

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

opxrd/analyser.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,19 @@ def plot_pattern_dbs(self, title : str):
8787
print('done')
8888

8989
def plot_effective_components(self):
90-
for db in self.databases:
90+
markers = ['o','s','^','v','D','p','*','+','x']
91+
92+
for db_num, db in enumerate(self.databases):
9193
max_components = len(db.patterns)
9294
standardized_intensities = [p.get_pattern_data()[1] for p in db.patterns]
9395
pca = PCA(n_components=max_components)
9496
db_pca_coords = pca.fit_transform(standardized_intensities)
9597

96-
plot_components = min(10, max_components)
9798
accuracies = []
98-
x = np.linspace(0,plot_components/max_components, num=plot_components)
99-
for n_comp in range(plot_components):
99+
num_datpoints = min(20, max_components)
100+
x = np.linspace(0,1, num=num_datpoints)
101+
for frac in x:
102+
n_comp = int(frac * max_components)
100103
mismatches = []
101104
limited_pca = db_pca_coords[:,:n_comp]
102105
zero_padded_comp = np.pad(limited_pca, ((0, 0), (0, max_components - n_comp)))
@@ -109,11 +112,11 @@ def plot_effective_components(self):
109112
accuracies.append(mismatch)
110113
print(f'Computed accuracy for {db.name} with {n_comp} components = {mismatch}')
111114

112-
plt.plot(x,accuracies, label=db.name)
115+
plt.plot(x,accuracies, label=db.name, marker=markers[db_num])
113116

114117
plt.xlabel(f'Fraction of maximum components')
115-
plt.ylabel(f'Average relative mismatch $/lange \delta /rangle$')
116-
plt.legend(loc='lower right')
118+
plt.ylabel(f'Average relative mismatch $\overline{{\Delta}}$')
119+
plt.legend(loc='upper right')
117120

118121
plt.show()
119122

@@ -222,9 +225,9 @@ def print_total_counts(self):
222225

223226

224227
if __name__ == "__main__":
225-
test_dirpath = '/tmp/opxrd_test'
226-
full_dirpath = '/home/daniel/aimat/data/opXRD/test'
227-
opxrd_databases = OpXRD.as_database_list(root_dirpath=test_dirpath)
228+
test_dirpath = '/home/daniel/aimat/data/opXRD/test'
229+
full_dirpath = '/home/daniel/aimat/data/opXRD/final'
230+
opxrd_databases = OpXRD.as_database_list(root_dirpath=full_dirpath)
228231
analyser = DatabaseAnalyser(databases=opxrd_databases, output_dirpath='/tmp/opxrd_analysis')
229232
analyser.plot_effective_components()
230233

0 commit comments

Comments
 (0)