Share your solutions or ask questions about the ZOS-API, ZPL, or DLLs. Code shared in these spaces is not reviewed by Zemax except for the Code Exchange.
When developing a project in Python, it is important to have a clean and isolated environment to avoid conflicts with other packages or dependencies. This is where virtual environments come in handy. In this guide, I will show you how to set up a virtual environment for a project in PyCharm.Step 1: Install Virtualenv in Command Promptpip install virtualenvStep 2: Create a new PyCharm projectCreate a new PyCharm project through File > New Project.check the right bottom interpreter is the one you created just now, in this case(zos_venv)Step 3: Configure the new virtual environmentOpen the terminal by clicking on the Terminal tab at the bottom of the screen. To activate the virtual environment, navigate to the location of the virtual environment in the terminal using the cd command. Once you are in the correct directory, you can activate the virtual environmentcd .\zos_venvcd .\Scripts.\activateStep 4: Configure the new virtual environmentThe environment name (in this case zos_venv) a
I need to simulate a gaussian beam in non sequential mode, which has 850 nm wavelength, 15 degree diveregence angle (half angle) and the beam raduis of 2.563 mm at 10 mm which has the cross section of the beam profile shape as attached below, but when putting this values using the Gaussian source it doesnt give me the same results. By using the skewRaysCircular I cannot get the gaussain beam profile and it just shows me a ring, how can I get a gaussian beam profile in the output?
This Source DLL models an Astigmatic Gaussian Source. It is based on rays but the statistical distribution of rays gives a picture of a diffracting Gaussian beam. It is valid for small angles (paraxial approximation) and when propagating in free space. So clipping at apertures and aberrations will give incorrect results.w0x, w0y are the real beam waist radii (defined at the 1/e2 intensity point) in the XZ and YZ planes. They includes M^2. z0x, z0y are the positions of the beam waist in the XZ and YZ planes. z0<0: in propagation direction if the waist is located before source. M^2x, M^2y are the quality factors in the XZ and YZ planes.For more information, see "Representation of a Gaussian beam by rays" by P. P. Crooker, W. B. Colson, and J. Blau - Physics Department, Naval Postgraduate School, Monterey, California 93943Authors:Steffen Erhard and @Dirk Broemme Click here to download Date Version OpticStudio Version Comment 2020/05/06 1.0 21.1.2 Creation 2023/0
Hi all,I want to save data and images of detectors automatically with ZPL. So I made the ZPL code as below. For n = 2, 6, 1 ####### get Detector viewer in img. winnum = n+1 OpenAnalysisWindow "Dvr", cfgpath$ ExportJPG winnum, imgfile$ ####### get Detector viewer in dat. #ModifySettings cfgtxt$, DVW_SHOW, 1 # extraction middle row data from 2d data GetTextFile datfile$, "Dvr", cfgtxt$ , 1 ConvertFileFormat datfile$, 1 #Unicode to ANSINext Once I open all detector viewer windows, I tried to save images and data in detector number order. However, I couldn’t save each detector data/image because it cannot recognize the number of detector in this code. What should I do? Or, are there better method to do it? Please help me. Thanks in advance.
In OpticStudio, currently we only support one dimensional grating. However, it's not difficult to simulate 2D grating. Here we will show an example using diffractive DLL.You may compile it with the instructions or use the DLL file attached to this article. Before we start, here are some articles for required background knowledge that we will not repeat in this forum post. How diffractive surfaces are modeled in OpticStudio (KBA) How diffraction ray-tracing is calculated (forum post) Custom DLLs in OpticStudio: An overview of user-defined surfaces, objects, and other DLL types (KBA) How to compile a User-Defined DLL (KBA) Let's simply open the attached cpp file and observe how it works.This example is mainly modified from the built-in sample \Documents\Zemax\DLL\Diffractive\diff_samp_1.c To compile the program as C++ code. We package the functions with extern 'C'. In this example, we only want to return diffraction ray direction and its relative intensity. So setting data = 1
API (Python and MATLAB Interactive Extension) Calculate the Ray Transfer (ABCD) Matrix for thick Lens
To compute the ABCD matrix, OpticStudio traces rays over a very small region centered upon the reference field position. Usually, this is the center of the field of view. OpticStudio allows selection of which field position to use for reference.By default, OpticStudio sets the corner of the field grid in object space to be at the maximum radial field distance. Because object height is linear with the tangent of the field angle, the full width of the field when angles are used to define the field is given byWhere θr is the maximum radial field angle at the corner of the field.The ray coordinates in image space for the very small field of view are used to determine the ABCD matrix components. The use of an ABCD matrix allows for coordinate rotations. If the image surface is rotated, such that a y object coordinate images to both an x and a y image coordinate, the ABCD matrix will automatically account for the rotation. The grid distortion plot shows the linear grid, and then marks the ac
Is it possible to calculate the 'field Type' 'Angle' (Code 0) from the 'field Type' 'Real Image Height' (Code 3) with a ZPL script? It is basically what the Zemax 'Field data editor' offers with the 'Convert to' option. However, I do not need to *convert* the field type, but just have to determine the value. With 'Single Ray Trace' as well as with the operand 'RAID', I only get one angle. But I need the two angles as defined for the 'field Type' 'Angle' Thank you and best regards, Christof.
This forum post is a place to collect update history of diffractive tools beta functions, which includes all RCWA DLLs (and visualization API), polygon DLL, and Zemax Grating Data (ZGD) DLL. Content:1. Overview2. Resources3. Change history OverviewCurrently in OpticStudio, we are adding some useful DLLs to enhance the ability of fully simualting gratings. They allow OpticStudio to consider the efficiency when rays pass through diffractive optical elements (DOE), such like 1D/2D gratings, binary optics, or volume holograms. These extensions can be found in OpticStudio installations.These tools improve frequently based on users’ feedback. We decide to provide functions with DLL so it can be updaetd fast upon users' request. Between each OpticStudio public releases, there might be several minor updates and bug fixes. This forum post is a place for changes history.Note all tools provided here are only available with OpticStudio Premium Subscription. If users are interested in these functio
In this forum post, a sample C++ code to read value from a text file in DLL is shared. This is mainly a supplement to the follwoing knowledge base article. The only difference is we will do the similar thing with C++ code to how how to do this in C++ style. How to read a static data file into a user-defined surface In the attachments, a sample code is attached. This code does the same thing as shown in the following forum post. The difference is the diffraction efficiency data is read from a text file. Simulate 2D diffraction grating using customized diffractive DLL We will explain line by line in below. The first thing to do is to define a global variable, which is declared outside of all the functions. As discussed here, during ray-tracing in OpticStudio, the DLL will be called several times. For the global variable, the inside value is unchanged and the DLL can always see the same data in different thread. Our plan is to read data from text file and save it in this global va
These two User-defined surfaces DLL creates an array of hexagonal arranged lenses and an array of staggered lenses. The code is based on us_array.c.us_array_hex.dll has 4 parameters: the number of lenses in X and Y direction and the width and height of each lens.us_array_staggered.dll has 3 parameters: the number of lenses in X and Y direction and the width of the lens.Language: CppLocation: \Documents\Zemax\DLL\Surfaces\ [MOD: added the folder location for the DLL] Click here to download Date Version OpticStudio Version Comment 2018/01/06 1.0 - Creation
Hi, In the ZOSAPI, the settings for the Physical Optics Propagation analysis feature are now fully implemented: So as an example, we may set the settings in the 'General' and 'Beam Definition' tabs using the ZOSAPI in MATLAB: TheSystem = TheApplication.PrimarySystem; TheAnalyses = TheSystem.Analyses; newPOP = TheAnalyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.PhysicalOpticsPropagation); newPOP.HasAnalysisSpecificSettings; newPOP_Settings = newPOP.Settings(); newPOP_Settings.Wavelength.SetWavelengthNumber(1); newPOP_Settings.Field.SetFieldNumber(1); newPOP_Settings.StartSurface.SetSurfaceNumber(1); newPOP_Settings.EndSurface.SetSurfaceNumber(4); newPOP_Settings.SurfaceToBeam = 0.0; newPOP_Settings.UsePolarization = true; newPOP_Settings.SeparateXY = false; newPOP_Settings.UseDiskStorage = false; newPOP_Settings.BeamType = ZOSAPI.Analysis.PhysicalOptics.POPBeamTypes.GaussianWaist; newPOP_Settings.XSampling = ZOSAPI.Analysis.SampleSizes.S_128x128; newPOP
Sometimes, we may design the system starting from the 'image' back to the 'object'. For example, this is often the case for those systems that are designed to be viewed by eye, like AR/VR, HUD. In this case, normally, if we want to check the relative illumination, we need to reverse the system to check because the tool 'Relative Illumination' only calculates that on last surface in the system.Here we will provide another way to calculate it using a macro so that you don't need to reverse the system.Note here we at the same time is also demoing how you can verify the calculation theory of the RI. RI is actually much easier to calculate if the system is reversely designed! First, by reading the following forum post, we know that relative illumination at each field is exactly linearly dependent to the area of the beam in cosine space in image space.So, here is the plan. We want to write a macro to calculate the beam area in cosine space for each field, normalize it, and then get the the R
The download contains 3 Python scripts:a script to read / parse a ZRD (Zemax Ray Database) file a script to read / parse a Binary ZBF (Zemax Beam File) file a script to read / parse a Binary DAT / SDF Source File Click here to download Date Version OpticStudio Version Comment 2022/01/01 1.0 - Creation
This User-Defined Surface DLL provides a realistic model of relief-type diffractive lenses based on zone-decomposition. Using zone-decomposition, diffraction into multiple orders can be accurately considered at once, and this method inherently accounts for wavelength dispersion and diffraction efficiency by modelling the actual shape of the diffractive element.Application examples include the creation of advanced intraocular lens models, where the different orders are designed to provide sharp vision for multiple viewing distances, thereby substituting accommodation of the natural crystalline lens.This application is discussed in detail in the following knowledgebase article:Realistic modeling of relief-type diffractive intraocular lenses using User-Defined Surface DLLs – Knowledgebase (zemax.com) Click here to download Date Version OpticStudio Version Comment 2022/07/15 1.0 - Creation
Within the API, we are able to quickly pull Peak Irradiance, Total Power, and Total Hits by using the property GetDetectorData as described in the forum post 'Methods for extracting detector data through the API.' However, this property will not take into account an applied ZRD file. We can apply a ZRD file to a Detector Viewer window, so is there a way to extract the same information from there?
In this post, it’s introduced how to simulate realistic grid wire polarizer with RCWA function that comes with OpticStudio 20.2.(Source: https://www.thorlabs.com/newgrouppage9.cfm?objectgroup_id=5510) Note there are many different types of polarizerFor polarizer based on birefringent crystal, check the following article: How to design birefringent polarizers For polarizer based on coating, there is no an article specific to introduction, but users can refer to the following article to know how to set up a coating and assign to object for beam splitting: How to model a dichroic beam splitter Then it’s also worth to note the existence of a build-in ideal coating “PASS_P”. This coating allows P polarization to pass and reflect light with S polarization. Note the coating method can only work for obliquely incident beam. Usually this kind of polarizer is made as a cube or a plate oblique placed in the system. More information can be found in this forum post: 'Pass_P' coating fail for the mo
In the last few weeks, I have received questions regarding how we can use the ZOS-API to pull single ray trace information. For convenience, I will post my answers here in a single post. I pulled together three different methods for extracting single ray trace data. Below I will list the methods with sample code in Python and Mathematica. I’m happy to provide samples in other languages if needed! If you have other methods you use for this kind of analysis, feel free to add them as a reply! Method 1 - Use the Single Ray Trace analysisThis method can be used to pull the results of the Single Ray Trace analysis window. The benefit of this method is that the results are pulled for all surfaces at once. The drawback of this method is that the data is provided in text form. The output is a TXT file which must be parsed back into the program you are using. This is discussed in a bit more detail here: How to set RayInfo.Vignetted in ZOS-API_Python Python########### Define the constants across
Hello, I would like to save graphical plot in detector viewer into a picture file by ZOS-API.I looked at some similar questions in community but most of those tell that “get numerical data and draw a plot using the numerical data” or “that feature is in request” 1 year go.So, I am wondering if that feature is implemented already or not.To me, GUI already has that feature and hence it seems that if there is a function in ZOS-API to call that feature in GUI, it gets the job done. Does anybody know that? RegardsKazu
I use Detectorviewers in text mode to export the results of my simulations to disk.Futher processing is done via python, where the plain textfile gets parsed.I prefer to not using the ZOS API as this limits me in the python verison i use. Problem is: The Detector Viewer numbers are really error-prone as sometimes i close a window and open another one and the numbers i have to put into SAVEWINDOW keyword are just wrong by then.I would prefer using the detector number instead using SAVEDETECTOR keyword. But this saves in some binary format i did not find any specs upon for reading that in. Is there any description on the DDR/DDx file format?Is there any way to obtaining the detector data into python? Best regardsOlli
Hello. I guess my question is fairly straight forward. However, I am not very used to any optimization procedures, so any help will be appreciated. Assuming I have a source and a detector, and some surfaces inbetween in a non-sequential setting. I need to write a merit funtion that maximizes flux on the detector - but only for rays hitting a specific surface in between source and detector. While this is easily done by filter strings in a simple detector view, I was unsure on how to implement this in the optimization. Therefore Zemax provided some help a while ago in form of this ZPLM operand detector = PVHX() clear = NSDD(1,0,0,0) NSTR 1, 0, 0, 0, 0, 0, 0, 1, 'Test.ZRD', 'H4' ZRDPLAYBACK 'Test.ZRD', 1, detector, 1 X = NSDD(1, detector, -3, 0) OPTRETURN 0, X So I specify my detector in H(x) and then clear all detectors, run a raytrace with the filter string applied (in this case hit surface 4) and point it back to the detector. So now this returns the rays hitting the detector under con
I have a simple lens diagram where my goal is to decenter one of the two elements, and record the change in the Ray X Center value of the footprint diagram. I have found how to view/change the Decenter X column of the coordinate break using TheSystem.LDE.GetSurfaceAt(2).GetCellAt(12).get_Value() and xx.DoubleValue =. Next, I need to pull out the value of Ray X Center from the footprint diagram after propogating the changes made by altering the decenter. Either through grabbing the single value, or even saving the entire footprint diagram text values. I have found what I believe is the correct location for this data at TheSystem.Analyses.Get_AnalysisAtIndex(2), as xx.get_GetAnalysisName() returns 'FootprintSettings'. I have not yet been able to find a method (through tab completing in PyCharm) that returns the data in any way. How can I pull out the footprint diagram information?
We have created a public repository called https://github.com/ansys/optical-automation. We are hoping to gradually move our solutions to this Ansys open project on GitHub.How to use Ansys optical-automationAnsys optical-automation comes with a documentation: https://ansys-internal.github.io/optical-automation/This section shows how to clone the GitHub repository and run the code in Visual Studio. Note the Visual Studio is not absolutely required. Users can use their preferred tool to sync the GIT repository and preferred IDE tool to run the Python project. Here we simply use Visual Studio as an example. Visual Studio installationUsers can download and install the latest Visual Studio in the following link: https://visualstudio.microsoft.com/vs/community/During the installation, the Python development must be selected as below.GitHub repository configurationAfter the installation, we can launch the Visual Studio and click Clone a repository.Copy and paste the link below to the Repositor
A user asked why when using ZPL macro to save the Cross Section Row Coherent Irradiance data from Detector Viewer, the .txt file he got does not match the information displayed in the Text tab of the Detector Viewer. Instead of seeing a 2-column data of X position versus Irradiance, he kept seeing 3-column data displaying “Spatial Frequency, X and Y” This is because in his code, the Configuration file is saved with the settings displayed in the Graph tab of the Detector Viewer, where the Cross Section Row is data value #4 in the “Show As:” dropdown list, (the index starts at 0). However, the GETTEXTFILE keyword is retrieving data from the Text tab of the Detector Viewer, where there isn’t a data value #4 in the “Show As:” dropdown list, so OpticStudio simply saves the data from the last available data value #3 which is the “Geometric MTF”. In order to save the data for the Cross Section Row irradiance, you need to use MODIFYSETTINGS
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.