Skip to content

Commit 652174d

Browse files
Added 18 analysis functions, 5 helper functions
Analysis Functions: zGetPSFCrossSec(), zModifyFFTPSFSettings() zSetFFTPSFCrossSecSettings(), zSetHuygensPSFCrossSecSettings(), zModifyHuygensPSFCrossSecSettings(), zGetPSF(), zSetFFTPSFSettings(), zModifyFFTPSFSettings(), zSetHuygensPSFSettings(), zModifyHuygensPSFSettings(), zGetMTF(), zSetFFTMTFSettings(), zModifyFFTMTFSettings(), zSetHuygensMTFSettings(), zModifyHuygensMTFSettings(), zGetImageSimulation(), zSetImageSimulationSettings(), zModifyImageSimulationSettings(), Other functions added: zGetNumField(), zGetNumSurf(), zGetNumWave(), zGetImageSpaceNA(), zGetIndexPrimWave(), Function name changes: zCalculateHiatus() to zGetHiatus()
1 parent b3ddbee commit 652174d

File tree

12 files changed

+2487
-705
lines changed

12 files changed

+2487
-705
lines changed

Examples/Scripts/beamFileWrite.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@
2929
#(nx, ny) = im.size
3030
(nx, ny) = (64, 64)
3131

32+
#
3233
Ex_real = [[0 for x in range(nx)] for y in range(ny)]
3334
Ex_imag = [[0 for x in range(nx)] for y in range(ny)]
3435
Ey_real = [[0 for x in range(nx)] for y in range(ny)]
3536
Ey_imag = [[0 for x in range(nx)] for y in range(ny)]
3637

3738
for i in range(ny):
3839
for j in range(nx):
39-
Ex_real[i][nx-j-1] = pix[i, j]
40-
#print(pix[i,j])
40+
Ex_real[nx-j-1][i] = pix[i, j]
4141

4242
n=(nx,ny)
4343
efield = (Ex_real, Ex_imag, Ey_real, Ey_imag)

Examples/Scripts/searchLargestHiatusLens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ def find(self):
248248
textFileName = exampleDirectory + '\\' + "searchSpecAttr_Prescription.txt"
249249

250250
#Get the Hiatus for the lens design
251-
hiatus = ln.zCalculateHiatus(textFileName,keepFile=False)
251+
hiatus = ln.zGetHiatus(textFileName, keepFile=False)
252252

253253
if hiatus > HIATUS_UPPER_LIMIT:
254254
continue

README.markdown

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
##### Current revision:
66

7-
0.7.7 (Last significant update on 06/21/2014)
7+
0.8.0 (Last significant update on 07/13/2014)
88

