mjhoptics / ray-optics

geometric ray tracing for optical systems
BSD 3-Clause "New" or "Revised" License
263 stars 54 forks source link

Wavefront became strange when lens is at a distance of FFL to the STOP #142

Closed quentGit closed 5 months ago

quentGit commented 5 months ago

Dear Michael Hayford,

First, thank you for your nice module.

I get an issue with wavefront : when the space before the system is near of it front focal lenght, the wavefront values became strange for a field with an angle of 0. The wavefront is normal when the distance before the system is not his ffl, or when the angle is not 0. Also, it seems to depend on the system, as I get the error for a Thorlabs lens but I cannot reproduce it with the triplet example of ray-optics documentation.

I put some code below that reproduce the effect :

from rayoptics.environment import *
import numpy as np
from rayoptics.gui import dashboards
import ipywidgets as widgets
from rayoptics import raytr

pupil=22.5
wvl_and_weight=[(510,1)]
fld=[0]

opm = OpticalModel()
sm = opm['seq_model']
osp = opm['optical_spec']
pm = opm['parax_model']
em = opm['ele_model']
pt = opm['part_tree']
ar = opm['analysis_results']

opm.radius_mode = True
sm.do_apertures = True
sm.gaps[0].thi = 1e10

osp['wvls'] = WvlSpec(wvl_and_weight)
osp.pupil.value=pupil
osp['fov'] = FieldSpec(osp, key=['object', 'angle'], flds=fld, is_relative=False)

sm.add_surface([0,0],sd=pupil/2)
sm.set_stop()
sm.add_surface([0,0])
sm.add_surface([106.237415,10.6000, 'N-BK7,Schott'],sd=25.4)
sm.add_surface([-92.104793,6.00000, 'N-SF2,Schott'],sd=25.4)
sm.add_surface([-409.394327,0],sd=25.4)
sm.add_surface([0,190.59622227040197])

opm.update_model()

When there is no ffl before the system, we get this :

sm.list_model()

fld, wvl, foc = osp.lookup_fld_wvl_focus(0)
wavefront = analyses.eval_wavefront(opm,num_rays=128,fld=fld, wvl=wvl,foc=0)
c_2=wavefront[:,:,2].copy()
c_2Mask = np.ma.masked_where(np.logical_not(np.isnan(c_2)),c_2)
plt.figure()
plt.title("Wavefront")
plt.imshow(c_2Mask.data,cmap='jet')#,cmap="BrBG_r")
plt.colorbar()
plt.show()
              r            t        medium     mode   zdr      sd
  Obj:     0.000000  1.00000e+10       air             1      0.0000
 Stop:     0.000000      0.00000       air             1      11.250
    2:     0.000000      0.00000       air             1      11.250
    3:   106.237415      10.6000     N-BK7             1      11.250
    4:   -92.104793      6.00000     N-SF2             1      10.909
    5:  -409.394327      0.00000       air             1      10.756
    6:     0.000000      190.596       air             1      10.748
  Img:     0.000000      0.00000                       1   0.0020472

errorWVF1

But if I put ffl before the sytem, I get :

sm.gaps[2].thi=198.59357423827296
opm.update_model()
sm.list_model()

fld, wvl, foc = osp.lookup_fld_wvl_focus(0)
wavefront = analyses.eval_wavefront(opm,num_rays=128,fld=fld, wvl=wvl,foc=0)
c_2=wavefront[:,:,2].copy()
c_2Mask = np.ma.masked_where(np.logical_not(np.isnan(c_2)),c_2)
plt.figure()
plt.title("Wavefront")
plt.imshow(c_2Mask.data,cmap='jet')#,cmap="BrBG_r")
plt.colorbar()
plt.show()
              r            t        medium     mode   zdr      sd
  Obj:     0.000000  1.00000e+10       air             1      0.0000
 Stop:     0.000000      0.00000       air             1      11.250
    2:     0.000000      198.594       air             1      11.250
    3:   106.237415      10.6000     N-BK7             1      11.250
    4:   -92.104793      6.00000     N-SF2             1      10.909
    5:  -409.394327      0.00000       air             1      10.756
    6:     0.000000      190.596       air             1      10.748
  Img:     0.000000      0.00000                       1   0.0020472

errorWVF2

I can manage to avoid it by changing the distance before the system, but if you know what goes wrong, it would be helpful.

Thanks and Best Regards, quentGit

mjhoptics commented 5 months ago

Hello @quentGit, Thank you for your nice comments and detailed report. I haven't found the exact problem yet, but I suspect that it has something to do with the exit pupil being exactly telecentric in the second example. Changing the separation from 198.59357 -> 198.6 makes the issue go away, for instance. The first order data shows very large values for the exit pupil distance and size; if that isn't handled correctly, I can imagine why garbage might be the result.

efl               199.9
f                 199.9
f'                199.9
ffl          -2.842e-14
pp1               199.9
bfl               190.6
ppk              -9.344
pp sep            5.909
f/#               8.886
m            -1.999e-08
red          -5.001e+07
obj_dist          1e+10
obj_ang               1
enp_dist             -0
enp_radius        11.25
na obj        1.125e-09
n obj                 1
img_dist          190.6
img_ht             3.49
exp_dist     -2.012e+18
exp_radius    1.132e+17
na img         -0.05618
n img                 1
optical invariant       0.1964

Hopefully this explanation is helpful; I'll continue to look at the problem, although it may take some time to resolve. Thanks, Mike Hayford

quentGit commented 5 months ago

Hello @mjhoptics ,

Thank you for your explanation !

quentGit

quentGit commented 5 months ago

Thank you for this fixing !