simplipfy.Helpers package
Submodules
simplipfy.Helpers.impedanceConverter module
- simplipfy.Helpers.impedanceConverter.ComponentToImpedance(netlistLine: str, omega_0: float | str = None, skipElementTypes=None, replaceElementType=None, replaceValueWith=None, debug=False, newLine=False) str
- Parameters:
netlistLine – a line of a lcapy.Circuit.netlist()
omega_0 – circular frequency used for the conversion to impedance, If None symbol lcapy.omega_0 is used.
skipElementTypes – List of element types that should not be converted to impedance, if None [“V”, “W”] is used
replaceElementType – dictionary with element types as keys and the new element type as value, if None {“R”: “Z”, “L”: “Z”, “C”: “Z”} is used
replaceValueWith – dictionary with element types as keys and the new value as value, if None {“R”: “value”, “L”: “j*value*omega_0”, “C”: “-j/(value*omega_0)”} is used
Converts the value of a NetlistLine to impedance. Extracts the value from the NetlistLine.value property replaces it with the according impedance value and replaces the type with the according impedance type. Then reconstructs the new NetlistLine and returns the netlist as a string.
E.g.: converts: C2 5 6 {100}; C2 5 6 100; down; to: Z2 5 6 {-j/(100*omega_0)}; down
skipElementTypes = ["V", "W"] replaceElementType = {"R": "Z", "L": "Z", "C": "Z"} replaceValueWith = {"R": "value", "L": "j*value*omega_0", "C": "-j/(value*omega_0)"}
- simplipfy.Helpers.impedanceConverter.FileToImpedance(filename: str) str
- Parameters:
filename – filename to open, with path and extension
- Returns:
converted netlist as str
Converts a netlist file that has a mixture of R L C elements to Z (impedance)
- simplipfy.Helpers.impedanceConverter.ImpedanceToComponent(strNetlistLine: str = None, netlistLine: NetlistLine = None, omega_0: float | str = None) str
- Parameters:
strNetlistLine – a line of a lcapy.Circuit.netlist()
netlistLine – simplipfy.Helpers.netlistLine.NetlistLine() Object, created from strNetlistLine
omega_0 – circular frequency used for the conversion to impedance, If None symbol lcapy.omega_0 is used.
- Returns:
The converted netlist line as a string with the transformed value and type
Converts a NetlistLine to its corresponding Component (R, L, or C) if it is not possible it returns the input strNetlistLine
- simplipfy.Helpers.impedanceConverter.NeedsConversion(netlist: str, checkForTypes=None) bool
- Parameters:
netlist – netlist as a list of strings, lines separated by
checkForTypes – list of types to check for, if None [“R”, “L”, “C”] is used
- Returns:
True if there is more than one type of component in the netlist, False otherwise
Checks if there is more than one type of component in the netlist/circuit. Checks for R, L, and C by default
- simplipfy.Helpers.impedanceConverter.ValueToComponent(value, omega_0: float | str = None) -> (<class 'sympy.core.mul.Mul'>, <class 'str'>)
- Parameters:
value – the value to convert
omega_0 – circular frequency used for the conversion to impedance, If None symbol lcapy.omega_0 is used.
- Returns:
The converted value and the type of the component
Converts an impedance value to its corresponding component value
- simplipfy.Helpers.impedanceConverter.getOmegaFromCircuit(circuit: Circuit) float | Mul | None
- Parameters:
circuit – lcapyInskale.Circuit object
- Returns:
If omega_0 is a float returns a float, if it is a string returns a sympy expression in any other case
- Warns:
If there are multiple sources in the circuit, a warning is raised and the first source is used returns 0
Retrieves omega_0 from the circuit.
simplipfy.Helpers.langSymbols module
- class simplipfy.Helpers.langSymbols.LangSymbols(args: Dict[str, str] = {})
Bases:
objectThis class is used to define some language-specific symbols used in text, equations and labels (e.g., voltage across R1 in German U1 in English V1)
simplipfy.Helpers.netlistLine module
- class simplipfy.Helpers.netlistLine.NetlistLine(line: str)
Bases:
objectWrapper for lcapy Objects to access frequently used attributes
- complexComponent = ['Z', 'ZR', 'ZL', 'ZC']
- electricalComponent = ['R', 'L', 'C', 'Z', 'ZR', 'ZL', 'ZC']
- property label: str
- meters = ['VM', 'AM']
- realComponent = ['R', 'L', 'C']
- reconstruct() str
- Returns:
reconstructed string
reconstructs self.line from the parsed elements self.type, self.typeSuffix, self.startNode, self.endNode, self.ac_dc, self.value, self.phase, self.omega, self.drawParam
- sources = ['V', 'I']
- swapNodes()
swaps the nodes of the netlist line, result:
self.posNode = self.negNode self.negNode = self.posNode
- class simplipfy.Helpers.netlistLine.NetlistLineParser(*args, **kwargs)
Bases:
object
simplipfy.Helpers.solution module
- class simplipfy.Helpers.solution.Solution(steps: list[SolutionStep], langSymbols: LangSymbols)
Bases:
object- addKeyMapping(accessKey, realKey: str) None
- Parameters:
accessKey – key that you want to use
realKey – key name from this class step0, step1, step2, …
- Returns:
None
If a KeyError is thrown, a dictionary is searched. If it is in the dictionary the __getItem__ or __getAttr__ it is tried again with the specified key in the Dictionary
- static check_path(path: str)
checks if the Solution directory exists, if not, it will be created
- draw(filename: str = 'circuit', path: str = None) None
- Parameters:
filename – optional filename, files will be named filename_step<n>.svg n = 0,1 …, len(availableSteps)
path – directory in which to save the json-Files in, if None save in current directory
- Returns:
None
- Raises:
ValueError – if path is not a directory
Saves a svg-File for each step in the Solution.
- drawStep(step, filename=None, path: str = None) str
- Parameters:
step – step0, step1, step2, …, step<n> …, self.getAvailableSteps returns all valid steps
filename – optional filename, files will be named filename_step<n>.svg n = 0,1 …, len(availableSteps)
path – directory in which to save the json-File in, if None save in the current directory
- Returns:
path to the svg-File
- Raises:
ValueError – if path is not a directory
Draws the circuit for a specific step
- exportAsDicts() list[dict]
- Returns:
list of dictionaries, list contains each step as a dict for details of dict see exportStepAsDict
- exportAsJsonFiles(path: str = None, filename: str = 'circuit')
- Parameters:
path – Directory in which to save the json-File in, if None save in current directory
filename – json-File will be named <filename>_step<n>.json n = 0,1 …, len(availableSteps)
debug – Print dictionary used to create the json-File
Export all steps to json-Files.
- exportCircuitInfo(step) Step0ExportDict
:returns the circuit information of step0 as a dictionary
- exportStepAsDict(step) ExportDictBase
:returns the circuit information of any step in the solution as a dictionary
- exportStepAsJson(step: str, path: str = None, filename: str = 'circuit') str
- Parameters:
step – step0, step1, step2, …, step<n> …, self.getAvailableSteps returns all valid steps
path – directory in which to save the json-File in, if None save in current directory
filename – json-File will be named <filename>_step<n>.json n = 0,1 …, len(availableSteps)
debug – print dictionary used to create the json-File
Export a step to a json-File
- getAvailableSteps(skip: set[str]) list[str]
- Parameters:
skip – set of step names to skip
- Returns:
List of string with the names of the steps
Returns all available Steps
- static getElementSpecificValue(element: R | C | L | Z, unit=False) ConstantDomainExpression
- Parameters:
element – Mnacpts.R | mnacpts.L | mnacpts.C | mnacpts.Z
unit – if True the Unit (ohm, F, H) is added to the str
- Returns:
lcapy Object of value if the unit is true with unit set in the object.
Lcapy does not have a function to get the value of a component e.g.: Resistance for R1 and capacitance of C1 This function is used to get the value of a component. It uses the type of the component to determine which field to access to return the correct value.
- removeKeyMapping(accessKey)
removes the mapping of a key that was added with self.addKeyMapping
- steps(skip: set[str] = None) Iterable[SolutionStep]
- Parameters:
skip – defines a set of step names that should be skipped
- Returns:
yields the steps of the solution
simplipfy.Helpers.unitPrefixer module
- class simplipfy.Helpers.unitPrefixer.SIUnitPrefixer
Bases:
object- getSIPrefix(value: float | int | Mul | Expr) Prefix
:param value to get the prefix for :returns: the sympy.prefix for the given value
get the nearest unit prefix value
E.g.: 10,000 F -> 10 kF 0.0001 F -> 100 mF
- getSIPrefixedExpr(value: float | int | Mul | Expr, minExponent=3) Expr
add the nearest unit prefix to float, int, lcapy.ConstantFrequencyResponseDomainExpression or sympy.Mul prefixes are sympy.physics.units.prefixes.PREFIXES
- getSIPrefixedMul(value: float | int | Mul | Expr, minExponent=3) Mul
add the nearest unit prefix to float, int, lcapy.ConstantFrequencyResponseDomainExpression or sympy.Mul prefixes are sympy.physics.units.prefixes.PREFIXES
simplipfy.Helpers.unitWorkAround module
- class simplipfy.Helpers.unitWorkAround.UnitWorkAround
Bases:
objectAdd units to values based on the type of the element
- static addUnit(val, cptType)
- static getUnit(element: R | C | L | Z) ConstantFrequencyResponseDomainExpression
- Parameters:
element – value to add unit
- Returns:
unit, as lcapy Object
Returns the unit of an element
for R, Z -> ohm for C -> F for L -> H