AscEditor¶
Class used for manipulating LTSpice asc files.
- class PyLTSpice.editor.asc_editor.AscEditor(asc_file: str)[source]¶
Bases:
BaseEditor
Class made to update directly the ltspice ASC files
- add_instruction(instruction: str) None [source]¶
Serves to add SPICE instructions to the simulation netlist. For example:
.tran 10m ; makes a transient simulation .meas TRAN Icurr AVG I(Rs1) TRIG time=1.5ms TARG time=2.5ms" ; Establishes a measuring .step run 1 100, 1 ; makes the simulation run 100 times
- Parameters:
instruction (str) – Spice instruction to add to the netlist. This instruction will be added at the end of the netlist, typically just before the .BACKANNO statement
- Returns:
Nothing
- property circuit_file: Path¶
Returns the netlist as a string
- get_component_value(element: str) str [source]¶
Returns the value of a component retrieved from the netlist.
- Parameters:
element (str) – Reference of the circuit element to get the value.
- Returns:
value of the circuit element .
- Return type:
str
- Raises:
ComponentNotFoundError - In case the component is not found
NotImplementedError - for not supported operations
- get_components(prefixes='*') list [source]¶
Returns a list of components that match the list of prefixes indicated on the parameter prefixes. In case prefixes is left empty, it returns all the ones that are defined by the REPLACE_REGEXES. The list will contain the designators of all components found.
- Parameters:
prefixes (str) – Type of prefixes to search for. Examples: ‘C’ for capacitors; ‘R’ for Resistors; etc… See prefixes in SPICE documentation for more details. The default prefix is ‘*’ which is a special case that returns all components.
- Returns:
A list of components matching the prefixes demanded.
- get_parameter(param: str) str [source]¶
Retrieves a Parameter from the Netlist
- Parameters:
param (str) – Name of the parameter to be retrieved
- Returns:
Value of the parameter being sought
- Return type:
str
- Raises:
ParameterNotFoundError - In case the component is not found
- remove_component(designator: str)[source]¶
Removes a component from the design. Note: Current implementation only allows removal of a component from the main netlist, not from a sub-circuit.
- Parameters:
designator (str) – Component reference in the design. Ex: V1, C1, R1, etc…
- Returns:
Nothing
- Raises:
ComponentNotFoundError - When the component doesn’t exist on the netlist.
- remove_instruction(instruction: str) None [source]¶
Usage a previously added instructions. Example:
LTC.remove_instruction(".STEP run -1 1023 1")
This only works if the instruction exactly matches the line on the netlist. This means that space characters, and upper case and lower case differences will not match the line.
- Parameters:
instruction (str) – The list of instructions to remove. Each instruction is of the type ‘str’
- Returns:
Nothing
- set_component_value(device: str, value: Union[str, int, float]) None [source]¶
Changes the value of a component, such as a Resistor, Capacitor or Inductor. For components inside subcircuits, use the subcirciut designator prefix with ‘:’ as separator (Example X1:R1) Usage:
LTC.set_component_value('R1', '3.3k') LTC.set_component_value('X1:C1', '10u')
- Parameters:
device (str) – Reference of the circuit element to be updated.
value (str, int or float) – value to be be set on the given circuit element. Float and integer values will automatically formatted as per the engineering notations ‘k’ for kilo, ‘m’, for mili and so on.
- Raises:
ComponentNotFoundError - In case the component is not found
ValueError - In case the value doesn’t correspond to the expected format
NotImplementedError - In case the circuit element is defined in a format which is not supported by this version.
If this is the case, use GitHub to start a ticket. https://github.com/nunobrum/PyLTSpice
- set_element_model(element: str, model: str) None [source]¶
Changes the value of a circuit element, such as a diode model or a voltage supply. Usage:
LTC.set_element_model('D1', '1N4148') LTC.set_element_model('V1' "SINE(0 1 3k 0 0 0)")
- Parameters:
element (str) – Reference of the circuit element to be updated.
model (str) – model name of the device to be updated
- Raises:
ComponentNotFoundError - In case the component is not found
ValueError - In case the model format contains irregular characters
NotImplementedError - In case the circuit element is defined in a format which is not supported by this version.
If this is the case, use GitHub to start a ticket. https://github.com/nunobrum/PyLTSpice
- set_parameter(param: str, value: Union[str, int, float]) None [source]¶
Adds a parameter to the SPICE netlist.
Usage:
LTC.set_parameter("TEMP", 80)
This adds onto the netlist the following line:
.PARAM TEMP=80
This is an alternative to the set_parameters which is more pythonic in it’s usage, and allows setting more than one parameter at once.
- Parameters:
param (str) – Spice Parameter name to be added or updated.
value (str, int or float) – Parameter Value to be set.
- Returns:
Nothing