rkm-codes


Namerkm-codes JSON
Version 0.6 PyPI version JSON
download
home_page
SummaryQuantiPhy support for RKM codes.
upload_time2023-04-14 23:39:13
maintainer
docs_urlNone
authorKen Kundert
requires_python>=3.6
license
keywords quantiphy rkm
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. initialize RKM codes

    >>> from rkm_codes import set_prefs
    >>> set_prefs(
    ...     rkm_maps=None, units_to_rkm_base_code=None, map_sf=None,
    ...     show_units=None, strip_zeros=None, minus_sign=None, prec=None
    ... )

RKM codes
=========

| Version: 0.6
| Released: 2023-04-14
|

.. image:: https://pepy.tech/badge/rkm_codes/month
    :target: https://pepy.tech/project/rkm_codes

..  image:: https://github.com/KenKundert/rkm_codes/actions/workflows/build.yaml/badge.svg
    :target: https://github.com/KenKundert/rkm_codes/actions/workflows/build.yaml

.. image:: https://img.shields.io/coveralls/KenKundert/rkm_codes.svg
    :target: https://coveralls.io/r/KenKundert/rkm_codes

.. image:: https://img.shields.io/pypi/v/rkm_codes.svg
    :target: https://pypi.python.org/pypi/rkm_codes

.. image:: https://img.shields.io/pypi/pyversions/rkm_codes.svg
    :target: https://pypi.python.org/pypi/rkm_codes/

RKM codes are used to represent electrical quantities in labels, particularly on
schematics and on the components themselves.  They are standardized in various
national and international standards, including: IEC 60062 (1952) (formerly IEC 62),
DIN 40825 (1973), BS 1852 (1974), IS 8186 (1976) and EN 60062 (1993).
IEC-60062 was significantly updated in 2016.

RKM codes were originally used as part marking codes.  This shorthand
notation is widely used in electrical engineering to denote the values of
resistors and capacitors in circuit diagrams and in the production of electronic
circuits (for example in bills of material and in silk screens). This method
avoids overlooking the decimal separator, which may not be rendered reliably on
components or when duplicating documents.

The popularity of RKM codes was fading because they address a problem that is 
less common today. However they are making something of a come back as all the 
characters in a RKM code are either letters or digits and so they can be 
embedded in a software identifier without introducing illegal characters.

IEC 60062 is described in https://en.wikipedia.org/wiki/RKM_code.

Essentially an RKM version of a number is the number with a scale factor where
the decimal point is replaced by the scale factor. For example, a resistance of
4.7kΩ becomes 4k7. If there is no scale factor, the decimal point is replaced by
a letter that signifies the type of the component.  For example, a resistance of
4.7Ω becomes 4r7.

Resistance examples::

    R47 → 0.47 Ω
    4R7 → 4.7 Ω
    470R → 470 Ω
    4K7 → 4.7 kΩ
    47K → 47 kΩ
    47K3 → 47.3 kΩ
    470K → 470 kΩ
    4M7 → 4.7 MΩ

In the standard, large values are assumed to be resistances and small values are
assumed to be capacitances.  So 4k7 is a resistance and 2n5 is a capacitance.
However, this package also supports a version of RKM codes where the units are
not implied by the value, making RKM codes suitable for a wider variety of value
types, such as voltage, current, and inductance.


Installing
----------

This package converts RKM codes to `QuantiPhy Quantities
<https://quantiphy.readthedocs.io>`_ and Quantities to RKM codes.

Install with::

    pip3 install --user rkm_codes

Requires Python 3.6 or better.


Converting to and from RKM Codes
--------------------------------

The following is a simple example of how to convert back and forth between RKM
codes and Quantities::

    >>> from rkm_codes import from_rkm, to_rkm
    >>> r = from_rkm('6K8')
    >>> r
    Quantity('6.8k')

    >>> to_rkm(r)
    '6K8'

