Last active
May 27, 2021 15:54
ZOS-API: Wavefront Map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Modules | |
import matplotlib.pyplot as plt | |
# Definition from Standalone application | |
def reshape(data, x, y, transpose = False): | |
"""Converts a System.Double[,] to a 2D list for plotting or post processing | |
Parameters | |
---------- | |
data : System.Double[,] data directly from ZOS-API | |
x : x width of new 2D list [use var.GetLength(0) for dimension] | |
y : y width of new 2D list [use var.GetLength(1) for dimension] | |
transpose : transposes data; needed for some multi-dimensional line series data | |
Returns | |
------- | |
res : 2D list; can be directly used with Matplotlib or converted to | |
a numpy array using numpy.asarray(res) | |
""" | |
if type(data) is not list: | |
data = list(data) | |
var_lst = [y] * x; | |
it = iter(data) | |
res = [list(islice(it, i)) for i in var_lst] | |
if transpose: | |
return self.transpose(res); | |
return res | |
# Create a Wavefront Map analysis | |
MyWavefrontMap = TheSystem.Analyses.New_Analysis(ZOSAPI.Analysis.AnalysisIDM.WavefrontMap) | |
# Retrieve Wavefront Map settings | |
MyWavefrontMapSettings = MyWavefrontMap.GetSettings() | |
# Change to field number 2 | |
MyWavefrontMapSettings.Field.SetFieldNumber(2) | |
# Apply new settings | |
MyWavefrontMap.ApplyAndWaitForCompletion() | |
# Check the implementation status of this analysis feature in the ZOSAPI | |
print('Does Wavefront Map have fully-implemented settings?', MyWavefrontMap.HasAnalysisSpecificSettings) | |
# Retrieve Wavefront Map results | |
MyWavefrontMapResults = MyWavefrontMap.GetResults() | |
MyWavefrontMapGrid = MyWavefrontMapResults.GetDataGrid(0).Values | |
MyWavefrontMapArray = reshape(MyWavefrontMapGrid, MyWavefrontMapGrid.GetLength(0), MyWavefrontMapGrid.GetLength(1)) | |
# Plot results | |
plt.figure() | |
plt.imshow(MyWavefrontMapArray) | |
plt.show() | |
# (additional) Retrieve RMS wavefront error from a Merit Function operand | |
RMS_WaveFront = TheSystem.MFE.GetOperandValue(ZOSAPI.Editors.MFE.MeritOperandType.ZERN, -4, 2, 2, 1, 0, 0, 0, 0) | |
print(RMS_WaveFront) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment