physu 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- physu-0.1.0/.gitignore +29 -0
- physu-0.1.0/AGENTS.md +21 -0
- physu-0.1.0/LICENSE +21 -0
- physu-0.1.0/PKG-INFO +128 -0
- physu-0.1.0/README.md +96 -0
- physu-0.1.0/pyproject.toml +73 -0
- physu-0.1.0/src/physu/__init__.py +22 -0
- physu-0.1.0/src/physu/constants.py +56 -0
- physu-0.1.0/src/physu/exceptions.py +18 -0
- physu-0.1.0/src/physu/kinematics/__init__.py +92 -0
- physu-0.1.0/src/physu/kinematics/accelerated.py +312 -0
- physu-0.1.0/src/physu/kinematics/circular.py +238 -0
- physu-0.1.0/src/physu/kinematics/projectile.py +250 -0
- physu-0.1.0/src/physu/kinematics/uniform.py +111 -0
- physu-0.1.0/src/physu/kinematics/vertical.py +225 -0
- physu-0.1.0/src/physu/units.py +133 -0
- physu-0.1.0/src/physu/validation.py +193 -0
- physu-0.1.0/tests/test_constants.py +34 -0
- physu-0.1.0/tests/test_kinematics.py +271 -0
- physu-0.1.0/tests/test_units.py +72 -0
- physu-0.1.0/tests/test_validation.py +88 -0
physu-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Local planning docs & scratch scripts (not committed to GitHub)
|
|
2
|
+
ROADMAP.md
|
|
3
|
+
playground.py
|
|
4
|
+
|
|
5
|
+
# Python
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*$py.class
|
|
9
|
+
*.so
|
|
10
|
+
.Python
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
ENV/
|
|
17
|
+
|
|
18
|
+
# Distribution / packaging
|
|
19
|
+
build/
|
|
20
|
+
dist/
|
|
21
|
+
*.egg-info/
|
|
22
|
+
.eggs/
|
|
23
|
+
|
|
24
|
+
# Testing & tooling caches
|
|
25
|
+
.pytest_cache/
|
|
26
|
+
.ruff_cache/
|
|
27
|
+
.mypy_cache/
|
|
28
|
+
.coverage
|
|
29
|
+
htmlcov/
|
physu-0.1.0/AGENTS.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# AGENTS.md — `physu` Project Guidelines
|
|
2
|
+
|
|
3
|
+
## 1. Project Overview
|
|
4
|
+
- **Package Name (PyPI & `import`):** `physu` (`pip install physu` / `import physu`).
|
|
5
|
+
- **Purpose:** A Python library providing physics formulas, laws, and utilities, designed to scale progressively across independent physics domains/modules.
|
|
6
|
+
- **Core Differentiator:** Strict dimensional checking and physical unit handling using **`pint`** for all input and output quantities.
|
|
7
|
+
|
|
8
|
+
## 2. Language Policy
|
|
9
|
+
- **All project artifacts in English:** All source code, module names, function/class names, parameters, docstrings, comments, error messages, tests, README, and repository documentation (`AGENTS.md`, etc.) must be written in **English**.
|
|
10
|
+
|
|
11
|
+
## 3. Technical & Architectural Guidelines
|
|
12
|
+
- **Working Directory:** `d:\Proyectos\physicspythob`
|
|
13
|
+
- **Primary Dependency:** `pint` for units and dimensional validation.
|
|
14
|
+
- **Physical & Dimensional Validation:**
|
|
15
|
+
- Validate dimensional compatibility for every physical parameter (e.g., length, time, mass).
|
|
16
|
+
- Validate physical domain constraints (e.g., disallow negative mass or negative time where non-physical, negative discriminants under square roots, division by zero) by raising clear exceptions (`ValueError`, `pint.DimensionalityError`, or custom library exceptions).
|
|
17
|
+
- **Modular Scalability:**
|
|
18
|
+
- Organize physics areas into independent submodules (e.g., `kinematics`, `dynamics`, `energy`, `thermodynamics`, `electromagnetism`, etc.) sharing a single centralized `pint.UnitRegistry` instance to prevent mismatches between `Quantity` objects from separate registries.
|
|
19
|
+
- Keep naming, type annotations, and docstrings consistent across all modules.
|
|
20
|
+
- **Testing & Quality:**
|
|
21
|
+
- Every new module or formula must include unit tests (e.g., with `pytest`) verifying: expected numerical results, conversions across compatible units, and expected failures on incompatible dimensions or physically invalid inputs.
|
physu-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 taxnam23
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
physu-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: physu
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A modular Python physics library with strict unit and dimensional validation powered by Pint.
|
|
5
|
+
Project-URL: Homepage, https://github.com/taxnam23
|
|
6
|
+
Project-URL: Repository, https://github.com/taxnam23/physu
|
|
7
|
+
Project-URL: Issues, https://github.com/taxnam23/physu/issues
|
|
8
|
+
Author-email: taxnam23 <tarfanam342@gmail.com>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: dimensional-analysis,kinematics,physics,pint,scientific-computing,units
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: Education
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
24
|
+
Classifier: Typing :: Typed
|
|
25
|
+
Requires-Python: >=3.10
|
|
26
|
+
Requires-Dist: pint>=0.23
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# physu
|
|
34
|
+
|
|
35
|
+
A modular Python physics library with strict unit and dimensional validation powered by [Pint](https://pint.readthedocs.io/).
|
|
36
|
+
|
|
37
|
+
## Features
|
|
38
|
+
|
|
39
|
+
- **Strict dimensional safety:** Rejects incompatible dimensions (such as mass where velocity is expected) via `pint.DimensionalityError`.
|
|
40
|
+
- **Physical domain validation:** Rejects non-physical inputs (negative time, zero radius, unreachable trajectories, `NaN`, or non-finite values) via `PhysicalDomainError` (a `ValueError` subclass).
|
|
41
|
+
- **Centralized `UnitRegistry`:** Shares a single `physu.ureg` across all modules and normalizes strings (`"72 km/h"`), `physu.ureg` quantities, and quantities from external Pint registries.
|
|
42
|
+
- **Clean SI outputs:** Calculations return normalized SI `pint.Quantity` objects that can be converted to any compatible unit with `.to(...)`.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install physu
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
For local development (including `pytest`, `ruff`, and `mypy`):
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install -e ".[dev]"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Requires Python `>= 3.10`.
|
|
57
|
+
|
|
58
|
+
## Quickstart
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import pint
|
|
62
|
+
from physu import PhysicalDomainError, ureg
|
|
63
|
+
from physu.constants import STANDARD_GRAVITY
|
|
64
|
+
from physu.kinematics import (
|
|
65
|
+
accelerated_displacement,
|
|
66
|
+
centripetal_acceleration,
|
|
67
|
+
displacement,
|
|
68
|
+
projectile_range,
|
|
69
|
+
time_to_height,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
# 1D Uniform Motion (MRU)
|
|
73
|
+
dx = displacement("72 km/h", "10 s")
|
|
74
|
+
print(dx) # 200.0 meter
|
|
75
|
+
print(dx.to("km")) # 0.2 kilometer
|
|
76
|
+
|
|
77
|
+
# 1D Uniformly Accelerated Motion (MRUA)
|
|
78
|
+
dx_acc = accelerated_displacement(10 * (ureg.m / ureg.s), "2 m/s^2", "5 s")
|
|
79
|
+
print(dx_acc) # 75.0 meter
|
|
80
|
+
|
|
81
|
+
# Vertical Motion (returns both times when reaching 15 m: going up & coming down)
|
|
82
|
+
times = time_to_height("20 m/s", "15 m", gravity="10 m/s^2")
|
|
83
|
+
print(times) # (Quantity(1.0, "second"), Quantity(3.0, "second"))
|
|
84
|
+
|
|
85
|
+
# 2D Projectile Motion
|
|
86
|
+
rng = projectile_range("20 m/s", "45 deg", gravity=STANDARD_GRAVITY)
|
|
87
|
+
print(round(rng, 2)) # 40.79 meter
|
|
88
|
+
|
|
89
|
+
# Uniform Circular Motion (UCM)
|
|
90
|
+
ac = centripetal_acceleration("2 m", angular_velocity="60 rpm")
|
|
91
|
+
print(round(ac, 2)) # 78.96 meter / second ** 2
|
|
92
|
+
|
|
93
|
+
# Catching dimensional & physical errors
|
|
94
|
+
try:
|
|
95
|
+
displacement("10 kg", "2 s")
|
|
96
|
+
except pint.DimensionalityError as exc:
|
|
97
|
+
print("Dimension error:", exc)
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
time_to_height("20 m/s", "25 m", gravity="10 m/s^2")
|
|
101
|
+
except PhysicalDomainError as exc:
|
|
102
|
+
print("Domain error:", exc)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Modules
|
|
106
|
+
|
|
107
|
+
- **`physu.units`**: Centralized `ureg`, `Quantity`, `to_quantity`, `check_dimension`, `convert_to`, `to_si`, and `to_unit`.
|
|
108
|
+
- **`physu.exceptions`**: `PhysuError` and `PhysicalDomainError`.
|
|
109
|
+
- **`physu.validation`**: `validate_quantity`, `require_non_negative`, `require_positive`, `require_non_zero`, and `require_range`.
|
|
110
|
+
- **`physu.constants`**: Fundamental SI / CODATA 2022 constants (`STANDARD_GRAVITY`, `SPEED_OF_LIGHT`, `GRAVITATIONAL_CONSTANT`, `PLANCK_CONSTANT`, `ELEMENTARY_CHARGE`, `BOLTZMANN_CONSTANT`, `AVOGADRO_CONSTANT`, `MOLAR_GAS_CONSTANT`, `STANDARD_ATMOSPHERE`, `ELECTRON_MASS`, `PROTON_MASS`, `VACUUM_PERMITTIVITY`, `VACUUM_PERMEABILITY`).
|
|
111
|
+
- **`physu.kinematics`**:
|
|
112
|
+
- `uniform`: MRU (`displacement`, `position`, `average_velocity`, `travel_time`)
|
|
113
|
+
- `accelerated`: MRUA / SUVAT (`final_velocity`, `displacement`, `position`, `displacement_from_velocities`, `acceleration`, `torricelli_velocity`, `time_to_velocity`, `time_to_displacement`)
|
|
114
|
+
- `vertical`: Free fall and vertical throw (`vertical_position`, `vertical_velocity`, `free_fall_distance`, `free_fall_speed`, `free_fall_time`, `time_to_peak`, `max_height`, `time_to_height`)
|
|
115
|
+
- `projectile`: 2D projectile motion (`velocity_components`, `projectile_flight_time`, `projectile_max_height`, `projectile_range`, `projectile_position`, `projectile_velocity`)
|
|
116
|
+
- `circular`: Uniform circular motion (`tangential_speed`, `angular_velocity_from_speed`, `centripetal_acceleration`, `period_from_frequency`, `frequency_from_period`, `angular_velocity_from_period`, `angular_velocity_from_frequency`, `period_from_angular_velocity`, `frequency_from_angular_velocity`, `angular_displacement`, `arc_length`)
|
|
117
|
+
|
|
118
|
+
## Development
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pytest
|
|
122
|
+
ruff check src tests
|
|
123
|
+
mypy src
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
[MIT](LICENSE)
|
physu-0.1.0/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# physu
|
|
2
|
+
|
|
3
|
+
A modular Python physics library with strict unit and dimensional validation powered by [Pint](https://pint.readthedocs.io/).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Strict dimensional safety:** Rejects incompatible dimensions (such as mass where velocity is expected) via `pint.DimensionalityError`.
|
|
8
|
+
- **Physical domain validation:** Rejects non-physical inputs (negative time, zero radius, unreachable trajectories, `NaN`, or non-finite values) via `PhysicalDomainError` (a `ValueError` subclass).
|
|
9
|
+
- **Centralized `UnitRegistry`:** Shares a single `physu.ureg` across all modules and normalizes strings (`"72 km/h"`), `physu.ureg` quantities, and quantities from external Pint registries.
|
|
10
|
+
- **Clean SI outputs:** Calculations return normalized SI `pint.Quantity` objects that can be converted to any compatible unit with `.to(...)`.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install physu
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
For local development (including `pytest`, `ruff`, and `mypy`):
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install -e ".[dev]"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Requires Python `>= 3.10`.
|
|
25
|
+
|
|
26
|
+
## Quickstart
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
import pint
|
|
30
|
+
from physu import PhysicalDomainError, ureg
|
|
31
|
+
from physu.constants import STANDARD_GRAVITY
|
|
32
|
+
from physu.kinematics import (
|
|
33
|
+
accelerated_displacement,
|
|
34
|
+
centripetal_acceleration,
|
|
35
|
+
displacement,
|
|
36
|
+
projectile_range,
|
|
37
|
+
time_to_height,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# 1D Uniform Motion (MRU)
|
|
41
|
+
dx = displacement("72 km/h", "10 s")
|
|
42
|
+
print(dx) # 200.0 meter
|
|
43
|
+
print(dx.to("km")) # 0.2 kilometer
|
|
44
|
+
|
|
45
|
+
# 1D Uniformly Accelerated Motion (MRUA)
|
|
46
|
+
dx_acc = accelerated_displacement(10 * (ureg.m / ureg.s), "2 m/s^2", "5 s")
|
|
47
|
+
print(dx_acc) # 75.0 meter
|
|
48
|
+
|
|
49
|
+
# Vertical Motion (returns both times when reaching 15 m: going up & coming down)
|
|
50
|
+
times = time_to_height("20 m/s", "15 m", gravity="10 m/s^2")
|
|
51
|
+
print(times) # (Quantity(1.0, "second"), Quantity(3.0, "second"))
|
|
52
|
+
|
|
53
|
+
# 2D Projectile Motion
|
|
54
|
+
rng = projectile_range("20 m/s", "45 deg", gravity=STANDARD_GRAVITY)
|
|
55
|
+
print(round(rng, 2)) # 40.79 meter
|
|
56
|
+
|
|
57
|
+
# Uniform Circular Motion (UCM)
|
|
58
|
+
ac = centripetal_acceleration("2 m", angular_velocity="60 rpm")
|
|
59
|
+
print(round(ac, 2)) # 78.96 meter / second ** 2
|
|
60
|
+
|
|
61
|
+
# Catching dimensional & physical errors
|
|
62
|
+
try:
|
|
63
|
+
displacement("10 kg", "2 s")
|
|
64
|
+
except pint.DimensionalityError as exc:
|
|
65
|
+
print("Dimension error:", exc)
|
|
66
|
+
|
|
67
|
+
try:
|
|
68
|
+
time_to_height("20 m/s", "25 m", gravity="10 m/s^2")
|
|
69
|
+
except PhysicalDomainError as exc:
|
|
70
|
+
print("Domain error:", exc)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Modules
|
|
74
|
+
|
|
75
|
+
- **`physu.units`**: Centralized `ureg`, `Quantity`, `to_quantity`, `check_dimension`, `convert_to`, `to_si`, and `to_unit`.
|
|
76
|
+
- **`physu.exceptions`**: `PhysuError` and `PhysicalDomainError`.
|
|
77
|
+
- **`physu.validation`**: `validate_quantity`, `require_non_negative`, `require_positive`, `require_non_zero`, and `require_range`.
|
|
78
|
+
- **`physu.constants`**: Fundamental SI / CODATA 2022 constants (`STANDARD_GRAVITY`, `SPEED_OF_LIGHT`, `GRAVITATIONAL_CONSTANT`, `PLANCK_CONSTANT`, `ELEMENTARY_CHARGE`, `BOLTZMANN_CONSTANT`, `AVOGADRO_CONSTANT`, `MOLAR_GAS_CONSTANT`, `STANDARD_ATMOSPHERE`, `ELECTRON_MASS`, `PROTON_MASS`, `VACUUM_PERMITTIVITY`, `VACUUM_PERMEABILITY`).
|
|
79
|
+
- **`physu.kinematics`**:
|
|
80
|
+
- `uniform`: MRU (`displacement`, `position`, `average_velocity`, `travel_time`)
|
|
81
|
+
- `accelerated`: MRUA / SUVAT (`final_velocity`, `displacement`, `position`, `displacement_from_velocities`, `acceleration`, `torricelli_velocity`, `time_to_velocity`, `time_to_displacement`)
|
|
82
|
+
- `vertical`: Free fall and vertical throw (`vertical_position`, `vertical_velocity`, `free_fall_distance`, `free_fall_speed`, `free_fall_time`, `time_to_peak`, `max_height`, `time_to_height`)
|
|
83
|
+
- `projectile`: 2D projectile motion (`velocity_components`, `projectile_flight_time`, `projectile_max_height`, `projectile_range`, `projectile_position`, `projectile_velocity`)
|
|
84
|
+
- `circular`: Uniform circular motion (`tangential_speed`, `angular_velocity_from_speed`, `centripetal_acceleration`, `period_from_frequency`, `frequency_from_period`, `angular_velocity_from_period`, `angular_velocity_from_frequency`, `period_from_angular_velocity`, `frequency_from_angular_velocity`, `angular_displacement`, `arc_length`)
|
|
85
|
+
|
|
86
|
+
## Development
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pytest
|
|
90
|
+
ruff check src tests
|
|
91
|
+
mypy src
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.26"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "physu"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "A modular Python physics library with strict unit and dimensional validation powered by Pint."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "taxnam23", email = "tarfanam342@gmail.com" },
|
|
15
|
+
]
|
|
16
|
+
keywords = [
|
|
17
|
+
"physics",
|
|
18
|
+
"units",
|
|
19
|
+
"pint",
|
|
20
|
+
"dimensional-analysis",
|
|
21
|
+
"kinematics",
|
|
22
|
+
"scientific-computing",
|
|
23
|
+
]
|
|
24
|
+
classifiers = [
|
|
25
|
+
"Development Status :: 3 - Alpha",
|
|
26
|
+
"Intended Audience :: Education",
|
|
27
|
+
"Intended Audience :: Science/Research",
|
|
28
|
+
"Intended Audience :: Developers",
|
|
29
|
+
"License :: OSI Approved :: MIT License",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Programming Language :: Python :: 3.14",
|
|
36
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
37
|
+
"Typing :: Typed",
|
|
38
|
+
]
|
|
39
|
+
dependencies = [
|
|
40
|
+
"pint>=0.23",
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
[project.optional-dependencies]
|
|
44
|
+
dev = [
|
|
45
|
+
"pytest>=8.0",
|
|
46
|
+
"ruff>=0.6",
|
|
47
|
+
"mypy>=1.11",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[project.urls]
|
|
51
|
+
Homepage = "https://github.com/taxnam23"
|
|
52
|
+
Repository = "https://github.com/taxnam23/physu"
|
|
53
|
+
Issues = "https://github.com/taxnam23/physu/issues"
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.wheel]
|
|
56
|
+
packages = ["src/physu"]
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
testpaths = ["tests"]
|
|
60
|
+
addopts = "-ra -q"
|
|
61
|
+
|
|
62
|
+
[tool.ruff]
|
|
63
|
+
line-length = 100
|
|
64
|
+
target-version = "py310"
|
|
65
|
+
src = ["src", "tests"]
|
|
66
|
+
|
|
67
|
+
[tool.ruff.lint]
|
|
68
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
69
|
+
|
|
70
|
+
[tool.mypy]
|
|
71
|
+
python_version = "3.10"
|
|
72
|
+
strict = true
|
|
73
|
+
mypy_path = "src"
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""physu: A modular Python physics library powered by Pint."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from . import constants, exceptions, kinematics, units, validation
|
|
6
|
+
from .exceptions import PhysicalDomainError, PhysuError
|
|
7
|
+
from .units import Quantity, ureg
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
10
|
+
|
|
11
|
+
__all__ = [
|
|
12
|
+
"PhysicalDomainError",
|
|
13
|
+
"PhysuError",
|
|
14
|
+
"Quantity",
|
|
15
|
+
"__version__",
|
|
16
|
+
"constants",
|
|
17
|
+
"exceptions",
|
|
18
|
+
"kinematics",
|
|
19
|
+
"units",
|
|
20
|
+
"ureg",
|
|
21
|
+
"validation",
|
|
22
|
+
]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Fundamental physical constants as Pint quantities bound to ``physu.ureg``.
|
|
2
|
+
|
|
3
|
+
Values follow the 2019 SI redefinition and CODATA 2022 recommended values.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
import math
|
|
9
|
+
|
|
10
|
+
import pint
|
|
11
|
+
|
|
12
|
+
from .units import Quantity
|
|
13
|
+
|
|
14
|
+
# Mechanics & gravitation
|
|
15
|
+
STANDARD_GRAVITY: pint.Quantity = Quantity(9.80665, "m / s^2")
|
|
16
|
+
GRAVITATIONAL_CONSTANT: pint.Quantity = Quantity(6.67430e-11, "m^3 / (kg * s^2)")
|
|
17
|
+
|
|
18
|
+
# Relativity & quantum mechanics
|
|
19
|
+
SPEED_OF_LIGHT: pint.Quantity = Quantity(299_792_458, "m / s")
|
|
20
|
+
PLANCK_CONSTANT: pint.Quantity = Quantity(6.62607015e-34, "J * s")
|
|
21
|
+
REDUCED_PLANCK_CONSTANT: pint.Quantity = Quantity(
|
|
22
|
+
6.62607015e-34 / (2.0 * math.pi),
|
|
23
|
+
"J * s",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# Electromagnetism
|
|
27
|
+
ELEMENTARY_CHARGE: pint.Quantity = Quantity(1.602176634e-19, "C")
|
|
28
|
+
VACUUM_PERMITTIVITY: pint.Quantity = Quantity(8.8541878188e-12, "F / m")
|
|
29
|
+
VACUUM_PERMEABILITY: pint.Quantity = Quantity(1.25663706127e-6, "N / A^2")
|
|
30
|
+
|
|
31
|
+
# Thermodynamics & chemistry
|
|
32
|
+
BOLTZMANN_CONSTANT: pint.Quantity = Quantity(1.380649e-23, "J / K")
|
|
33
|
+
AVOGADRO_CONSTANT: pint.Quantity = Quantity(6.02214076e23, "1 / mol")
|
|
34
|
+
MOLAR_GAS_CONSTANT: pint.Quantity = AVOGADRO_CONSTANT * BOLTZMANN_CONSTANT
|
|
35
|
+
STANDARD_ATMOSPHERE: pint.Quantity = Quantity(101_325, "Pa")
|
|
36
|
+
|
|
37
|
+
# Atomic & particle masses
|
|
38
|
+
ELECTRON_MASS: pint.Quantity = Quantity(9.1093837139e-31, "kg")
|
|
39
|
+
PROTON_MASS: pint.Quantity = Quantity(1.67262192595e-27, "kg")
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"AVOGADRO_CONSTANT",
|
|
43
|
+
"BOLTZMANN_CONSTANT",
|
|
44
|
+
"ELECTRON_MASS",
|
|
45
|
+
"ELEMENTARY_CHARGE",
|
|
46
|
+
"GRAVITATIONAL_CONSTANT",
|
|
47
|
+
"MOLAR_GAS_CONSTANT",
|
|
48
|
+
"PLANCK_CONSTANT",
|
|
49
|
+
"PROTON_MASS",
|
|
50
|
+
"REDUCED_PLANCK_CONSTANT",
|
|
51
|
+
"SPEED_OF_LIGHT",
|
|
52
|
+
"STANDARD_ATMOSPHERE",
|
|
53
|
+
"STANDARD_GRAVITY",
|
|
54
|
+
"VACUUM_PERMEABILITY",
|
|
55
|
+
"VACUUM_PERMITTIVITY",
|
|
56
|
+
]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Custom exception hierarchy for physical domain and library errors in physu."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class PhysuError(Exception):
|
|
7
|
+
"""Base exception for all physu-specific errors."""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PhysicalDomainError(PhysuError, ValueError):
|
|
11
|
+
"""Raised when an input violates a physical domain constraint.
|
|
12
|
+
|
|
13
|
+
Examples include negative time or mass where non-physical, zero radius or
|
|
14
|
+
denominator, or negative discriminants that yield non-real solutions.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
__all__ = ["PhysicalDomainError", "PhysuError"]
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Kinematics formulas and utilities for physu."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from . import accelerated, circular, projectile, uniform, vertical
|
|
6
|
+
from .accelerated import (
|
|
7
|
+
acceleration,
|
|
8
|
+
displacement_from_velocities,
|
|
9
|
+
final_velocity,
|
|
10
|
+
time_to_displacement,
|
|
11
|
+
time_to_velocity,
|
|
12
|
+
torricelli_velocity,
|
|
13
|
+
)
|
|
14
|
+
from .accelerated import displacement as accelerated_displacement
|
|
15
|
+
from .accelerated import position as accelerated_position
|
|
16
|
+
from .circular import (
|
|
17
|
+
angular_displacement,
|
|
18
|
+
angular_velocity_from_frequency,
|
|
19
|
+
angular_velocity_from_period,
|
|
20
|
+
angular_velocity_from_speed,
|
|
21
|
+
arc_length,
|
|
22
|
+
centripetal_acceleration,
|
|
23
|
+
frequency_from_angular_velocity,
|
|
24
|
+
frequency_from_period,
|
|
25
|
+
period_from_angular_velocity,
|
|
26
|
+
period_from_frequency,
|
|
27
|
+
tangential_speed,
|
|
28
|
+
)
|
|
29
|
+
from .projectile import (
|
|
30
|
+
projectile_flight_time,
|
|
31
|
+
projectile_max_height,
|
|
32
|
+
projectile_position,
|
|
33
|
+
projectile_range,
|
|
34
|
+
projectile_velocity,
|
|
35
|
+
velocity_components,
|
|
36
|
+
)
|
|
37
|
+
from .uniform import average_velocity, displacement, position, travel_time
|
|
38
|
+
from .vertical import (
|
|
39
|
+
free_fall_distance,
|
|
40
|
+
free_fall_speed,
|
|
41
|
+
free_fall_time,
|
|
42
|
+
max_height,
|
|
43
|
+
time_to_height,
|
|
44
|
+
time_to_peak,
|
|
45
|
+
vertical_position,
|
|
46
|
+
vertical_velocity,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"accelerated",
|
|
51
|
+
"accelerated_displacement",
|
|
52
|
+
"accelerated_position",
|
|
53
|
+
"acceleration",
|
|
54
|
+
"angular_displacement",
|
|
55
|
+
"angular_velocity_from_frequency",
|
|
56
|
+
"angular_velocity_from_period",
|
|
57
|
+
"angular_velocity_from_speed",
|
|
58
|
+
"arc_length",
|
|
59
|
+
"average_velocity",
|
|
60
|
+
"centripetal_acceleration",
|
|
61
|
+
"circular",
|
|
62
|
+
"displacement",
|
|
63
|
+
"displacement_from_velocities",
|
|
64
|
+
"final_velocity",
|
|
65
|
+
"free_fall_distance",
|
|
66
|
+
"free_fall_speed",
|
|
67
|
+
"free_fall_time",
|
|
68
|
+
"frequency_from_angular_velocity",
|
|
69
|
+
"frequency_from_period",
|
|
70
|
+
"max_height",
|
|
71
|
+
"period_from_angular_velocity",
|
|
72
|
+
"period_from_frequency",
|
|
73
|
+
"position",
|
|
74
|
+
"projectile",
|
|
75
|
+
"projectile_flight_time",
|
|
76
|
+
"projectile_max_height",
|
|
77
|
+
"projectile_position",
|
|
78
|
+
"projectile_range",
|
|
79
|
+
"projectile_velocity",
|
|
80
|
+
"tangential_speed",
|
|
81
|
+
"time_to_displacement",
|
|
82
|
+
"time_to_height",
|
|
83
|
+
"time_to_peak",
|
|
84
|
+
"time_to_velocity",
|
|
85
|
+
"torricelli_velocity",
|
|
86
|
+
"travel_time",
|
|
87
|
+
"uniform",
|
|
88
|
+
"velocity_components",
|
|
89
|
+
"vertical",
|
|
90
|
+
"vertical_position",
|
|
91
|
+
"vertical_velocity",
|
|
92
|
+
]
|