Package empro :: Package toolkit :: Package analysis :: Module display_template_generation
[frames] | no frames]

Source Code for Module empro.toolkit.analysis.display_template_generation

  1  # Copyright 1983-2019 Keysight Technologies, Inc, Keysight Confidential 
  2   
  3  # Generate a data display template (ddt) for the node names that are passed. 
  4  # The top level function is generateDisplayTemplate. To use it, one needs to  
  5  # supply the file name of the output ddt file, an array of node names to be plotted  
  6  # and the parameterData. A testing function is attached at the end of this script. 
  7   
  8  import random 
  9  import math 
 10  # used to indent the text written to the ddt file 
 11  unitIndent = "    " 
 12  # used to calculate plot position, controls the margin around the plot 
 13  leftMargin = 150 
 14  rightMargin = 150 
 15  topMargin = 1500 
 16  bottomMargin = 1250 
 17  displayRatio = 16.0/9.0 
 18  # keep count of markers to place them as m1, m2, m3, etc.  
 19  markerCount = None 
 20   
 21  # top level function to generate a ddt file 
 22  # fileName  - name of the ddt file to be generated 
 23  # nodeNames - node names that need to be plotted after the simulation 
 24  # parameterData - parameters set in xxPro parameter window  
25 -def generateDisplayTemplate(fileName, nodeNames, switchingFreq):
26 global markerCount 27 28 # default, last number of cycles to be plotted 29 lastNCyclesEqnName = 'lastNCycles' 30 defaultLastNCycles = 2 31 32 #pageId = random.randint(1000000000,9999999999) 33 ddtLines = [] 34 35 # start of function _DDStemplateSaveRestore_ 36 ddtLines.append('defun _DDStemplateSaveRestore_()\n{') 37 38 # write header of ddt file 39 ddtLines.append('decl ddsId, ddWinId, ddoId, pageId, goId, traceId, axisId, plotId, markerId;') 40 ddtLines.append('\nddsId = get_dds();') 41 ddtLines.append('\nddoId = get(ddsId, "CurrentObject");') 42 ddtLines.append('\npageId = get(ddoId, "CurrentPage");') 43 #ddtLines.append('set(pageId, "Uid", %d);\n' % pageId) 44 #ddtLines.append('set(pageId, "Name", "Voltage Spikes Analysis");') 45 #ddtLines.append('set(pageId, "Invisible", FALSE);') 46 ddtLines.append('\nset(ddoId, "EnableExpressionUpdates", FALSE);') 47 48 # add an equation to control number of cycles 49 #ddtLines.append('\n//Equation to select the number of cycles to be plotted') 50 ddtLines.append('goId = get_new(pageId, "Equation");') 51 ddtLines.append(unitIndent + 'set(goId, "Expression", "lastNCycles = %d");' % defaultLastNCycles) 52 ddtLines.append(unitIndent + 'set(goId, "Left", -1000);') 53 ddtLines.append(unitIndent + 'set(goId, "Top", -250);') 54 55 # initialize the marker count to 1 56 markerCount = 1 57 58 # calculate the position and plot the nodes 59 stepX = 6000.0 60 stepY = 6500.0 61 origin = [1000.0, 1000.0] 62 numberOfColumns = math.floor(math.sqrt(len(nodeNames)*displayRatio)) 63 for ind in range(0, len(nodeNames)): 64 dx = stepX*(ind%numberOfColumns) 65 dy = stepY*(ind//numberOfColumns) 66 newOrigin = [origin[0]+dx, origin[1]+dy] 67 pos = [newOrigin[0]+leftMargin, newOrigin[1]+stepY-bottomMargin, newOrigin[0]+stepX-rightMargin, newOrigin[1]+bottomMargin] 68 ddtLines.append(generatePlot(nodeNames[ind], switchingFreq, pos, 1)) 69 70 # generate equations page 71 ddtLines.append(generateEquationPage(switchingFreq, lastNCyclesEqnName, 1)) 72 73 # set base class object 74 ddtLines.append('\nset(ddoId, "UpdateAllExpressions", TRUE);') 75 ddtLines.append('set(ddoId, "EnableExpressionUpdates", TRUE);') 76 77 # View All command, to display all the plots on the window 78 ddtLines.append('\nset(ddsId, "Action", ddsToolZoomAll);') 79 80 # end of function _DDStemplateSaveRestore_ 81 ddtLines.append('}') 82 83 # call function _DDStemplateSaveRestore_ 84 ddtLines.append('_DDStemplateSaveRestore_();') 85 86 # Create list of plotted node names as comment 87 ddtLines.append('\n// Node names plotted:') 88 for ind in range(0, len(nodeNames)): 89 ddtLines.append('// ' + str(ind) + ': ' + nodeNames[ind]) 90 ddtLines.append('\n') 91 92 ddtLines = '\n'.join(ddtLines) 93 94 # write to the file 95 with open(fileName, "w") as fp: 96 fp.write(ddtLines) 97 fp.close() 98 return 0
99 100 # generate a plot for nodeName 101 # position are specified as [left, bottom, right, top]
102 -def generatePlot(nodeName, switchingFreq, pos, nIndent):
103 #uid = random.randint(1000000000,9999999999) 104 plot = [] 105 plot.append('\ngoId = get_new(pageId, "Plot");') 106 plot.append(unitIndent*nIndent + 'set(goId, "InitPlot", 0);') 107 #plot.append(unitIndent*nIndent + 'set(goId, "Uid", %d);' % uid) 108 plot.append(unitIndent*nIndent + 'set(goId, "NameId", 0);') 109 plot.append(unitIndent*nIndent + 'set(goId, "Name", "default");') 110 plot.append(unitIndent*nIndent + 'set(goId, "Right", %d);' % pos[2]) 111 plot.append(unitIndent*nIndent + 'set(goId, "Bottom", %d);' % pos[1]) 112 plot.append(unitIndent*nIndent + 'set(goId, "Left", %d);' % pos[0]) 113 plot.append(unitIndent*nIndent + 'set(goId, "Top", %d);' % pos[3]) 114 plot.append(unitIndent*nIndent + 'set(goId, "Zrot", 0.0);') 115 plot.append(unitIndent*nIndent + 'set(goId, "Yrot", 0.0);') 116 plot.append(unitIndent*nIndent + 'set(goId, "Xrot", 0.0);') 117 plot.append(unitIndent*nIndent + 'set(goId, "Status", 0);') 118 plot.append(unitIndent*nIndent + 'set(goId, "LineColor", 0);') 119 plot.append(unitIndent*nIndent + 'set(goId, "LineType", 0);') 120 plot.append(unitIndent*nIndent + 'set(goId, "LineWidth", 7);') 121 plot.append(unitIndent*nIndent + 'set(goId, "FillPattern", -1);') 122 plot.append(unitIndent*nIndent + 'set(goId, "FillColor", 0);') 123 plot.append(unitIndent*nIndent + 'set(goId, "LegendOnOff", TRUE);') 124 plot.append(unitIndent*nIndent + 'set(goId, "leftMargingin", %d);' % leftMargin) 125 plot.append(unitIndent*nIndent + 'set(goId, "rightMargingin", %d);' % rightMargin) 126 plot.append(unitIndent*nIndent + 'set(goId, "topMargingin", %d);' % topMargin) 127 plot.append(unitIndent*nIndent + 'set(goId, "bottomMargingin", %d);' % bottomMargin) 128 plot.append(unitIndent*nIndent + 'set(goId, "Title", "%s");' % nodeName) 129 plot.append(unitIndent*nIndent + 'set(goId, "TitleFont", "Arial For CAE");') 130 plot.append(unitIndent*nIndent + 'set(goId, "TitleFontSize", 150);') 131 plot.append(unitIndent*nIndent + 'set(goId, "TitleColor", 0);') 132 plot.append(generateFourAxes(nIndent)) 133 plot.append(generateTrace(nodeName, nIndent)) 134 result = '%s[_startIndex::_stopIndex]' % nodeName 135 if switchingFreq > 0: 136 plot.append(generateMarkers(result, switchingFreq, nIndent)) 137 #plot.append('set(goId, "PlotLogoHideOnOff", FALSE);') 138 plot = '\n'.join(plot) 139 return plot
140 141 # generate 4 axes for the plot
142 -def generateFourAxes(nIndent):
143 axes = [] 144 axes.append(unitIndent*nIndent + 'axisId = get_new(goId, "Axis", ddsXaxis, "X Axis");') 145 axes.append(generateAxis(nIndent+1)) 146 axes.append(unitIndent*nIndent + 'axisId = get_new(goId, "Axis", ddsYaxis, "Y Axis");') 147 axes.append(generateAxis(nIndent+1)) 148 axes = '\n'.join(axes) 149 return axes
150 151 # generate 1 axis
152 -def generateAxis(nIndent):
153 axis = [] 154 # uid = random.randint(1000000000,9999999999) 155 axis.append(unitIndent*nIndent + 'if (axisId != NULL) {') 156 #axis.append(unitIndent*(nIndent+1) + 'set(axisId, "Uid", %d);' % uid) 157 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "Color", 104);') 158 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "UserLabel", "");') 159 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "LabelColor", 0);') 160 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "TicksOnOff", TRUE);') 161 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "GridOnOff", TRUE);') 162 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "LabelsOnOff", TRUE);') 163 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "FontSize", 140);') 164 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "LineThick", 14);') 165 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "LineType", 0);') 166 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "TickFontSize", 140);') 167 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "AutoscaleOnOff", TRUE);') 168 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "Logarithmic", FALSE);') 169 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "Font", "Arial For CAE");') 170 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "Format", ddsFormatAutomatic);') 171 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "AxisLabelRot", 0);') 172 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "NumDigits", 3);') 173 axis.append(unitIndent*(nIndent+1) + 'set(axisId, "DisplayAllIndependentData", TRUE);') 174 axis.append(unitIndent*nIndent + '}') 175 axis = '\n'.join(axis) 176 return axis
177 178 # generate a trace on the axes
179 -def generateTrace(node, nIndent):
180 trace = [] 181 # uid = random.randint(1000000000,9999999999) 182 trace.append(unitIndent*nIndent + 'traceId = get_new(goId, "Trace", "%s[_startIndex::_stopIndex]", "X Axis", "Y Axis");' % node) 183 trace.append(generateTraceFormat(nIndent+1)) 184 trace.append(unitIndent*(nIndent+1) + 'if (traceId != NULL) {') 185 trace.append(unitIndent*(nIndent+2) + 'set(traceId, "TraceType", ddsAutomaticTraceType);') 186 trace.append(unitIndent*(nIndent+2) + 'set(traceId, "Color", 1);') 187 #trace.append(unitIndent*(nIndent+1) + 'set(traceId, "Uid", %d);' % uid) 188 trace.append(unitIndent*(nIndent+2) + 'set(traceId, "UIIndex", 0);') 189 trace.append(unitIndent*(nIndent+2) + 'set(traceId, "Status", 43008);') 190 trace.append(unitIndent*(nIndent+1) + '}') 191 trace = '\n'.join(trace) 192 return trace
193 194 # generate format for a trace
195 -def generateTraceFormat(nIndent):
196 traceFormat = [] 197 traceFormat.append(unitIndent*nIndent + 'if (traceId != NULL) {') 198 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "LineThick", 7);') 199 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "LineType", ddsSolidLineType);') 200 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "FillPattern", 0);') 201 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "SymbolType", ddsCircleSymbol);') 202 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "SymbolsOnOff", FALSE);') 203 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "DisplaySinglePointSymbols", TRUE);') 204 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "SymbolsSpacing", 15);') 205 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "AlwaysDisplayTransitions", FALSE);') 206 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "SpectralArrowheadsOnOff", TRUE);') 207 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "LabelSubtracesOnOff", TRUE);') 208 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "FillHistogramsOnOff", FALSE);') 209 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "Format", ddsFormatAutomatic);') 210 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "NumDigits", 3);') 211 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "Font", "Arial For CAE");') 212 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "FontSize", 112);') 213 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "LineColorAutoSequence", FALSE);') 214 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "LineTypeAutoSequence", FALSE);') 215 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "SymbolTypeAutoSequence", FALSE);') 216 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "LineColorAutoSequenceOrder", 3);') 217 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "LineTypeAutoSequenceOrder", 1);') 218 traceFormat.append(unitIndent*(nIndent+1) + 'set(traceId, "SymbolTypeAutoSequenceOrder", 2);') 219 traceFormat.append(unitIndent*(nIndent+1) + 'if (DDSnumTraceTypes > 8) {') 220 traceFormat.append(unitIndent*(nIndent+2) + 'set(traceId, "NumberOfDensityColors", 16);') 221 traceFormat.append(unitIndent*(nIndent+2) + 'set(traceId, "DensityColorOffset", 0);') 222 traceFormat.append(unitIndent*(nIndent+2) + 'set(traceId, "DensityStartColor", 20);') 223 traceFormat.append(unitIndent*(nIndent+2) + 'set(traceId, "DensitySymbolType", ddsDotSymbol);') 224 traceFormat.append(unitIndent*(nIndent+1) + '}') 225 traceFormat.append(unitIndent*nIndent + '}') 226 traceFormat = '\n'.join(traceFormat) 227 return traceFormat
228 229 230 # generate an equation page that calculates startIndex, stopIndex 231 # based on switching frequency and number of cycles to be plotted
232 -def generateEquationPage(switchingFreq, lastNCyclesEqnName, nIndent):
233 pageName = '_equations_' 234 pageInvisibile = 'FALSE'; 235 expressionList = generateExpressionList(switchingFreq, lastNCyclesEqnName) 236 237 # create the equation page 238 equationPage = [] 239 equationPage.append(generatePageId(nIndent)) 240 equationPage.append(setPageVisibility(pageInvisibile, nIndent)) 241 equationPage.append(generateEquation(expressionList, nIndent)) 242 equationPage = '\n'.join(equationPage) 243 return equationPage 244
245 -def generateExpressionList(switchingFreq, lastNCyclesEqnName):
246 if switchingFreq > 0: 247 startIndexExp = '_startIndex = _pe_findStartIndex(%f, %s, time)' % (switchingFreq, lastNCyclesEqnName) 248 else: 249 startIndexExp = '0' 250 stopIndexExp = '_stopIndex = sweep_size(time) - 1' 251 expressionList = [startIndexExp, stopIndexExp] 252 return expressionList
253 254 # generate pageId
255 -def generatePageId(nIndent):
256 pageId = '\npageId = get_new(ddoId, "Page");' 257 return pageId
258 259 # generate equation
260 -def generateEquation(expressionList, nIndent):
261 topPosition = 0 262 bottomPosition = 250 263 equation = [] 264 for ind in expressionList: 265 equation.append('\ngoId = get_new(pageId, "Equation");') 266 equation.append(unitIndent*nIndent + 'set(goId, "Expression", "%s");' % ind) 267 equation.append(unitIndent*nIndent + 'set(goId, "Bottom", %s);' % bottomPosition) 268 equation.append(unitIndent*nIndent + 'set(goId, "Top", %s);' % topPosition) 269 topPosition = topPosition + 375 270 bottomPosition = bottomPosition + 375 271 equation = '\n'.join(equation) 272 return equation
273 274 # generate markers
275 -def generateMarkers(result, switchingFreq, nIndent):
276 marker = [] 277 marker.append(generateBaselineMarker(result, switchingFreq, nIndent)) 278 marker.append(generatePeakMarker(result, nIndent)) 279 marker.append(generateNextPeakMarker(result, switchingFreq, nIndent)) 280 marker = ''.join(marker) 281 return marker
282
283 -def generateBaselineMarker(result, switchingFreq, nIndent):
284 global markerCount 285 baselineMarker = unitIndent*nIndent + 'markerId = get_new(traceId, "MarkerNew", "m%d", "_pe_findBaselineValueTime(%s, %f)", 0, "", "", 1, "");\n' % (markerCount, result, switchingFreq) 286 markerCount += 1 287 return baselineMarker
288
289 -def generatePeakMarker(result, nIndent):
290 global markerCount 291 peakMarker = [] 292 peakMarker.append(unitIndent*nIndent + 'markerId = get_new(traceId, "MarkerNew", "m%d", "_pe_findMaxValueTime(%s)", 0, "", "", 1, "m%d");' % (markerCount, result, markerCount-1)) 293 peakMarker.append(unitIndent*(nIndent+1) + 'if (markerId != NULL) {') 294 peakMarker.append(unitIndent*(nIndent+2) + 'set(markerId, "DeltaModeStatus", 1);') 295 peakMarker.append(unitIndent*(nIndent+2) + 'set(markerId, "ReadoutIndeVisualLabel", 0);') 296 peakMarker.append(unitIndent*(nIndent+1) + '}\n') 297 peakMarker = '\n'.join(peakMarker) 298 markerCount += 1 299 return peakMarker
300
301 -def generateNextPeakMarker(result, switchingFreq, nIndent):
302 global markerCount 303 nextPeakMarker = [] 304 nextPeakMarker.append(unitIndent*nIndent + 'markerId = get_new(traceId, "MarkerNew", "m%d", "_pe_findNextPeakValueTime(%s, %f)", 0, "", "", 1, "m%d");' % (markerCount, result, switchingFreq, markerCount-1)) 305 nextPeakMarker.append(unitIndent*(nIndent+1) + 'if (markerId != NULL) {') 306 nextPeakMarker.append(unitIndent*(nIndent+2) + 'set(markerId, "DeltaModeStatus", 1);') 307 nextPeakMarker.append(unitIndent*(nIndent+2) + 'set(markerId, "ReadoutDepeVisualLabel", 0);') 308 nextPeakMarker.append(unitIndent*(nIndent+1) + '}') 309 nextPeakMarker = '\n'.join(nextPeakMarker) 310 markerCount += 1 311 return nextPeakMarker
312 313 # set base class object for equation
314 -def setPageVisibility(pageInvisibile, nIndent):
315 baseClassObject = [] 316 #baseClassObject.append('set(pageId, "Name", "%s");' % pageName) 317 baseClassObject.append(unitIndent*nIndent + 'set(pageId, "Invisible",%s);' % pageInvisibile) 318 baseClassObject = ''.join(baseClassObject) 319 return baseClassObject
320