{ "info": { "author": "Chris L Barnes", "author_email": "barnesc@janelia.hhmi.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6" ], "description": "# coordinates\n\n[![Build Status](https://travis-ci.org/clbarnes/coordinates.svg?branch=master)](https://travis-ci.org/clbarnes/coordinates)\n\nConvenience class for dealing with coordinates which need both maths and explicit ordering.\n\nSupports python 3.4+\n\n## Motivation\n\nNumpy arrays are great for doing maths with coordinates stored as arrays.\n\nDicts are great for dealing with coordinate systems where the order keeps changing \n(e.g. between C and Fortran order).\n\nBut what if you want both?\n\n(Note: if you're doing *lots* of maths... stick with `numpy`)\n\n## Installation\n\n```bash\npip install coordinates\n```\n\n## Usage\n\n`Coordinate`s are `Mapping`s (i.e. `dict`-like). They don't expose an interface for mutation, but\nwe're all consenting adults so if you really want to modify the internal `_dict`, I won't\nstop you.\n\n### Instantiation\n\nThey can be instantiated in any of the ways a `dict` can (from another `Mapping`, a sequence of pairs,\nsome keyword arguments, or a mixture of the above).\n\n```python\nfrom coordinates import Coordinate\n\nCoordinate({'x': 1, 'y': 2})\nCoordinate({'x': 1}, y=2)\nCoordinate([('x', 1), ('y', 2)])\nCoordinate(x=1, y=2)\n```\n\nIf an order is defined (more on this later), you can also instantiate a `Coordinate` from a single \nargument which is a sequence, or from a number of `*args`.\n\n```python\nCoordinate([1, 2], order='xy')\nCoordinate(1, 2, order='xy')\n\nCoordinate.default_order = 'xy'\nCoordinate([1, 2])\nCoordinate(1, 2)\n```\n\nBecause `Mapping`s can be instantiated from other `Mapping`s, you can \"extend\" existing coordinates \ninto new dimensions.\n\n```python\ncoord_2d = Coordinate(x=1, y=2)\ncoord_3d = Coordinate(coord_2d, z=3)\n```\n\nFinally, many `Coordinate`s can be instantiated lazily using `from_sequence`:\n\n```python\nCoordinate.from_sequence([(1, 2, 3), (3, 4, 5)], order='xyz')\nCoordinate.from_sequence([{'x': 1, 'y': 2}, {'x': 3, 'y': 4}], z=10)\n```\n\nTo note: \n\n- `order`-dependent instantiation is incompatible with `**kwargs`\n- Instantiation from a sequence of tuples will fail in 2D because it will be interpreted as \nkey-value pairs. Use a comprehension here instead: `Coordinate.from_sequence(zip('xy', row) for row in sequence)`\n\n### Maths\n\nCoordinates do maths like you might expect them to, where the other operand is anything dict-like\nwith the same keys, or a number.\n\n```python\ncoord = Coordinate(x=1, y=2, z=3)\n\ncoord * 2 == Coordinate(x=2, y=4, z=6)\n>>> True\n\ncoord ** 2 == Coordinate(x=1, y=4, z=9)\n>>> True\n\ncoord + coord == Coordinate(x=2, y=4, z=3)\n>>> True\n\ncoord += 1 # coord is a reference to a new object; no mutation\ncoord == Coordinate(x=2, y=3, z=4)\n>>> True\n\nabs(Coordinate(x=-10, y=10)) == Coordinate(x=10, y=10)\n>>> True\n\nimport math\nmath.ceil(Coordinate(x=0.5)) == Coordinate(x=1)\n>>> True\n\nmath.floor(Coordinate(x=0.5)) == Coordinate(x=0)\n>>> True\n```\n\nThey also have some convenience methods for getting the sum, product or norm of their keys.\n\n```python\ncoord.sum() == 9\n>>> True\n\ncoord.prod() == 24\n>>> True\n\nCoordinate(x=3, y=4).norm(order=2) == 5\n>>> True\n```\n\n### Ordering\n\nYou can get the keys, values or items of the `Coordinate` in a specific order:\n\n```python\ncoord.to_list('yxz') == [2, 1, 3]\n>>> True\n\nlist(coord.items('yxz')) == [('y', 2), ('x', 1), ('z', 3)]\n>>> True\n```\n\nThe default order for a single instance can be given on instantiation, or mutated (this does not affect equality).\n\nThe default order for all `Coordinate`s can be set on the class. This affects existing instances, but does not \noverride their order if it was set explicitly.\n\nIf neither an instance `order` or a class `default_order` is set, it falls back to reverse lexicographic.\n\n```python\ncoord3 = Coordinate(x=1, y=2, z=3, order='zxy')\ncoord3.order = 'yzx'\n\nCoordinate.default_order = 'xyz'\n```\n\n### Subclassing\n\nIf you're working in one space, the `spaced_coordinate` factory can create custom subclasses with a fixed set of\nkeys and optionally a default order.\n\n```python\nfrom coordinates import spaced_coordinate\nCoordinateXYZC = spaced_coordinate('CoordinateXYZC', 'xyzc')\n\n# this will raise a ValueError\nCoordinateXYZC(x=1, y=2, z=3)\n```\n\nOr you can subclass `Coordinate` directly.\n\n### Value access\n\nCoordinate values can be accessed with dict-like syntax (`coord['x']`, `coord.get('y', 2)`) or, for convenience,\nattribute-like (`coord.z`) if the keys are strings.\n\n## Note\n\nIf you don't want the order-related functionality for another application, the base class `MathDict` is \nimplemented here too.\n\n\n", "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/clbarnes/coordinates", "keywords": "coordinate spatial mathdict", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "coordinates", "package_url": "https://pypi.org/project/coordinates/", "platform": "", "project_url": "https://pypi.org/project/coordinates/", "project_urls": { "Homepage": "https://github.com/clbarnes/coordinates" }, "release_url": "https://pypi.org/project/coordinates/0.3.0/", "requires_dist": null, "requires_python": ">=3.4", "summary": "Convenience class for doing maths with explicit coordinates", "version": "0.3.0" }, "last_serial": 5254254, "releases": { "0.1.2": [ { "comment_text": "", "digests": { "md5": "c1916389c38d5a21da69a8e6b8df8b0c", "sha256": "dee2c6a7fd35ee079bb40ee4edf6ebb849d1edf66b46374f7da2ce25632305dd" }, "downloads": -1, "filename": "coordinates-0.1.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c1916389c38d5a21da69a8e6b8df8b0c", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.4", "size": 7525, "upload_time": "2018-04-04T00:06:23", "url": "https://files.pythonhosted.org/packages/56/4b/edc9843de7274043568e9c0447feb2ee2fe0dde606018a71e99aa535f250/coordinates-0.1.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "4ac5033ed471d19ce4b0cc493131bc57", "sha256": "bbc6e65f3e1c1d4677bdcf61832b2fe925af192149458be584c2f57a07df259c" }, "downloads": -1, "filename": "coordinates-0.1.2.tar.gz", "has_sig": false, "md5_digest": "4ac5033ed471d19ce4b0cc493131bc57", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 7588, "upload_time": "2018-04-04T00:06:23", "url": "https://files.pythonhosted.org/packages/71/85/d92703f671fd554e5f775f0490f6af5820a09a96c9582c87ee141696350f/coordinates-0.1.2.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "24809d644fb0af9505407c1446b6a3a2", "sha256": "31df50b95dde1fb37541baeba71548937bcda4da99307906bd5c826cd8966e89" }, "downloads": -1, "filename": "coordinates-0.2.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "24809d644fb0af9505407c1446b6a3a2", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.4", "size": 8136, "upload_time": "2018-04-04T02:37:27", "url": "https://files.pythonhosted.org/packages/d2/79/93c586a986150d06fc7c3b55e509e1b879407db0ef04a7ba54e61afd5e6b/coordinates-0.2.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5b5e56d8122e01db72da4e4f00b0139a", "sha256": "72ab6bd1edcbc0d18c22a0f925f5aef00bbeb26b2eaad547cf14ece5d2806071" }, "downloads": -1, "filename": "coordinates-0.2.0.tar.gz", "has_sig": false, "md5_digest": "5b5e56d8122e01db72da4e4f00b0139a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 9988, "upload_time": "2018-04-04T02:37:28", "url": "https://files.pythonhosted.org/packages/9c/0e/6a1828f2f33b87900e0cc52f86b84ae2c9a3dd8bef8b82158168edc3fa02/coordinates-0.2.0.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "1f0b9bc182093deb127fee78b97e3995", "sha256": "f67dcc97fd32e98813d21335814ece624f11de7b75055a4d3d0039d257e2c285" }, "downloads": -1, "filename": "coordinates-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1f0b9bc182093deb127fee78b97e3995", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.4", "size": 7198, "upload_time": "2019-05-10T21:41:26", "url": "https://files.pythonhosted.org/packages/a2/eb/6b5895f94bffafd0db7d9746c64c7df17697e08a2848e802cebcadc6aa93/coordinates-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ca9335ac6fbaeb1e53438a1a7a52b3c7", "sha256": "911fd864c30ebb3e1d16b0118f18bc52d7ef27d74d20b3d4d51fbc400777f380" }, "downloads": -1, "filename": "coordinates-0.3.0.tar.gz", "has_sig": false, "md5_digest": "ca9335ac6fbaeb1e53438a1a7a52b3c7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 6627, "upload_time": "2019-05-10T21:41:27", "url": "https://files.pythonhosted.org/packages/8c/ad/efe67de5f2207885fbf977226f742fe18dedefb38fffc1b416cab544fe84/coordinates-0.3.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1f0b9bc182093deb127fee78b97e3995", "sha256": "f67dcc97fd32e98813d21335814ece624f11de7b75055a4d3d0039d257e2c285" }, "downloads": -1, "filename": "coordinates-0.3.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "1f0b9bc182093deb127fee78b97e3995", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": ">=3.4", "size": 7198, "upload_time": "2019-05-10T21:41:26", "url": "https://files.pythonhosted.org/packages/a2/eb/6b5895f94bffafd0db7d9746c64c7df17697e08a2848e802cebcadc6aa93/coordinates-0.3.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ca9335ac6fbaeb1e53438a1a7a52b3c7", "sha256": "911fd864c30ebb3e1d16b0118f18bc52d7ef27d74d20b3d4d51fbc400777f380" }, "downloads": -1, "filename": "coordinates-0.3.0.tar.gz", "has_sig": false, "md5_digest": "ca9335ac6fbaeb1e53438a1a7a52b3c7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.4", "size": 6627, "upload_time": "2019-05-10T21:41:27", "url": "https://files.pythonhosted.org/packages/8c/ad/efe67de5f2207885fbf977226f742fe18dedefb38fffc1b416cab544fe84/coordinates-0.3.0.tar.gz" } ] }