Skip to content

Instantly share code, notes, and snippets.

Parsing the Seidel Coefficient text results to display the Seidel aberration coefficients in wave
# Imports
import numpy as np
import matplotlib.pyplot as plt
# Initializations
legend = []
spha = []
coma = []
asti = []
fcur = []
dist = []
cla = []
ctr = []
ii = 0
# Open Seidel Coefficient text file
with open("E:\\SeidelCoeffs.txt") as seidel_file:
# Read lines until "wave" block
for line in seidel_file:
if "in Waves" in line:
break
# Skip header
seidel_file.readline()
seidel_file.readline()
# Remove unnecessary space characters
line = seidel_file.readline().replace(" ", "")
# Loop over the "wave" block
while line != "\n":
split_line = line.split("\t")
legend.append(split_line[0])
spha.append(float(split_line[1]))
coma.append(float(split_line[2]))
asti.append(float(split_line[3]))
fcur.append(float(split_line[4]))
dist.append(float(split_line[5]))
cla.append(float(split_line[6]))
ctr.append(float(split_line[7]))
line = seidel_file.readline().replace(" ", "")
ii += 1
# Display
width = 0.4
x_axis = 7*width*np.arange(len(legend))
plt.figure(figsize=(12,8), dpi= 100, facecolor='w', edgecolor='k')
plt.bar(x_axis, spha, width, label = 'SPHA')
plt.bar(x_axis+width, coma, width, label = 'COMA')
plt.bar(x_axis+width*2, asti, width, label = 'ASTI')
plt.bar(x_axis+width*3, fcur, width, label = 'FCUR')
plt.bar(x_axis+width*4, dist, width, label = 'DIST')
plt.bar(x_axis+width*5, cla, width, label = 'CLA')
plt.bar(x_axis+width*6, ctr, width, label = 'CTR')
for point in x_axis:
plt.axvline(point-width/2, color='lightgray')
plt.axvline(x_axis[-1]+7*width-width/2, color='lightgray')
plt.axhline(0, color='k')
plt.title("Seidel Aberration Coefficients in Waves")
plt.xticks(x_axis+3*width, legend)
plt.legend(loc='upper center', bbox_to_anchor=(0.5, -0.1),
fancybox=True, shadow=True, ncol=7)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment