{ "info": { "author": "Ken Kundert", "author_email": "rkm_codes@nurdletech.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "Natural Language :: English", "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Utilities" ], "description": ".. initialize RKM codes\n\n >>> from rkm_codes import set_prefs\n >>> set_prefs(rkm_maps=None, units_to_rkm_base_code=None, map_sf=None)\n\nRKM codes\n=========\n\n| Version: 0.2.0\n| Released: 2018-09-14\n|\n\n.. image:: https://img.shields.io/travis/KenKundert/rkm_codes/master.svg\n :target: https://travis-ci.org/KenKundert/rkm_codes\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 meant also as part marking code. 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. They also provide the benefit that\nthe characters within a RKM code are either letters or digits, and so can be\nembedded within identifiers without introducing invalid 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 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\nThis package is used to convert RKM codes to `QuantiPhy Quantities \n`_ and Quantities to RKM codes.\n\nInstall with::\n\n pip3 install --user rkm_codes\n\nRequires Python3.4 or better.\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('6k8\u03a9')\n Quantity('6.8 k\u03a9')\n\n >>> i = from_rkm('2u5A')\n >>> i\n Quantity('2.5 uA')\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\u03bc5A'\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\u03bc501A'\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\u03bc50100A'\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\u03a9')\n Quantity('6.8 \u03a9')\n\n >>> from_rkm('2d5V')\n Quantity('2.5 V')\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\u03a9')\n Quantity('6.8 k\u03a9')\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(k='K'))\n >>> c = from_rkm('5u')\n >>> to_rkm(c)\n '5u'\n\n\nPin 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)\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_250n_sink\n rampgen_ibias_out_2u5_src\n dac_vref_out_1v2\n vdda_in_2v5\n", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/kenkundert/rkm_codes/tarball/master", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://nurdletech.com/linux-utilities/rkm_codes", "keywords": "rkm codes", "license": "GPLv3+", "maintainer": "", "maintainer_email": "", "name": "rkm_codes", "package_url": "https://pypi.org/project/rkm_codes/", "platform": "", "project_url": "https://pypi.org/project/rkm_codes/", "project_urls": { "Download": "https://github.com/kenkundert/rkm_codes/tarball/master", "Homepage": "https://nurdletech.com/linux-utilities/rkm_codes" }, "release_url": "https://pypi.org/project/rkm_codes/0.2.0/", "requires_dist": null, "requires_python": "", "summary": "Quantiphy support for RKM codes.", "version": "0.2.0" }, "last_serial": 4272576, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "9e6f73b0059f35e951529ae8481db418", "sha256": "037a4b69ceffb231e02a64bd782f357e69d5defbd4d0ada821c19cfba8feca60" }, "downloads": -1, "filename": "rkm_codes-0.1.0.tar.gz", "has_sig": true, "md5_digest": "9e6f73b0059f35e951529ae8481db418", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6956, "upload_time": "2018-09-13T01:58:20", "url": "https://files.pythonhosted.org/packages/41/6f/e64b95bb84643b876cf9ba7e6cfcd573b78006ba50069f412bb4fdabf61e/rkm_codes-0.1.0.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "1b4cb1636d3f9a2e3264b84615e1a322", "sha256": "0047a78e17b19e2c9bf05042235939dc3d770e27eaaed56e75c8fb663f7f64de" }, "downloads": -1, "filename": "rkm_codes-0.2.0.tar.gz", "has_sig": true, "md5_digest": "1b4cb1636d3f9a2e3264b84615e1a322", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7583, "upload_time": "2018-09-14T14:32:10", "url": "https://files.pythonhosted.org/packages/cc/02/89768dd139255dad1eb9cd1c5505166beb320227762e6b08a8e24867ea94/rkm_codes-0.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1b4cb1636d3f9a2e3264b84615e1a322", "sha256": "0047a78e17b19e2c9bf05042235939dc3d770e27eaaed56e75c8fb663f7f64de" }, "downloads": -1, "filename": "rkm_codes-0.2.0.tar.gz", "has_sig": true, "md5_digest": "1b4cb1636d3f9a2e3264b84615e1a322", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7583, "upload_time": "2018-09-14T14:32:10", "url": "https://files.pythonhosted.org/packages/cc/02/89768dd139255dad1eb9cd1c5505166beb320227762e6b08a8e24867ea94/rkm_codes-0.2.0.tar.gz" } ] }