{"id":34074294,"url":"https://github.com/ketakopter/spq","last_synced_at":"2025-12-14T09:00:38.127Z","repository":{"id":54132925,"uuid":"345638066","full_name":"ketakopter/spq","owner":"ketakopter","description":"Simple Physical Quantities for Python - Unit conversions made easy","archived":false,"fork":false,"pushed_at":"2025-07-16T09:55:56.000Z","size":153,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-27T04:26:41.889Z","etag":null,"topics":["numpy-arrays","physical-quantities","python","unit-conversions","units"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ketakopter.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"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}},"created_at":"2021-03-08T11:49:13.000Z","updated_at":"2025-07-16T09:56:00.000Z","dependencies_parsed_at":"2024-10-24T18:16:49.770Z","dependency_job_id":"961e0527-89cd-49c2-8194-6e5965726674","html_url":"https://github.com/ketakopter/spq","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/ketakopter/spq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketakopter%2Fspq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketakopter%2Fspq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketakopter%2Fspq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketakopter%2Fspq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ketakopter","download_url":"https://codeload.github.com/ketakopter/spq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ketakopter%2Fspq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27724099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-14T02:00:11.348Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["numpy-arrays","physical-quantities","python","unit-conversions","units"],"created_at":"2025-12-14T09:00:23.274Z","updated_at":"2025-12-14T09:00:38.113Z","avatar_url":"https://github.com/ketakopter.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SPQ\nSimple Physical Quantities for Python - Unit conversions made easy\n\n## The name of the game\n\nSPQ is a small python package for working easily with physical quantities and different units, with\nthe goal of having a **compact** interface and an **easy** way of defining units.\n\n```python\n\u003e\u003e\u003e from spq.spq.aero import Dist\n\u003e\u003e\u003e a = Dist.fromft(3.3)\n\u003e\u003e\u003e a\n1.00584\n\u003e\u003e\u003e a.km\n0.00100584\n```\n\nA physical quantity has factory methods to initialize the quantity from any of the defined units,\nresulting in a functional interface. The units are accessible as attributes of the quantity,\nresulting in a compact interface. No \"convert_to\", no strings needed - just ask for the value in the\nwanted unit directly.\n\nInternally the value of the quantity is expressed in the main unit (e.g. _m_ for distance). You can\nuse the variable to feed them into any function and perform calculations: this way the computations\nwill be consistent. If you like, you can convert a variable to another unit for your output. Or you\ncan use the package to perform quick unit conversions. It works with numpy arrays, too.\n\n```python\n\u003e\u003e\u003e Dist.fromkm(np.linspace(1,5,5)).m\narray([1000., 2000., 3000., 4000., 5000.])\n```\n\nSPQ provides physical quantities and units in isolated modules. Instead of having a library to\nhandle all imaginable units, each application will define and/or load their needed definitions.\nReady-to-use modules are provided in the **spq** sub-package. If you want to create your own\ndefinitions, you can use the functionalities of the **base** sub-package. See examples and\ninstructions below.\n\n\n## Examples\n\nThe most basic stuff is using one of the physical quantities to input and show\nthe quantity in the units that you want.\n\n```python\n\u003e\u003e\u003e a = Dist(34)\n\u003e\u003e\u003e a.ft\n111.54855643044618\n\n\u003e\u003e\u003e b = Dist.fromft(15000)\n\u003e\u003e\u003e b\n4572.0\n\u003e\u003e\u003e b.ft\n14999.999999999998\n```\n\nIt works with numpy arrays too, and the array is converted easily to the desired units:\n\n```python\n\u003e\u003e\u003e import numpy as np\n\u003e\u003e\u003e b = Dist.fromft(np.linspace(1,5,5))\n\u003e\u003e\u003e print(b)\n[0.3048 0.6096 0.9144 1.2192 1.524 ]\n\u003e\u003e\u003e print(b.km)\n[0.0003048 0.0006096 0.0009144 0.0012192 0.001524 ]\n```\n\nYou can start variables from the units you want, and use the variables in functions that expect a\nconsistent set of units, like SI:\n\n```python\n\u003e\u003e\u003e from spq.spq.aero import Dist, Mass\n\n\u003e\u003e\u003e def earthGravForce(m, r):\n...   mu = 3.986e14  # in m3/s2\n...   return mu*m/r**2\n\n\u003e\u003e\u003e m = Mass.fromlb(23)\n\u003e\u003e\u003e r = Dist.frommi(5000)\n\u003e\u003e\u003e earthGravForce(m, r)\n64.22337018599708\n\n\u003e\u003e\u003e earthGravForce(10.43262, 8046720.0) # if we had input the values in kg and m directly. Same result, disregarding inaccuracies in the inputs.\n64.22334242237929\n```\n\nAnd many more functionalities to make working with units really easy. You can find more examples in\nthe [examples](examples) directory.\n\nIf you would like to try it live, try with the following Ipython notebook:\n\n* [Showcase](examples/Spq_showcase.ipynb) - [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ketakopter/spq/HEAD?filepath=examples%2FSpq_showcase.ipynb) - [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ketakopter/spq/blob/main/examples/Spq_showcase.ipynb)\n\n\n## Installation\n\nYou can install the package from PyPi:\n\n``` shell\n$ pip install spq\n```\n\nOtherwise, clone the git repository to have the files in your system and install with pip:\n\n``` shell\n$ git clone git://github.com/ketakopter/spq.git\n$ cd spq\n$ pip install .\n```\n\n\n## Loading physical quantities\n\nSPQ is organized in modules that contain the definitions of units and physical quantities. Currently\nthe *aero* module is available for users.\n\n```python\nfrom spq.spq.aero import Dist, Vel\n```\n\nThe definition of physical quantities and units is fully specified in a json file. The best is to\ninspect [the file](spq/spq/pq-aero.json).\n\n### Loading custom physical quantities/units\n\nThe *environ* module lets one load the definitions from a file defined in the `SPQFILE` environment\nvariable, following the same syntax as the file above.\n\n``` python\nimport os\nos.environ['SPQFILE'] = '/path/to/file'\nfrom spq.spq.environ import Dist, Mass\n```\n\nYou can build your own module using the functionalities of the `spq.base` package. This lets you\ndefine units and conversions in a variety of ways: from a json file, dictionary of units, or a\ncustom graph. The best is to inspect how the `spq.spq.aero` module loads the definitions, and check\nthe [example notebook](examples/Spq_creation_examples.ipynb). You can also try it live: [![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/ketakopter/spq/HEAD?filepath=examples%2FSpq_creation_examples.ipynb) - [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ketakopter/spq/blob/main/examples/Spq_creation_examples.ipynb)\n\n\n### Available units\n\nAt runtime, you can see the available units of a physical\nquantity with the `_units` attribute:\n\n```python\n\u003e\u003e\u003e Dist._units\n['m', 'ft', 'km', 'nm', 'mi', 'inch']\n```\n\nIf you want to know what is the \"working\" unit of a physical quantity, inspect the `_mainUnit` attribute:\n\n```python\n\u003e\u003e\u003e Dist._mainUnit\n'm'\n```\n\n## What SPQ is, and what is not\n\nThe goal of SPQ was to be able to quickly work with quantities and output results in different\nunits, especially for interactive work. The variables derive from `float` and `np.ndarray` to be\nable to feed them to existing functions, and the value is internally stored in SI units (by default)\nin order to have consistent computations. The idea was to work with numerical values, no strings\nneeded. Having the units as attributes makes it really easy to write the output in the wanted units\nor plot them, like `plt.plot(x.mi, y.mph)`.\n\nAlso, the definition of physical quantities and units should be easy. The json file defining the\ndefaults was easy to prepare and extending it is immediate.\n\nSPQ allows to have definitions for each application. It is **not** meant to be a library that\nhandles all the imaginable units. The functionalities allow to have independent definitions, that\nare best tailored for each application.\n\nSPQ is **not** intended to be a full-fledged physical quantities library, like when you multiply a\nlength by a force you get a torque (or an energy...). Doing that would need to define relationships\nbetween physical quantities, define how operators work, and it would over-complicate the library for\nthe intended use. Doing computations with SPQ objects just results in floats or arrays; it's up to\nthe user to initialize whatever physical quantity with the results.\n\n## Requirements\n\nSPQ works with Python 3 (tested with Python 3.7 and 3.12). The only needed dependency is Numpy.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fketakopter%2Fspq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fketakopter%2Fspq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fketakopter%2Fspq/lists"}