{"id":48570687,"url":"https://github.com/ultrasphere-dev/ultrasphere","last_synced_at":"2026-04-08T14:31:20.604Z","repository":{"id":301660747,"uuid":"1009962642","full_name":"ultrasphere-dev/ultrasphere","owner":"ultrasphere-dev","description":"Vilenkin–Kuznetsov–Smorodinsky polyspherical (hyperspherical) coordinates in NumPy / PyTorch","archived":false,"fork":false,"pushed_at":"2026-04-07T21:23:31.000Z","size":1232,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-07T23:20:27.888Z","etag":null,"topics":["array-api","hypersphere","spherical-coordinates"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ultrasphere-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":["ultrasphere-dev"]}},"created_at":"2025-06-28T04:00:21.000Z","updated_at":"2026-04-07T21:23:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"a5c2edba-2ff4-4a75-bac9-1f74633e568d","html_url":"https://github.com/ultrasphere-dev/ultrasphere","commit_stats":null,"previous_names":["34j/ultrasphere","ultrasphere-dev/ultrasphere"],"tags_count":28,"template":false,"template_full_name":null,"purl":"pkg:github/ultrasphere-dev/ultrasphere","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultrasphere-dev%2Fultrasphere","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultrasphere-dev%2Fultrasphere/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultrasphere-dev%2Fultrasphere/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultrasphere-dev%2Fultrasphere/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ultrasphere-dev","download_url":"https://codeload.github.com/ultrasphere-dev/ultrasphere/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ultrasphere-dev%2Fultrasphere/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31559691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["array-api","hypersphere","spherical-coordinates"],"created_at":"2026-04-08T14:31:19.869Z","updated_at":"2026-04-08T14:31:20.583Z","avatar_url":"https://github.com/ultrasphere-dev.png","language":"Python","readme":"# ultrasphere\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/ultrasphere-dev/ultrasphere/actions/workflows/ci.yml?query=branch%3Amain\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/ultrasphere-dev/ultrasphere/ci.yml?branch=main\u0026label=CI\u0026logo=github\u0026style=flat-square\" alt=\"CI Status\" \u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://ultrasphere.readthedocs.io\"\u003e\n    \u003cimg src=\"https://img.shields.io/readthedocs/ultrasphere.svg?logo=read-the-docs\u0026logoColor=fff\u0026style=flat-square\" alt=\"Documentation Status\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/ultrasphere-dev/ultrasphere\"\u003e\n    \u003cimg src=\"https://img.shields.io/codecov/c/github/ultrasphere-dev/ultrasphere.svg?logo=codecov\u0026logoColor=fff\u0026style=flat-square\" alt=\"Test coverage percentage\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/astral-sh/uv\"\u003e\n    \u003cimg src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json\" alt=\"uv\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/astral-sh/ruff\"\u003e\n    \u003cimg src=\"https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json\" alt=\"Ruff\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/pre-commit/pre-commit\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit\u0026logoColor=white\u0026style=flat-square\" alt=\"pre-commit\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://pypi.org/project/ultrasphere/\"\u003e\n    \u003cimg src=\"https://img.shields.io/pypi/v/ultrasphere.svg?logo=python\u0026logoColor=fff\u0026style=flat-square\" alt=\"PyPI Version\"\u003e\n  \u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/pypi/pyversions/ultrasphere.svg?style=flat-square\u0026logo=python\u0026amp;logoColor=fff\" alt=\"Supported Python versions\"\u003e\n  \u003cimg src=\"https://img.shields.io/pypi/l/ultrasphere.svg?style=flat-square\" alt=\"License\"\u003e\n\u003c/p\u003e\n\n---\n\n**Documentation**: \u003ca href=\"https://ultrasphere.readthedocs.io\" target=\"_blank\"\u003ehttps://ultrasphere.readthedocs.io \u003c/a\u003e\n\n**Source Code**: \u003ca href=\"https://github.com/ultrasphere-dev/ultrasphere\" target=\"_blank\"\u003ehttps://github.com/ultrasphere-dev/ultrasphere \u003c/a\u003e\n\n---\n\nVilenkin–Kuznetsov–Smorodinsky (VKS) polyspherical (hyperspherical) coordinates in NumPy / PyTorch\n\n## Installation\n\nInstall this via pip (or your favourite package manager):\n\n```shell\npip install ultrasphere[plot]\n```\n\n## Usage\n\n### Spherical Coordinates ↔ Cartesian Coordinates\n\nFirst import the module and create a spherical coordinates object.\n\n```python\n\u003e\u003e\u003e import ultrasphere as us\n\u003e\u003e\u003e from array_api_compat import numpy as np\n\u003e\u003e\u003e from array_api_compat import torch\n\u003e\u003e\u003e rng = np.random.default_rng(0)\n\u003e\u003e\u003e c = us.create_spherical()\n```\n\nGetting spherical coordinates from cartesian coordinates:\n\n```python\n\u003e\u003e\u003e spherical = c.from_cartesian(torch.asarray([1.0, 2.0, 3.0]))\n\u003e\u003e\u003e spherical\n{'r': tensor(3.7417), 'phi': tensor(1.1071), 'theta': tensor(0.6405)}\n```\n\nGetting cartesian coordinates from spherical coordinates:\n\n```python\n\u003e\u003e\u003e c.to_cartesian(spherical)\n{0: tensor(1.), 1: tensor(2.0000), 2: tensor(3.)}\n```\n\n### Using various VKS polyspherical coordinates\n\n```python\n\u003e\u003e\u003e us.create_polar()\nSphericalCoordinates(a)\n\u003e\u003e\u003e us.create_spherical()\nSphericalCoordinates(ba)\n\u003e\u003e\u003e us.create_standard(3)\nSphericalCoordinates(bba)\n\u003e\u003e\u003e us.create_standard_prime(4)\nSphericalCoordinates(b'b'b'a)\n\u003e\u003e\u003e us.create_hopf(3)\nSphericalCoordinates(ccaacaa)\n\u003e\u003e\u003e us.create_from_branching_types(\"cbab'a\")\nSphericalCoordinates(cbab'a)\n\u003e\u003e\u003e us.create_random(10, rng=rng)\nSphericalCoordinates(cacccaaaba)\n```\n\nOne can convert between Cartesian coordinates and VKS polyspherical coordinates in the same way as above.\n\nThe name of the spherical nodes and cartesian nodes can be obtained by:\n\n```python\n\u003e\u003e\u003e c = us.create_standard(5)\n\u003e\u003e\u003e c.s_nodes\n['theta0', 'theta1', 'theta2', 'theta3', 'theta4']\n\u003e\u003e\u003e c.s_ndim\n5\n\u003e\u003e\u003e c.c_nodes\n[0, 1, 2, 3, 4, 5]\n\u003e\u003e\u003e c.c_ndim\n6\n```\n\n`\"r\"` is a special node which represents the radius and is not included in `s_nodes`.\n\nThe definition and notation of VKS polyspherical coordinates follows [Cohl2012, Appendix B].\nFollowing sections would also help understand the VKS polyspherical coordinates.\n\n- [Cohl2012] Cohl, H. (2012). Fourier, Gegenbauer and Jacobi Expansions for a Power-Law Fundamental Solution of the Polyharmonic Equation and Polyspherical Addition Theorems. Symmetry, Integrability and Geometry: Methods and Applications (SIGMA), 9. https://doi.org/10.3842/SIGMA.2013.042\n\n### Drawing spherical coordinates using rooted trees (Vilenkin's method of trees)\n\n#### Python\n\n\u003c!-- skip: start --\u003e\n\n```python\n\u003e\u003e\u003e c = us.create_from_branching_types(\"ccabbab'b'ba\")\n\u003e\u003e\u003e us.draw(c)\n(6.5, 3.5)\n```\n\n\u003c!-- skip: end --\u003e\n\n#### CLI\n\n```shell\nultrasphere \"ccabbab'b'ba\"\n```\n\nOutput:\n\n![ccabbab'b'ba](https://raw.githubusercontent.com/ultrasphere-dev/ultrasphere/main/coordinates.jpg)\n\nThe image shows how Cartesian coordinates (leaf nodes) are calculated from spherical coordinates (internal nodes).\n\nFor example, $x_{10}$, corresponding to node `10`, is a leaf node which ancestors are `[θ0, θ2, θ7, θ8, θ9]`. The edges which connect these nodes are named `[sin, cos, cos, sin, sin]`, respectively. Thus, $x_{10}$ is calculated as:\n\n$$\nx_{10} = \\sin \\theta_0 \\cos \\theta_2 \\cos \\theta_7 \\sin \\theta_8 \\sin \\theta_9\n$$\n\n### Integration over sphere using spherical coordinates\n\n```python\n\u003e\u003e\u003e c = us.create_spherical()\n\u003e\u003e\u003e f = lambda spherical: spherical[\"theta\"] ** 2 * spherical[\"phi\"]\n\u003e\u003e\u003e np.round(us.integrate(\n...     c,\n...     f,\n...     False, # does not support separation of variables\n...     10, # number of quadrature points\n...     xp=np # the array namespace\n... ), 5)\nnp.float64(110.02621)\n```\n\n### Random sampling\n\nSampling random points uniformly from the unit ball:\n\n```python\n\u003e\u003e\u003e c = us.create_spherical()\n\u003e\u003e\u003e points_ball = us.random_ball(c, shape=(), xp=np, rng=rng)\n\u003e\u003e\u003e points_ball\narray([0.12504754, 0.45095196, 0.32752147])\n\u003e\u003e\u003e np.linalg.vector_norm(points_ball)\nnp.float64(0.5711960026239531)\n```\n\nSampling random points uniformly from the sphere (does not include interior points):\n\n```python\n\u003e\u003e\u003e points_sphere = us.random_ball(c, shape=(), xp=np, surface=True, rng=rng)\n\u003e\u003e\u003e points_sphere\narray([-0.89670228, -0.44166441,  0.02928439])\n\u003e\u003e\u003e np.linalg.vector_norm(points_sphere)\nnp.float64(1.0)\n```\n\n#### References\n\n- Barthe, F., Guédon, O., Mendelson, S., \u0026 Naor, A. (2005). A probabilistic approach to the geometry of the ? P n -ball. The Annals of Probability, 33. https://doi.org/10.1214/009117904000000874\n\n## Contributors ✨\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --\u003e\n\u003c!-- markdownlint-disable --\u003e\n\u003c!-- markdownlint-enable --\u003e\n\u003c!-- ALL-CONTRIBUTORS-LIST:END --\u003e\n\u003c!-- prettier-ignore-end --\u003e\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n\n## Credits\n\n[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](https://github.com/copier-org/copier)\n\nThis package was created with\n[Copier](https://copier.readthedocs.io/) and the\n[browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)\nproject template.\n\nThe code examples in the documentation and docstrings are\nautomatically tested as doctests using [Sybil](https://sybil.readthedocs.io/).\n","funding_links":["https://github.com/sponsors/ultrasphere-dev"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fultrasphere-dev%2Fultrasphere","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fultrasphere-dev%2Fultrasphere","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fultrasphere-dev%2Fultrasphere/lists"}