35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import numpy as np
|
|
from sklearn.preprocessing import StandardScaler
|
|
|
|
energies = [2803, 2811, 2819, 2826, 2834, 2842, 2850, 2858, 2866, 2874,
|
|
2882, 2890, 2897, 2905, 2913, 2921, 2929, 2937, 2945, 2953,
|
|
2961, 2969, 2977, 2985, 2993, 3001, 3009, 3018, 3026, 3034,
|
|
3042, 3050]
|
|
|
|
def load_slabs(width=512, height=512):
|
|
slabs = []
|
|
i_min, i_max = np.inf, 0
|
|
for e in energies:
|
|
s = np.genfromtxt(f"test_sample/HeLa_F-SRS_512x512_{e}cm-1.txt", delimiter=",")[0:height,0:width]
|
|
slabs.append({"e":e, "data":s, "total":int(s.sum())})
|
|
|
|
i_min, i_max = min(i_min, s.min()), max(i_max, s.max())
|
|
|
|
return slabs, i_min, i_max
|
|
|
|
def as_np_array(slabs):
|
|
return np.array(list(map(lambda s:s["data"].flat, slabs)))
|
|
|
|
def compute_errors(slabs, d=np.linalg.norm):
|
|
n = slabs.size(1)
|
|
errors = np.zeros(n, n)
|
|
for i in range(n):
|
|
for j in range(i+1, n):
|
|
errors[i,j] = errors[j,i] = d(slabs[i] - slabs[j])
|
|
return errors
|
|
|
|
def scale(X):
|
|
scaler = StandardScaler().set_output(transform="pandas")
|
|
Y = scaler.fit_transform(X)
|
|
print(Y.shape)
|
|
return Y
|