Generates a dictionary with traces (key = label, value = trace object) from LTspice plot data (saved as .txt file). :param txtFile: Name of the text file stored in the ini.txt_path directory :type txtFile: str :return: Dictionary with key-value pairs: - key: *str
(txtFile)
| 1521 | return figObject |
| 1522 | |
| 1523 | def LTspiceData2Traces(txtFile): |
| 1524 | """ |
| 1525 | Generates a dictionary with traces (key = label, value = trace object) from |
| 1526 | LTspice plot data (saved as .txt file). |
| 1527 | |
| 1528 | :param txtFile: Name of the text file stored in the ini.txt_path directory |
| 1529 | :type txtFile: str |
| 1530 | |
| 1531 | :return: Dictionary with key-value pairs: |
| 1532 | |
| 1533 | - key: *str*: label of the trace |
| 1534 | - value: *SLiCAPplots.trace* trace object |
| 1535 | |
| 1536 | :rtype: dict |
| 1537 | """ |
| 1538 | try: |
| 1539 | f = open(ini.txt_path + txtFile, 'r', encoding='utf-8', errors='replace') |
| 1540 | lines = f.readlines() |
| 1541 | f.close() |
| 1542 | except: |
| 1543 | print('Error: could not find LTspice trace data:', ini.txt_path + txtFile) |
| 1544 | return {} |
| 1545 | traceDict = {} |
| 1546 | # Check for parameter stepping |
| 1547 | if len(lines) > 2 and lines[1].split()[0] == 'Step': |
| 1548 | start = 1 |
| 1549 | else: |
| 1550 | start = 0 |
| 1551 | label = None |
| 1552 | xData = [] |
| 1553 | yData = [] |
| 1554 | label = None |
| 1555 | traceNum = 0 |
| 1556 | for i in range(start, len(lines)): |
| 1557 | lineData = lines[i].split() |
| 1558 | if len(lineData) > 2 and ' '.join(lineData[0:2]) == 'Step Information:': |
| 1559 | if label != None: |
| 1560 | newTrace = trace([xData, yData]) |
| 1561 | newTrace.label = label |
| 1562 | traceDict[label] = newTrace |
| 1563 | xData = [] |
| 1564 | yData = [] |
| 1565 | traceNum += 1 |
| 1566 | label = lineData[2] |
| 1567 | elif len(lineData) == 2: |
| 1568 | try: |
| 1569 | xData.append(eval(lineData[0])) |
| 1570 | yData.append(eval(lineData[1])) |
| 1571 | except: |
| 1572 | if label != None: |
| 1573 | newTrace = trace([xData, yData]) |
| 1574 | newTrace.label = label |
| 1575 | newTrace.color = ini.default_colors[0] |
| 1576 | traceDict[label] = newTrace |
| 1577 | label = lineData[1] |
| 1578 | newTrace = trace([xData, yData]) |
| 1579 | newTrace.label = label |
| 1580 | traceDict[label] = newTrace |