Skip to content

Commit

Permalink
Added 18 analysis functions, 5 helper functions
Browse files Browse the repository at this point in the history
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()
  • Loading branch information
indranilsinharoy committed Jul 14, 2014
1 parent b3ddbee commit 652174d
Show file tree
Hide file tree
Showing 12 changed files with 2,487 additions and 705 deletions.
4 changes: 2 additions & 2 deletions Examples/Scripts/beamFileWrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@
#(nx, ny) = im.size
(nx, ny) = (64, 64)

#
Ex_real = [[0 for x in range(nx)] for y in range(ny)]
Ex_imag = [[0 for x in range(nx)] for y in range(ny)]
Ey_real = [[0 for x in range(nx)] for y in range(ny)]
Ey_imag = [[0 for x in range(nx)] for y in range(ny)]

for i in range(ny):
for j in range(nx):
Ex_real[i][nx-j-1] = pix[i, j]
#print(pix[i,j])
Ex_real[nx-j-1][i] = pix[i, j]

n=(nx,ny)
efield = (Ex_real, Ex_imag, Ey_real, Ey_imag)
Expand Down
2 changes: 1 addition & 1 deletion Examples/Scripts/searchLargestHiatusLens.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def find(self):
textFileName = exampleDirectory + '\\' + "searchSpecAttr_Prescription.txt"

#Get the Hiatus for the lens design
hiatus = ln.zCalculateHiatus(textFileName,keepFile=False)
hiatus = ln.zGetHiatus(textFileName, keepFile=False)

if hiatus > HIATUS_UPPER_LIMIT:
continue
Expand Down
12 changes: 9 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

##### Current revision:

0.7.7 (Last significant update on 06/21/2014)
0.8.0 (Last significant update on 07/13/2014)

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

