%matplotlib inline
isdark = False
from rayoptics.environment import *
from rayoptics.elem.elements import Element
from rayoptics.raytr.trace import apply_paraxial_vignetting
opm = OpticalModel()
sm = opm.seq_model
osp = opm.optical_spec
pm = opm.parax_model
#osp.pupil = PupilSpec(osp, key=['object', 'pupil'], value=60.84)
osp.pupil = PupilSpec(osp, key=['image', 'f/#'], value=0.98)
osp.field_of_view = FieldSpec(osp, key=['object', 'angle'], flds=[0., 19.98])
osp.spectral_region = WvlSpec([(486.1327, 0.5), (587.5618, 1.0), (656.2725, 0.5)], ref_wl=1)
opm.system_spec.title = 'Nikkor Z 58mm f0.95 - WO 2019/229849 Example 1'
opm.system_spec.dimensions = 'MM'
opm.radius_mode = True
d22 = 2.68
sm.gaps[0].thi=1e10
sm.add_surface([108.488,7.65,1.902650,35.77])
asp1 = EvenPolynomial(r=108.488, cc=0.,
coefs=[0.,-3.82177E-07,-6.06486E-11,-3.80172E-15,-1.32266E-18])
sm.ifcs[sm.cur_surface].profile = asp1
sm.add_surface([-848.550,2.80,1.552981,55.07])
sm.add_surface([50.252,18.12])
sm.add_surface([-60.720,2.80,1.612660,44.46])
sm.add_surface([2497.500,9.15,1.593190,67.90])
sm.add_surface([-77.239,0.40])
sm.add_surface([113.763,10.95,1.848500,43.79])
sm.add_surface([-178.060,0.40])
sm.add_surface([70.659,9.74,1.593190,67.90])
sm.add_surface([-1968.500,0.20])
sm.add_surface([289.687,8.00,1.593190,67.90])
sm.add_surface([-97.087,2.80,1.738000,32.33])
sm.add_surface([47.074,8.70])
sm.add_surface([0, 5.29])
sm.set_stop()
sm.add_surface([-95.230,2.20,1.612660,44.46])
sm.add_surface([41.204,11.55,1.497820,82.57])
sm.add_surface([-273.092,0.20])
sm.add_surface([76.173,9.50,1.883000,40.69])
sm.add_surface([-101.575,0.20])
sm.add_surface([176.128,7.45,1.953750,32.33])
asp20 = EvenPolynomial(r=176.128, cc=0.,
coefs=[0.,-1.15028E-06,-4.51771E-10,2.72670E-13,-7.66812E-17])
sm.ifcs[sm.cur_surface].profile = asp20
sm.add_surface([-67.221,1.80,1.738000,32.33])
sm.add_surface([55.510,d22])
sm.add_surface([71.413,6.35,1.883000,40.69])
sm.add_surface([-115.025,1.81,1.698950,30.13])
sm.add_surface([46.943,0.80])
sm.add_surface([55.281,9.11,1.883000,40.69])
sm.add_surface([-144.041,3.00,1.765538,46.76])
sm.add_surface([52.858,14.50])
asp28 = EvenPolynomial(r=52.858, cc=0.,
coefs=[0.,3.18645E-06,-1.14718E-08,7.74567E-11,-2.24225E-13,3.34790E-16,-1.70470E-19])
sm.ifcs[sm.cur_surface].profile = asp28
sm.add_surface([0,1.60,1.516800,64.14])
sm.add_surface([0,1.00])
sm.ifcs[1].max_aperture = 66.80 / 2.0
sm.ifcs[2].max_aperture = 65.82 / 2.0
sm.ifcs[3].max_aperture = 57.94 / 2.0
sm.ifcs[4].max_aperture = 58.28 / 2.0
sm.ifcs[5].max_aperture = 65.32 / 2.0
sm.ifcs[6].max_aperture = 65.32 / 2.0
sm.ifcs[7].max_aperture = 70.90 / 2.0
sm.ifcs[8].max_aperture = 70.90 / 2.0
sm.ifcs[9].max_aperture = 65.00 / 2.0
sm.ifcs[10].max_aperture = 65.00 / 2.0
sm.ifcs[11].max_aperture = 61.06 / 2.0
sm.ifcs[12].max_aperture = 59.42 / 2.0
sm.ifcs[13].max_aperture = 50.24 / 2.0
sm.ifcs[14].max_aperture = 47.918 / 2.0
sm.ifcs[15].max_aperture = 49.92 / 2.0
sm.ifcs[16].max_aperture = 49.92 / 2.0
sm.ifcs[17].max_aperture = 49.92 / 2.0
sm.ifcs[18].max_aperture = 51.12 / 2.0
sm.ifcs[19].max_aperture = 51.12 / 2.0
sm.ifcs[20].max_aperture = 46.80 / 2.0
sm.ifcs[21].max_aperture = 45.36 / 2.0
sm.ifcs[22].max_aperture = 39.84 / 2.0
sm.ifcs[23].max_aperture = 39.46 / 2.0
sm.ifcs[24].max_aperture = 39.46 / 2.0
sm.ifcs[25].max_aperture = 39.46 / 2.0
sm.ifcs[26].max_aperture = 38.94 / 2.0
sm.ifcs[27].max_aperture = 38.28 / 2.0
sm.ifcs[28].max_aperture = 38.28 / 2.0
sm.ifcs[29].max_aperture = 44.30 / 2.0
sm.list_surfaces()
0 Surface(lbl='Obj', profile=Spherical(c=0.0), interact_mode=transmit) 1 Surface(profile=EvenPolynomial(c=0.009217609320846545, cc=0.0, coefs=[0.0, -3.82177e-07, -6.06486e-11, -3.80172e-15, -1.32266e-18]), interact_mode=transmit) 2 Surface(profile=Spherical(c=-0.0011784809380708267), interact_mode=transmit) 3 Surface(profile=Spherical(c=0.01989970548435883), interact_mode=transmit) 4 Surface(profile=Spherical(c=-0.016469038208168644), interact_mode=transmit) 5 Surface(profile=Spherical(c=0.0004004004004004004), interact_mode=transmit) 6 Surface(profile=Spherical(c=-0.012946827379950543), interact_mode=transmit) 7 Surface(profile=Spherical(c=0.008790204196443482), interact_mode=transmit) 8 Surface(profile=Spherical(c=-0.005616084465910367), interact_mode=transmit) 9 Surface(profile=Spherical(c=0.014152478806662986), interact_mode=transmit) 10 Surface(profile=Spherical(c=-0.000508001016002032), interact_mode=transmit) 11 Surface(profile=Spherical(c=0.003452001643152782), interact_mode=transmit) 12 Surface(profile=Spherical(c=-0.010300040170156663), interact_mode=transmit) 13 Surface(profile=Spherical(c=0.021243149084420276), interact_mode=transmit) 14 Surface(profile=Spherical(c=0.0), interact_mode=transmit) 15 Surface(profile=Spherical(c=-0.01050089257586895), interact_mode=transmit) 16 Surface(profile=Spherical(c=0.024269488399184545), interact_mode=transmit) 17 Surface(profile=Spherical(c=-0.003661769660041305), interact_mode=transmit) 18 Surface(profile=Spherical(c=0.01312801123757762), interact_mode=transmit) 19 Surface(profile=Spherical(c=-0.009844942160964805), interact_mode=transmit) 20 Surface(profile=EvenPolynomial(c=0.005677688953488373, cc=0.0, coefs=[0.0, -1.15028e-06, -4.51771e-10, 2.7267e-13, -7.66812e-17]), interact_mode=transmit) 21 Surface(profile=Spherical(c=-0.01487630353609735), interact_mode=transmit) 22 Surface(profile=Spherical(c=0.01801477211313277), interact_mode=transmit) 23 Surface(profile=Spherical(c=0.014003052665481075), interact_mode=transmit) 24 Surface(profile=Spherical(c=-0.008693762225603129), interact_mode=transmit) 25 Surface(profile=Spherical(c=0.021302430607332296), interact_mode=transmit) 26 Surface(profile=Spherical(c=0.018089397803947107), interact_mode=transmit) 27 Surface(profile=Spherical(c=-0.006942467769593379), interact_mode=transmit) 28 Surface(profile=EvenPolynomial(c=0.0189186121306141, cc=0.0, coefs=[0.0, 3.18645e-06, -1.14718e-08, 7.74567e-11, -2.24225e-13, 3.3479e-16, -1.7047e-19]), interact_mode=transmit) 29 Surface(profile=Spherical(c=0.0), interact_mode=transmit) 30 Surface(profile=Spherical(c=0.0), interact_mode=transmit) 31 Surface(lbl='Img', profile=Spherical(c=0.0), interact_mode=transmit)
sm.list_gaps()
0 Gap(t=10000000000.0, medium=Air()) 1 Gap(t=7.65, medium=Glass(nd=1.90265, vd=35.77, mat='', cat='')) 2 Gap(t=2.8, medium=Glass(nd=1.552981, vd=55.07, mat='', cat='')) 3 Gap(t=18.12, medium=Air()) 4 Gap(t=2.8, medium=Glass(nd=1.61266, vd=44.46, mat='', cat='')) 5 Gap(t=9.15, medium=Glass(nd=1.59319, vd=67.9, mat='', cat='')) 6 Gap(t=0.4, medium=Air()) 7 Gap(t=10.95, medium=Glass(nd=1.8485, vd=43.79, mat='', cat='')) 8 Gap(t=0.4, medium=Air()) 9 Gap(t=9.74, medium=Glass(nd=1.59319, vd=67.9, mat='', cat='')) 10 Gap(t=0.2, medium=Air()) 11 Gap(t=8.0, medium=Glass(nd=1.59319, vd=67.9, mat='', cat='')) 12 Gap(t=2.8, medium=Glass(nd=1.738, vd=32.33, mat='', cat='')) 13 Gap(t=8.7, medium=Air()) 14 Gap(t=5.29, medium=Air()) 15 Gap(t=2.2, medium=Glass(nd=1.61266, vd=44.46, mat='', cat='')) 16 Gap(t=11.55, medium=Glass(nd=1.49782, vd=82.57, mat='', cat='')) 17 Gap(t=0.2, medium=Air()) 18 Gap(t=9.5, medium=Glass(nd=1.883, vd=40.69, mat='', cat='')) 19 Gap(t=0.2, medium=Air()) 20 Gap(t=7.45, medium=Glass(nd=1.95375, vd=32.33, mat='', cat='')) 21 Gap(t=1.8, medium=Glass(nd=1.738, vd=32.33, mat='', cat='')) 22 Gap(t=2.68, medium=Air()) 23 Gap(t=6.35, medium=Glass(nd=1.883, vd=40.69, mat='', cat='')) 24 Gap(t=1.81, medium=Glass(nd=1.69895, vd=30.13, mat='', cat='')) 25 Gap(t=0.8, medium=Air()) 26 Gap(t=9.11, medium=Glass(nd=1.883, vd=40.69, mat='', cat='')) 27 Gap(t=3.0, medium=Glass(nd=1.765538, vd=46.76, mat='', cat='')) 28 Gap(t=14.5, medium=Air()) 29 Gap(t=1.6, medium=Glass(nd=1.5168, vd=64.14, mat='', cat='')) 30 Gap(t=1.0, medium=Air())
opm.update_model()
sm.list_model()
r t medium mode zdr sd Obj: 0.000000 1.00000e+10 air 1 3.6357e+09 1: 108.488000 7.65000 903.358 1 55.609 2: -848.550000 2.80000 553.551 1 52.287 3: 50.252000 18.1200 air 1 50.758 4: -60.720000 2.80000 613.445 1 45.517 5: 2497.500000 9.15000 593.679 1 45.812 6: -77.239000 0.400000 air 1 46.791 7: 113.763000 10.9500 849.438 1 46.715 8: -178.060000 0.400000 air 1 43.532 9: 70.659000 9.74000 593.679 1 43.234 10: -1968.500000 0.200000 air 1 36.461 11: 289.687000 8.00000 593.679 1 36.237 12: -97.087000 2.80000 738.323 1 30.247 13: 47.074000 8.70000 air 1 28.398 Stop: 0.000000 5.29000 air 1 22.285 15: -95.230000 2.20000 613.445 1 23.818 16: 41.204000 11.5500 498.826 1 24.423 17: -273.092000 0.200000 air 1 28.365 18: 76.173000 9.50000 883.407 1 28.457 19: -101.575000 0.200000 air 1 29.111 20: 176.128000 7.45000 954.323 1 29.086 21: -67.221000 1.80000 738.323 1 28.015 22: 55.510000 2.68000 air 1 27.630 23: 71.413000 6.35000 883.407 1 27.621 24: -115.025000 1.81000 699.301 1 26.458 25: 46.943000 0.800000 air 1 26.045 26: 55.281000 9.11000 883.407 1 26.045 27: -144.041000 3.00000 766.468 1 24.035 28: 52.858000 14.5000 air 1 23.295 29: 0.000000 1.60000 517.641 1 21.877 30: 0.000000 1.00000 air 1 21.774 Img: 0.000000 0.00000 1 21.683
pm.first_order_data()
efl 59.62 ffl 1.66 pp1 61.28 bfl 0.9925 ppk 58.63 f/# 0.98 m -0.000125 red -1.677e+08 obj_dist 1e+10 obj_ang 19.98 enp_dist 69.29 enp_radius 30.42 na obj 3.042e-09 n obj 1 img_dist 1 img_ht 21.68 exp_dist -51.57 exp_radius 26.82 na img -0.4545 n img 1 optical invariant 11.06
opm.ele_model.elements_from_sequence(sm)
elmn = [e for e in opm.ele_model.elements if isinstance(e, Element)]
elmn[0].sd = 66.8/2
elmn[1].sd = 65.82/2
elmn[2].sd = 65.32/2
elmn[3].sd = 65.32/2
elmn[4].sd = 70.90/2
elmn[5].sd = 65.0/2
elmn[6].sd = 61.06/2
elmn[7].sd = 59.42/2
elmn[8].sd = 50.24/2
elmn[9].sd = 49.92/2
elmn[10].sd = 49.92/2
elmn[11].sd = 51.12/2
elmn[12].sd = 46.8/2
elmn[13].sd = 45.36/2
elmn[14].sd = 39.46/2
elmn[15].sd = 39.46/2
elmn[16].sd = 38.94/2
elmn[17].sd = 44.3/2
opm.ele_model.list_elements()
0: E1 (Element): Element: EvenPolynomial(c=0.009217609320846545, cc=0.0, coefs=[0.0, -3.82177e-07, -6.06486e-11, -3.80172e-15, -1.32266e-18]), Spherical(c=-0.0011784809380708267), t=7.6500, sd=33.4000, glass: 903.358 1: E2 (Element): Element: Spherical(c=-0.0011784809380708267), Spherical(c=0.01989970548435883), t=2.8000, sd=32.9100, glass: 553.551 2: AirGap E2-E3 (AirGap): Gap(t=18.12, medium=Air()) 3: E3 (Element): Element: Spherical(c=-0.016469038208168644), Spherical(c=0.0004004004004004004), t=2.8000, sd=32.6600, glass: 613.445 4: E4 (Element): Element: Spherical(c=0.0004004004004004004), Spherical(c=-0.012946827379950543), t=9.1500, sd=32.6600, glass: 593.679 5: AirGap E4-E5 (AirGap): Gap(t=0.4, medium=Air()) 6: E5 (Element): Element: Spherical(c=0.008790204196443482), Spherical(c=-0.005616084465910367), t=10.9500, sd=35.4500, glass: 849.438 7: AirGap E5-E6 (AirGap): Gap(t=0.4, medium=Air()) 8: E6 (Element): Element: Spherical(c=0.014152478806662986), Spherical(c=-0.000508001016002032), t=9.7400, sd=32.5000, glass: 593.679 9: AirGap E6-E7 (AirGap): Gap(t=0.2, medium=Air()) 10: E7 (Element): Element: Spherical(c=0.003452001643152782), Spherical(c=-0.010300040170156663), t=8.0000, sd=30.5300, glass: 593.679 11: E8 (Element): Element: Spherical(c=-0.010300040170156663), Spherical(c=0.021243149084420276), t=2.8000, sd=29.7100, glass: 738.323 12: AirGap E8-Aperture Stop (AirGap): Gap(t=8.7, medium=Air()) 13: Aperture Stop (DummyInterface): Surface(profile=Spherical(c=0.0), interact_mode=transmit) 14: AirGap Aperture Stop-E9 (AirGap): Gap(t=5.29, medium=Air()) 15: E9 (Element): Element: Spherical(c=-0.01050089257586895), Spherical(c=0.024269488399184545), t=2.2000, sd=25.1200, glass: 613.445 16: E10 (Element): Element: Spherical(c=0.024269488399184545), Spherical(c=-0.003661769660041305), t=11.5500, sd=24.9600, glass: 498.826 17: AirGap E10-E11 (AirGap): Gap(t=0.2, medium=Air()) 18: E11 (Element): Element: Spherical(c=0.01312801123757762), Spherical(c=-0.009844942160964805), t=9.5000, sd=24.9600, glass: 883.407 19: AirGap E11-E12 (AirGap): Gap(t=0.2, medium=Air()) 20: E12 (Element): Element: EvenPolynomial(c=0.005677688953488373, cc=0.0, coefs=[0.0, -1.15028e-06, -4.51771e-10, 2.7267e-13, -7.66812e-17]), Spherical(c=-0.01487630353609735), t=7.4500, sd=25.5600, glass: 954.323 21: E13 (Element): Element: Spherical(c=-0.01487630353609735), Spherical(c=0.01801477211313277), t=1.8000, sd=23.4000, glass: 738.323 22: AirGap E13-E14 (AirGap): Gap(t=2.68, medium=Air()) 23: E14 (Element): Element: Spherical(c=0.014003052665481075), Spherical(c=-0.008693762225603129), t=6.3500, sd=22.6800, glass: 883.407 24: E15 (Element): Element: Spherical(c=-0.008693762225603129), Spherical(c=0.021302430607332296), t=1.8100, sd=19.7300, glass: 699.301 25: AirGap E15-E16 (AirGap): Gap(t=0.8, medium=Air()) 26: E16 (Element): Element: Spherical(c=0.018089397803947107), Spherical(c=-0.006942467769593379), t=9.1100, sd=19.7300, glass: 883.407 27: E17 (Element): Element: Spherical(c=-0.006942467769593379), EvenPolynomial(c=0.0189186121306141, cc=0.0, coefs=[0.0, 3.18645e-06, -1.14718e-08, 7.74567e-11, -2.24225e-13, 3.3479e-16, -1.7047e-19]), t=3.0000, sd=19.4700, glass: 766.468 28: AirGap E17-E18 (AirGap): Gap(t=14.5, medium=Air()) 29: E18 (Element): Element: Spherical(c=0.0), Spherical(c=0.0), t=1.6000, sd=22.1500, glass: 517.641 30: AirGap E18-Image (AirGap): Gap(t=1.0, medium=Air()) 31: Image (DummyInterface): Surface(lbl='Img', profile=Spherical(c=0.0), interact_mode=transmit)
osp.field_of_view.fields
[Field(x=0.0, y=0.0, wt=1.0), Field(x=0.0, y=19.98, wt=1.0)]
osp.field_of_view.fields[1]
Field(x=0.0, y=19.98, wt=1.0)
# manually set vignetting for the full field point
osp.field_of_view.fields[1].vly = .7
osp.field_of_view.fields[1].vuy = .5
#apply_paraxial_vignetting(opm)
layout_plt = plt.figure(FigureClass=InteractiveLayout, opt_model=opm, do_draw_rays=True, do_paraxial_layout=False,
is_dark=isdark).plot()
#for i, ifc in enumerate(sm.ifcs):
# sd = abs(pm.ax[i][0]) + abs(pm.pr[i][0])
# ifc.set_max_aperture(sd)
#em = opm.ele_model
#for i, e in enumerate(em.elements):
# if isinstance(e, elements.Element):
# sd1 = sm.ifcs[e.s1_indx].max_aperture
# sd2 = sm.ifcs[e.s2_indx].max_aperture
# e.sd = max(sd1, sd2)
#layout_plt = plt.figure(FigureClass=InteractiveLayout,
# opt_model=opm, do_draw_rays=False, do_paraxial_layout=False, is_dark=isdark).plot()
#opm.ele_model.list_elements()
# Plot the transverse ray aberrations
abr_plt = plt.figure(FigureClass=RayFanFigure, opt_model=opm,
data_type='Ray', scale_type=Fit.All_Same, is_dark=isdark).plot()
# Plot the wavefront aberration
wav_plt = plt.figure(FigureClass=RayFanFigure, opt_model=opm,
data_type='OPD', scale_type=Fit.All_Same, is_dark=isdark).plot()
# Plot spot diagrams
spot_plt = plt.figure(FigureClass=SpotDiagramFigure, opt_model=opm,
scale_type=Fit.User_Scale, user_scale_value=0.1, is_dark=isdark).plot()