Solved

How to stop Field type setting automatically changing while using python API in interactive mode?

  • 12 June 2023
  • 4 replies
  • 81 views

Hello All,

 

I am using python with the interactive session to run image simulations by varying lens position (to induce defocus and tilt). I have noticed that when the object distance is set to infinity, and when the API connects to the interactive session the field type remains as angles (my default setting). However, when the object distance is set to finite values the field type automatically changes to object height on connection and before the image simulation can run.

Is this a fail safe to prevent errors during image simulation? What would be the significance of such a setting?

Should I change all my image simulations (with finite object distance) to be done with object height type field setting? 

Thanks for your answers in advance,

Amit

icon

Best answer by David.Nguyen 18 July 2023, 11:50

View original

4 replies

Userlevel 7
Badge +2

Hi Amit,

 

I don’t seem to be able to reproduce the issue. Assume the following system before interactive extension connection with Angle field type and a finite OBJECT Thickness:

Then, the system, upon connection, remains the same for me:

As a sanity check, I ran the following command, which is True:

TheSystem.SystemData.Fields.GetFieldType() == ZOSAPI.SystemData.FieldType.Angle

Would you be able to share your code and tell us what version of OpticStudio you are using?

Take care,

 

David

Hi David,

 

thank you for your response.

Interactive connection (not connected) with field setting definition showing object angle as the Type

Interactive connection (connected) with field setting definition showing object height as the Type

 

Unfortunately I am not able to attach my code as a file so I am just pasting the script:

#here starts the standard boiler plate code for interactive mode

import itertools

import matplotlib.pyplot as plt

import clr, os, winreg

from itertools import islice

import shutil

import numpy as np

from icecream import ic

import csv…

…….

…….

#until here is the standard boilerplate code for interactive mode

if __name__ == '__main__':

 

    # run the design lockdown tool to fix diameters, remove solves

    LockdownTool = TheSystem.Tools.OpenDesignLockdown()

    LockdownTool.UsePrecisionRounding = True

    LockdownTool.DecimalPrecision = 3

    LockdownTool.RunAndWaitForCompletion()

    LockdownTool.Close()

    # ! [e07s01_py]

    surf0 = TheSystem.LDE.GetSurfaceAt(0)

    surf2 = TheSystem.LDE.GetSurfaceAt(2)

    surf13 = TheSystem.LDE.GetSurfaceAt(13)

    #surf16 = TheSystem.LDE.GetSurfaceAt(16)

 

object_distance = [7500]  #2000,3000,4000,5000

img_pos = [0.550,0.555,0.560,0.565,0.570,0.575,0.580,0.585,0.590,0.600,0.610,0.615,0.620,0.625,0.630,0.635,0.640,0.645,0.650] #    setting position of imager from last surface of filter


 

# tilt_x = [0]

# tilt_y = [0]

#Loop to change decenter value and run image simulation and save file by moving to a new location

#all_tol = [[img_pos],[tilt_x],[tilt_y]]

tolerance = list(itertools.product(img_pos,object_distance))

 

#here are the lines to run image analysis, move files to specified folder, run MTF over field analysis and defocus analysis and save them as txt files#

for first,second, in tolerance:

    imager = first

    #xtilt = second

    #ytilt = third

    object_dist = second

    #ic(imager)

    #ic(type(imager))

    surf0.GetCellAt(3).DoubleValue = object_dist

    # surf2.GetCellAt(14).FloatValue = xtilt #setting the x tilt value

    # surf2.GetCellAt(15).FloatValue = ytilt #setting the y tilt value

    # surf15.GetCellAt(14).FloatValue = xtilt*-1 #setting the x tilt value

    # surf15.GetCellAt(15).FloatValue = ytilt*-1 #setting the y tilt value

    surf13.GetCellAt(3).DoubleValue = imager #setting the imager position

 

    #starting a new image analysis

    image_analysis = TheSystem.Analyses.New_ImageSimulation()

    image_analysis.ApplyAndWaitForCompletion()

    image_analysis.Close()

 

    #file location and name specifications for image simulation files

    src_folder = r"C:\Users\thiii\Documents\Zemax\IMAFiles\\"

    #dst_folder = r"E:\ZEMAX automation\Img_sim\"

    dst_folder_images = r"D:\ZEMAX automation\Img_sim\Images\\"

    dst_folder_mtfheatmap = r"D:\ZEMAX automation\Img_sim\MTFmap"

    dst_folder_defocus = r"D:\ZEMAX automation\Img_sim\Defocusmap"

    file_name = 'Blur2.jpg'

    # Split name and extension

    data = os.path.splitext(file_name)

    only_name = data[0]

    extension = data[1]

    # Adding the new name

    new_base = only_name + str(object_dist) + str(imager) + extension

    # construct full file path

    new_name = os.path.join(dst_folder_images, new_base)

    # move file

    shutil.move(src_folder + file_name, new_name)


 

    #starting a new geometric MTF heatmap analysis

    mtf_heatmap = TheSystem.Analyses.New_GeometricMtfMap()

    mtf_heatmap.ApplyAndWaitForCompletion()

    mtf_heatmap_results = mtf_heatmap.GetResults()

    heatmapfile = mtf_heatmap_results.GetTextFile(dst_folder_mtfheatmap + str(object_dist) + str(imager) + ".txt" )

    mtf_heatmap.Close()

 

    #starting a new full field defocus analysis

    field_aberration = TheSystem.Analyses.New_FullFieldAberration ()

    field_aberration.ApplyAndWaitForCompletion()

    field_aberration_results = field_aberration.GetResults()

    defocusfile=field_aberration_results.GetTextFile(dst_folder_defocus +str(object_dist) + str(imager) + ".txt" )

    field_aberration.Close()

 

Thanks and regards,
Amit

 

Userlevel 7
Badge +2

Hi Amit,

 

I think the issue is that you are running a Design Lockdown. Please read this excerpt from the Help File about the Design Lockdown tool:

A number of steps are generally required to take a system designed in sequential mode into a production system.   In particular all idealized inputs of the system must be converted into real manufacturing inputs.  The Design Lockdown Tool automates this conversion by:

...

Switching from the use of image-based field point definitions (if they are being used) to object-based definitions.  The primary wavelength is used for this conversion. 

  • For finite conjugate systems, Object Height is used as the field definition. 
  • For infinite conjugates, Angle is used as the field definition, unless the system is already using Theodolite Angles. 
  • Systems with multiple configurations will not be converted to object-based field definitions; any analysis features or conversion to non-sequential should be manually verified if the sequential system is defined with image-based field definitions. 

Hope this helps. Take care,

 

David

Dear David,

 

wow, thankyou. That was overlooked by me.

Thank you for pointing it out.

 

Best regards,
Amit

Reply