FFT/2d_fourie/analysis.py
2023-03-01 12:50:53 +01:00

82 lines
2.1 KiB
Python

import numpy as np
import matplotlib.pyplot as plt
import glob
def eval_data(file):
data = np.load(file)
percentage = data["percentage"]
out = data["out"]
out = np.array(out)
print(out.shape)
fig, all_axs = plt.subplots(2, out.shape[0])
axs = all_axs[0, :]
axs2 = all_axs[1, :]
for o, ax, ax2, lab in zip(out, axs, axs2, ["rutile", "mono_twin", "mono"]):
# ax.plot(percentage, o/np.max(o, axis=0))
ax.plot(percentage, o/o[0])
# ax.plot(percentage, o)
o = np.mean(o, axis=1)
o = o/o[0]
ax2.plot(percentage, o)
ax2.plot([0, 1], [o[0], o[-1]], "k:")
ax.set_title(lab)
if "ising" in file:
fig.suptitle("Ising")
else:
fig.suptitle("Random")
fig.savefig(f"{file}.png")
def parse_lists(out):
lists = []
for o in out:
lists.append(np.stack(o))
max = 0
for l in lists:
print(l.shape)
if max < l.shape[1]:
max = l.shape[1]
lists = [np.pad(l, ((0, 0), (0, max-l.shape[1]))) for l in lists]
for l in lists:
print(l.shape)
return np.stack(lists)
def eval_data_print(file):
data = np.load(file, allow_pickle=True)
percentage = data["percentage"]
out = parse_lists(data["out"])
out = np.array(out)
print(out.shape)
out = out[[0, 2], :, :]
print(out.shape)
fig, all_axs = plt.subplots(2, out.shape[0])
axs = all_axs[0, :]
axs2 = all_axs[1, :]
for o, ax, ax2, lab in zip(out, axs, axs2, ["rutile", "monoclinic", "mono"]):
# ax.plot(percentage, o/np.max(o, axis=0))
ax.plot(percentage, o/o[0])
# ax.plot(percentage, o)
o = np.mean(o, axis=1)
o = o/o[0]
ax2.plot(percentage, o)
ax2.plot([0, 1], [o[0], o[-1]], "k:")
ax.set_title(lab)
if "ising" in file:
fig.suptitle("Ising")
else:
fig.suptitle("Random")
for ax in all_axs.flatten():
ax.set_xlabel("Rutile Phase")
ax.set_ylabel("Normalized Intensity")
plt.tight_layout()
if __name__ == "__main__":
for f in glob.glob("*.npz"):
eval_data_print(f)
plt.show()