Expand Down Expand Up @@ -33,15 +33,21 @@ print("Hello Zemax version: ", link.zGetVersion())
link.close()
```

You may also see few more examples [here](http://nbviewer.ipython.org/github/indranilsinharoy/PyZDDE/tree/master/Examples/).
#### More examples

You may see few examples [here](http://nbviewer.ipython.org/github/indranilsinharoy/PyZDDE/tree/master/Examples/).

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.


#### Features

* Functions for using all "data items" defined in Zemax manual
* Supports both Python 2.7 and Python 3.3/3.4
* Supports both Unicode and extended ascii text
* 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()`
* 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()`
* Special functions for better interactive use with IPython notebooks. Examples include `ipzCaptureWindow()`, `ipzGetFirst()`, `ipzGetPupil()`, `ipzGetSystemAper()`, `ipzGetTextWindow()`
* Quick generation of few simple optical systems (see `pyzdde.systems` module)


#### Overview
Expand Down
4 changes: 2 additions & 2 deletions Test/pyZDDEunittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Licence: MIT License
# This file is subject to the terms and conditions of the MIT License.
# For further details, please refer to LICENSE.txt
# Revision: 0.7.7
# Revision: 0.8.0
#-------------------------------------------------------------------------------
from __future__ import division
from __future__ import print_function
Expand Down Expand Up @@ -55,7 +55,7 @@ def setUp(self):

def tearDown(self):
# Tear down unit test
if self.link0.connection:
if self.link0._connection:
self.link0.zDDEClose()
else:
print("Server was already terminated")
Expand Down
38 changes: 38 additions & 0 deletions ZMXFILES/Information.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
return phase data in POP analysis


RESET_SETTINGS_FFTPSF.CFG
-------------------------
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
return FFT PSF analysis


RESET_SETTINGS_FFTPSFCS.CFG
---------------------------
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
return FFT PSF Cross section analysis


RESET_SETTINGS_HUYGENSPSF.CFG
-----------------------------
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
return Huygens PSF analysis


RESET_SETTINGS_HUYGENSPSFCS.CFG
-------------------------------
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
return Huygens PSF Cross section analysis

RESET_SETTINGS_FFTMTF.CFG
-------------------------
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
return FFT MTF analysis

RESET_SETTINGS_HUYGENSMTF.CFG
-----------------------------
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
return FFT MTF analysis

RESET_SETTINGS_IMGSIM.CFG
-------------------------
most basic settings file (created using "reset" on "LENS.ZMX" lens file) to
return image simulation analysis

Unit-test files
***************

Expand Down
2 changes: 1 addition & 1 deletion pyzdde/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Licence: MIT License
# This file is subject to the terms and conditions of the MIT License.
# For further details, please refer to LICENSE.txt
# Revision: 0.7.6
# Revision: 0.8.0
#-------------------------------------------------------------------------------
from os import path as _path
import sys as _sys
Expand Down
6 changes: 3 additions & 3 deletions pyzdde/ddeclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Copyright: (c) David Naylor
# Licence: New BSD license (Please see the file Notice.txt for further details)
# Website: http://code.activestate.com/recipes/577654-dde-client/
# Revision: 0.7.6
# Revision: 0.8.0
#-------------------------------------------------------------------------------
from __future__ import print_function
import sys
Expand Down Expand Up @@ -212,10 +212,10 @@ def Request(self, item, timeout=None):
try:
reply = self.ddec.request(item, int(timeout*1000)) # convert timeout into milliseconds
except DDEError:
err_str = sys.exc_info()[1]
err_str = str(sys.exc_info()[1])
error = err_str[err_str.find('err=')+4:err_str.find('err=')+10]
if error == hex(DMLERR_DATAACKTIMEOUT):
print("Timeout reached. Please use a higher timeout.\n")
print("TIMEOUT REACHED. Please use a higher timeout.\n")
return reply

def RequestArrayTrace(self, ddeRayData, timeout=None):
Expand Down
149 changes: 149 additions & 0 deletions pyzdde/systems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
#-------------------------------------------------------------------------------
# Name: systems.py
# Purpose: Simple optical systems for quick setup with PyZDDE.
# Copyright: (c) Indranil Sinharoy, Southern Methodist University, 2012 - 2014
# Licence: MIT License
# This file is subject to the terms and conditions of the MIT License.
# For further details, please refer to LICENSE.txt
# Revision: 0.8.0
#-------------------------------------------------------------------------------
"""simple optical systems for quick setup with PyZDDE & Zemax. The docstring
examples assume that PyZDDe is imported as ``import pyzdde.zdde as pyz``,
a PyZDDE communication object is then created as ``ln = pyz.createLink()``
or ``ln = pyz.PyZDDE(); ln.zDDEInit()`` and ``systems`` (this module) is
imported as ``import pyzdde.systems as optsys``
"""
from __future__ import division
from __future__ import print_function

def zMakeIdealThinLens(ddeLn, fl=50, fn=5, stop_pos=0, stop_shift=0, opd_mode=1,
zmx_mode=0):
"""Creates an ideal thin lens of the given specification consisting of
a STOP and a PARAXIAL surface in the zemax server.
Parameters
----------
ddeLn : object
pyzdde object
fl : float, optional
focal length (measured in air of unity index) in lens units
fn : float, optional
f-number (image space f/#)
stop_pos : integer (0/1), optional
use 0 to place STOP before (to the left of) the paraxial
surface, 1 to place STOP after (to the right)
stop_shift : integer, optional
axial distance between STOP and paraxial surface
opd_mode : integer (0, 1, 2 or 3), optional
the OPD mode, which indicates how Zemax should calculate the
optical path difference for rays refracted by the paraxial lens.
* ``opd_mode=0`` is fast and accurate if the aberrations are not
severe. Zemax uses parabasal ray tracing in this mode.
* ``opd_mode=1`` is the most accurate.
* ``opd_mode=2`` assumes that the lens is used at infinite
conjugates.
* ``opd_mode=3`` is similar to ``opd_mode=0``, except that zemax
traces paraxial rays instead of paraxial rays.
zmx_mode : integer (0, 1, or 2), optional
zemax mode. 0 for sequential, 1 for hybrid, 2 for mixed. Currently
ignored.
Returns
-------
None
Examples
--------
>>> import pyzdde.zdde as pyz
>>> ln = pyz.createLink()
>>> optsys.zMakeIdealThinLens(ln)
>>> optsys.zMakeIdealThinLens(ln, fl=100, fn=5, opd_mode=0)
>>> optsys.zMakeIdealThinLens(ln, stop_shift=5)
>>> optsys.zMakeIdealThinLens(ln, stop_pos=1, stop_shift=5)
Notes
-----
1. For more information see "Paraxial" under "Sequential surface type
definitions" in the Zemax manual.
2. Use ``ln.zPushLens(1)`` update lens into the LDE
"""
if stop_pos < 0 or stop_pos > 1:
raise ValueError("Expecting stop_pos to be either 0 or 1")
epd = fl/fn
stop_surf = 2 if stop_pos else 1
para_surf = 1 if stop_pos else 2
ddeLn.zNewLens()
ddeLn.zInsertSurface(para_surf)
ddeLn.zSetSystemAper(aType=0, stopSurf=stop_surf, apertureValue=epd)
if stop_pos:
ddeLn.zSetSurfaceData(para_surf, code=3, value=stop_shift)
else:
ddeLn.zSetSurfaceData(stop_surf, code=3, value=stop_shift)
ddeLn.zSetSurfaceData(para_surf, code=0, value='PARAXIAL')
ddeLn.zSetSurfaceParameter(para_surf, parameter=1, value=fl) # focallength
ddeLn.zSetSurfaceParameter(para_surf, parameter=2, value=opd_mode)
surf_beforeIMA, thickness_code = 2, 1
solve_type, height, pupil_zone = 2, 0, 0 # Marginal ray height
ddeLn.zSetSolve(surf_beforeIMA, thickness_code, solve_type, height, pupil_zone)

def zMakeIdealCollimator(ddeLn, fl=50, fn=5, ima_dist=10, opd_mode=1, zmx_mode=0):
"""Creates a collimator using an ideal thin lens of the given
specification.
The model consists of just 3 surfaces in the LDE -- OBJ, STOP
(paraxial surface) and IMA plane.
Parameters
----------
ddeLn : object
pyzdde object
fl : float, optional
focal length (measured in air of unity index) in lens units
fn : float, optional
f-number (image space f/#)
ima_dist : integer, optional
axial distance the paraxial surface and IMA (observation plane)
opd_mode : integer (0, 1, 2 or 3), optional
the OPD mode, which indicates how Zemax should calculate the
optical path difference for rays refracted by the paraxial lens.
* ``opd_mode=0`` is fast and accurate if the aberrations are not
severe. Zemax uses parabasal ray tracing in this mode.
* ``opd_mode=1`` is the most accurate.
* ``opd_mode=2`` assumes that the lens is used at infinite
conjugates.
* ``opd_mode=3`` is similar to ``opd_mode=0``, except that zemax
traces paraxial rays instead of paraxial rays.
zmx_mode : integer (0, 1, or 2), optional
zemax mode. 0 for sequential, 1 for hybrid, 2 for mixed. Currently
ignored.
Returns
-------
None
Examples
--------
>>> optsys.zMakeIdealCollimator(ln)
>>> optsys.zMakeIdealCollimator(ln, fl=100, fn=5, opd_mode=0)
>>> optsys.zMakeIdealThinLens(ln, stop_shift=5)
>>> optsys.zMakeIdealThinLens(ln, stop_pos=1, stop_shift=5)
Notes
-----
1. For more information see "Paraxial" under "Sequential surface type
definitions" in the Zemax manual.
2. Use ``ln.zPushLens(1)`` update lens into the LDE
"""
epd = fl/fn
ddeLn.zNewLens()
ddeLn.zSetSystemAper(aType=0, stopSurf=1, apertureValue=epd)
ddeLn.zSetSystemProperty(code=18, value1=1) # Afocal Image Space
ddeLn.zSetSurfaceData(surfaceNumber=0, code=3, value=fl)
ddeLn.zSetSurfaceData(surfaceNumber=1, code=0, value='PARAXIAL')
ddeLn.zSetSurfaceData(surfaceNumber=1, code=3, value=ima_dist)
ddeLn.zSetSurfaceParameter(surfaceNumber=1, parameter=1, value=fl) # focallength
ddeLn.zSetSurfaceParameter(surfaceNumber=1, parameter=2, value=opd_mode)
2 changes: 1 addition & 1 deletion pyzdde/utils/pyzddeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Licence: MIT License
# This file is subject to the terms and conditions of the MIT License.
# For further details, please refer to LICENSE.txt
# Revision: 0.7.7
# Revision: 0.8.0
#-------------------------------------------------------------------------------
from __future__ import print_function

Expand Down
5 changes: 2 additions & 3 deletions pyzdde/zcodes/zemaxbuttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Licence: MIT License
# This file is subject to the terms and conditions of the MIT License.
# For further details, please refer to LICENSE.txt
# Revision: 0.7.7
# Revision: 0.8.0
#-------------------------------------------------------------------------------
from __future__ import print_function
import re as _re
Expand Down Expand Up @@ -128,8 +128,7 @@ class _Buttons(object):
"MFE": "Merit Function Editor",
"Mfl": "Merit Function List",
"Mfo": "Make Focal",
"Mgm": "Geometric MTF Map",
"Mtf": "Modulation TF",
"Mtf": "Modulation Transfer Function (FFT MTF)",
"Mth": "MTF vs. Field",
"NCE": "Non-Sequential Editor",
"New": "New File",
Expand Down
4 changes: 2 additions & 2 deletions pyzdde/zcodes/zemaxoperands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# Licence: MIT License
# This file is subject to the terms and conditions of the MIT License.
# For further details, please refer to LICENSE.txt
# Revision: 0.7.7
# Revision: 0.8.0
#-------------------------------------------------------------------------------
from __future__ import print_function
import re as _re
Expand Down Expand Up @@ -54,7 +54,7 @@ class _Operands(object):
"non-paraxial systems"),
"ATAN": "Arctangent of the value of the operand defined by Op#.",
"AXCL": ("Axial color, measured in lens units for focal systems and diopters "
"for afocal systems. This is the image separation between the two"
"for afocal systems. This is the image separation between the two"
"wavelengths defined by Wave1 and Wave2"),
"BFSD": "Best Fit Sphere (BFS) data.",
"BIOC": ("Biocular Convergence. Returns the convergence between two eye "
Expand Down
Loading

0 comments on commit 652174d

Please sign in to comment.