Notice that in this case the quantity does not include units. That is because by
default *rkm_codes* assumes unitless numbers. You can change this behavior.  Out
of the box *rkm_codes* supports two kinds of numbers, unitless and those that
follow the IEC60062 standard. You can switch between those two kinds of numbers
using something like this::

    >>> from rkm_codes import set_prefs, IEC60062_MAPS, UNITLESS_MAPS
    >>> r = from_rkm('6k8')
    >>> r
    Quantity('6.8k')

    >>> set_prefs(rkm_maps=IEC60062_MAPS)
    >>> from_rkm('6k8')
    Quantity('6.8 kΩ')

    >>> set_prefs(rkm_maps=UNITLESS_MAPS)
    >>> from_rkm('6k8')
    Quantity('6.8k')

In either case, *rkm_codes* allows you to explicitly specify the units, which
always overrides any implied units::

    >>> set_prefs(rkm_maps=UNITLESS_MAPS)
    >>> from_rkm('6kΩ8')
    Quantity('6.8 kΩ')

    >>> i = from_rkm('2uA5')
    >>> i
    Quantity('2.5 uA')

The primary argument for *to_rkm* can be a string, a float, or a quantity::

    >>> print(to_rkm('12.5 nA', prec=2))
    12n5

    >>> print(to_rkm(12.5e-9, prec=2))
    12n5

    >>> from quantiphy import Quantity
    >>> print(to_rkm(Quantity('12.5 nA'), prec=2))
    12n5

When converting to an RKM code, you can instruct that the units be included::

    >>> to_rkm(i, show_units=True)
    '2µA5'

You can also indicate how many digits should be included::

    >>> to_rkm(i.add(1e-9), prec=5, show_units=True)
    '2µA501'

Normally, any excess zeros are removed, but you can change that too::

    >>> to_rkm(i.add(1e-9), prec=5, show_units=True, strip_zeros=False)
    '2µA50100'

To shorten the output code it is possible to remove the base code when it is
extraneous::

    >>> from quantiphy import Quantity
    >>> to_rkm(Quantity('470Ω'), show_units=False)
    '470'

    >>> to_rkm(Quantity('470Ω'), show_units=False, strip_code=False)
    '470r'

Here is a short program that illustrates some of the options of *to_rkm*::

    >>> from rkm_codes import from_rkm, to_rkm, set_prefs, IEC60062_MAPS

    >>> set_prefs(prec=4)

    >>> q = from_rkm('0μΩ47')
    >>> while q < 1e6:
    ...     vals = [
    ...         q,
    ...         to_rkm(q),
    ...         to_rkm(q, strip_code=False),
    ...         to_rkm(q, show_units=True),
    ...         to_rkm(q, strip_zeros=False)
    ...     ]
    ...     print(' '.join(['  {:<9}'.format(v) for v in vals]).strip())
    ...     q = q.scale(10)
    470 nΩ      470n        470n        470nΩ       470n00
    4.7 uΩ      4µ7         4µ7         4µΩ7        4µ7000
    47 uΩ       47µ         47µ         47µΩ        47µ000
    470 uΩ      470µ        470µ        470µΩ       470µ00
    4.7 mΩ      4m7         4m7         4mΩ7        4m7000
    47 mΩ       47m         47m         47mΩ        47m000
    470 mΩ      470m        470m        470mΩ       470m00
    4.7 Ω       4r7         4r7         4Ω7         4r7000
    47 Ω        47          47r         47Ω         47r000
    470 Ω       470         470r        470Ω        470r00
    4.7 kΩ      4K7         4K7         4KΩ7        4K7000
    47 kΩ       47K         47K         47KΩ        47K000
    470 kΩ      470K        470K        470KΩ       470K00

If you prefer not to use the small SI scale factors, which would be more in
keeping with IEC60062 for resistors, you can specify that ``quantiphy.Quantity``
use a restricted ``output_sf``::

    >>> q = from_rkm('0μΩ47')
    >>> q.output_sf = 'TGMk'   # this line is new
    >>> while q < 1e6:
    ...     vals = [
    ...         q,
    ...         to_rkm(q),
    ...         to_rkm(q, strip_code=False),
    ...         to_rkm(q, show_units=True),
    ...         to_rkm(q, strip_zeros=False)
    ...     ]
    ...     print(' '.join(['  {:<9}'.format(v) for v in vals]).strip())
    ...     q = q.scale(10)
    470e-9 Ω    0           0r          0Ω          r0000
    4.7e-6 Ω    0           0r          0Ω          r0000
    47e-6 Ω     0           0r          0Ω          r0000
    470e-6 Ω    r0005       r0005       Ω0005       r0005
    4.7e-3 Ω    r0047       r0047       Ω0047       r0047
    47e-3 Ω     r047        r047        Ω047        r0470
    470e-3 Ω    r47         r47         Ω47         r4700
    4.7 Ω       4r7         4r7         4Ω7         4r7000
    47 Ω        47          47r         47Ω         47r000
    470 Ω       470         470r        470Ω        470r00
    4.7 kΩ      4K7         4K7         4KΩ7        4K7000
    47 kΩ       47K         47K         47KΩ        47K000
    470 kΩ      470K        470K        470KΩ       470K00

