Hello!
I am able to read in the tabular numerical values from a ZTD file.
But how can I read in the column names, row names and extra data as you see in a ZTD file?

Thanks
Hello!
I am able to read in the tabular numerical values from a ZTD file.
But how can I read in the column names, row names and extra data as you see in a ZTD file?
Thanks
Hi Asuku,
To get the Column Name and Extra Data, you should use the MonteCarloData.GetMetadata()
method. The column name will either be the Name
parameter or the GetOperandType()
method depending on if the column itself is an operand or extra calculated tolerance data. The extra data is actually the parameters for the column, so you would use the NumberOfParameters
property and the GetParameter()
method to retrieve these values. You need to check if the parameter is a double, integer, or a string value. The code to retrieve these values would look like:
import numpy as np
# open & run the tool
tool = TheSystem.Tools.OpenToleranceDataViewer()
tool.FileName = full_file_name
tool.RunAndWaitForCompletion()
# get the matrix data (using numpy for numeric arrays is easier than nested lists)
data = np.asarray(tool.MonteCarloData.Values.Data)
num_rows, num_cols = data.shape
# Get column name & summary (`GetMetadata` is 0-indexed)
for idx in range(num_cols):
col = tool.MonteCarloData.GetMetadata(idx)
if col.IsOperand:
print(str(col.GetOperandType()))
else:
print(col.Name)
for jdx in range(col.NumberOfParameters):
param = col.GetParameter(jdx)
if param.IsDouble:
print('\t%s : %f' % (param.Name, param.DoubleValue))
elif param.IsInt:
print('\t%s : %i' % (param.Name, param.IntValue))
elif param.IsString:
print('\t%s : %s' % (param.Name, param.StringValue))
else:
print('Error in parsing parameter')
# always close your tool
tool.Close()
Since each row is just a collection of numbers and the Monte Carlo files themselves are always numbered (default of MC_Txxxx.zmx if saved to disk), the “MC_n” itself isn’t saved in the ZTD file...this would just take up extra space on disk and isn’t necessary. If you want to recreate the MC_n for the rows, you can take the num_rows
from the np.asarray(tool.MonteCarloData.Values.Data)
, loop through all the rows, and recreate the row labels.
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.