Resources that are useful for creating eucational materials related to the study of optics and require Python2.7.
opticspy
¶This looks handy - it looks like the method for specifying set-ups is quite straightforward.
#%%capture
#!pip2 install opticspy
!pip2 install --upgrade git+https://github.com/Sterncat/opticspy.git
Collecting git+https://github.com/Sterncat/opticspy.git Cloning https://github.com/Sterncat/opticspy.git to /tmp/pip-req-build-HKRXlX Requirement already satisfied, skipping upgrade: numpy>=1.9.3 in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from opticspy==0.2.1) (1.15.0) Requirement already satisfied, skipping upgrade: matplotlib>=1.4.3 in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from opticspy==0.2.1) (2.1.0) Collecting unwrap (from opticspy==0.2.1) Downloading https://files.pythonhosted.org/packages/0f/a0/c1f7d5b06ee68e0e3f64d279323f61dbca0c32053f0d6d06f56132d3f322/unwrap-0.1.1.tar.gz Requirement already satisfied, skipping upgrade: six>=1.10 in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.4.3->opticspy==0.2.1) (1.11.0) Requirement already satisfied, skipping upgrade: python-dateutil>=2.0 in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.4.3->opticspy==0.2.1) (2.6.1) Requirement already satisfied, skipping upgrade: backports.functools_lru_cache in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.4.3->opticspy==0.2.1) (1.4) Requirement already satisfied, skipping upgrade: subprocess32 in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.4.3->opticspy==0.2.1) (3.2.7) Requirement already satisfied, skipping upgrade: pytz in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.4.3->opticspy==0.2.1) (2017.2) Requirement already satisfied, skipping upgrade: cycler>=0.10 in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.4.3->opticspy==0.2.1) (0.10.0) Requirement already satisfied, skipping upgrade: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from matplotlib>=1.4.3->opticspy==0.2.1) (2.2.0) Requirement already satisfied, skipping upgrade: cffi>=0.7 in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from unwrap->opticspy==0.2.1) (1.10.0) Requirement already satisfied, skipping upgrade: pycparser in /home/nbuser/anaconda2_501/lib/python2.7/site-packages (from cffi>=0.7->unwrap->opticspy==0.2.1) (2.18) Building wheels for collected packages: opticspy, unwrap Running setup.py bdist_wheel for opticspy ... done Stored in directory: /tmp/pip-ephem-wheel-cache-NeM8pM/wheels/ad/35/f5/2cc5cee6cda4534dcf5603e0d6b0fd92aa1db9caf98f839ba5 Running setup.py bdist_wheel for unwrap ... done Stored in directory: /home/nbuser/.cache/pip/wheels/a6/f6/90/907e1c41c75b731a3cb0485f309813c6940cdf44844bd380ee Successfully built opticspy unwrap Installing collected packages: unwrap, opticspy Successfully installed opticspy-0.2.1 unwrap-0.1.1
%matplotlib inline
from opticspy.ray_tracing import *
New_Lens = lens.Lens(lens_name='Triplet',creator='XF')
New_Lens.FNO = 5
New_Lens.lens_info()
Triplet XF
New_Lens.add_wavelength(wl = 656.30)
New_Lens.add_wavelength(wl = 587.60)
New_Lens.add_wavelength(wl = 486.10)
New_Lens.list_wavelengths()
Add wavelength 656.3nm done Add wavelength 587.6nm done Add wavelength 486.1nm done List all wavelength information ('Wavelength', 486.1, 'nm') ('Wavelength', 587.6, 'nm') ('Wavelength', 656.3, 'nm')
New_Lens.add_field_YAN(angle=0)
New_Lens.add_field_YAN(angle=14)
New_Lens.add_field_YAN(angle=20)
New_Lens.list_fields()
Add field angle:0 degree done Add field angle:14 degree done Add field angle:20 degree done list all fields information ('Field angle:', 0) ('Field angle:', 14) ('Field angle:', 20)
#The following cell raises an error
#IOError: [Errno 2] No such file or directory:
#'/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_database/library.yml'
# The glass database exists as a folder in:
#https://github.com/Sterncat/opticspy/tree/master/opticspy/ray_tracing/glass_database
#So it's not being installed properly?
# Seems like evidence of s/thing related commented out in https://github.com/Sterncat/opticspy/blob/master/setup.py
!ls /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy
aperture.py gauss.pyc jones.py seidel.py aperture.pyc hartmann.py jones.pyc seidel.pyc asphere.py hartmann.pyc lens test asphere.pyc __init__.py mplot3d tools.py diffraction123.py __init__.pyc phaseunwrap.py tools.pyc diffraction123.pyc interferometer_seidel.py phaseunwrap.pyc zernike.py diffraction.py interferometer_seidel.pyc ray_tracing zernike.pyc diffraction.pyc interferometer_zenike.py seidel2.py zernike_rec.py gauss.py interferometer_zenike.pyc seidel2.pyc zernike_rec.pyc
New_Lens.add_surface(number=1,radius=10000000,thickness=1000000,glass='air',output=True)
New_Lens.add_surface(number=2,radius=41.15909,thickness=6.097555 ,glass='S-BSM18_ohara',output=True)
New_Lens.add_surface(number=3,radius=-957.83146,thickness=9.349584,glass='air',output=True)
New_Lens.add_surface(number=4,radius=-51.32104,thickness=2.032518,glass='N-SF2_schott',output=True)
New_Lens.add_surface(number=5,radius=42.37768 ,thickness=5.995929 ,glass='air',output=True)
-----------------------Add surface:------------------------------- ------------------------------------------------------------------ | Num | Radius | Thickness | Glass | STO | ------------------------------------------------------------------ | 1 | Infinity | Infinity | air | False | ------------------------------------------------------------------ -----------------------Add surface:------------------------------- ------------------------------------------------------------------ | Num | Radius | Thickness | Glass | STO | ------------------------------------------------------------------ | 2 | 41.1591 | 6.0976 | S-BSM18_ohara | False | ------------------------------------------------------------------
IOErrorTraceback (most recent call last) <ipython-input-7-8b6207385061> in <module>() 1 New_Lens.add_surface(number=1,radius=10000000,thickness=1000000,glass='air',output=True) ----> 2 New_Lens.add_surface(number=2,radius=41.15909,thickness=6.097555 ,glass='S-BSM18_ohara',output=True) 3 New_Lens.add_surface(number=3,radius=-957.83146,thickness=9.349584,glass='air',output=True) 4 New_Lens.add_surface(number=4,radius=-51.32104,thickness=2.032518,glass='N-SF2_schott',output=True) 5 New_Lens.add_surface(number=5,radius=42.37768 ,thickness=5.995929 ,glass='air',output=True) /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/lens.pyc in add_surface(self, number, radius, thickness, glass, STO, output) 80 #-----------------------surface functions----------------------- 81 def add_surface(self,number,radius,thickness,glass,STO=False,output=False): ---> 82 surface.add(self,number,radius,thickness,glass,STO,output) 83 # def update_surface(self,number,radius,thickness,index,STO): 84 # surface.update(self,number,radius,thickness,index,STO) /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/surface.pyc in add(self, number, radius, thickness, glass, STO, output) 47 New_Surface = Surface(wavelength_list = self.wavelength_list,number=number,\ 48 radius=radius,thickness=thickness,glass=glass,STO=STO,\ ---> 49 __diameter__=0) 50 self.surface_list.append(New_Surface) 51 /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/surface.pyc in __init__(self, wavelength_list, number, radius, thickness, glass, STO, __diameter__) 15 self.radius = radius 16 self.glass = glass ---> 17 self.indexlist = glass_funcs.glass2indexlist(wavelength_list,glass) 18 self.thickness = thickness 19 self.STO = STO /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_funcs.pyc in glass2indexlist(wavelength_list, glassname) 25 glass_catalog_name = glassname[n+1:] 26 glass_name = glassname[:n] ---> 27 catalog = RefractiveIndex() 28 for w in wavelength_list: 29 mat = catalog.getMaterial('glass', glass_catalog_name, glass_name) /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_function/refractiveIndex.pyc in __init__(self, databasePath) 35 """ 36 self.referencePath = os.path.normpath(databasePath) ---> 37 f = open(os.path.join(self.referencePath, os.path.normpath("library.yml")), "r") 38 # print(f) 39 self.catalog = yaml.safe_load(f) IOError: [Errno 2] No such file or directory: '/home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/glass_database/library.yml'
New_Lens.refresh_paraxial()
------------Calculating EFL--------------- ('start surface:', 2) ('end surface:', 0)
IndexErrorTraceback (most recent call last) <ipython-input-8-7d3213005ced> in <module>() ----> 1 New_Lens.refresh_paraxial() /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/lens.pyc in refresh_paraxial(self) 36 37 def refresh_paraxial(self): ---> 38 self.EFL = first_order_tools.EFL(self,0,0) 39 self.EPD = self.EFL/self.FNO 40 self.EP_thickness = first_order_tools.EP(self) /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/first_order_tools.pyc in EFL(Lens, start_surface, end_surface) 92 def EFL(Lens,start_surface,end_surface): 93 print('------------Calculating EFL---------------') ---> 94 A,B,C,D = ABCD_start_end(Lens,start_surface,end_surface) 95 EFL = -1/C 96 print('Rear Focal Length f\':',-1/C) /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/first_order_tools.pyc in ABCD_start_end(Lens, start_surface, end_surface) 75 # print i 76 # print '--------------------------------' ---> 77 A,B,C,D = ABCD(RT_matrix) 78 return A,B,C,D 79 /home/nbuser/anaconda2_501/lib/python2.7/site-packages/opticspy/ray_tracing/first_order_tools.pyc in ABCD(matrix_list) 38 output: ABCD matrix 39 ''' ---> 40 M = matrix_list.pop() 41 while matrix_list: 42 M = __np__.dot(M,matrix_list.pop()) IndexError: pop from empty list
dict_list = trace.trace_draw_ray(New_Lens)
draw.draw_system(New_Lens)