circuitsascode.utilities module¶
Utility functions.
- circuitsascode.utilities.apply_units(v, units)[source]¶
Apply unit to a dimensionless value. Return dimensional values unchanged.
- Parameters
v (numeric, unit) – The value to which units will be applied.
units (unit) – Unit to apply to the value.
- Returns
A value with a Pint unit applied to it.
- Return type
unit
Example
>>> from circuitsascode.utilities import * >>> apply_units(5, units.volts) <Quantity(5, 'volt')> >>> apply_units(10 * units.ohms, units.kohms) <Quantity(10, 'ohm')> >>> apply_units(1000000 * units.volts, units.volts) <Quantity(1.0, 'megavolt')>
- circuitsascode.utilities.find_nearest_c(c, e_series='E24')[source]¶
Find the nearest E-series capacitor value to the given value.
- Parameters
c (numeric/Part, unit) – Capacitor Part or capacitance as a number with or without an attached Pint nanofarad unit.
e_series (string, optional) – E-series of capacitor values (E3, E6, E12, E24, E48, E96, E192). Defaults to “E24” (5%).
- Returns
The closest E-series value with Pint Farad unit attached.
- Return type
unit
Example
>>> from circuitsascode.utilities import * >>> find_nearest_c(350) <Quantity(360.0, 'nanofarad')> >>> find_nearest_r(350 * units.microfarad, "E12") <Quantity(330.0, 'microfarad')>
- circuitsascode.utilities.find_nearest_r(r, e_series='E24')[source]¶
Find the nearest E-series resistor value to the given value.
- Parameters
r (numeric/Part, unit) – Resistor Part or resistance as a number with or without an attached Pint Ohm unit.
e_series (string, optional) – E-series of resistor values (E3, E6, E12, E24, E48, E96, E192). Defaults to “E24” (5%).
- Returns
The closest E-series value with Pint Ohm unit attached.
- Return type
unit
Example
>>> from circuitsascode.utilities import * >>> find_nearest_r(350) <Quantity(360.0, 'ohm')> >>> find_nearest_r(350 * units.kohm, "E12") <Quantity(330.0, 'kiloohm')>