MCPcopy Index your code
hub / github.com/SLiCAP/SLiCAP_python / LTspiceAC2SLiCAPtraces

Function LTspiceAC2SLiCAPtraces

SLiCAP/SLiCAPplots.py:1583–1645  ·  view source on GitHub ↗

This function converts the results of a single-run LTspice AC analysis into two traces (mag, phase) that can be added to SLiCAP plots. Stepping is not (yet) supported. :param fileName: Name of the file. The file should be located in the ditectory given in *ini.

(fileName, dB=False, color='c')

Source from the content-addressed store, hash-verified

1581 return traceDict
1582
1583def LTspiceAC2SLiCAPtraces(fileName, dB=False, color='c'):
1584 """
1585 This function converts the results of a single-run LTspice AC analysis
1586 into two traces (mag, phase) that can be added to SLiCAP plots.
1587 Stepping is not (yet) supported.
1588
1589 :param fileName: Name of the file. The file should be located in
1590 the ditectory given in *ini.txt_path*.
1591 :type fileName: str
1592
1593 :param dB: True if the trace magnitude should be in dB, else False.
1594 Default value = False
1595 :type dB: bool
1596
1597 :param color: Matplotlib color name. Valid names can be found at:
1598 https://matplotlib.org/stable/gallery/color/named_colors.html
1599 Default value is cyan (c); this does not correspond with one
1600 of the standard gain colors of the asymptotic-gain model.
1601 :type color: str
1602
1603 :return: a list with two trace dicts, magnitude and phase, respectively.
1604 :rtype: list
1605
1606 :Example:
1607
1608 >>> LTmag, LTphase = LTspiceAC2SLiCAPtraces('LTspiceACdata.txt')
1609 """
1610 try:
1611 f = open(ini.txt_path + fileName, 'r', encoding='utf-8', errors='replace')
1612 lines = f.readlines()
1613 f.close()
1614 except:
1615 print('Cannot find: ', fileName)
1616 lines = []
1617 freqs = []
1618 mag = []
1619 phase = []
1620 for i in range(len(lines)):
1621 if i != 0:
1622 line = lines[i].split()
1623 if ini.hz:
1624 freqs.append(eval(line[0]))
1625 else:
1626 freqs.append(eval(line[0])*2*np.pi)
1627 dBmag, deg = line[1].split(',')
1628 dBmag = eval(dBmag[1:-2])
1629 deg = eval(deg[0:-2])
1630 if not dB:
1631 mag.append(10**(dBmag/20))
1632 else:
1633 mag.append(dBmag)
1634 if ini.hz:
1635 phase.append(deg)
1636 else:
1637 phase.append(np.pi*deg/180)
1638 LTmag = trace([freqs, mag])
1639 LTmag.label = 'LTmag'
1640 LTmag.color = color

Callers

nothing calls this directly

Calls 1

traceClass · 0.85

Tested by

no test coverage detected