{ "info": { "author": "Marcel Rieger", "author_email": "python-scinum@googlegroups.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3" ], "description": "![scinum logo](https://raw.githubusercontent.com/riga/scinum/master/logo250.png \"scinum logo\")\n\n[![Build Status](https://travis-ci.org/riga/scinum.svg?branch=master)](https://travis-ci.org/riga/scinum) [![Documentation Status](https://readthedocs.org/projects/scinum/badge/?version=latest)](http://scinum.readthedocs.org/en/latest/?badge=latest) [![Package Status](https://img.shields.io/pypi/v/scinum.svg?style=flat)](https://pypi.python.org/pypi/scinum) [![License](https://img.shields.io/github/license/riga/scinum.svg)](https://github.com/riga/scinum/blob/master/LICENSE) [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/riga/scinum/master?filepath=example.ipynb)\n\nscinum provides a simple `Number` class that wraps plain floats or [NumPy](http://www.numpy.org/) arrays and adds support for multiple uncertainties, automatic (gaussian) error propagation, and scientific rounding.\n\n\n### Usage\n\nThe following examples demonstrate the most common use cases. For more info, see the [API documentation](http://scinum.readthedocs.org/en/latest/?badge=latest) or open the [example.ipynb](https://github.com/riga/scinum/blob/master/example.ipynb) notebook on binder: [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/riga/scinum/master?filepath=example.ipynb)\n\n\n###### Number definition\n\n```python\nfrom scinum import Number, UP, DOWN\n\nnum = Number(5, (2, 1))\nprint(num) # -> 5.00 +2.00-1.00\n\n# get the nominal value\nprint(num.nominal) # -> 5.0\nprint(num.n) # -> 5.0 (shorthand)\nprint(num()) # -> 5.0 (shorthand)\n\n# get uncertainties\nprint(num.get_uncertainty()) # -> (2.0, 1.0)\nprint(num.u()) # -> (2.0, 1.0) (shorthand)\nprint(num.u(direction=UP)) # -> 2.0\n\n# get shifted values\nprint(num.get()) # -> 5.0 (no shift)\nprint(num.get(UP)) # -> 7.0 (up shift)\nprint(num(UP)) # -> 7.0 (up shift, shorthand)\nprint(num.get(DOWN)) # -> 4.0 (down shift)\nprint(num(DOWN)) # -> 4.0 (down shift, shorthand)\n```\n\n\n###### Multiple uncertainties\n\n```python\nfrom scinum import Number, ABS, REL\n\nnum = Number(2.5, {\n \"sourceA\": 0.5, # absolute 0.5, both up and down\n \"sourceB\": (1.0, 1.5), # absolute 1.0 up, 1.5 down\n \"sourceC\": (REL, 0.1), # relative 10%, both up and down\n \"sourceD\": (REL, 0.1, 0.2), # relative 10% up, 20% down\n \"sourceE\": (1.0, REL, 0.2), # absolute 1.0 up, relative 20% down\n \"sourceF\": (REL, 0.3, ABS, 0.3) # relative 30% up, absolute 0.3 down\n})\n```\n\n\n###### Formatting and rounding\n\n`Number.str()` provides some simple formatting tools, including `latex` and `root latex` support, as well as scientific rounding rules:\n\n```python\n# output formatting\nn = Number(8848, 10)\nn.str(unit=\"m\") # -> \"8848.0 +- 10.0 m\"\nn.str(unit=\"m\", force_asymmetric=True) # -> \"8848.0 +10.0-10.0 m\"\nn.str(unit=\"m\", scientific=True) # -> \"8.848 +- 0.01 x 1E3 m\"\nn.str(unit=\"m\", si=True) # -> \"8.848 +- 0.01 km\"\nn.str(unit=\"m\", style=\"latex\") # -> \"$8848.0 \\pm 10.0\\,m$\"\nn.str(unit=\"m\", style=\"latex\", si=True) # -> \"8.848 \\pm 0.01\\,km\"\nn.str(unit=\"m\", style=\"root\") # -> \"8848.0 #pm 10.0 m\"\nn.str(unit=\"m\", style=\"root\", si=True) # -> \"8.848 #pm 0.01 km\"\n\n# output rounding\nn = Number(17.321, {\"a\": 1.158, \"b\": 0.453})\nn.str() # -> '17.321 +- 1.158 (a) +- 0.453 (b)'\nn.str(\"%.1f\") # -> '17.3 +- 1.2 (a) +- 0.5 (b)'\nn.str(\"publication\") # -> '17.32 +- 1.16 (a) +- 0.45 (b)'\nn.str(\"pdg\") # -> '17.3 +- 1.2 (a) +- 0.5 (b)'\n```\n\nFor situations that require more sophisticated rounding and formatting rules, you might want to checkout:\n\n- [`sn.split_value()`](http://scinum.readthedocs.io/en/latest/#split-value)\n- [`sn.match_precision()`](http://scinum.readthedocs.io/en/latest/#match-precision)\n- [`sn.round_uncertainty()`](http://scinum.readthedocs.io/en/latest/#round-uncertainty)\n- [`sn.round_value()`](http://scinum.readthedocs.io/en/latest/#round-value)\n- [`sn.infer_si_prefix()`](http://scinum.readthedocs.io/en/latest/#infer-si-prefix)\n\n\n###### NumPy arrays\n\n```python\nfrom scinum import Number, ABS, REL\nimport numpy as np\n\nnum = Number(np.array([3, 4, 5]), 2)\nprint(num)\n# [ 3. 4. 5.]\n# + [ 2. 2. 2.]\n# - [ 2. 2. 2.]\n\nnum = Number(np.array([3, 4, 5]), {\n \"sourceA\": (np.array([0.1, 0.2, 0.3]), REL, 0.5) # absolute values for up, 50% down\n})\nprint(num)\n# [ 3. 4. 5.]\n# + sourceA [ 0.1 0.2 0.3]\n# - sourceA [ 1.5 2. 2.5]\n```\n\n\n###### Uncertainty propagation\n\n```python\nfrom scinum import Number\n\nnum = Number(5, 1)\nprint(num + 2) # -> '7.0 +- 1.0'\nprint(num * 3) # -> '15.0 +- 3.0'\n\nnum2 = Number(2.5, 1.5)\nprint(num + num2) # -> '7.5 +- 1.80277563773'\nprint(num * num2) # -> '12.5 +- 7.90569415042'\n\n# add num2 to num and consider their uncertainties to be fully correlated, i.e. rho = 1\nnum.add(num2, rho=1)\nprint(num) # -> '7.5 +- 2.5'\n```\n\n\n###### Math operations\n\nAs a drop-in replacement for the `math` module, scinum provides an object `ops` that contains math operations that are aware of guassian error propagation.\n\n```python\nfrom scinum import Number, ops\n\nnum = ops.log(Number(5, 2))\nprint(num) # -> 1.61 (+0.40, -0.40)\n\nnum = ops.exp(ops.tan(Number(5, 2)))\nprint(num) # -> 0.03 (+0.85, -0.85)\n```\n\n\n###### Custom operations\n\nThere might be situations where a specific operation is not (yet) contained in the `ops` object. In this case, you can easily register a new one via:\n\n```python\nfrom scinum import Number, ops\n\n@ops.register\ndef my_op(x):\n return x * 2 + 1\n\n@my_op.derive\ndef my_op(x):\n return 2\n\nnum = ops.my_op(Number(5, 2))\nprint(num) # -> 11.00 (+4.00, -4.00)\n```\n\nPlease note that there is no need to register *simple* functions like in the particular example above as most of them are just composite operations whose propagation rules (derivatives) are already known.\n\n\n### Installation and dependencies\n\nVia [pip](https://pypi.python.org/pypi/scinum)\n\n```bash\npip install scinum\n```\n\nor by simply copying the file into your project.\n\nNumpy is an optional dependency.\n\n\n### Contributing\n\nIf you like to contribute, I'm happy to receive pull requests. Just make sure to add a new test cases and run them via:\n\n```bash\n> python -m unittest tests\n```\n\n\n##### Testing\n\nIn general, tests should be run for different environments:\n\n- Python 2.7\n- Python 3.X (X \u2265 5)\n\n\n##### Docker\n\nTo run tests in a docker container, do:\n\n```bash\ngit clone https://github.com/riga/scinum.git\ncd scinum\n\ndocker run --rm -v `pwd`:/scinum -w /scinum python:3.6 python -m unittest tests\n```\n\n\n### Development\n\n- Source hosted at [GitHub](https://github.com/riga/scinum)\n- Report issues, questions, feature requests on [GitHub Issues](https://github.com/riga/scinum/issues)", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/riga/scinum", "keywords": "scientific,numbers,error,systematics,propagation", "license": "BSD-3-Clause", "maintainer": "", "maintainer_email": "", "name": "scinum", "package_url": "https://pypi.org/project/scinum/", "platform": "", "project_url": "https://pypi.org/project/scinum/", "project_urls": { "Homepage": "https://github.com/riga/scinum" }, "release_url": "https://pypi.org/project/scinum/1.0.2/", "requires_dist": null, "requires_python": ">=2.7", "summary": "Scientific numbers with multiple uncertainties and correlation-aware, gaussian propagation.", "version": "1.0.2" }, "last_serial": 4925423, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "242bef5b704d4af830122f9d4ea05783", "sha256": "89a15a3f969ce7e3972f6f3cae323227782fcd9ff8d5e3a62217f4c228ae0e04" }, "downloads": -1, "filename": "scinum-0.0.1.tar.gz", "has_sig": false, "md5_digest": "242bef5b704d4af830122f9d4ea05783", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1643, "upload_time": "2017-09-04T17:22:56", "url": "https://files.pythonhosted.org/packages/55/90/2b57deede0d82dc87bb54898cae1b6449b2161a97e023bdca5c53b155fb1/scinum-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "c24f0904b737c9951d0576091fff3c04", "sha256": "37a1d75756c41a19b1375586651092efa271d6e66d48f8327017b1529540305b" }, "downloads": -1, "filename": "scinum-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c24f0904b737c9951d0576091fff3c04", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13597, "upload_time": "2017-09-11T12:20:50", "url": "https://files.pythonhosted.org/packages/ea/95/dca62af90f62f46b1564fd738d9f91a6b5d0cd2ef8bd1488e8c3d6cbb49b/scinum-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "d71e1f0346961c1b483a5e06c076e41f", "sha256": "77e451cb13582ea588a98fc507b85443b3d9d9cef0021c378e7d95e9ca09d6d8" }, "downloads": -1, "filename": "scinum-0.1.1.tar.gz", "has_sig": false, "md5_digest": "d71e1f0346961c1b483a5e06c076e41f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13650, "upload_time": "2017-09-23T16:02:03", "url": "https://files.pythonhosted.org/packages/68/eb/edf5d5fb2098098d31a2f00e49b6613da5db893f69a526784e71bbe63afe/scinum-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "b609beaee509ec87055c6cd55c53746f", "sha256": "217f96a2661ca77a31a9d03adfd25eddf9c089be93264999168312386f7cd22a" }, "downloads": -1, "filename": "scinum-0.2.0.tar.gz", "has_sig": false, "md5_digest": "b609beaee509ec87055c6cd55c53746f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17613, "upload_time": "2018-01-08T22:54:18", "url": "https://files.pythonhosted.org/packages/ca/c9/e08bb063ade5763fb9ace08ac1dce2862681a61ab8e9739b05cb3c3cebfc/scinum-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "1400d4c5b35e6e41a5cdca646a5abfcc", "sha256": "2bd660ab72baaed154abb5acf8c4e7a0a15f36ce88b3a51189680e5c235c11ed" }, "downloads": -1, "filename": "scinum-0.2.1.tar.gz", "has_sig": false, "md5_digest": "1400d4c5b35e6e41a5cdca646a5abfcc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17670, "upload_time": "2018-01-09T07:01:21", "url": "https://files.pythonhosted.org/packages/0e/c6/3a7440e85aa037131200b675ffe69934ea5b921158be15f70cd88059e0fe/scinum-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "6ae8c9671bcf679dc32f6ce393be1770", "sha256": "6ddd7bdd1c340e68e2bc95c5139faf9848cf9c05fbd6f1e0d65877fc1129a123" }, "downloads": -1, "filename": "scinum-0.2.2.tar.gz", "has_sig": false, "md5_digest": "6ae8c9671bcf679dc32f6ce393be1770", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17710, "upload_time": "2018-02-05T22:45:01", "url": "https://files.pythonhosted.org/packages/ec/f9/5882199dbd475192b367ac55cf15f73d4e5e8e80b1d9c15814790ea976b4/scinum-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "3082306968daeef968d4f17e30b413f4", "sha256": "257dcf50d86aa3f84e3cd29f5e1ac5b2d6dee4332e42e19c378c01e3f790bec4" }, "downloads": -1, "filename": "scinum-0.2.3.tar.gz", "has_sig": false, "md5_digest": "3082306968daeef968d4f17e30b413f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17710, "upload_time": "2018-02-20T20:40:00", "url": "https://files.pythonhosted.org/packages/25/63/8daad66b43ff9e46a7a606cbb8197b3e2c0b4d6a87f039a89b34ede913df/scinum-0.2.3.tar.gz" } ], "0.2.4": [ { "comment_text": "", "digests": { "md5": "dc29b38524fcf69c9f402c271cee4fb9", "sha256": "300418f567462893862afc4e527bf18c816424865cd984a201a454fa2ccd17bb" }, "downloads": -1, "filename": "scinum-0.2.4.tar.gz", "has_sig": false, "md5_digest": "dc29b38524fcf69c9f402c271cee4fb9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18145, "upload_time": "2018-09-22T13:04:51", "url": "https://files.pythonhosted.org/packages/80/eb/388e5e1d097a54cc8a593871773954cbdc4075274054f1e63c444b195a4e/scinum-0.2.4.tar.gz" } ], "0.2.5": [ { "comment_text": "", "digests": { "md5": "493c09d3bb0c59a809ac6bbd02577e0e", "sha256": "085d7afd6caae1c21c5780a670dfd1c5078f13a87b8371a68821481a5079d22e" }, "downloads": -1, "filename": "scinum-0.2.5.tar.gz", "has_sig": false, "md5_digest": "493c09d3bb0c59a809ac6bbd02577e0e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 17706, "upload_time": "2018-10-28T13:35:51", "url": "https://files.pythonhosted.org/packages/24/66/9540b230240e473dcdbd71746f8dc19ab719e9f6774e50b4ceaf77301f96/scinum-0.2.5.tar.gz" } ], "0.2.6": [ { "comment_text": "", "digests": { "md5": "8241e4fd76f15e615127844fe5937b0a", "sha256": "7f8bfb0ccd88cfb2e051bbc2637213864db546408390b479b6867dbb0c0d9638" }, "downloads": -1, "filename": "scinum-0.2.6.tar.gz", "has_sig": false, "md5_digest": "8241e4fd76f15e615127844fe5937b0a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 17707, "upload_time": "2018-10-28T14:13:15", "url": "https://files.pythonhosted.org/packages/54/c6/d53222c403e2c7934424f44ae5b0993e19ce3d5ec52df09b09998b4a0a3e/scinum-0.2.6.tar.gz" } ], "0.2.7": [ { "comment_text": "", "digests": { "md5": "00f498987f8d84c539dd1169e62ca58a", "sha256": "c04bd34bbc649924776dbc8d9792af4fac3ec54a795b5891eae876f88396b49f" }, "downloads": -1, "filename": "scinum-0.2.7.tar.gz", "has_sig": false, "md5_digest": "00f498987f8d84c539dd1169e62ca58a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 17596, "upload_time": "2018-10-28T14:22:29", "url": "https://files.pythonhosted.org/packages/9e/8f/6dd6abe778cad36bf774f037f1fc96b9a3329c4dc68b790fb94c34eea217/scinum-0.2.7.tar.gz" } ], "0.2.8": [ { "comment_text": "", "digests": { "md5": "9781f61cb9e3a2ab2325c937e02f7abb", "sha256": "4743c0d4c51299eb188af13f8135f01a92d0b3304616158b88b5eda1756258da" }, "downloads": -1, "filename": "scinum-0.2.8.tar.gz", "has_sig": false, "md5_digest": "9781f61cb9e3a2ab2325c937e02f7abb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 17740, "upload_time": "2019-01-04T14:18:36", "url": "https://files.pythonhosted.org/packages/b6/73/6e2b498bdb6520f30532cb5266c043c8bb5f062a4d45a5f909c953ec8323/scinum-0.2.8.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "79615d7dcd6e8f09a8a4a134c7eafc0d", "sha256": "752942bdbeb402b5aff6e12c95c798400e9eee29ddd38ca3d96511785215bec6" }, "downloads": -1, "filename": "scinum-1.0.0.tar.gz", "has_sig": false, "md5_digest": "79615d7dcd6e8f09a8a4a134c7eafc0d", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 18203, "upload_time": "2019-03-11T14:17:46", "url": "https://files.pythonhosted.org/packages/7e/83/171a7c74642d2f89e31632c9fcd8cb54916ec71d12b83fa70646797bfcee/scinum-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "17963b26bd99389ea1687fe47dcfbc66", "sha256": "4025bc4fc0f90d58054999e2cb58292abf0cbf6bca2d9bacf5eafe13be154fa9" }, "downloads": -1, "filename": "scinum-1.0.1.tar.gz", "has_sig": false, "md5_digest": "17963b26bd99389ea1687fe47dcfbc66", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 18182, "upload_time": "2019-03-11T14:27:54", "url": "https://files.pythonhosted.org/packages/82/28/81a428bf4c7d1d2b229c146ec3e2ca199cbd17acb9da0b7f5507c9d5be2d/scinum-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "633b660ba99bc66d2812aa38f85a3472", "sha256": "56e640342b3eedf38730fc5d53f57996134072499681724df3aaaf6c0a17a2c7" }, "downloads": -1, "filename": "scinum-1.0.2.tar.gz", "has_sig": false, "md5_digest": "633b660ba99bc66d2812aa38f85a3472", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 18218, "upload_time": "2019-03-11T14:31:25", "url": "https://files.pythonhosted.org/packages/be/87/202b3f5380954608e6249d9c89d2f1044b7e096d492571b492511b6569b0/scinum-1.0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "633b660ba99bc66d2812aa38f85a3472", "sha256": "56e640342b3eedf38730fc5d53f57996134072499681724df3aaaf6c0a17a2c7" }, "downloads": -1, "filename": "scinum-1.0.2.tar.gz", "has_sig": false, "md5_digest": "633b660ba99bc66d2812aa38f85a3472", "packagetype": "sdist", "python_version": "source", "requires_python": ">=2.7", "size": 18218, "upload_time": "2019-03-11T14:31:25", "url": "https://files.pythonhosted.org/packages/be/87/202b3f5380954608e6249d9c89d2f1044b7e096d492571b492511b6569b0/scinum-1.0.2.tar.gz" } ] }