conversions.prefix_conversions ============================== .. py:module:: conversions.prefix_conversions .. autoapi-nested-parse:: Convert International System of Units (SI) and Binary prefixes Classes ------- .. autoapisummary:: conversions.prefix_conversions.BinaryUnit conversions.prefix_conversions.SIUnit Functions --------- .. autoapisummary:: conversions.prefix_conversions.convert_binary_prefix conversions.prefix_conversions.convert_si_prefix Module Contents --------------- .. py:class:: BinaryUnit(*args, **kwds) Bases: :py:obj:`enum.Enum` Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access: >>> Color.RED - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:attribute:: exa :value: 6 .. py:attribute:: giga :value: 3 .. py:attribute:: kilo :value: 1 .. py:attribute:: mega :value: 2 .. py:attribute:: peta :value: 5 .. py:attribute:: tera :value: 4 .. py:attribute:: yotta :value: 8 .. py:attribute:: zetta :value: 7 .. py:class:: SIUnit(*args, **kwds) Bases: :py:obj:`enum.Enum` Create a collection of name/value pairs. Example enumeration: >>> class Color(Enum): ... RED = 1 ... BLUE = 2 ... GREEN = 3 Access them by: - attribute access: >>> Color.RED - value lookup: >>> Color(1) - name lookup: >>> Color['RED'] Enumerations can be iterated over, and know how many members they have: >>> len(Color) 3 >>> list(Color) [, , ] Methods can be added to enumerations, and members can have their own attributes -- see the documentation for details. .. py:attribute:: atto :value: -18 .. py:attribute:: centi :value: -2 .. py:attribute:: deca :value: 1 .. py:attribute:: deci :value: -1 .. py:attribute:: exa :value: 18 .. py:attribute:: femto :value: -15 .. py:attribute:: giga :value: 9 .. py:attribute:: hecto :value: 2 .. py:attribute:: kilo :value: 3 .. py:attribute:: mega :value: 6 .. py:attribute:: micro :value: -6 .. py:attribute:: milli :value: -3 .. py:attribute:: nano :value: -9 .. py:attribute:: peta :value: 15 .. py:attribute:: pico :value: -12 .. py:attribute:: tera :value: 12 .. py:attribute:: yocto :value: -24 .. py:attribute:: yotta :value: 24 .. py:attribute:: zepto :value: -21 .. py:attribute:: zetta :value: 21 .. py:function:: convert_binary_prefix(known_amount: float, known_prefix: str | BinaryUnit, unknown_prefix: str | BinaryUnit) -> float Wikipedia reference: https://en.wikipedia.org/wiki/Metric_prefix >>> convert_binary_prefix(1, BinaryUnit.giga, BinaryUnit.mega) 1024 >>> convert_binary_prefix(1, BinaryUnit.mega, BinaryUnit.giga) 0.0009765625 >>> convert_binary_prefix(1, BinaryUnit.kilo, BinaryUnit.kilo) 1 >>> convert_binary_prefix(1, 'giga', 'mega') 1024 >>> convert_binary_prefix(1, 'gIGa', 'mEGa') 1024 .. py:function:: convert_si_prefix(known_amount: float, known_prefix: str | SIUnit, unknown_prefix: str | SIUnit) -> float Wikipedia reference: https://en.wikipedia.org/wiki/Binary_prefix Wikipedia reference: https://en.wikipedia.org/wiki/International_System_of_Units >>> convert_si_prefix(1, SIUnit.giga, SIUnit.mega) 1000 >>> convert_si_prefix(1, SIUnit.mega, SIUnit.giga) 0.001 >>> convert_si_prefix(1, SIUnit.kilo, SIUnit.kilo) 1 >>> convert_si_prefix(1, 'giga', 'mega') 1000 >>> convert_si_prefix(1, 'gIGa', 'mEGa') 1000