You can create your own maps by passing in a dictionary that maps a RKM base
code character into a scale factor and units. For example, you could create
a map that uses 'd' or 'D' to represent the decimal point in numbers without
scale factors rather than 'r', 'c', etc.  For example::

    >>> set_prefs(rkm_maps=dict(d=('', ''), D=('', '')))
    >>> from_rkm('6d8')
    Quantity('6.8')

    >>> from_rkm('2d5')
    Quantity('2.5')

Passing *None* for the value of a map returns it to its default value.

If *rkm_codes* encounters a RKM base code character that is not in the map, it
simply uses that character. In this way, scale factors are handled::

    >>> from_rkm('6k8')
    Quantity('6.8k')

When converting from Quantities to RKM codes, you can override the default
mappings from units to RKM base code characters. The default mapping maps 'Ω'
and 'Ohm' to 'r', 'F' to 'c', 'H' to 'l', 'V' to 'v', and 'A' to 'i'.  However,
you may prefer uppercase base characters, which is more in alignment with the
original standard. To get that, you can use something like this::

    >>> rkm_base_code_mappings = {
    ...     'Ω': 'R',
    ...     'Ohm': 'R',
    ...     'F': 'C',
    ...     'H': 'L',
    ...     'V': 'V',
    ...     'A': 'I',
    ... }
    >>> set_prefs(rkm_maps=IEC60062_MAPS, units_to_rkm_base_code=rkm_base_code_mappings)
    >>> r = from_rkm('k0012')
    >>> to_rkm(r)
    '1R2'

You can control the scale factors used by to_rkm() by setting *map_sf* using
*set_prefs*. The default maps 'u' to 'μ' and 'k' to 'K'. You might wish to
prevent the use of 'μ' while retaining the use of 'K', which you can do with::

    >>> set_prefs(map_sf=dict(u='µ'))
    >>> c = from_rkm('5u')
    >>> to_rkm(c)
    '5µ'


Finding RKM Codes
-----------------

*find_rkm* is available for finding the RKM codes embedded in text strings.
Using it, you can iterate through all the numbers specified using RKM::

    >>> from rkm_codes import find_rkm

    >>> text = '''
    ...     An RKM code that may include explicitly specified. Examples of
    ...     acceptable RKM codes for resistance include:   R47 (0.47 Ω), 4R7
    ...     (4.7 Ω), 470R (470 Ω), 4K7 (4.7 kΩ), 47K (47 kΩ), 47K3 (47.3 kΩ),
    ...     470K (470 kΩ), and 4M7 (4.7 MΩ).
    ... '''
    >>> for num in find_rkm(text):
    ...     print(num)
    470 mΩ
    4.7 Ω
    470 Ω
    4.7 kΩ
    47 kΩ
    47.3 kΩ
    470 kΩ
    4.7 MΩ

When the RKM code is not isolated by punctuation or spaces it can get confused
by leading and trailing text.  You can often resolve this issue by restricting
the matches to either the leading or trailing digit forms of the RKM code. Do so
by specifying either 'ld' or 'td' as a second argument.  For example::

    >>> for num in find_rkm('sink200nA'):
    ...     print(num)
    200 msink

    >>> for num in find_rkm('sink200nA', 'ld'):
    ...     print(num)
    200 nA


Pin Name Generator Example
--------------------------

