In [1]:
# imports
from __future__ import division
import os, sys, time
import numpy as np
import matplotlib.pyplot as plt
import pyzdde.zdde as pyz
import pyzdde.arraytrace as at
%matplotlib inline
In [2]:
plotDir = os.path.join('C:\Users\CAD User\Desktop\lsstzemax\data', 'lsst_defocus')
if not os.path.isdir(plotDir): os.mkdir(plotDir)
In [3]:
ln = pyz.createLink() # create a DDE link object for communication
In [4]:
zfile = os.path.join('C:\Users\CAD User\Desktop\lsstzemax\zemax', 'lsst_defocus.zmx')
In [5]:
ln.zLoadFile(zfile)
Out[5]:
In [6]:
# Surfaces in the sequential lens data editor
ln.ipzGetLDE()
In [7]:
# General System properties
ln.zGetSystem()
Out[7]:
In [8]:
# Paraxial/ first order properties of the system
ln.zGetFirst()
Out[8]:
In [9]:
# duplicate of zGetFirst() for use in the notebook
ln.ipzGetFirst()
In [10]:
# ... another example is the zGetSystemAper() that returns information about the aperture.
# The aperture type is retuned as a code which we might not remember always ...
ln.zGetSystemAper()
Out[10]:
In [11]:
# ...with the duplicate, ipzGetSystemAper(), we can immediately know that
# the aperture type is the Entrance Pupil Diameter (EPD)
ln.ipzGetSystemAper()
In [12]:
# information about the field definition
ln.ipzGetFieldData()
In [13]:
hx = 0.0
hy = 0.0
spirals = 10 #100
rays = 600 #6000
(xu,yu,zu,intensityu) = ln.zSpiralSpot(hx,hy,1,spirals,rays)
(xg,yg,zg,intensityg) = ln.zSpiralSpot(hx,hy,2,spirals,rays)
(xr,yr,zr,intensityr) = ln.zSpiralSpot(hx,hy,3,spirals,rays)
(xi,yi,zi,intensityi) = ln.zSpiralSpot(hx,hy,4,spirals,rays)
(xz,yz,zz,intensityz) = ln.zSpiralSpot(hx,hy,5,spirals,rays)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.set_aspect('equal')
ax.scatter(xu,yu,s=5,c='blue',linewidth=0.35,zorder=20)
ax.scatter(xg,yg,s=5,c='green',linewidth=0.35,zorder=21)
ax.scatter(xr,yr,s=5,c='red',linewidth=0.35,zorder=22)
ax.scatter(xi,yi,s=5,c='magenta',linewidth=0.35,zorder=23)
ax.scatter(xz,yz,s=5,c='yellow',linewidth=0.35,zorder=24)
ax.set_xlabel('x');ax.set_ylabel('y')
fig.suptitle('Spiral Spot')
ax.grid(color='lightgray', linestyle='-', linewidth=1)
ax.ticklabel_format(scilimits=(-2,2))
plt.show()
In [14]:
def many_spots(ln, hxs,hys,wavenum=1,spirals=10,rays=600):
fovxs, fovys, xs, ys = np.array([]), np.array([]), np.array([]), np.array([])
for hx, hy in zip(hxs,hys):
(x,y,z,intensity) = ln.zSpiralSpot(hx,hy,wavenum,spirals,rays)
fovxs, fovys, xs, ys = np.append(fovxs,hx*np.ones((len(x),1))), np.append(fovys,hy*np.ones((len(y),1))), np.append(xs,x), np.append(ys,y)
return fovxs, fovys, xs, ys
In [15]:
hxs, hys = np.linspace(-1.75,1.75,5), np.linspace(-1.75,1.75,5)
[HXs,HYs] = np.meshgrid(hxs,hys)
hxs, hys = HXs.flatten(), HYs.flatten()
fovxu, fovyu, xu, yu = many_spots(ln, hxs, hys, wavenum=1, spirals=10, rays=600)
fovxg, fovyg, xg, yg = many_spots(ln, hxs, hys, wavenum=2, spirals=10, rays=600)
fovxr, fovyt, xr, yr = many_spots(ln, hxs, hys, wavenum=3, spirals=10, rays=600)
fovxi, fovyi, xi, yi = many_spots(ln, hxs, hys, wavenum=4, spirals=10, rays=600)
fovxz, fovyz, xz, yz = many_spots(ln, hxs, hys, wavenum=5, spirals=10, rays=600)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.set_aspect('equal')
ax.scatter(xu,yu,s=5,c='blue',linewidth=0.35,zorder=20)
ax.scatter(xg,yg,s=5,c='green',linewidth=0.35,zorder=21)
ax.scatter(xr,yr,s=5,c='red',linewidth=0.35,zorder=22)
ax.scatter(xi,yi,s=5,c='magenta',linewidth=0.35,zorder=23)
ax.scatter(xz,yz,s=5,c='yellow',linewidth=0.35,zorder=24)
ax.set_xlabel('x');ax.set_ylabel('y')
fig.suptitle('Spiral Spot')
ax.grid(color='lightgray', linestyle='-', linewidth=1)
ax.ticklabel_format(scilimits=(-2,2))
plt.show()
In [16]:
hxs, hys = np.linspace(-1.75,1.75,10), np.linspace(-1.75,1.75,10)
[HXs,HYs] = np.meshgrid(hxs,hys)
hxs, hys = HXs.flatten(), HYs.flatten()
fovx, fovy, x, y = many_spots(ln, hxs, hys, wavenum=1, spirals=10, rays=60)
fov = np.sqrt(fovx**2 + fovy**2)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111)
ax.set_aspect('equal')
plt.scatter(x,y,s=5,c=fov,linewidth=0.35,zorder=21)
plt.xlabel('x [mm]')
plt.ylabel('y [mm]')
cbar = plt.colorbar()
cbar.set_label('FOV [degrees]')
plt.grid(color='lightgray', linestyle='-', linewidth=1)
#ax.ticklabel_format(scilimits=(-2,2))
plt.axis([-600,600,-600,600])
plt.show()
In [17]:
filename = os.path.join(plotDir,'spots.dat')
fid = open(filename,'w')
for a,b,c,d in zip(fovx,fovy,x,y):
fid.write('%.5f %.5f %.5f %.5f\n'%(a,b,c,d))
fid.close()