diff --git a/examples/basic-usages/unit.py b/examples/basic-usages/unit.py index b4f9efc9..44f6b4a8 100755 --- a/examples/basic-usages/unit.py +++ b/examples/basic-usages/unit.py @@ -2,38 +2,44 @@ #################################################################################################### -import PySpice.Logging.Logging as Logging +from PySpice.Logging import Logging logger = Logging.setup_logging() #################################################################################################### -from PySpice import Circuit +from PySpice import Circuit, Simulator #################################################################################################### -from PySpice.Unit import * +# pylint: disable=no-name-in-module +from PySpice.Unit import ( + kilo, + as_Ω, u_kOhm, U_Ω, u_kΩ, + u_Degree, u_Hz, u_mA, u_mH, u_ms, u_uF, u_V, +) +# pylint: enable=no-name-in-module -foo = kilo(1) # unit less +foo = kilo(1) # unit less resistance_unit = U_Ω resistance1 = u_kΩ(1) -resistance1 = u_kOhm(1) # ASCII variant +resistance1 = u_kOhm(1) # ASCII variant resistance1 = 1@u_kΩ # using Python 3.5 syntax resistance1 = 1 @u_kΩ # space doesn't matter -resistance1 = 1 @ u_kΩ # +resistance1 = 1 @ u_kΩ -resistance2 = as_Ω(resistance1) # check unit +resistance2 = as_Ω(resistance1) # check unit -resistances = u_kΩ(range(1, 11)) # same as [u_kΩ(x) for x in range(1, 11)] +resistances = u_kΩ(range(1, 11)) # same as [u_kΩ(x) for x in range(1, 11)] resistances = range(1, 11)@u_kΩ # using Python 3.5 syntax capacitance = u_uF(200) inductance = u_mH(1) temperature = u_Degree(25) -voltage = resistance1 * u_mA(1) # compute unit +voltage = resistance1 * u_mA(1) # compute unit frequency = u_ms(20).frequency period = u_Hz(50).period @@ -78,9 +84,24 @@ circuit.V('input', 1, circuit.gnd, 10*u.V) circuit.R(1, 1, 2, 2*u.kΩ) -circuit.R(2, 1, 3, 1*u.kΩ) -circuit.R(3, 2, circuit.gnd, 1*u.kΩ) +circuit.R(2, 1, 3, 1*u.MΩ) +circuit.R(3, 2, circuit.gnd, 1*u.mΩ) circuit.R(4, 3, circuit.gnd, 2*u.kΩ) circuit.R(5, 3, 2, 2*u.kΩ) print(circuit) + +simulator = Simulator.factory() +simulation = simulator.simulation(circuit, temperature=25, nominal_temperature=25) +analysis = simulation.operating_point() + +for node in analysis.nodes.values(): + # Fixme: format value + unit + # Fixme: DeprecationWarning: Conversion of an arraywith ndim > 0 + # to a scalar is deprecated, and will error in future. Ensure you + # extract a single element from your array before performing this + # operation. (Deprecated NumPy 1.25.) + # _ = float(node) + _ = float(node[0]) + print(f'Node {node}: {_:4.1f} V') +#o#