As a practical example of the use of RKM codes, imagine wanting a program that
creates pin names for an electrical circuit based on a naming convention.  It
would take a table of pin characteristics that are used to create the names.
For example::

    >>> from quantiphy import Quantity
    >>> from rkm_codes import to_rkm, set_prefs as set_rkm_prefs

    >>> pins = [
    ...     dict(kind='ibias', direction='out', polarity='sink', dest='dac', value='250nA'),
    ...     dict(kind='ibias', direction='out', polarity='src', dest='rampgen', value='2.5μA'),
    ...     dict(kind='vref', direction='out', dest='dac', value='1.25V'),
    ...     dict(kind='vdda', direction='in', value='2.5V'),
    ... ]
    >>> set_rkm_prefs(map_sf={}, units_to_rkm_base_code=None, show_units=True, prec=2)

    >>> for pin in pins:
    ...     components = []
    ...     if 'value' in pin:
    ...         pin['VALUE'] = to_rkm(Quantity(pin['value']))
    ...     for name in ['dest', 'kind', 'direction', 'VALUE', 'polarity']:
    ...         if name in pin:
    ...             components.append(pin[name])
    ...     print('_'.join(components))
    dac_ibias_out_250nA_sink
    rampgen_ibias_out_2uA5_src
    dac_vref_out_1V25
    vdda_in_2V5


Releases
--------

**Latest development release**:
    | Version: 0.6
    | Released: 2023-04-14

**0.6 (2023-04-14)**:
    - Suppress *rkm_code*’s use of the new SI scale factors in `QuantiPhy 
      <https://quantiphy.readthedocs.io>`_ so that ``R`` is no longer treated as 
      a scale factor when using the latest version of *QuantiPhy*.

**0.5 (2020-02-01)**:
    - Allow argument to *to_rkm()* to be a string or simple number
    - Added *strip_code* preference
    - With small numbers show 0 rather than exponent

**0.4 (2019-08-29)**:
    - added *find_rkm()*

**0.3 (2019-08-23)**:
    - move the units to the middle of the number with the scale factor
    - added support for signed numbers
    - added *show_units*, *strip_zeros*, *minus_sign*, and *prec* to preferences
    - this release is not backward compatible; units at the end of the number
      are no longer supported

**0.2 (2018-09-14)**:
    - fixed issue in *set_prefs()*

