使用以下工具对Python项目和脚本进行测试:
Windows(64位)中安装的 Python 3.7.2 (https://www.python.org/downloads/)-Python编译器
用于 Windows 扩展的 Python (64位, Python 3.7) (https://github.com/mhammond/pywin32/releases) - 支持COM
Windows 桌面上的 Microsoft Visual Studio Express 2013 (https://www.visualstudio.com/en-us/products/visual-studio-express-vs.aspx) - 易于使用的 IDE
Visual Studio 中的 Python工具 (https://pytools.codeplex.com/)- 集成到 Visual Studio
设计规格如下的单透镜:
光线来自无限远,半视场角为5°,单一波长(d光,0.587mm)。
准直的入射光被聚焦为最小的RMS光斑半径,均匀射入视场中。
F 数为10,入瞳直径为 40 mm。
材料为 N-BK7。
光阑为位于透镜之后单独的表面,可以自由移动。
至少3片透镜,并且中心厚度不超过15mm。
透镜的边缘厚度最小为3mm,空气间隙最小为 0.5 mm
在脚本中,转到 “# Insert Code Here
” 然后输入:
TheSystem = zosapi.TheSystem;
TheSystem.New(False);
上述程序表示完整的光学系统,对应于独立的 . ZMX文件。现在创建包含新文件路径的字符串。为了使脚本更加灵活,将使用 SamplesDir
属性来创建文件路径。
fileOut = zosapi.TheApplication.SamplesDir "\Sequential\Objectives\Single Lens Example wizard EFFL.zmx";
zosapi.TheSystem.SaveAs(fileOut);
TheSystemData
包含系统的所有基本数据,可以用其设置光圈、视场、波长等。
# Aperture
TheSystemData = TheSystem.SystemData;
TheSystemData.Aperture.ApertureValue = 40;
# Fields
TheSystemData.Fields.AddField(0,5.0,1.0);
# Wavelength preset
TheSystemData.Wavelengths.SelectWavelengthPreset(constants.WavelengthPreset_d_0p587);
对于枚举常量,如: WavelengthPreset
, Python 将每个常量创建为{enum name}_{enum value}
.
# Lens data
TheLDE = TheSystem.LDE;
TheLDE.InsertNewSurfaceAt(1);
TheLDE.InsertNewSurfaceAt(1);
Surface_1 = TheLDE.GetSurfaceAt(1);
Surface_2 = TheLDE.GetSurfaceAt(2);
Surface_3 = TheLDE.GetSurfaceAt(3);
Surface_1.Thickness = 10.0;
Surface_1.Comment = 'front of lens';
Surface_1.Material = 'N-BK7';
Surface_2.Thickness = 50.0;
Surface_2.Comment = 'rear of lens';
Surface_3.Comment = 'Stop is free to move';
Surface_3.Thickness = 350.0;
# Make thicknesses and radii variable
Surface_1.RadiusCell.MakeSolveVariable();
Surface_1.ThicknessCell.MakeSolveVariable();
Surface_2.RadiusCell.MakeSolveVariable();
Surface_2.ThicknessCell.MakeSolveVariable();
Surface_3.ThicknessCell.MakeSolveVariable();
# Save and close
The System.Save();
如上图所示,使用以下代码来设置优化向导:
# Merit functions
TheMFE = TheSystem.MFE;
wizard = TheMFE.SEQOptimizationWizard;
wizard.Type = 0; # RMS
wizard.Data = 1; # Spot Radius
wizard.Reference = 0; # Centroid
wizard.Ring = 2; # 3 Rings
wizard.Arm = 0; # 6 Arms
wizard.IsGlassUsed = True;
wizard.GlassMin = 3;
wizard.GlassMax = 15;
wizard.GlassEdge = 3;
wizard.IsAirUsed = True;
wizard.AirMin = 0.5;
wizard.AirMax = 1000;
wizard.AirEdge = 0.5;
wizard.IsAssumeAxialSymmetryUsed = True;
wizard.CommonSettings.OK();
CommonSettings
部分,可以实现“OK 按钮”的功能。Operand_1=TheMFE.InsertNewOperandAt(1);
Operand_1.ChangeType(constants.MeritOperandType_EFFL);
Operand_1.Target = 400.0;
Operand_1.Weight = 1.0;
设置完成之后,评价函数如下所示:
# Local optimisation till completion
LocalOpt = TheSystem.Tools.OpenLocalOptimization();
LocalOpt.Algorithm = constants.OptimizationAlgorithm_DampedLeastSquares;
LocalOpt.Cycles = constants.OptimizationCycles_Automatic;
LocalOpt.NumberOfCores = 8;
baseTool = CastTo(LocalOpt, "ISystemTool")
baseTool.RunAndWaitForCompletion();
baseTool.Close();
OpenLocalOptimization()
返回ILocalOptimization
接口,而所有的运行、关闭等等都返回 ISystemTool
接口。因此,需要将派生类对象转换为基类对象,以访问基类中的内容。# Save and close
TheSystem.Save();
运行脚本之后,在 OpticStudio 中打开. ZMX 文件,并查看优化后的镜头。