-
Notifications
You must be signed in to change notification settings - Fork 54
/
test_Centroid.py
48 lines (40 loc) · 1.45 KB
/
test_Centroid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
Test script for testing the Centroid and D4sigma commands.
"""
from LightPipes import *
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib import patches
wavelength = 1500*nm
size = 25*mm
N = 500
F=Begin(size,wavelength,N)
F=CircAperture(F, 5*mm, x_shift=-6*mm, y_shift=-2*mm)
F=Fresnel(F, 3*m)
Xc,Yc, NXc, NYc =Centroid(F)
sx, sy = D4sigma(F)
I0=Intensity(F)
# Axes ...
fig, main_ax = plt.subplots(figsize=(5, 5))
divider = make_axes_locatable(main_ax)
top_ax = divider.append_axes("top", 1.05, pad=0.1, sharex=main_ax)
right_ax = divider.append_axes("right", 1.05, pad=0.1, sharey=main_ax)
# Make some labels invisible
top_ax.xaxis.set_tick_params(labelbottom=False)
right_ax.yaxis.set_tick_params(labelleft=False)
# Labels ...
main_ax.set_xlabel('X [mm]')
main_ax.set_ylabel('Y [mm]')
top_ax.set_ylabel('Intensity [a.u.]')
right_ax.set_xlabel('Intensity [a.u.]')
#plot ...
main_ax.pcolormesh(F.xvalues/mm, F.yvalues/mm, I0)
main_ax.axvline(Xc/mm, color='r', ls='--')
main_ax.axhline(Yc/mm, color='g', ls='--')
main_ax.text((Xc+0.6*sx)/mm,(Yc+1*mm)/mm,r'$Y_c={:4.2f} mm$'.format(Yc/mm), color='g')
main_ax.text((Xc+1*mm)/mm,(Yc+0.6*sy)/mm,r'$X_c={:4.2f} mm$'.format(Xc/mm), color='r')
main_ax.add_patch(patches.Ellipse((Xc/mm, Yc/mm), sx/mm, sy/mm, fill=False, lw=1,color='w', ls='--'))
right_ax.plot(I0[:,NXc],F.yvalues/mm, 'r-', lw=1)
top_ax.plot(F.xvalues/mm,I0[NYc,:], 'g-', lw=1)
plt.show()