def ZernikeCoefficients(self, fileName=None): # Zernike Standard Coefficients Analysis Results zernike = self.TheSystem.Analyses.New_Analysis( constants.AnalysisIDM_ZernikeStandardCoefficients) zernike_setting = zernike.GetSettings() baseSetting = CastTo(zernike_setting, 'IAS_ZernikeStandardCoefficients') baseSetting.Field.SetFieldNumber(0) baseSetting.Wavelength.UseAllWavelengths() baseSetting.Surface.UseImageSurface() # Extract Zernike Coefficients base = CastTo(zernike, 'IA_') base.ApplyAndWaitForCompletion() zernike_results = base.GetResults() results = CastTo(zernike_results, 'IAR_') file = fileName if fileName is not None else "res.txt" import os cwd = os.getcwd() path = self.datadir + file results.GetTextFile(path) coefficients = extractZernikeCoefficents(path) np.savetxt(self.datadir + "zernike.csv", coefficients, delimiter=",") zernike.Close()
def StandardSpot(self, referType): spot = self.__TheAnalyses.New_Analysis( constants.AnalysisIDM_StandardSpot) spot_setting = spot.GetSettings() baseSetting = CastTo(spot_setting, 'IAS_Spot') baseSetting.Field.UseAllFields() baseSetting.ReferTo = eval(dictReferType[referType]) base = CastTo(spot, 'IA_') base.ApplyAndWaitForCompletion() spot_results = base.GetResults() return spot_results
def SpotDiagramAnalysisResults(self): # Spot Diagram Analysis Results spot = self.TheSystem.Analyses.New_Analysis( constants.AnalysisIDM_StandardSpot) spot_setting = spot.GetSettings() baseSetting = CastTo(spot_setting, 'IAS_Spot') baseSetting.Field.SetFieldNumber(0) baseSetting.Wavelength.UseAllWavelengths() baseSetting.Surface.UseImageSurface() # extract RMS & Geo spot size for field points base = CastTo(spot, 'IA_') base.ApplyAndWaitForCompletion() spot_results = base.GetResults() f = open(self.datadir + "rmsgeo.txt", "w+") f.write( str(spot_results.SpotData.GetRMSSpotSizeFor(1, 1)) + "\n" + str(spot_results.SpotData.GetGeoSpotSizeFor(1, 1))) # print('RMS radius: %6.3f' % # (spot_results.SpotData.GetRMSSpotSizeFor(1, 1))) # print('GEO radius: %6.3f' % # (spot_results.SpotData.GetGeoSpotSizeFor(1, 1))) spot.Close()
plt.draw() #! [e22s06_py] # Spot Diagram Analysis Results spot = TheSystem.Analyses.New_Analysis(constants.AnalysisIDM_StandardSpot) spot_setting = spot.GetSettings() baseSetting = CastTo(spot_setting, 'IAS_Spot') baseSetting.Field.SetFieldNumber(0) baseSetting.Wavelength.SetWavelengthNumber(0) baseSetting.ReferTo = constants.ReferTo_Centroid #! [e22s06_py] #! [e22s07_py] # extract RMS & Geo spot size for field points base = CastTo(spot, 'IA_') base.ApplyAndWaitForCompletion() #spot_results = spot.GetResults() spot_results = base.GetResults() print('RMS radius: %6.3f %6.3f %6.3f' % (spot_results.SpotData.GetRMSSpotSizeFor( 1, 1), spot_results.SpotData.GetRMSSpotSizeFor( 2, 1), spot_results.SpotData.GetRMSSpotSizeFor(3, 1))) print('GEO radius: %6.3f %6.3f %6.3f' % (spot_results.SpotData.GetGeoSpotSizeFor( 1, 1), spot_results.SpotData.GetGeoSpotSizeFor( 2, 1), spot_results.SpotData.GetGeoSpotSizeFor(3, 1))) #! [e22s07_py] # This will clean up the connection to OpticStudio. # Note that it closes down the server instance of OpticStudio, so you for maximum performance do not do # this until you need to.
# make your modifications to it # MODIFYSETTINGS are defined in the ZPL help files: The Programming Tab > About the ZPL > Keywords settings.ModifySettings(cfgFile, 'SHA_ROTX', '90') settings.ModifySettings(cfgFile, 'SHA_ROTY', '0') settings.ModifySettings(cfgFile, 'SHA_ROTZ', '0') # now load in the modified settings settings.LoadFrom(cfgFile) # If you want to overwrite your default CFG, copy it after you are done modifying the settings: # CFG_fullname = os.environ.get('USERPROFILE') + '\\Documents\\Zemax\\Configs\\POP.CFG' # copyfile(cfgFile, CFG_fullname) # We don't need the temp file any more, so delete it if os.path.exists(cfgFile): os.remove(cfgFile) # Run the analysis with the new settings baseTool = CastTo(analysis, 'IA_') baseTool.ApplyAndWaitForCompletion() # ! [e15s06_py] # ! [e15s07_py] # remove all variables and add a F# solve on last surface radius TheLDE = TheSystem.LDE # IOpticalSystemTools tools = TheSystem.Tools tools.RemoveAllVariables() Surface_Last = TheLDE.GetSurfaceAt(TheLDE.NumberOfSurfaces - 2) Solver = Surface_Last.RadiusCell.CreateSolveType( constants.SolveType_FNumber) Solver._S_FNumber.FNumber = 3.1415 Surface_Last.RadiusCell.SetSolveData(Solver) SampleFile = zosapi.TheApplication.SamplesDir + '\\API\\Python\\e15_Seq_Optimization\\OptimizedFile1.ZMX' TheSystem.SaveAs(SampleFile)