**0.1 (2018-09-12)**:
    - initial release




            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "rkm-codes",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "quantiphy,rkm",
    "author": "Ken Kundert",
    "author_email": "rkm_codes@nurdletech.com",
    "download_url": "https://files.pythonhosted.org/packages/91/93/a0423cbe92076382e73a961f1df0a28248a762d9bc045866bf5205ef05dd/rkm_codes-0.6.tar.gz",
    "platform": null,
    "description": ".. initialize RKM codes\n\n    >>> from rkm_codes import set_prefs\n    >>> set_prefs(\n    ...     rkm_maps=None, units_to_rkm_base_code=None, map_sf=None,\n    ...     show_units=None, strip_zeros=None, minus_sign=None, prec=None\n    ... )\n\nRKM codes\n=========\n\n| Version: 0.6\n| Released: 2023-04-14\n|\n\n.. image:: https://pepy.tech/badge/rkm_codes/month\n    :target: https://pepy.tech/project/rkm_codes\n\n..  image:: https://github.com/KenKundert/rkm_codes/actions/workflows/build.yaml/badge.svg\n    :target: https://github.com/KenKundert/rkm_codes/actions/workflows/build.yaml\n\n.. image:: https://img.shields.io/coveralls/KenKundert/rkm_codes.svg\n    :target: https://coveralls.io/r/KenKundert/rkm_codes\n\n.. image:: https://img.shields.io/pypi/v/rkm_codes.svg\n    :target: https://pypi.python.org/pypi/rkm_codes\n\n.. image:: https://img.shields.io/pypi/pyversions/rkm_codes.svg\n    :target: https://pypi.python.org/pypi/rkm_codes/\n\nRKM codes are used to represent electrical quantities in labels, particularly on\nschematics and on the components themselves.  They are standardized in various\nnational and international standards, including: IEC 60062 (1952) (formerly IEC 62),\nDIN 40825 (1973), BS 1852 (1974), IS 8186 (1976) and EN 60062 (1993).\nIEC-60062 was significantly updated in 2016.\n\nRKM codes were originally used as part marking codes.  This shorthand\nnotation is widely used in electrical engineering to denote the values of\nresistors and capacitors in circuit diagrams and in the production of electronic\ncircuits (for example in bills of material and in silk screens). This method\navoids overlooking the decimal separator, which may not be rendered reliably on\ncomponents or when duplicating documents.\n\nThe popularity of RKM codes was fading because they address a problem that is \nless common today. However they are making something of a come back as all the \ncharacters in a RKM code are either letters or digits and so they can be \nembedded in a software identifier without introducing illegal characters.\n\nIEC 60062 is described in https://en.wikipedia.org/wiki/RKM_code.\n\nEssentially an RKM version of a number is the number with a scale factor where\nthe decimal point is replaced by the scale factor. For example, a resistance of\n4.7k\u03a9 becomes 4k7. If there is no scale factor, the decimal point is replaced by\na letter that signifies the type of the component.  For example, a resistance of\n4.7\u03a9 becomes 4r7.\n\nResistance examples::\n\n    R47 \u2192 0.47 \u03a9\n    4R7 \u2192 4.7 \u03a9\n    470R \u2192 470 \u03a9\n    4K7 \u2192 4.7 k\u03a9\n    47K \u2192 47 k\u03a9\n    47K3 \u2192 47.3 k\u03a9\n    470K \u2192 470 k\u03a9\n    4M7 \u2192 4.7 M\u03a9\n\nIn the standard, large values are assumed to be resistances and small values are\nassumed to be capacitances.  So 4k7 is a resistance and 2n5 is a capacitance.\nHowever, this package also supports a version of RKM codes where the units are\nnot implied by the value, making RKM codes suitable for a wider variety of value\ntypes, such as voltage, current, and inductance.\n\n\nInstalling\n----------\n\nThis package converts RKM codes to `QuantiPhy Quantities\n<https://quantiphy.readthedocs.io>`_ and Quantities to RKM codes.\n\nInstall with::\n\n    pip3 install --user rkm_codes\n\nRequires Python 3.6 or better.\n\n\nConverting to and from RKM Codes\n--------------------------------\n\nThe following is a simple example of how to convert back and forth between RKM\ncodes and Quantities::\n\n    >>> from rkm_codes import from_rkm, to_rkm\n    >>> r = from_rkm('6K8')\n    >>> r\n    Quantity('6.8k')\n\n    >>> to_rkm(r)\n    '6K8'\n\nNotice that in this case the quantity does not include units. That is because by\ndefault *rkm_codes* assumes unitless numbers. You can change this behavior.  Out\nof the box *rkm_codes* supports two kinds of numbers, unitless and those that\nfollow the IEC60062 standard. You can switch between those two kinds of numbers\nusing something like this::\n\n    >>> from rkm_codes import set_prefs, IEC60062_MAPS, UNITLESS_MAPS\n    >>> r = from_rkm('6k8')\n    >>> r\n    Quantity('6.8k')\n\n    >>> set_prefs(rkm_maps=IEC60062_MAPS)\n    >>> from_rkm('6k8')\n    Quantity('6.8 k\u03a9')\n\n    >>> set_prefs(rkm_maps=UNITLESS_MAPS)\n    >>> from_rkm('6k8')\n    Quantity('6.8k')\n\nIn either case, *rkm_codes* allows you to explicitly specify the units, which\nalways overrides any implied units::\n\n    >>> set_prefs(rkm_maps=UNITLESS_MAPS)\n    >>> from_rkm('6k\u03a98')\n    Quantity('6.8 k\u03a9')\n\n    >>> i = from_rkm('2uA5')\n    >>> i\n    Quantity('2.5 uA')\n\nThe primary argument for *to_rkm* can be a string, a float, or a quantity::\n\n    >>> print(to_rkm('12.5 nA', prec=2))\n    12n5\n\n    >>> print(to_rkm(12.5e-9, prec=2))\n    12n5\n\n    >>> from quantiphy import Quantity\n    >>> print(to_rkm(Quantity('12.5 nA'), prec=2))\n    12n5\n\nWhen converting to an RKM code, you can instruct that the units be included::\n\n    >>> to_rkm(i, show_units=True)\n    '2\u00b5A5'\n\nYou can also indicate how many digits should be included::\n\n    >>> to_rkm(i.add(1e-9), prec=5, show_units=True)\n    '2\u00b5A501'\n\nNormally, any excess zeros are removed, but you can change that too::\n\n    >>> to_rkm(i.add(1e-9), prec=5, show_units=True, strip_zeros=False)\n    '2\u00b5A50100'\n\nTo shorten the output code it is possible to remove the base code when it is\nextraneous::\n\n    >>> from quantiphy import Quantity\n    >>> to_rkm(Quantity('470\u03a9'), show_units=False)\n    '470'\n\n    >>> to_rkm(Quantity('470\u03a9'), show_units=False, strip_code=False)\n    '470r'\n\nHere is a short program that illustrates some of the options of *to_rkm*::\n\n    >>> from rkm_codes import from_rkm, to_rkm, set_prefs, IEC60062_MAPS\n\n    >>> set_prefs(prec=4)\n\n    >>> q = from_rkm('0\u03bc\u03a947')\n    >>> while q < 1e6:\n    ...     vals = [\n    ...         q,\n    ...         to_rkm(q),\n    ...         to_rkm(q, strip_code=False),\n    ...         to_rkm(q, show_units=True),\n    ...         to_rkm(q, strip_zeros=False)\n    ...     ]\n    ...     print(' '.join(['  {:<9}'.format(v) for v in vals]).strip())\n    ...     q = q.scale(10)\n    470 n\u03a9      470n        470n        470n\u03a9       470n00\n    4.7 u\u03a9      4\u00b57         4\u00b57         4\u00b5\u03a97        4\u00b57000\n    47 u\u03a9       47\u00b5         47\u00b5         47\u00b5\u03a9        47\u00b5000\n    470 u\u03a9      470\u00b5        470\u00b5        470\u00b5\u03a9       470\u00b500\n    4.7 m\u03a9      4m7         4m7         4m\u03a97        4m7000\n    47 m\u03a9       47m         47m         47m\u03a9        47m000\n    470 m\u03a9      470m        470m        470m\u03a9       470m00\n    4.7 \u03a9       4r7         4r7         4\u03a97         4r7000\n    47 \u03a9        47          47r         47\u03a9         47r000\n    470 \u03a9       470         470r        470\u03a9        470r00\n    4.7 k\u03a9      4K7         4K7         4K\u03a97        4K7000\n    47 k\u03a9       47K         47K         47K\u03a9        47K000\n    470 k\u03a9      470K        470K        470K\u03a9       470K00\n\nIf you prefer not to use the small SI scale factors, which would be more in\nkeeping with IEC60062 for resistors, you can specify that ``quantiphy.Quantity``\nuse a restricted ``output_sf``::\n\n    >>> q = from_rkm('0\u03bc\u03a947')\n    >>> q.output_sf = 'TGMk'   # this line is new\n    >>> while q < 1e6:\n    ...     vals = [\n    ...         q,\n    ...         to_rkm(q),\n    ...         to_rkm(q, strip_code=False),\n    ...         to_rkm(q, show_units=True),\n    ...         to_rkm(q, strip_zeros=False)\n    ...     ]\n    ...     print(' '.join(['  {:<9}'.format(v) for v in vals]).strip())\n    ...     q = q.scale(10)\n    470e-9 \u03a9    0           0r          0\u03a9          r0000\n    4.7e-6 \u03a9    0           0r          0\u03a9          r0000\n    47e-6 \u03a9     0           0r          0\u03a9          r0000\n    470e-6 \u03a9    r0005       r0005       \u03a90005       r0005\n    4.7e-3 \u03a9    r0047       r0047       \u03a90047       r0047\n    47e-3 \u03a9     r047        r047        \u03a9047        r0470\n    470e-3 \u03a9    r47         r47         \u03a947         r4700\n    4.7 \u03a9       4r7         4r7         4\u03a97         4r7000\n    47 \u03a9        47          47r         47\u03a9         47r000\n    470 \u03a9       470         470r        470\u03a9        470r00\n    4.7 k\u03a9      4K7         4K7         4K\u03a97        4K7000\n    47 k\u03a9       47K         47K         47K\u03a9        47K000\n    470 k\u03a9      470K        470K        470K\u03a9       470K00\n\nYou can create your own maps by passing in a dictionary that maps a RKM base\ncode character into a scale factor and units. For example, you could create\na map that uses 'd' or 'D' to represent the decimal point in numbers without\nscale factors rather than 'r', 'c', etc.  For example::\n\n    >>> set_prefs(rkm_maps=dict(d=('', ''), D=('', '')))\n    >>> from_rkm('6d8')\n    Quantity('6.8')\n\n    >>> from_rkm('2d5')\n    Quantity('2.5')\n\nPassing *None* for the value of a map returns it to its default value.\n\nIf *rkm_codes* encounters a RKM base code character that is not in the map, it\nsimply uses that character. In this way, scale factors are handled::\n\n    >>> from_rkm('6k8')\n    Quantity('6.8k')\n\nWhen converting from Quantities to RKM codes, you can override the default\nmappings from units to RKM base code characters. The default mapping maps '\u03a9'\nand 'Ohm' to 'r', 'F' to 'c', 'H' to 'l', 'V' to 'v', and 'A' to 'i'.  However,\nyou may prefer uppercase base characters, which is more in alignment with the\noriginal standard. To get that, you can use something like this::\n\n    >>> rkm_base_code_mappings = {\n    ...     '\u03a9': 'R',\n    ...     'Ohm': 'R',\n    ...     'F': 'C',\n    ...     'H': 'L',\n    ...     'V': 'V',\n    ...     'A': 'I',\n    ... }\n    >>> set_prefs(rkm_maps=IEC60062_MAPS, units_to_rkm_base_code=rkm_base_code_mappings)\n    >>> r = from_rkm('k0012')\n    >>> to_rkm(r)\n    '1R2'\n\nYou can control the scale factors used by to_rkm() by setting *map_sf* using\n*set_prefs*. The default maps 'u' to '\u03bc' and 'k' to 'K'. You might wish to\nprevent the use of '\u03bc' while retaining the use of 'K', which you can do with::\n\n    >>> set_prefs(map_sf=dict(u='\u00b5'))\n    >>> c = from_rkm('5u')\n    >>> to_rkm(c)\n    '5\u00b5'\n\n\nFinding RKM Codes\n-----------------\n\n*find_rkm* is available for finding the RKM codes embedded in text strings.\nUsing it, you can iterate through all the numbers specified using RKM::\n\n    >>> from rkm_codes import find_rkm\n\n    >>> text = '''\n    ...     An RKM code that may include explicitly specified. Examples of\n    ...     acceptable RKM codes for resistance include:   R47 (0.47 \u03a9), 4R7\n    ...     (4.7 \u03a9), 470R (470 \u03a9), 4K7 (4.7 k\u03a9), 47K (47 k\u03a9), 47K3 (47.3 k\u03a9),\n    ...     470K (470 k\u03a9), and 4M7 (4.7 M\u03a9).\n    ... '''\n    >>> for num in find_rkm(text):\n    ...     print(num)\n    470 m\u03a9\n    4.7 \u03a9\n    470 \u03a9\n    4.7 k\u03a9\n    47 k\u03a9\n    47.3 k\u03a9\n    470 k\u03a9\n    4.7 M\u03a9\n\nWhen the RKM code is not isolated by punctuation or spaces it can get confused\nby leading and trailing text.  You can often resolve this issue by restricting\nthe matches to either the leading or trailing digit forms of the RKM code. Do so\nby specifying either 'ld' or 'td' as a second argument.  For example::\n\n    >>> for num in find_rkm('sink200nA'):\n    ...     print(num)\n    200 msink\n\n    >>> for num in find_rkm('sink200nA', 'ld'):\n    ...     print(num)\n    200 nA\n\n\nPin Name Generator Example\n--------------------------\n\nAs a practical example of the use of RKM codes, imagine wanting a program that\ncreates pin names for an electrical circuit based on a naming convention.  It\nwould take a table of pin characteristics that are used to create the names.\nFor example::\n\n    >>> from quantiphy import Quantity\n    >>> from rkm_codes import to_rkm, set_prefs as set_rkm_prefs\n\n    >>> pins = [\n    ...     dict(kind='ibias', direction='out', polarity='sink', dest='dac', value='250nA'),\n    ...     dict(kind='ibias', direction='out', polarity='src', dest='rampgen', value='2.5\u03bcA'),\n    ...     dict(kind='vref', direction='out', dest='dac', value='1.25V'),\n    ...     dict(kind='vdda', direction='in', value='2.5V'),\n    ... ]\n    >>> set_rkm_prefs(map_sf={}, units_to_rkm_base_code=None, show_units=True, prec=2)\n\n    >>> for pin in pins:\n    ...     components = []\n    ...     if 'value' in pin:\n    ...         pin['VALUE'] = to_rkm(Quantity(pin['value']))\n    ...     for name in ['dest', 'kind', 'direction', 'VALUE', 'polarity']:\n    ...         if name in pin:\n    ...             components.append(pin[name])\n    ...     print('_'.join(components))\n    dac_ibias_out_250nA_sink\n    rampgen_ibias_out_2uA5_src\n    dac_vref_out_1V25\n    vdda_in_2V5\n\n\nReleases\n--------\n\n**Latest development release**:\n    | Version: 0.6\n    | Released: 2023-04-14\n\n**0.6 (2023-04-14)**:\n    - Suppress *rkm_code*\u2019s use of the new SI scale factors in `QuantiPhy \n      <https://quantiphy.readthedocs.io>`_ so that ``R`` is no longer treated as \n      a scale factor when using the latest version of *QuantiPhy*.\n\n**0.5 (2020-02-01)**:\n    - Allow argument to *to_rkm()* to be a string or simple number\n    - Added *strip_code* preference\n    - With small numbers show 0 rather than exponent\n\n**0.4 (2019-08-29)**:\n    - added *find_rkm()*\n\n**0.3 (2019-08-23)**:\n    - move the units to the middle of the number with the scale factor\n    - added support for signed numbers\n    - added *show_units*, *strip_zeros*, *minus_sign*, and *prec* to preferences\n    - this release is not backward compatible; units at the end of the number\n      are no longer supported\n\n**0.2 (2018-09-14)**:\n    - fixed issue in *set_prefs()*\n\n**0.1 (2018-09-12)**:\n    - initial release\n\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "QuantiPhy support for RKM codes.",
    "version": "0.6",
    "split_keywords": [
        "quantiphy",
        "rkm"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "28d89a514973979562b5ca3b9e4904bced755c66e2229bdfaef2860a282a3d5c",
                "md5": "34130a2f3b0fd5c1766bfe2a7a3f19a2",
                "sha256": "62431bcece10fc52c6a50b15270874abe50a27cd072038ad4e363e3c696bee6d"
            },
            "downloads": -1,
            "filename": "rkm_codes-0.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "34130a2f3b0fd5c1766bfe2a7a3f19a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 10391,
            "upload_time": "2023-04-14T23:39:11",
            "upload_time_iso_8601": "2023-04-14T23:39:11.636790Z",
            "url": "https://files.pythonhosted.org/packages/28/d8/9a514973979562b5ca3b9e4904bced755c66e2229bdfaef2860a282a3d5c/rkm_codes-0.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9193a0423cbe92076382e73a961f1df0a28248a762d9bc045866bf5205ef05dd",
                "md5": "657b545dd2b5c5c47326dd7a75d7d6e7",
                "sha256": "4d1ccea5f6aa3857e5127530983a1f75b8a1a22f3756adbdea0f9649d45e8432"
            },
            "downloads": -1,
            "filename": "rkm_codes-0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "657b545dd2b5c5c47326dd7a75d7d6e7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 11839,
            "upload_time": "2023-04-14T23:39:13",
            "upload_time_iso_8601": "2023-04-14T23:39:13.526408Z",
            "url": "https://files.pythonhosted.org/packages/91/93/a0423cbe92076382e73a961f1df0a28248a762d9bc045866bf5205ef05dd/rkm_codes-0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-14 23:39:13",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "rkm-codes"
}
        
Elapsed time: 0.06386s