xzos / pyzdde Goto Github PK
View Code? Open in Web Editor NEWZemax/ OpticStudio Extension using Python
License: MIT License
Zemax/ OpticStudio Extension using Python
License: MIT License
It is highly desirable to have a function for doing bulk ray tracing. PyZDDE doesn't have such a function.
Hello,
I have recently installed windows 10 (instead of Windows 7) on my PC and had to re-installed Python / Anaconda, which installed the version 3.6 of Python.
Now, I have a problem with py scripts I wrote that used to work with my previous OS/Anaconda version (althouth I do not remember which Anaconda/Python version was installed on my previous setup).
Namely it is the call to
at.zArrayTrace(rd, timeout=5000)
that fails and return an error message.
Any idea if this problem is related to the python / Anaconda version I am using ?
Thanks,
Stephane
This is not really a bug or an immediate problem as the library works as expected. However, it seems that the PyZDDE class is currently more complicated than it needs to be. It should be made simple and elegant. Obviously, when I started coding PyZDDE, I didn't know much Python and hence the complicated class definition. There are some ideas, but currently the real work on it is in the back burner.
if I execute the example beamFileWrite.py the Beamfile is rotated wrongly.
That is probably because zemax sets the origin(0,0) to the left bottom corner and not to the left top as it's done for pixel coordinates normally. Furthermore I suggest to change
Ex_real[i][nx-j-1] = pix[i, j]
into
Ex_real[i][j] = pix[i, j]
missing comma line 3231:
args3 = "{x:1.20f},{y:1.20f},{z:1.20f}".format(x=x,y=y,z=z)
should be:
args3 = "{x:1.20f},{y:1.20f},{z:1.20f},".format(x=x,y=y,z=z)
(simular bugs in zGetPolTraceDirect and zGetPolTrace)
Since the Zernike coefficients are a function of the wavelength and field position, the coefficients do not have any meaning without information about the wavelength and field position in the meta-data (zInfo
) portion of the data returned by zGetZernike()
function. So, the field position and wavelength should also be returned by the function.
Hello,
I have zemax 2009, is it compatible with it?. Thanks very much!
Hi,
I am trying to use zSaveDetector
which gives me error code -2
. I am using a Rectangular detector in NSC mode. Post running a ray trace using zNSCTrace
I use the zSaveDetector
command
ln = pyz.createLink()
ln.zGetRefresh()
zmxfile = os.path.split(ln.zGetFile())[1]
ln.zNSCTrace(1,0,timeout=5000)
ln.zSaveDetector(1,36,location+'sample.ddr')
Hi, sorry to bother you, but I always get timeout errors when trying to run the Hello World mini-example:
from __future__ import print_function
import matplotlib.pyplot as plt # import plotting module
import pyzdde.zdde as pyz # import pyzdde module
ln = pyz.createLink() # DDE link object
print("Hello Zemax version: ", ln.zGetVersion())
ln.close()
produces the error:
TIMEOUT REACHED. Please use a higher timeout.
Hello Zemax version: -998
I suspect this is because I am using a OpticStudio Standard license instead of a professional license, could that be? I have been looking for a while now and didn't find anything concerning those requirements in the PyZDDE manuals or any change logs of Zemax versions for that matter.
My specifications:
Zemax OpticStudio 14.2 Standard
Windows 10 Professional, Version 10.0.17134 Build 17134
Python 3.6 (also tried 3.5.5)
Thanks a lot in advance! Best,
Richard
Dear Indranil, It looks like the people from Zemax added at least two new useful operands since the last version of the pyzdde zemaxoperands.py has been issued. Indeed, The CEHX and CEHY operands allow to directly retrive the x and y position of the centroid of the Huygens PSF for a chosen optical system which can be useful in some cases to consider over the spot centroid (e.g. CENX, CENY). Since pyzdde has been wisely designed, it has been easy to add these two new operands to the list, and you way want to add them to the distribution for other people to use.
Best regards,
Ben
Those lines seem to be broken or they do not match the Zemax Response, fd._make and the length of rs don't match, for n=0 and n>0, this results in a error about the input argument number.
Setting the fields works.
These days i found pyZDDE in github and tried to verify it. It ran OK except for the code line "link.ipzCaptureWindow2('Lay',gamma=0.25)".The ipython notebook was dead with indicating Kernel busy in the upper right. I don't know what's happening.
Hi,
I have some issue when I run a script using PyZDDE multiple times. The first time it works without problems, only the consecutive executions will give an error message. The script stills seems to execute everything, however. Am I maybe missing some commands to close the link properly?
Thanks in advance!
Olf
Here is the scrip I am using:
import pyzdde.zdde as pyz
link = pyz.PyZDDE()
link.zDDEInit()
link.zLoadFile(r'C:\Users\user\test_seq.zmx')
print link.zSetField(1,2,3)
link.zSaveFile(r'C:\Users\user\test_seq_bearbeitet.zmx')
pyz.closeLink()
link.zDDEClose()
Here is the Python console output:
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Imported NumPy 1.8.1, SciPy 0.14.0, Matplotlib 1.3.1
+ guidata 1.6.1, guiqwt 2.3.2
Type "scientific" for more details.
>>> runfile('Z:/projekte/P100223_Conti_3D_HUD/Simulationen/ZemaxPython.py', wdir=r'Z:/projekte/P100223_Conti_3D_HUD/Simulationen')
141013
fieldData(xf=2.0, yf=3.0, wgt=1.0, vdx=0.0, vdy=0.0, vcx=0.0, vcy=0.0, van=0.0)
>>> runfile('Z:/projekte/P100223_Conti_3D_HUD/Simulationen/ZemaxPython.py', wdir=r'Z:/projekte/P100223_Conti_3D_HUD/Simulationen')
UMD has deleted: pyzdde.zcodes.zemaxoperands, pyzdde.config, pyzdde, pyzdde.utils.pyzddeutils, pyzdde.zcodes, pyzdde.ddeclient, pyzdde.utils, pyzdde.zcodes.zemaxbuttons, pyzdde.zdde
Exception TypeError: "'NoneType' object is not callable" in <bound method PyZDDE.__del__ of PyZDDE(appName='', appNum=1, connection=False, macroPath=None)> ignored
141013
fieldData(xf=2.0, yf=3.0, wgt=1.0, vdx=0.0, vdy=0.0, vcx=0.0, vcy=0.0, van=0.0)
>>>
Hello,
Recently I've been experiencing problems using the function zGetTraceArray in order to perform spot plots. The function was working perfectly a few month ago when I wrote the code, though lately the code remains stuck when executing the code, more precisely at line 83 of the arraytrace.py file (e.g. return _arrayTrace(rd, int(timeout)) ). For some reason this piece of code never replies back whatever the timeout I set. I'm not sure why this happens but for some reason the dll remains silent. Have you experienced such a problem ?
All the best,
Ben
I think the default values for zOptimize should be numOfCycles = 0, algorithm=0, since these are the default values if you press enter in the optimization window in Zemax
Functions are listed but lack description on the wiki. Propose filling out the documentation.
The Zemax Documentation for July 8, 2011, page 640 defines some empty bytes in the BeamFiles.
I'd like to know If there is a new specification of zbf-Files which lefts this out. If not I'd change this. (as I did here)
In @CatherineH 's readBeamFile the lines reading the empty bytes from zbf were commented. Why?
Btw: the Bug wasn't found during testing with PyZDDE/Examples/Scripts/beamFileRead/Write.py
as it is in write and load functions... And I'm not sure if zemax would claim it - tomorrow I'll test.
Hello together,
when communicating with Zemax, the method _sendDDEcommand is often called. Usually the answer variable reply contains a byte object (Python 3). However, if an error occurs (e.g. timeout), a string (str) is contained in reply (e.g. '-998'). Then the decode command
reply = reply.decode('ascii').rstrip()
fails.
A solution might be to use the following version of the function:
def _sendDDEcommand(self, cmd, timeout=None):
"""Method to send command to DDE client
"""
global _global_pyver3
reply = self._conversation.Request(cmd, timeout)
if _global_pyver3:
if type(reply) is bytes:
reply = reply.decode('ascii').rstrip()
else:
reply = reply.rstrip()
return reply
However, it might also be, that it is not desired that any string is returned by _conversation.Request.
Cheers
Marc
Hi,
I know the title might sound a bit weird but I have trouble with a python script using pyZDDE giving (only sometimes!) different results for PhysicalOpticsPropagation than Zemax itself. I am not even sure if this is a pyZDDE problem, but maybe someone has encountered something similar already and can help.
So the situation is the following: I have two similar optical setups (Two different zmx-files) in Zemax and I want to find the focus. To do this I have one python script where I specify the zmx-file and use pyZDDE to plot the spot in the image plane for different distances of the image plane from the last surface. Everthing works fine with this script: I get nice 2D-plots, can calculate the spot size and find the focus for both optical systems. However, when I want to reproduce the focal spot in Zemax itself, for one zmx-file (one of the optical systems) the spot is the same, for the other one it is completely different and the image plane has to be shifted approximately 50um to see the focal spot.
I have tried different things like to restart zemax and python, saving or not saving before changing between the two cases but the result is always the same.
Hello,
I start to use the pyzdde library few days ago and I would like to thank you because it's a great job. But I have an issue with the zSetSolve function. When I use it, it raise the following error :
" if data:
UnboundLocalError: local variable 'data' referenced before assignment "
below, I put the way how I call the function :
dataP = [2,0,0.0,-1.0,0] #(solvetype,pickupSurfaceNb,offSet,Scalefactor,column)
dataP[1] = int(surfnum)
status2 = links.zSetSolve(surfnum + 2,8,tuple(dataP))
Best regards
Dear indranil,
I've been encountering some problems with new systems lately and was wondering whether this could be related to issue #61. Indeed I'm loading a simple TMA within zemax (I can surely provide you the generic zemax file for testing if needed), and what I see is that when I load it within zemax through pyzdde, the global coordinate reference surface and stop surface positions have been changed. I compared the .zmx text files before being loaded and after to reach that conclusion. So it looks like somehow these two parameters are changed after loading some systems into zemax. What I can do then is change the parameters back in the zemax session and then let the script continue, or change the stop surface back using zSetAperture, however, I can't find a way to change the GHRS from pyzdde. Have you experienced this problem ?
Cheers
Ben
Hi,
Two questions:
is there a way to retrieve the Zernike coefficients themselves? ie. the functionality of the GetZernike command in ZPL. I can get the text file with them using the 'Zst' button, but what I could really use is the coefficients returned to the python layer.
when using the zGetPSF method, I get the error:
TypeError: list indices must be integers, not NoneType
at line 7223 of zGetPSF
thanks Aaron
The function to set global DDE timeout using the function zSetTimeout
has not been implemented. Currently, the default timeout value is the a fixed value of 1 minute, as set by the dde in PyWin32. Also, the inability to set independent timeout for some functions such as zNSCTrace
, which generally takes several minutes to complete, is very limiting. The user must be able to set these two types of timeout values.
The function call to ipzCaptureWindow()
times out with the message "Timeout reached before PNG file was ready", and doesn't embed the desired graphic into an IPython console/notebook.
Examining a bit further, it seems that the root cause of this problem is that ImageMagick's convert.exe is unable to convert the EMF into PNG file because "VCOMP100.DLL" is missing from the computer (System Error message).
Hello,
I've come across the ipzCaptureWindow function, but this only seems to work inside the IPython environment. Since I'm working on a bigger project I cannot use IPython. I'd like to export a screenshot of a window to a designated .jpg (or .png or .bmp) file.
I've seen the W01_PyZDDE_ExportJPEGWIN01.ZPL macro, but I cannot dynamically specify the filename, causing it to write it to the same file when I execute the macro multiple times.
I've edited the macro to tell the filename to use the date:
CLOSEWINDOW
DATAPATH$ = $DATAPATH()
date$ = $DATE()
PRINT date$
filename$ = DATAPATH$ + date$
EXPORTJPG 1, filename$, 500
I use the following to execute the macro within python
ln.zExecuteZPLMacro('SAVEIM.ZPL')
This would be a good solution if $DATE() were to return both date ánd time, however, it only returns the date time format from windows, which outputs only Month-Day-Year (and no time) and I need a smaller timescale.
Preferably, I'd like to be able to assign my own filename. Is this possible within PyZDDE?
PS. I need to save a large number of these windows while changing parameters of the design using PyZDDE. So using macro's as a solution is not an option.
Kind regards
I tried to run following code and got error.
ValueError: could not convert string to float: 'BAD COMMAND'
I want to know how to avoid this error.
I use Python 3.6 and Zemax 150624.
import numpy as np
import matplotlib.pyplot as plt
import pyzdde.zdde as pyz
import os
ln = pyz.createLink()
print("Hello Zemax version: ", ln.zGetVersion())
ln.zSetSurfaceData (0, 1, "0.0")
ln.zSetSurfaceData (0, 3, 0.0)
ln.zSetSurfaceData (1, 3, 0.0)
ln.zSetSurfaceData (2, 3, 0.0)
print(ln.zGetSurfaceParameter (3, 3))
ln.zSetSurfaceData (3, 3, 0.0)
ln.close()
Hello,
I recently gave a piece of code using PyZDDE (trying to preach the good news around) to a colleague and it looks like he's not able to make it work.
From the logs I see that the problem occurs in zGetPSF where the "assert ret == 0" is false (ret gets a value of -1 instead of 0). This value is returned by zGetTextFile. From the documentation I understand that such a value of -1 is associated with the fact that a text file could not be saved (Zemax may not have received a full path name or extention). The log seems quite self-explaining, the problem being that I can't test my colleague's issue further since he's currently not in the country.
So I was wondering whether you already experienced such an issue using zGetPSF, I'm sure it's most likely coming from something we forgot to do at setup but without the possibility to make printouts etc, its tough to solve.
Thanks much for your help,
Best regards,
Ben
zGetDetector Viewer returns ValueError: could not convert string to float: W2
(where W2 is a filter string from the detector .CFG file.
Looking through readDetectorViewerTextFile in zfileutils (around line 678) it looks like the function doesn't account for the fact that the text file outputted by the detector is changed when a ray database and a filter string are included in the detector config (see attached files after the "Smoothing" line, meaning that it attempts to read the filter string as the detector X position, causing the value error.
Edit: I'm using Zemax 13 in case you need a version number
detectorViewerFile.txt
detectorViewerFile with ZRD and dfilter.txt
Hello,
Does ln.zSetMulticon() support strings for the value argument? The documentation suggests only floats, but then I don't see how you could enter any configuration values for 'GLSS' in that case. Is there different method I'm not aware of?
Cheers,
Hi,
This is following issue #71
I get the following error on trying to use
self.ln.zGetDetectorViewer(displayData=True,settingsFile=settingsFile,txtFile=txtfile,keepFile=True,timeout=600)
C:\Users\shbhu\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pyzdde\zfileutils.py in readDetectorViewerTextFile(pyz, textFileName, displayData)
649 >>> info, gridData = zfu.readDetectorViewerTextFile(pyz, textFileName, True)
650 """
--> 651 line_list = pyz._readLinesFromFile(pyz._openFile(textFileName))
652 # Meta data
653 detNumSurfNumPat = r'Detector\s*\d{1,4}\s*,\s*NSCG\sSurface\s*\d{1,4}'
C:\Users\shbhu\AppData\Local\Enthought\Canopy\edm\envs\User\lib\site-packages\pyzdde\zdde.py in _openFile(fileName)
12143 global _global_use_unicode_text
12144 if _global_use_unicode_text:
> 12145 f = open(fileName, u'rb')
12146 else:
12147 f = open(fileName, 'r')
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/shbhu/Desktop/test.txt'
I checked the source code, and this function which GetDetectorViewer() calls -
ret = self.zGetTextFile(textFileName, 'Dvr', cfgFile, getTextFlag,
timeout)
This function runs without error and returns 0. However it is not creating the textFile. Thus the zfileutils are giving an error.
This sends the following DDE command -
cmd = 'GetTextFile,"{tF}",{aT},"{sF}",{fl:d}'.format(tF=textFileName,
aT=analysisType,sF=settingsFile,fl=flag)
reply = self._sendDDEcommand(cmd, timeout)
This command runs without error and returns 'OK' when I call it -
cmd = 'GetTextFile,"{tF}",{aT},"{sF}",{fl:d}'.format(tF=loc+'test.txt', aT='Dvr',sF='',fl=0)
However, there is no file generated in the directory specified by 'loc'
Hi,
First off, thanks for the work you put into this.
I have an issue with:
I am unsure why the float is truncated to 4 dp - it seems you're unnecessarily throwing away 32bit float precision. I have a ZPL macro utilitising a raytrace that is particularly sensitive to the pupil/field coordinates and the code above produces inconsistent results between ZPL/PyZDDE raytrace calls with the same input parameters.
When ASCII output is selected for text file encoding in Zemax preferences, Zemax uses extended ascii encoding for representing special characters such as
Hi,
I am trying to get the FFT PSF array from Zemax 16 with a simple code in python. The code is :
import sys, numpy
import os
PyZDDEPath = '..\PyZDDE'
if PyZDDEPath not in sys.path:
sys.path.append(PyZDDEPath)
import pyzdde.zdde as pyz
zDir = 'my path is here'
zmxfile = 'test.zmx'
filename = os.path.join(os.path.expanduser('~'), zDir, zmxfile)
pyz.setTextEncoding(1)
ln = pyz.createLink()
ln.zLoadFile(filename)
psfInfo, psfData = ln.zGetPSF()
print psfInfo
pyz.closeLink()
test.zmx is a simple paraxial lens, and I am trying to read the psf info.
I get the following error message:
X:\My Documents...>python zemaxGetPsf.py
TXT encoding is UNICODE; no change required
Traceback (most recent call last):
File "zemaxGetPsf.py", line 20, in
psfInfo, psfData = ln.zGetPSF()
File "..\PyZDDE\pyzdde\zdde.py", line 7241, in zGetPSF
psfGridData = _get2DList(line_list, start_line, img_grid_y)
File "..\PyZDDE\pyzdde\zdde.py", line 10329, in _get2DList
end_line = start_line + number_of_lines - 1
TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'
Exception TypeError: "'NoneType' object is not callable" in <bound method PyZDDE
.del of PyZDDE(appName='ZEMAX', appNum=1, connection=True, macroPath=None)>
ignored
I have been through the list of reported issues but haven't found a solution to this problem.
Do you see what can be the issue? Thank you for the python package by the way, that is very good!
Best regards,
Cyril
The following ValueError
is produced when there is a thickness solve present in the last surface:
[...]
In [3]: ln.zTiltDecenterElements(2, 24)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
----> 1 ln.zTiltDecenterElements(2, 24)
C:\...\...\pyzdde\zdde.py in zTiltDecenterElements(self, firstSurf, lastSurf, xdec, ydec, xtilt, ytilt, ztilt, order, cbComment1, cbComment2, dummySemiDiaToZero)
[...]
> 10172 self.zSetSolve(dummy, self.SOLVE_SPAR_THICK, *solve)
[...]
C:\...\...\pyzdde\zdde.py in zSetSolve(self, surfNum, code, *solveData)
5793 elif solveData[0] == self.SOLVE_THICK_PICKUP: # (P)
5794 data = ('{:d},{:1.20g},{:1.20g},{:d}'
-> 5795 .format(solveData[1], solveData[2], solveData[3], solveData[4])) # surface, scale-factor, offset, column
[...]
ValueError: Unknown format code 'd' for object of type 'float'
Hello!
First of all thank you very much for PyZDDE. :-) I'm new to the tool but I already have a lot of ideas how I can use it.
Some functionality I will definitely need is contained in the arraytrace module. However, when importing it I always get the WindowsError: [Error 126].
I saw that the ArrayTrace.dll has been modified to avoid that error 3 years ago. Nevertheless, I get the error.
Have I incorrectly installed PyZDDE. Does anyone have any recommendations how to get rid of the problem?
Thank you,
Gechas
Hi,
First of all thanks for the great amount of work done here !
I'd just want to report an easy fixable issue:
readZRDFile() from zfileutils.py does not close the file handle before raising the NotImplementedError in case the ZRD file is not uncompressed.
I think it should be done before raising the exception as the file remains locked. If one tries to update the ZRD (for instance calculating ray tracing from Zemax) she will have some trouble with a message box prompting that the file cannot be saved.
Best regards,
Jérémie.
Hi,
I am trying to generate footprints in Python and tried to use the following -
ln.zGetMetaFile('full_path+filename.wmf','Foo')
with the analysis code 'Foo'. Irrespective of the analysis code I enter, I always get the default output - the 2D layout. Could you please guide me as to where could the problem lie.
It returns code 0 and saves the 2D layout window as the file for option 1.
Hi,
The issue I had wasn't in setting operand type, I wasn't able to set a
string value for an operand. For example, I could set 'THIC' to 5 and 3
but not 'GLSS' to 'N-BK7' and 'SF-5'. It gave ValueError: Unknown format code 'g' for object of type 'str' from line 5254 of zdde.py under zSetMulticon().
Cheers,
Hi,
I started to implement some functions to read and write zrd files. So far I created a class for Zemax rays and a function to read the file.
My plan is to have a separate file for the ray class ind import it to the zdde.py file where I would add the read/write functions. I'll upload it to my fork soon and send you a pull request. If you have any better idea how to implement the functions, please let me know!
Could it be possible to do the bulk ray tracing by creating a ray file from Python and import this to Zemax? Might be a temporary solution for this problem...
Best,
Olf
Hello,
I read with interest the other issue opened a while ago about a problem with the zGetPsf() method when the encoding was not properly set.
I however currently come accross the same problem when calling zGetPsf() and get the following error message:
File "C:\Python27\lib\site-packages\pyzdde-2.0.1-py2.7.egg\pyzdde\zdde.py" line 7548 in zGetPsf data_spacing_line = line_list[_getFirstLineOfInterest(line_list, ' Data_spacing')])] Type error: List indices must be integers, not NoneType
Is this problem related to the other one? I tried both encoding to check but none worked out.
All the best
It is probably not a bug in PyZDDE as such. Also, this error happens rarely (not always, and very hard to reproduce) when some of the functions such as zGetPOP()
request Zemax to export an analysis data as text file, and then the function tries to open the text file (in read mode), but is unable to do so because of file access denial. The error message is as follows (when it happens):
File " ...\PyZDDE\pyzdde\zdde.py", line 7022, in zGetPOP
line_list = _readLinesFromFile(_openFile(textFileName))
File "C: \...\PyZDDE\pyzdde\zdde.py", line 10657, in _openFi1e
f = open(fileName, 'r')
IOError: [Errno 13] Permission denied: 'C:\...\popData.txt'
Interestingly, when this error happens, the file outputted by Zemax doesn't show any owner. Instead it shows "Unable to display current owner". In normal cases, the owner of such files is usually the current user.
Also, when I execute icacls popData.txt
from the command prompt in the directory containing the file, to display the discretionary access control lists (DACLs) on the file, I get
popData.txt: Access is denied.
Successfully processed 0 files; Failed processing 1 files
This issue could also cause problems (doesn't seem to happen always) to functions like ipzGetTextWindow()
, zGetImageSimulation()
, zGetMTF()
, zGetPSF()
, zGetPSFCrossSec()
, zGetPOP()
, etc.
Hello,
First off, this package is excellent. Thank you for making and sharing it.
Comparing the documentation on paramN and fparamN in help(ln.zSetPOPSettings) suggests that the parameters are ordered as you read them in Zemax. The discrepancy I saw is that Zemax 15.5 SP2 would then suggest that fparamN 1 and 2 are Tilt About X (deg) and Y (deg) respectively but PyZDDE seems think that 1 and 2 are Waist X and Waist Y. That said, the way it is now makes paramN and fparamN behave more similarly if I remember correctly.
That caused me some confusion but I was able to sort out the difference after some examination. I just figured I'd throw in a request for that to be clarified or changed for future users.
Cheers!
Hi,
I have an error message when i run a script more than once.
Here the script, as simple as it could be:
# -*- coding: utf-8 -*-
import sys
import os
import matplotlib.pyplot as plt
import pyzdde.zdde as pyz
ln = pyz.createLink()
print(ln.zGetVersion()) # example
ln.close()
And here what is printed in a freshly started iPython console. Two runs are shown:
Python 2.7.11 |Anaconda 4.0.0 (64-bit)| (default, Feb 16 2016, 09:58:36) [MSC v.1500 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 4.1.2 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
%guiref -> A brief reference about the graphical user interface.
runfile('C:/Users/xxxx/Desktop/Temp/PyzDDE_tests/test_00.py', wdir='C:/Users/xxxx/Desktop/Temp/PyzDDE_tests')
160608
runfile('C:/Users/xxxx/Desktop/Temp/PyzDDE_tests/test_00.py', wdir='C:/Users/xxxx/Desktop/Temp/PyzDDE_tests')
160608
Exception TypeError: "'NoneType' object is not callable" in <bound method PyZDDE.__del__ of PyZDDE(appName='', appNum=1, connection=False, macroPath=None)> ignored
As you can see, I am using Anaconda, Python 2.7, Spyder.
Interestingly this does not happen the first time that I run the code.
I have tried to follow the recommendations in earlier posts ( #40) but it does not seem to have an effect.
I would appreciate any suggestions.
All the best,
andres
Indranil,
First of all, thank you very much for this amazing Python package, as it seems to work incredibly well so far. I have, however, been experiencing an issue that doesn't really make any sense to me. I'm currently using Zemax version 18.4 and am experiencing issues when I attempt to use the zGetTextFile method to create a .txt output file of all of the data associated with the RMS Field Map analysis. The code is as follows:
dir = os.path.dirname(os.path.realpath(__file__))
txtFileRFM = dir + "\rfmOutput.txt"
rmsFile = ln.zGetTextFile(textFileName=txtFileRFM, analysisType='Rfm', flag=0, timeout=None)
The part that's confusing me the most is that this exact same method works perfectly fine when attempting to access the Wavefront map data by passing in analysisType="Wfm"
. For some reason, however, when trying to access the RMS Field Map data, the zGetTextFile method keeps returning -1 as the output and thus my file with the RMS data never actually gets created anywhere.
Look forward to hearing from you soon.
Under Python 3.6.0 |Anaconda 4.3.1 (64-bit)| (default, Dec 23 2016, 11:57:41) [MSC v.1
900 64 bit (AMD64)] on win32
See the following error on pip install
:
(C:\ProgramData\Anaconda3) C:\Windows\system32>pip install pyzdde
Collecting pyzdde
Could not fetch URL https://pypi.python.org/simple/pyzdde/: There was a proble
m confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate v
erify failed (_ssl.c:749) - skipping
Could not find a version that satisfies the requirement pyzdde (from versions:
)
No matching distribution found for pyzdde
This may be due to corporate firewall
It seems like this lacks functionality for any of the physical optical analysis. I'll see if I can make it work.
Calling the function zGetTraceArray()
in Python 3 causes the function to fail, which doesn't happen in Python 2.7x. For example, consider the following code snippet:
r = np.linspace(0, 1, numRays)
theta = np.linspace(0, spirals*2.0*pi, numRays)
px = (r*np.cos(theta)).tolist()
py = (r*np.sin(theta)).tolist()
# trace the rays
tData = at.zGetTraceArray(numRays, [hx]*numRays, [hy]*numRays, px, py, waveNum=waveNum)
# parse traced data and plot
err, _, x, y, _, _, _, _, _, _, _, _, _ = tData
Executing the above in Python 3, fails and produces the following traceback:
File "...\PyZDDE\pyzdde\arraytrace.py", line 274, in zGetTraceArray
x[i-1] = rd[i].x
NameError: global name 'x' is not defined
Exception TypeError: 'unorderable types: int() <= NoneType()' in <bound method PyZDDE.__del__ of PyZDDE(appName='ZEMAX', appNum=1, connection=True, macroPath=None)> ignored
This happens because there is a change in how exec()
behaves in Python 2 vs Python 3.
In Python 3 executing
...
reals = ['x', 'y', 'z', 'l', 'm', 'n', 'l2', 'm2', 'n2', 'opd', 'intensity']
ints = ['error', 'vigcode']
for r in reals:
exec(r + " = [0.0] * numRays")
for i in ints:
exec(i + " = [0] * numRays")
...
creates the names x
, y
, etc. in the local namespace, but the Python interpreter searches for these variables in the global namespace [SO question]
I work with a Zemax file provided by a customer (so unfortunately, I cannot share it). It's a simple refractive telescope with 6 lenses.
My problem is: I cannot change the position of the system aperture STOP with PyZDDE.
I can do it manually in Zemax, it works well and there's nothing special.
If I use the following code:
`import pyzdde.zdde as pyz
filename = "C:\Zemax Model\Instrument_telescope.zmx"
link = pyz.createLink()
link.zLoadFile(filename)
link.zPushLens()
print link.zGetNumSurf()
print link.zGetSystemAper()
link.zSetSystemAper(aType=3,stopSurf=3,aperVal=20.)
print link.zGetSystemAper()
link.zPushLens()
print link.zGetSystemAper()
link.close()`
I get the following results:
19
systemAper(apertureType=3, stopSurf=1, value=39.8)
systemAper(apertureType=3, stopSurf=3, value=20.0)
systemAper(apertureType=3, stopSurf=1, value=39.8)
Press any key to continue . . .
Did I forget something ? Or could it be a bug ?
I checked with two other files (the Zemax sample Double Gauss 5 degrees, and another telescope from a different customer) and did not get this problem. This is an issue for me as I am writing a code that must be used with any optical system.
Thanks for the help
Jerome
Hello,
I am getting the error ' UTF-16 stream does not start with BOM' when I am doing the fiber coupling exercise. Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.