99
Brief change-log is available in the [News and Updates](https://github.com/indranilsinharoy/PyZDDE/wiki/News-and-updates) page.
1010

@@ -33,15 +33,21 @@ print("Hello Zemax version: ", link.zGetVersion())
3333
link.close()
3434
```
3535

36-
You may also see few more examples [here](http://nbviewer.ipython.org/github/indranilsinharoy/PyZDDE/tree/master/Examples/).
36+
#### More examples
37+
38+
You may see few examples [here](http://nbviewer.ipython.org/github/indranilsinharoy/PyZDDE/tree/master/Examples/).
39+
40+
Also, the repository [Intro2LensDesignByGeary](https://github.com/indranilsinharoy/Intro2LensDesignByGeary) contains notes from few chapters of the book "Introduction to Lens Design," by Joseph M. Geary, in the form of IPython notebooks.
41+
3742

3843
#### Features
3944

4045
* Functions for using all "data items" defined in Zemax manual
4146
* Supports both Python 2.7 and Python 3.3/3.4
4247
* Supports both Unicode and extended ascii text
43-
* Over 20 additional functions for more efficient use (more will be added in future). Examples include `zSetTimeout()`, `zExecuteZPLMacro()`, `zSpiralSpot()`, `zGetSeidelAberration()`, `zSetFieldTuple()`, `zGetFieldTuple()`, `zSetWaveTuple()`, `zGetWaveTuple()`, `zCalculateHiatus()`, `zGetPupilMagnification()`, `zGetPOP()`, `zSetPOPSettings()`, `zModifyPOPSettings()`
48+
* Over 25 additional functions for more efficient use (more will be added in future). Examples include `zSetTimeout()`, `zExecuteZPLMacro()`, `zSpiralSpot()`, `zGetSeidelAberration()`, `zSetFieldTuple()`, `zGetFieldTuple()`, `zSetWaveTuple()`, `zGetWaveTuple()`, `zCalculateHiatus()`, `zGetPupilMagnification()`, `zGetPOP()`, `zSetPOPSettings()`, `zModifyPOPSettings()`, `zGetPSF()`, `zGetPSFCrossSec()`, `zGetMTF()`, `zGetImageSimulation()`
4449
* Special functions for better interactive use with IPython notebooks. Examples include `ipzCaptureWindow()`, `ipzGetFirst()`, `ipzGetPupil()`, `ipzGetSystemAper()`, `ipzGetTextWindow()`
50+
* Quick generation of few simple optical systems (see `pyzdde.systems` module)
4551

4652

4753
#### Overview

Test/pyZDDEunittest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Licence: MIT License
77
# This file is subject to the terms and conditions of the MIT License.
88
# For further details, please refer to LICENSE.txt
9-
# Revision: 0.7.7
9+
# Revision: 0.8.0
1010
#-------------------------------------------------------------------------------
1111
from __future__ import division
1212
from __future__ import print_function
@@ -55,7 +55,7 @@ def setUp(self):
5555

5656
def tearDown(self):
5757
# Tear down unit test
58-
if self.link0.connection:
58+
if self.link0._connection:
5959
self.link0.zDDEClose()
6060
else:
6161
print("Server was already terminated")

ZMXFILES/Information.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,44 @@ most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
2626
return phase data in POP analysis
2727

2828

29+
RESET_SETTINGS_FFTPSF.CFG
30+
-------------------------
31+
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
32+
return FFT PSF analysis
33+
34+
35+
RESET_SETTINGS_FFTPSFCS.CFG
36+
---------------------------
37+
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
38+
return FFT PSF Cross section analysis
39+
40+
41+
RESET_SETTINGS_HUYGENSPSF.CFG
42+
-----------------------------
43+
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
44+
return Huygens PSF analysis
45+
46+
47+
RESET_SETTINGS_HUYGENSPSFCS.CFG
48+
-------------------------------
49+
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
50+
return Huygens PSF Cross section analysis
51+
52+
RESET_SETTINGS_FFTMTF.CFG
53+
-------------------------
54+
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
55+
return FFT MTF analysis
56+
57+
RESET_SETTINGS_HUYGENSMTF.CFG
58+
-----------------------------
59+
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
60+
return FFT MTF analysis
61+
62+
RESET_SETTINGS_IMGSIM.CFG
63+
-------------------------
64+
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
65+
return image simulation analysis
66+
2967
Unit-test files
3068
***************
3169

pyzdde/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Licence: MIT License
66
# This file is subject to the terms and conditions of the MIT License.
77
# For further details, please refer to LICENSE.txt
8-
# Revision: 0.7.6
8+
# Revision: 0.8.0
99
#-------------------------------------------------------------------------------
1010
from os import path as _path
1111
import sys as _sys

pyzdde/ddeclient.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Copyright: (c) David Naylor
1111
# Licence: New BSD license (Please see the file Notice.txt for further details)
1212
# Website: http://code.activestate.com/recipes/577654-dde-client/
13-
# Revision: 0.7.6
13+
# Revision: 0.8.0
1414
#-------------------------------------------------------------------------------
1515
from __future__ import print_function
1616
import sys
@@ -212,10 +212,10 @@ def Request(self, item, timeout=None):
212212
try:
213213
reply = self.ddec.request(item, int(timeout*1000)) # convert timeout into milliseconds
214214
except DDEError:
215-
err_str = sys.exc_info()[1]
215+
err_str = str(sys.exc_info()[1])
216216
error = err_str[err_str.find('err=')+4:err_str.find('err=')+10]
217217
if error == hex(DMLERR_DATAACKTIMEOUT):
218-
print("Timeout reached. Please use a higher timeout.\n")
218+
print("TIMEOUT REACHED. Please use a higher timeout.\n")
219219
return reply
220220

221221
def RequestArrayTrace(self, ddeRayData, timeout=None):

pyzdde/systems.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
#-------------------------------------------------------------------------------
2+
# Name: systems.py
3+
# Purpose: Simple optical systems for quick setup with PyZDDE.
4+
# Copyright: (c) Indranil Sinharoy, Southern Methodist University, 2012 - 2014
5+
# Licence: MIT License
6+
# This file is subject to the terms and conditions of the MIT License.
7+
# For further details, please refer to LICENSE.txt
8+
# Revision: 0.8.0
9+
#-------------------------------------------------------------------------------
10+
"""simple optical systems for quick setup with PyZDDE & Zemax. The docstring
11+
examples assume that PyZDDe is imported as ``import pyzdde.zdde as pyz``,
12+
a PyZDDE communication object is then created as ``ln = pyz.createLink()``
13+
or ``ln = pyz.PyZDDE(); ln.zDDEInit()`` and ``systems`` (this module) is
14+
imported as ``import pyzdde.systems as optsys``
15+
"""
16+
from __future__ import division
17+
from __future__ import print_function
18+
19+
def zMakeIdealThinLens(ddeLn, fl=50, fn=5, stop_pos=0, stop_shift=0, opd_mode=1,
20+
zmx_mode=0):
21+
"""Creates an ideal thin lens of the given specification consisting of
22+
a STOP and a PARAXIAL surface in the zemax server.
23+
24+
Parameters
25+
----------
26+
ddeLn : object
27+
pyzdde object
28+
fl : float, optional
29+
focal length (measured in air of unity index) in lens units
30+
fn : float, optional
31+
f-number (image space f/#)
32+
stop_pos : integer (0/1), optional
33+
use 0 to place STOP before (to the left of) the paraxial
34+
surface, 1 to place STOP after (to the right)
35+
stop_shift : integer, optional
36+
axial distance between STOP and paraxial surface
37+
opd_mode : integer (0, 1, 2 or 3), optional
38+
the OPD mode, which indicates how Zemax should calculate the
39+
optical path difference for rays refracted by the paraxial lens.
40+
41+
* ``opd_mode=0`` is fast and accurate if the aberrations are not
42+
severe. Zemax uses parabasal ray tracing in this mode.
43+
* ``opd_mode=1`` is the most accurate.
44+
* ``opd_mode=2`` assumes that the lens is used at infinite
45+
conjugates.
46+
* ``opd_mode=3`` is similar to ``opd_mode=0``, except that zemax
47+
traces paraxial rays instead of paraxial rays.
48+
49+
zmx_mode : integer (0, 1, or 2), optional
50+
zemax mode. 0 for sequential, 1 for hybrid, 2 for mixed. Currently
51+
ignored.
52+
53+
Returns
54+
-------
55+
None
56+
57+
Examples
58+
--------
59+
>>> import pyzdde.zdde as pyz
60+
>>> ln = pyz.createLink()
61+
>>> optsys.zMakeIdealThinLens(ln)
62+
>>> optsys.zMakeIdealThinLens(ln, fl=100, fn=5, opd_mode=0)
63+
>>> optsys.zMakeIdealThinLens(ln, stop_shift=5)
64+
>>> optsys.zMakeIdealThinLens(ln, stop_pos=1, stop_shift=5)
65+
66+
Notes
67+
-----
68+
1. For more information see "Paraxial" under "Sequential surface type
69+
definitions" in the Zemax manual.
70+
2. Use ``ln.zPushLens(1)`` update lens into the LDE
71+
"""
72+
if stop_pos < 0 or stop_pos > 1:
73+
raise ValueError("Expecting stop_pos to be either 0 or 1")
74+
epd = fl/fn
75+
stop_surf = 2 if stop_pos else 1
76+
para_surf = 1 if stop_pos else 2
77+
ddeLn.zNewLens()
78+
ddeLn.zInsertSurface(para_surf)
79+
ddeLn.zSetSystemAper(aType=0, stopSurf=stop_surf, apertureValue=epd)
80+
if stop_pos:
81+
ddeLn.zSetSurfaceData(para_surf, code=3, value=stop_shift)
82+
else:
83+
ddeLn.zSetSurfaceData(stop_surf, code=3, value=stop_shift)
84+
ddeLn.zSetSurfaceData(para_surf, code=0, value='PARAXIAL')
85+
ddeLn.zSetSurfaceParameter(para_surf, parameter=1, value=fl) # focallength
86+
ddeLn.zSetSurfaceParameter(para_surf, parameter=2, value=opd_mode)
87+
surf_beforeIMA, thickness_code = 2, 1
88+
solve_type, height, pupil_zone = 2, 0, 0 # Marginal ray height
89+
ddeLn.zSetSolve(surf_beforeIMA, thickness_code, solve_type, height, pupil_zone)
90+
91+
def zMakeIdealCollimator(ddeLn, fl=50, fn=5, ima_dist=10, opd_mode=1, zmx_mode=0):
92+
"""Creates a collimator using an ideal thin lens of the given
93+
specification.
94+
95+
The model consists of just 3 surfaces in the LDE -- OBJ, STOP
96+
(paraxial surface) and IMA plane.
97+
98+
Parameters
99+
----------
100+
ddeLn : object
101+
pyzdde object
102+
fl : float, optional
103+
focal length (measured in air of unity index) in lens units
104+
fn : float, optional
105+
f-number (image space f/#)
106+
ima_dist : integer, optional
107+
axial distance the paraxial surface and IMA (observation plane)
108+
opd_mode : integer (0, 1, 2 or 3), optional
109+
the OPD mode, which indicates how Zemax should calculate the
110+
optical path difference for rays refracted by the paraxial lens.
111+
112+
* ``opd_mode=0`` is fast and accurate if the aberrations are not
113+
severe. Zemax uses parabasal ray tracing in this mode.
114+
* ``opd_mode=1`` is the most accurate.
115+
* ``opd_mode=2`` assumes that the lens is used at infinite
116+
conjugates.
117+
* ``opd_mode=3`` is similar to ``opd_mode=0``, except that zemax
118+
traces paraxial rays instead of paraxial rays.
119+
120+
zmx_mode : integer (0, 1, or 2), optional
121+
zemax mode. 0 for sequential, 1 for hybrid, 2 for mixed. Currently
122+
ignored.
123+
124+
Returns
125+
-------
126+
None
127+
128+
Examples
129+
--------
130+
>>> optsys.zMakeIdealCollimator(ln)
131+
>>> optsys.zMakeIdealCollimator(ln, fl=100, fn=5, opd_mode=0)
132+
>>> optsys.zMakeIdealThinLens(ln, stop_shift=5)
133+
>>> optsys.zMakeIdealThinLens(ln, stop_pos=1, stop_shift=5)
134+
135+
Notes
136+
-----
137+
1. For more information see "Paraxial" under "Sequential surface type
138+
definitions" in the Zemax manual.
139+
2. Use ``ln.zPushLens(1)`` update lens into the LDE
140+
"""
141+
epd = fl/fn
142+
ddeLn.zNewLens()
143+
ddeLn.zSetSystemAper(aType=0, stopSurf=1, apertureValue=epd)
144+
ddeLn.zSetSystemProperty(code=18, value1=1) # Afocal Image Space
145+
ddeLn.zSetSurfaceData(surfaceNumber=0, code=3, value=fl)
146+
ddeLn.zSetSurfaceData(surfaceNumber=1, code=0, value='PARAXIAL')
147+
ddeLn.zSetSurfaceData(surfaceNumber=1, code=3, value=ima_dist)
148+
ddeLn.zSetSurfaceParameter(surfaceNumber=1, parameter=1, value=fl) # focallength
149+
ddeLn.zSetSurfaceParameter(surfaceNumber=1, parameter=2, value=opd_mode)

pyzdde/utils/pyzddeutils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Licence: MIT License
77
# This file is subject to the terms and conditions of the MIT License.
88
# For further details, please refer to LICENSE.txt
9-
# Revision: 0.7.7
9+
# Revision: 0.8.0
1010
#-------------------------------------------------------------------------------
1111
from __future__ import print_function
1212

pyzdde/zcodes/zemaxbuttons.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Licence: MIT License
77
# This file is subject to the terms and conditions of the MIT License.
88
# For further details, please refer to LICENSE.txt
9-
# Revision: 0.7.7
9+
# Revision: 0.8.0
1010
#-------------------------------------------------------------------------------
1111
from __future__ import print_function
1212
import re as _re
@@ -128,8 +128,7 @@ class _Buttons(object):
128128
"MFE": "Merit Function Editor",
129129
"Mfl": "Merit Function List",
130130
"Mfo": "Make Focal",
131-
"Mgm": "Geometric MTF Map",
132-
"Mtf": "Modulation TF",
131+
"Mtf": "Modulation Transfer Function (FFT MTF)",
133132
"Mth": "MTF vs. Field",
134133
"NCE": "Non-Sequential Editor",
135134
"New": "New File",

0 commit comments

Comments
 (0)