abstract-math 0.0.0.30__py3-none-any.whl → 0.0.0.32__py3-none-any.whl
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.
Potentially problematic release.
This version of abstract-math might be problematic. Click here for more details.
- abstract_math/solar_math/main.py +35 -35
- abstract_math/solar_math/src/constants/__init__.py +2 -2
- abstract_math/solar_math/src/constants/distance_constants.py +15 -15
- abstract_math/solar_math/src/constants/planet_constants.py +31 -31
- abstract_math/solar_math/src/constants/time_constants.py +11 -11
- abstract_math/solar_math/src/utils/escape_velocity.py +34 -25
- abstract_math/solar_math/src/utils/velocity_utils.py +53 -24
- {abstract_math-0.0.0.30.dist-info → abstract_math-0.0.0.32.dist-info}/METADATA +1 -1
- {abstract_math-0.0.0.30.dist-info → abstract_math-0.0.0.32.dist-info}/RECORD +11 -11
- {abstract_math-0.0.0.30.dist-info → abstract_math-0.0.0.32.dist-info}/WHEEL +0 -0
- {abstract_math-0.0.0.30.dist-info → abstract_math-0.0.0.32.dist-info}/top_level.txt +0 -0
abstract_math/solar_math/main.py
CHANGED
|
@@ -7,8 +7,8 @@ from .src.utils.geometry_utils import visible_area_flat, visible_surface_angle
|
|
|
7
7
|
from .src.utils import get_R_mu,get_normalized_distance,get_normalized_starting_velocity
|
|
8
8
|
from .src.imports import math, mul, div, add, exp # your abstract_math ops
|
|
9
9
|
from .src.constants import (
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
DEFAULT_DIST_UNIT,
|
|
11
|
+
DEFAULT_TIME_UNIT,
|
|
12
12
|
DEFAULT_PLANET,
|
|
13
13
|
DEFAULT_START_ALTITUDE,
|
|
14
14
|
DEFAULT_AS_RADIUS
|
|
@@ -18,19 +18,19 @@ def normalize_inputs(
|
|
|
18
18
|
planet: str,
|
|
19
19
|
start_altitude: float,
|
|
20
20
|
starting_velocity: float,
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
input_dist_unit: str,
|
|
22
|
+
input_time_unit: str,
|
|
23
23
|
target_distance: float = None,
|
|
24
24
|
) -> dict:
|
|
25
25
|
"""Normalize input altitudes and velocities into SI (meters, seconds)."""
|
|
26
|
-
start_alt_m = get_normalized_distance(start_altitude,
|
|
27
|
-
target_alt_m = get_normalized_distance(target_distance,
|
|
26
|
+
start_alt_m = get_normalized_distance(start_altitude, input_dist_unit)
|
|
27
|
+
target_alt_m = get_normalized_distance(target_distance, input_dist_unit)
|
|
28
28
|
|
|
29
29
|
v0_mps = get_normalized_starting_velocity(
|
|
30
30
|
start_altitude=start_alt_m,
|
|
31
31
|
starting_velocity=starting_velocity,
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
input_dist_unit=input_dist_unit,
|
|
33
|
+
input_time_unit=input_time_unit,
|
|
34
34
|
planet=planet,
|
|
35
35
|
)
|
|
36
36
|
|
|
@@ -45,43 +45,43 @@ def analyze_visible_surface(
|
|
|
45
45
|
max_steps: int = 20,
|
|
46
46
|
fov_range: tuple[int, int] = (20, 160),
|
|
47
47
|
fov_interval: int = 10,
|
|
48
|
-
|
|
49
|
-
display_units: str =
|
|
48
|
+
input_dist_unit: str = DEFAULT_DIST_UNIT, # how to interpret altitude numbers
|
|
49
|
+
display_units: str = DEFAULT_DIST_UNIT, # how to print areas/radii
|
|
50
50
|
planet: str = DEFAULT_PLANET,
|
|
51
51
|
printit: bool = False
|
|
52
52
|
):
|
|
53
53
|
"""
|
|
54
|
-
Scan altitudes/FOVs. Altitudes are interpreted in `
|
|
54
|
+
Scan altitudes/FOVs. Altitudes are interpreted in `input_dist_unit`.
|
|
55
55
|
Results are printed in `display_units`.
|
|
56
56
|
"""
|
|
57
57
|
# Planet radius and full area (compute in meters, convert for display)
|
|
58
|
-
r_m = planet_radius(planet,
|
|
58
|
+
r_m = planet_radius(planet, DEFAULT_DIST_UNIT)
|
|
59
59
|
full_area_m2 = 4.0 * math.pi * (r_m ** 2)
|
|
60
|
-
k_disp = dfactor(
|
|
60
|
+
k_disp = dfactor(DEFAULT_DIST_UNIT, display_units) # linear meter->display factor
|
|
61
61
|
full_area_disp = full_area_m2 * (k_disp ** 2) # convert area to display units^2
|
|
62
62
|
|
|
63
|
-
all_stats = {"output": "", "
|
|
63
|
+
all_stats = {"output": "", "input_dist_unit": input_dist_unit,
|
|
64
64
|
"display_units": display_units, "vars": []}
|
|
65
65
|
|
|
66
66
|
for i in range(1, max_steps + 1):
|
|
67
67
|
all_stats["vars"].append({})
|
|
68
|
-
altitude_in = altitude_step * i #
|
|
69
|
-
altitude_m = dconvert(altitude_in,
|
|
68
|
+
altitude_in = altitude_step * i # input_dist_unit
|
|
69
|
+
altitude_m = dconvert(altitude_in, input_dist_unit, DEFAULT_DIST_UNIT)
|
|
70
70
|
|
|
71
71
|
all_stats["vars"][-1]['altitude_input'] = altitude_in
|
|
72
|
-
all_stats["vars"][-1]['
|
|
72
|
+
all_stats["vars"][-1]['input_dist_unit'] = input_dist_unit
|
|
73
73
|
all_stats["vars"][-1]['fov'] = []
|
|
74
74
|
|
|
75
|
-
alt_pretty = dconvert(altitude_in,
|
|
75
|
+
alt_pretty = dconvert(altitude_in, input_dist_unit, display_units)
|
|
76
76
|
all_stats["output"] += (
|
|
77
|
-
f"\n=== Altitude: {altitude_in} {
|
|
77
|
+
f"\n=== Altitude: {altitude_in} {input_dist_unit} (≈ {alt_pretty:.3f} {display_units}) ===\n"
|
|
78
78
|
)
|
|
79
79
|
|
|
80
80
|
for fov in range(fov_range[0], fov_range[1] + 1, fov_interval):
|
|
81
81
|
# Compute visible area/radius in meters, convert to display units
|
|
82
|
-
area_m2, vis_radius_m = visible_area_flat(fov, altitude_m,
|
|
82
|
+
area_m2, vis_radius_m = visible_area_flat(fov, altitude_m, DEFAULT_DIST_UNIT)
|
|
83
83
|
area_disp = area_m2 * (k_disp ** 2)
|
|
84
|
-
vis_radius_disp = dconvert(vis_radius_m,
|
|
84
|
+
vis_radius_disp = dconvert(vis_radius_m, DEFAULT_DIST_UNIT, display_units)
|
|
85
85
|
|
|
86
86
|
# Span uses geometry only; r_m is in meters
|
|
87
87
|
_, angle_deg = visible_surface_angle(vis_radius_m, r_m)
|
|
@@ -213,10 +213,10 @@ def simulate_radial_flight_si(
|
|
|
213
213
|
def radial_travel(
|
|
214
214
|
starting_velocity: float = None,
|
|
215
215
|
start_altitude: float = None,
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
input_dist_unit: str = DEFAULT_DIST_UNIT,
|
|
217
|
+
input_time_unit: str = DEFAULT_TIME_UNIT,
|
|
218
|
+
output_dist_unit: str = DEFAULT_DIST_UNIT,
|
|
219
|
+
output_time_unit: str = DEFAULT_TIME_UNIT,
|
|
220
220
|
*,
|
|
221
221
|
planet: str = DEFAULT_PLANET,
|
|
222
222
|
dt_s: float = 1.0,
|
|
@@ -226,7 +226,7 @@ def radial_travel(
|
|
|
226
226
|
"""Wrapper: handles units, runs SI integrator, converts outputs."""
|
|
227
227
|
norm = normalize_inputs(
|
|
228
228
|
planet=planet, start_altitude=start_altitude, starting_velocity=starting_velocity,
|
|
229
|
-
|
|
229
|
+
input_dist_unit=input_dist_unit, input_time_unit=input_time_unit, target_distance=target_distance
|
|
230
230
|
)
|
|
231
231
|
|
|
232
232
|
sim = simulate_radial_flight_si(
|
|
@@ -241,8 +241,8 @@ def radial_travel(
|
|
|
241
241
|
return sim
|
|
242
242
|
|
|
243
243
|
# Output conversions
|
|
244
|
-
sec_per_out = seconds_per(
|
|
245
|
-
conv = lambda m: dconvert(m,
|
|
244
|
+
sec_per_out = seconds_per(output_time_unit)
|
|
245
|
+
conv = lambda m: dconvert(m, DEFAULT_DIST_UNIT, output_dist_unit)
|
|
246
246
|
|
|
247
247
|
return {
|
|
248
248
|
"ok": True,
|
|
@@ -250,20 +250,20 @@ def radial_travel(
|
|
|
250
250
|
"inputs": {
|
|
251
251
|
"start_altitude": start_altitude,
|
|
252
252
|
"starting_velocity": starting_velocity,
|
|
253
|
-
"
|
|
254
|
-
"
|
|
255
|
-
"
|
|
256
|
-
"
|
|
253
|
+
"input_dist_unit": input_dist_unit,
|
|
254
|
+
"input_time_unit": input_time_unit,
|
|
255
|
+
"output_dist_unit": output_dist_unit,
|
|
256
|
+
"output_time_unit": output_time_unit,
|
|
257
257
|
"target_distance": target_distance,
|
|
258
258
|
},
|
|
259
259
|
# final state
|
|
260
260
|
"altitude": conv(sim["altitude_m"]),
|
|
261
261
|
"radius_from_center": conv(sim["r_m"]),
|
|
262
262
|
"distance_traveled": conv(sim["traveled_m"]),
|
|
263
|
-
"velocity": mul(dconvert(sim["vEnd_mps"],
|
|
264
|
-
"velocity_escape_end": mul(dconvert(sim["vesc_end_mps"],
|
|
263
|
+
"velocity": mul(dconvert(sim["vEnd_mps"], DEFAULT_DIST_UNIT, output_dist_unit), sec_per_out),
|
|
264
|
+
"velocity_escape_end": mul(dconvert(sim["vesc_end_mps"], DEFAULT_DIST_UNIT, output_dist_unit), sec_per_out),
|
|
265
265
|
"time": div(sim["time_s"], sec_per_out),
|
|
266
|
-
"time_unit":
|
|
266
|
+
"time_unit": output_time_unit,
|
|
267
267
|
"g_end_mps2": sim["g_end_mps2"],
|
|
268
268
|
"g_ratio_surface": sim["g_ratio_surface"],
|
|
269
269
|
"steps": sim["steps"],
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
from .distance_constants import (
|
|
3
3
|
DISTANCE_CONVERSIONS, ALL_DISTANCE_UNITS,
|
|
4
4
|
normalize_distance_unit, get_distance_unit_conversions,
|
|
5
|
-
_factor, dconvert,
|
|
5
|
+
_factor, dconvert,DEFAULT_DIST_UNIT,DEFAULT_START_ALTITUDE
|
|
6
6
|
)
|
|
7
7
|
from .time_constants import (
|
|
8
8
|
TIME_CONVERSIONS, ALL_TIME_UNITS,
|
|
9
9
|
normalize_time_unit, get_time_unit_conversions,
|
|
10
|
-
time_factor, convert_time, seconds_per,
|
|
10
|
+
time_factor, convert_time, seconds_per,DEFAULT_TIME_UNIT
|
|
11
11
|
)
|
|
12
12
|
from .planet_constants import (
|
|
13
13
|
PLANETS, G, g0, MU_MOON,
|
|
@@ -19,7 +19,7 @@ DISTANCE_CONVERSIONS: Dict[str, Dict[str, Dict[str, float]]] = {
|
|
|
19
19
|
"feet": FEET
|
|
20
20
|
}
|
|
21
21
|
ALL_DISTANCE_UNITS = ("meters", "kilometers", "miles", "feet")
|
|
22
|
-
|
|
22
|
+
DEFAULT_DIST_UNIT="meters"
|
|
23
23
|
DEFAULT_START_ALTITUDE=0.0
|
|
24
24
|
# -------------------------
|
|
25
25
|
# Unit helpers
|
|
@@ -34,36 +34,36 @@ def normalize_distance_unit(unit: str) -> str:
|
|
|
34
34
|
# was: CONVERSIONS
|
|
35
35
|
raise ValueError(f"Unknown unit '{unit}'. Supported: {list(DISTANCE_CONVERSIONS.keys())}")
|
|
36
36
|
|
|
37
|
-
def get_distance_unit_conversions(
|
|
38
|
-
return DISTANCE_CONVERSIONS[normalize_distance_unit(
|
|
37
|
+
def get_distance_unit_conversions(dist_unit: str) -> Dict[str, Dict[str, float]]:
|
|
38
|
+
return DISTANCE_CONVERSIONS[normalize_distance_unit(dist_unit)]
|
|
39
39
|
|
|
40
|
-
def _factor(
|
|
40
|
+
def _factor(dist_unit_from: str, dist_unit_to: str) -> float:
|
|
41
41
|
"""Multiplicative factor s.t. value_in_to = value_in_from * factor."""
|
|
42
|
-
uf = get_distance_unit_conversions(
|
|
43
|
-
ut = get_distance_unit_conversions(
|
|
42
|
+
uf = get_distance_unit_conversions(dist_unit_from)["conv"]["meters"] # meters per 1 from-unit
|
|
43
|
+
ut = get_distance_unit_conversions(dist_unit_to)["conv"]["meters"] # meters per 1 to-unit
|
|
44
44
|
return div(uf, ut)
|
|
45
45
|
|
|
46
|
-
def dconvert(value: float,
|
|
47
|
-
return mul(value, _factor(
|
|
46
|
+
def dconvert(value: float, dist_unit_from: str, dist_unit_to: str) -> float:
|
|
47
|
+
return mul(value, _factor(dist_unit_from, dist_unit_to))
|
|
48
48
|
def get_normalized_distance(
|
|
49
49
|
distance: Optional[float] = None,
|
|
50
|
-
|
|
50
|
+
input_dist_units: str = DEFAULT_DIST_UNIT
|
|
51
51
|
):
|
|
52
52
|
distance = target_alt_m = distance or 0
|
|
53
53
|
if distance is not None:
|
|
54
54
|
target_alt_m = dconvert(value=distance,
|
|
55
|
-
unit_from=
|
|
56
|
-
unit_to=
|
|
55
|
+
unit_from=input_dist_units,
|
|
56
|
+
unit_to=DEFAULT_DIST_UNIT
|
|
57
57
|
)
|
|
58
58
|
return target_alt_m
|
|
59
59
|
def get_target_distance(
|
|
60
60
|
distance: Optional[float] = None,
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
input_dist_units: str = DEFAULT_DIST_UNIT,
|
|
62
|
+
output_dist_units: str = DEFAULT_DIST_UNIT,
|
|
63
63
|
):
|
|
64
64
|
distance = target_distance = distance or 0
|
|
65
65
|
if distance is not None:
|
|
66
66
|
target_distance = dconvert(value=distance,
|
|
67
|
-
unit_from=
|
|
68
|
-
unit_to=
|
|
67
|
+
unit_from=input_dist_units,
|
|
68
|
+
unit_to=output_dist_units)
|
|
69
69
|
return target_distance
|
|
@@ -57,7 +57,7 @@ for entry in PLANETS:
|
|
|
57
57
|
# -------------------------
|
|
58
58
|
# Public API
|
|
59
59
|
# -------------------------
|
|
60
|
-
def get_planet_vars(name: str,
|
|
60
|
+
def get_planet_vars(name: str, dist_unit: str = "meters") -> Dict[str, Any]:
|
|
61
61
|
"""
|
|
62
62
|
Return body properties with radius/diameter in `units`.
|
|
63
63
|
Mass in kg; mu in m^3/s^2; surface_g in m/s^2.
|
|
@@ -67,49 +67,49 @@ def get_planet_vars(name: str, units: str = "meters") -> Dict[str, Any]:
|
|
|
67
67
|
if body is None:
|
|
68
68
|
raise KeyError(f"Unknown body '{name}'. Available: {sorted(_BODY_BY_NAME.keys())}")
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
dist_unit_norm = normalize_distance_unit(units)
|
|
71
71
|
r_m = body["radius"]
|
|
72
72
|
d_m = body["diameter"]
|
|
73
73
|
|
|
74
74
|
out = dict(body)
|
|
75
|
-
out["radius"] = dconvert(r_m, "meters",
|
|
76
|
-
out["diameter"] = dconvert(d_m, "meters",
|
|
77
|
-
out["
|
|
78
|
-
out["
|
|
75
|
+
out["radius"] = dconvert(r_m, "meters", dist_unit_norm)
|
|
76
|
+
out["diameter"] = dconvert(d_m, "meters", dist_unit_norm)
|
|
77
|
+
out["radius_unit"] = dist_unit_norm
|
|
78
|
+
out["diameter_unit"] = dist_unit_norm
|
|
79
79
|
return out
|
|
80
80
|
|
|
81
|
-
def planet_radius(name: str = "earth",
|
|
82
|
-
return get_planet_vars(name,
|
|
81
|
+
def planet_radius(name: str = "earth", dist_unit: str = "meters") -> float:
|
|
82
|
+
return get_planet_vars(name, dist_unit)["radius"]
|
|
83
83
|
|
|
84
|
-
def planet_diameter(name: str = "earth",
|
|
85
|
-
return get_planet_vars(name,
|
|
84
|
+
def planet_diameter(name: str = "earth", dist_unit: str = "meters") -> float:
|
|
85
|
+
return get_planet_vars(name, dist_unit)["diameter"]
|
|
86
86
|
|
|
87
|
-
def full_planet_surface_area(name: str = "earth",
|
|
88
|
-
r = planet_radius(name,
|
|
87
|
+
def full_planet_surface_area(name: str = "earth", dist_unit: str = 'meters') -> float:
|
|
88
|
+
r = planet_radius(name,dist_unit)
|
|
89
89
|
return mul(4 * pi(), exp(r, 2))
|
|
90
90
|
|
|
91
|
-
def planet_volume(name: str = "earth",
|
|
92
|
-
r = planet_radius(name,
|
|
91
|
+
def planet_volume(name: str = "earth", dist_unit: str = 'meters') -> float:
|
|
92
|
+
r = planet_radius(name,dist_unit)
|
|
93
93
|
return mul((4.0/3.0) * pi(), exp(r, 3))
|
|
94
94
|
|
|
95
|
-
def planet_circumference(name: str = "earth",
|
|
96
|
-
r = planet_radius(name,
|
|
95
|
+
def planet_circumference(name: str = "earth", dist_unit: str = 'meters') -> float:
|
|
96
|
+
r = planet_radius(name,dist_unit)
|
|
97
97
|
return mul(2 * pi(), r)
|
|
98
98
|
|
|
99
99
|
def planet_mass(name: str = "earth") -> float:
|
|
100
100
|
return get_planet_vars(name)["mass"]
|
|
101
101
|
|
|
102
|
-
def planet_surface_g(name: str = "earth", as_g0: bool = False,
|
|
103
|
-
v = get_planet_vars(name,
|
|
102
|
+
def planet_surface_g(name: str = "earth", as_g0: bool = False, dist_unit: str = "meters") -> float:
|
|
103
|
+
v = get_planet_vars(name, dist_unit)["surface_g"]
|
|
104
104
|
return div(v, g0) if as_g0 else v
|
|
105
105
|
|
|
106
|
-
def escape_velocity(name: str = "earth", altitude: float = 0.0,
|
|
106
|
+
def escape_velocity(name: str = "earth", altitude: float = 0.0, dist_unit: str = "meters") -> float:
|
|
107
107
|
"""
|
|
108
108
|
Escape velocity (m/s) from altitude above surface.
|
|
109
109
|
"""
|
|
110
110
|
mu = _BODY_BY_NAME[_normalize_name(name)]["mu"]
|
|
111
111
|
r = _BODY_BY_NAME[_normalize_name(name)]["radius"] # meters
|
|
112
|
-
h_m = dconvert(altitude,
|
|
112
|
+
h_m = dconvert(altitude, dist_unit, "meters")
|
|
113
113
|
R = add(r, h_m)
|
|
114
114
|
return math.sqrt(mul(2.0, div(mu, R)))
|
|
115
115
|
|
|
@@ -119,31 +119,31 @@ def escape_velocity(name: str = "earth", altitude: float = 0.0, units: str = "me
|
|
|
119
119
|
def pi() -> float:
|
|
120
120
|
return math.pi
|
|
121
121
|
|
|
122
|
-
def earth_radius(
|
|
122
|
+
def earth_radius(dist_unit: str = 'meters') -> float:
|
|
123
123
|
return planet_radius('earth', units)
|
|
124
124
|
|
|
125
|
-
def earth_diameter(
|
|
126
|
-
return planet_diameter('earth',
|
|
125
|
+
def earth_diameter(dist_unit: str = 'meters') -> float:
|
|
126
|
+
return planet_diameter('earth', dist_unit)
|
|
127
127
|
|
|
128
|
-
def full_earth_surface_area(
|
|
129
|
-
r = earth_radius(
|
|
128
|
+
def full_earth_surface_area(dist_unit: str = 'meters') -> float:
|
|
129
|
+
r = earth_radius(dist_unit)
|
|
130
130
|
return mul(4 * pi(), exp(r, 2))
|
|
131
131
|
|
|
132
|
-
def earth_volume(
|
|
133
|
-
r = earth_radius(
|
|
132
|
+
def earth_volume(dist_unit: str = 'meters') -> float:
|
|
133
|
+
r = earth_radius(dist_unit)
|
|
134
134
|
return mul((4.0/3.0) * pi(), exp(r, 3))
|
|
135
135
|
|
|
136
|
-
def earth_circumference(
|
|
137
|
-
r = earth_radius(
|
|
136
|
+
def earth_circumference(dist_unit: str = 'meters') -> float:
|
|
137
|
+
r = earth_radius(dist_unit)
|
|
138
138
|
return mul(2 * pi(), r)
|
|
139
139
|
|
|
140
140
|
# =========================
|
|
141
141
|
# Radial toy + single-call wrapper
|
|
142
142
|
# =========================
|
|
143
|
-
def distance_per_sec_to_mps(v_per_sec: float,
|
|
143
|
+
def distance_per_sec_to_mps(v_per_sec: float, dist_unit: str) -> float:
|
|
144
144
|
"""Convert a speed given in `units`/s into m/s using your convert()."""
|
|
145
145
|
# v [units/s] * (meters per 1 units) => [m/s]
|
|
146
|
-
return mul(v_per_sec, get_distance_unit_conversions(_normalize_unit(
|
|
146
|
+
return mul(v_per_sec, get_distance_unit_conversions(_normalize_unit(dist_unit))["conv"]["meters"])
|
|
147
147
|
|
|
148
148
|
|
|
149
149
|
def get_body(planet: str) -> Dict[str, Any]:
|
|
@@ -21,32 +21,32 @@ TIME_CONVERSIONS = {
|
|
|
21
21
|
"days": DAYS,
|
|
22
22
|
}
|
|
23
23
|
ALL_TIME_UNITS = ("seconds", "minutes", "hours", "days")
|
|
24
|
-
|
|
25
|
-
def normalize_time_unit(
|
|
26
|
-
u =
|
|
24
|
+
DEFAULT_TIME_UNIT="s"
|
|
25
|
+
def normalize_time_unit(time_unit: str) -> str:
|
|
26
|
+
u = time_unit.strip().lower()
|
|
27
27
|
if u in TIME_CONVERSIONS:
|
|
28
28
|
return u
|
|
29
29
|
for key, values in TIME_CONVERSIONS.items():
|
|
30
30
|
if u in values.get("strings", []):
|
|
31
31
|
return key
|
|
32
|
-
raise ValueError(f"Unknown time unit '{
|
|
32
|
+
raise ValueError(f"Unknown time unit '{time_unit}'. Supported: {list(TIME_CONVERSIONS.keys())}")
|
|
33
33
|
|
|
34
|
-
def get_time_unit_conversions(
|
|
35
|
-
return TIME_CONVERSIONS[normalize_time_unit(
|
|
34
|
+
def get_time_unit_conversions(time_unit: str) -> dict:
|
|
35
|
+
return TIME_CONVERSIONS[normalize_time_unit(time_unit)]
|
|
36
36
|
|
|
37
|
-
def time_factor(
|
|
37
|
+
def time_factor(time_unit_from: str, time_unit_to: str) -> float:
|
|
38
38
|
"""
|
|
39
39
|
multiplicative factor s.t.
|
|
40
40
|
value_in_to = value_in_from * _time_factor(unit_from, unit_to)
|
|
41
41
|
|
|
42
42
|
seconds per 1 unit_from / seconds per 1 unit_to
|
|
43
43
|
"""
|
|
44
|
-
sf = get_time_unit_conversions(
|
|
45
|
-
st = get_time_unit_conversions(
|
|
44
|
+
sf = get_time_unit_conversions(time_unit_from)["conv"]["seconds"] # sec / unit_from
|
|
45
|
+
st = get_time_unit_conversions(time_unit_to)["conv"]["seconds"] # sec / unit_to
|
|
46
46
|
return sf / st
|
|
47
47
|
|
|
48
|
-
def convert_time(value: float,
|
|
49
|
-
return value * time_factor(
|
|
48
|
+
def convert_time(value: float, time_unit_from: str, time_unit_to: str) -> float:
|
|
49
|
+
return value * time_factor(time_unit_from, time_unit_to)
|
|
50
50
|
|
|
51
51
|
def seconds_per(unit: str) -> float:
|
|
52
52
|
"""Return seconds in one <unit> (unit aliases supported)."""
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# src/utils/escape_velocity.py
|
|
2
2
|
from ..imports import math, mul, div, add
|
|
3
3
|
from ..constants import (
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
DEFAULT_DIST_UNIT,
|
|
5
|
+
DEFAULT_TIME_UNIT,
|
|
6
6
|
DEFAULT_PLANET,
|
|
7
7
|
DEFAULT_START_ALTITUDE,
|
|
8
8
|
DEFAULT_AS_RADIUS
|
|
@@ -11,9 +11,9 @@ from ..constants.planet_constants import get_body,get_R_mu
|
|
|
11
11
|
from ..constants.distance_constants import dconvert,get_target_distance,get_normalized_distance
|
|
12
12
|
from ..constants.time_constants import get_time_unit_conversions, normalize_time_unit, seconds_per
|
|
13
13
|
from .velocity_utils import normalized_velocity_conversioin
|
|
14
|
-
def get_r_m(planet: str = DEFAULT_PLANET,start_altitude: float = DEFAULT_START_ALTITUDE,input_units: str =
|
|
14
|
+
def get_r_m(planet: str = DEFAULT_PLANET,start_altitude: float = DEFAULT_START_ALTITUDE,input_units: str = DEFAULT_DIST_UNIT,as_radius:bool = DEFAULT_AS_RADIUS):
|
|
15
15
|
R,mu = get_R_mu(planet=planet)
|
|
16
|
-
r_m = dconvert(start_altitude, input_units,
|
|
16
|
+
r_m = dconvert(start_altitude, input_units, DEFAULT_DIST_UNIT)
|
|
17
17
|
# Determine radius from center in meters
|
|
18
18
|
if not as_radius:
|
|
19
19
|
r_m = add(R, r_m)
|
|
@@ -23,7 +23,7 @@ def get_r_m(planet: str = DEFAULT_PLANET,start_altitude: float = DEFAULT_START_A
|
|
|
23
23
|
def get_vesc_mps(
|
|
24
24
|
planet: str = DEFAULT_PLANET,
|
|
25
25
|
start_altitude: float = DEFAULT_START_ALTITUDE,
|
|
26
|
-
|
|
26
|
+
input_dist_unit: str = DEFAULT_DIST_UNIT,
|
|
27
27
|
as_radius:bool = DEFAULT_AS_RADIUS
|
|
28
28
|
):
|
|
29
29
|
R,mu = get_R_mu(planet=planet)
|
|
@@ -36,35 +36,35 @@ def get_vesc_mps(
|
|
|
36
36
|
def get_normalized_starting_velocity(
|
|
37
37
|
start_altitude: float = None,
|
|
38
38
|
starting_velocity: float = None,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
input_dist_unit: str = DEFAULT_DIST_UNIT, # distance part of starting_velocity & start_distance
|
|
40
|
+
input_time_unit: str = DEFAULT_TIME_UNIT, # time part of starting_velocity
|
|
41
|
+
output_dist_unit: str = DEFAULT_DIST_UNIT,
|
|
42
|
+
output_time_unit: str = DEFAULT_TIME_UNIT,
|
|
43
43
|
planet: str = DEFAULT_PLANET
|
|
44
44
|
):
|
|
45
45
|
start_altitude = start_altitude or 0
|
|
46
46
|
if starting_velocity == None:
|
|
47
47
|
starting_velocity = escape_velocity_at(planet=planet,
|
|
48
48
|
start_altitude=start_altitude,
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
input_time_unit=input_time_unit,
|
|
50
|
+
input_dist_unit=input_dist_unit,
|
|
51
|
+
output_time_unit=output_time_unit,
|
|
52
|
+
output_dist_unit=output_dist_unit
|
|
53
53
|
)
|
|
54
54
|
return normalized_velocity_conversioin(
|
|
55
55
|
velocity=starting_velocity,
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
input_time_unit=input_time_unit,
|
|
57
|
+
input_dist_unit=input_dist_unit
|
|
58
58
|
)
|
|
59
59
|
|
|
60
60
|
def escape_velocity_at(
|
|
61
61
|
planet: str = DEFAULT_PLANET,
|
|
62
62
|
start_altitude: float = DEFAULT_START_ALTITUDE,
|
|
63
63
|
*,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
input_time_unit: str = DEFAULT_TIME_UNIT, # how to interpret `distance`
|
|
65
|
+
input_dist_unit: str = DEFAULT_DIST_UNIT, # how to interpret `distance`
|
|
66
|
+
output_dist_unit: str = DEFAULT_DIST_UNIT, # distance unit for the *speed*
|
|
67
|
+
output_time_unit: str = DEFAULT_TIME_UNIT, # time unit for the *speed*
|
|
68
68
|
as_radius: bool = DEFAULT_AS_RADIUS # False => `distance` is altitude above surface; True => radius from center
|
|
69
69
|
) -> dict:
|
|
70
70
|
"""
|
|
@@ -92,14 +92,23 @@ def escape_velocity_at(
|
|
|
92
92
|
return {"ok": False, "error": "distance must be a non-negative number"}
|
|
93
93
|
R,mu = get_R_mu(planet=planet)
|
|
94
94
|
# v_esc (m/s)
|
|
95
|
-
r_m = get_r_m(planet=planet,
|
|
96
|
-
|
|
95
|
+
r_m = get_r_m(planet=planet,
|
|
96
|
+
start_altitude=start_altitude,
|
|
97
|
+
input_dist_unit=input_dist_unit,
|
|
98
|
+
as_radius=as_radius
|
|
99
|
+
)
|
|
100
|
+
vesc_mps = get_vesc_mps(
|
|
101
|
+
planet=planet,
|
|
102
|
+
start_altitude=start_altitude,
|
|
103
|
+
input_dist_unit=input_dist_unit,
|
|
104
|
+
as_radius=as_radius
|
|
105
|
+
)
|
|
97
106
|
# Convert speed to <output_units>/<output_time>
|
|
98
|
-
vesc_units_per_time = dconvert(vesc_mps,
|
|
99
|
-
time_per = seconds_per(
|
|
107
|
+
vesc_units_per_time = dconvert(vesc_mps, DEFAULT_DIST_UNIT, output_dist_unit)
|
|
108
|
+
time_per = seconds_per(output_time_unit) # seconds per 1 output_time
|
|
100
109
|
vesc_out = mul(vesc_units_per_time, time_per) # <output_units>/<output_time>
|
|
101
110
|
# Also return the radius in output_units for convenience
|
|
102
|
-
r_out = dconvert(r_m,
|
|
111
|
+
r_out = dconvert(r_m, DEFAULT_DIST_UNIT, output_dist_unit)
|
|
103
112
|
|
|
104
113
|
return {
|
|
105
114
|
"ok": True,
|
|
@@ -107,5 +116,5 @@ def escape_velocity_at(
|
|
|
107
116
|
"radius_from_center": r_out,
|
|
108
117
|
"v_escape": vesc_out,
|
|
109
118
|
"v_escape_mps": vesc_mps,
|
|
110
|
-
"units": {"distance":
|
|
119
|
+
"units": {"distance": output_dist_unit, "time": output_time_unit}
|
|
111
120
|
}
|
|
@@ -2,51 +2,80 @@
|
|
|
2
2
|
from ..imports import *
|
|
3
3
|
from ..constants import *
|
|
4
4
|
|
|
5
|
-
def distance_per_time_to_mps(v: float,
|
|
5
|
+
def distance_per_time_to_mps(v: float, dist_unit: str, time_unit: str) -> float:
|
|
6
6
|
"""
|
|
7
|
-
Convert <v> in (<
|
|
7
|
+
Convert <v> in (<dist_unit>/<time_unit>) to m/s.
|
|
8
8
|
"""
|
|
9
9
|
# distance: unit -> meters
|
|
10
|
-
norm_dist_unit = normalize_distance_unit(
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
norm_dist_unit = normalize_distance_unit(
|
|
11
|
+
dist_unit
|
|
12
|
+
) # <-- was normalize_time_unit
|
|
13
|
+
meters_per_unit = get_distance_unit_conversions(
|
|
14
|
+
norm_dist_unit
|
|
15
|
+
)["conv"]["meters"]
|
|
16
|
+
v_meters_per_timeunit = mul(
|
|
17
|
+
v,
|
|
18
|
+
meters_per_unit
|
|
19
|
+
)
|
|
13
20
|
|
|
14
21
|
# time: timeunit -> seconds
|
|
15
|
-
sec_per_time = seconds_per(
|
|
16
|
-
|
|
22
|
+
sec_per_time = seconds_per(
|
|
23
|
+
time_unit
|
|
24
|
+
) # from time_constants.py
|
|
25
|
+
return div(
|
|
26
|
+
v_meters_per_timeunit,
|
|
27
|
+
sec_per_time
|
|
28
|
+
)
|
|
17
29
|
|
|
18
|
-
def mps_to_distance_per_time(v_mps: float,
|
|
30
|
+
def mps_to_distance_per_time(v_mps: float, dist_unit: str, time_unit: str) -> float:
|
|
19
31
|
"""
|
|
20
|
-
Convert m/s to <
|
|
32
|
+
Convert m/s to <dist_unit>/<time_unit>.
|
|
21
33
|
"""
|
|
22
|
-
norm_dist_unit = normalize_distance_unit(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
34
|
+
norm_dist_unit = normalize_distance_unit(
|
|
35
|
+
dist_unit
|
|
36
|
+
)
|
|
37
|
+
meters_per_unit = get_distance_unit_conversions(
|
|
38
|
+
norm_dist_unit
|
|
39
|
+
)["conv"]["meters"]
|
|
40
|
+
v_unit_per_sec = div(v_mps, meters_per_unit) # [dist_unit / s]
|
|
41
|
+
sec_per_time = seconds_per(
|
|
42
|
+
time_unit
|
|
43
|
+
)
|
|
44
|
+
return mul(
|
|
45
|
+
v_unit_per_sec,
|
|
46
|
+
sec_per_time
|
|
47
|
+
) # [dist_unit / time_unit]
|
|
27
48
|
|
|
28
49
|
|
|
29
50
|
|
|
30
51
|
|
|
31
52
|
def get_velocity_conversioin(
|
|
32
53
|
velocity,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
54
|
+
input_time_unit: str = DEFAULT_TIME_UNIT,
|
|
55
|
+
input_dist_unit: str = DEFAULT_DIST_UNIT,
|
|
56
|
+
output_dist_unit: str = DEFAULT_DIST_UNIT,
|
|
57
|
+
output_time_unit: str = DEFAULT_TIME_UNIT,
|
|
37
58
|
):
|
|
38
|
-
v0_mps = distance_per_time_to_mps(
|
|
39
|
-
|
|
59
|
+
v0_mps = distance_per_time_to_mps(
|
|
60
|
+
v=velocity,
|
|
61
|
+
dist_unit=input_dist_unit,
|
|
62
|
+
time_unit=input_time_unit
|
|
63
|
+
)
|
|
64
|
+
v0_unit_p_time = mps_to_distance_per_time(
|
|
65
|
+
v_mps=v0_mps,
|
|
66
|
+
dist_unit=output_dist_unit,
|
|
67
|
+
time_unit=output_time_unit
|
|
68
|
+
)
|
|
40
69
|
return v0_unit_p_time
|
|
41
70
|
|
|
42
71
|
def normalized_velocity_conversioin(
|
|
43
72
|
velocity,
|
|
44
|
-
|
|
45
|
-
|
|
73
|
+
input_time_unit: str = DEFAULT_TIME_UNIT,
|
|
74
|
+
input_dist_unit: str = DEFAULT_DIST_UNIT
|
|
46
75
|
):
|
|
47
76
|
v0_mps = get_velocity_conversioin(
|
|
48
77
|
velocity=velocity,
|
|
49
|
-
|
|
50
|
-
|
|
78
|
+
input_time_unit=input_time_unit,
|
|
79
|
+
input_dist_unit=input_dist_unit
|
|
51
80
|
)
|
|
52
81
|
return v0_mps
|
|
@@ -6,18 +6,18 @@ abstract_math/flask_scripts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMp
|
|
|
6
6
|
abstract_math/flask_scripts/flask_utils.py,sha256=bXF4PS1qJ1SDA2w6ecNHK1A3FmN4P-F2U6l6wPwhZgE,28511
|
|
7
7
|
abstract_math/solar_math/__init__.py,sha256=FfPkmWi3cQ3BLvUUUf6k22rGBE8scDL1EoM5l24biVo,39
|
|
8
8
|
abstract_math/solar_math/flask_utils.py,sha256=c82LrZ0dKC3Y8LxqOs1zDR6gRy8oXSx9balBD18gNB0,459
|
|
9
|
-
abstract_math/solar_math/main.py,sha256=
|
|
9
|
+
abstract_math/solar_math/main.py,sha256=7YYjAduPpt8oDxxr1rEJeC6LHQx49o8cfrui4O0Qc8g,9849
|
|
10
10
|
abstract_math/solar_math/src/__init__.py,sha256=qeal73F-NLu6sO_YSmD_komVpe17f0OFy2IfBR2QU_s,70
|
|
11
11
|
abstract_math/solar_math/src/imports.py,sha256=aiFyZLsoVwkGopAL0uLaIPordUizM7UT9shwShmf0f0,195
|
|
12
|
-
abstract_math/solar_math/src/constants/__init__.py,sha256=
|
|
13
|
-
abstract_math/solar_math/src/constants/distance_constants.py,sha256=
|
|
14
|
-
abstract_math/solar_math/src/constants/planet_constants.py,sha256=
|
|
15
|
-
abstract_math/solar_math/src/constants/time_constants.py,sha256=
|
|
12
|
+
abstract_math/solar_math/src/constants/__init__.py,sha256=VSo386-vGfJirycDGRGmLrjmi8GLXXW0kXJr2E7ZAnI,810
|
|
13
|
+
abstract_math/solar_math/src/constants/distance_constants.py,sha256=pqFgSB0WrIlmv0xhhy1biVjBTMXzxO3RsiKYes4bLT4,2893
|
|
14
|
+
abstract_math/solar_math/src/constants/planet_constants.py,sha256=XqdvEjoMuSv-3dCMwWNf9CE-6zFqWfvn_9WKvKE_NS4,6964
|
|
15
|
+
abstract_math/solar_math/src/constants/time_constants.py,sha256=9_7gCR3swAjyUwFNLja1keRxTYx4kzF39TB9Vwav_PM,1960
|
|
16
16
|
abstract_math/solar_math/src/utils/__init__.py,sha256=Vb2bfx1p9YSmhnbqXBjGVPt1OQZ9I7PG_fMQdFqj-3k,91
|
|
17
|
-
abstract_math/solar_math/src/utils/escape_velocity.py,sha256=
|
|
17
|
+
abstract_math/solar_math/src/utils/escape_velocity.py,sha256=rZkwf6gaBpciCmxUKnzLGXfI5P9JRkFSLyCvXNcsLtk,5245
|
|
18
18
|
abstract_math/solar_math/src/utils/geometry_utils.py,sha256=Ij4mASNFp2-CWy425fxMTEuMPuAZHs-E0qvi3BjaNkk,4169
|
|
19
|
-
abstract_math/solar_math/src/utils/velocity_utils.py,sha256=
|
|
20
|
-
abstract_math-0.0.0.
|
|
21
|
-
abstract_math-0.0.0.
|
|
22
|
-
abstract_math-0.0.0.
|
|
23
|
-
abstract_math-0.0.0.
|
|
19
|
+
abstract_math/solar_math/src/utils/velocity_utils.py,sha256=se1RiyLN3uhJwXy42_6JFidbDECWB_sVzt8F6HXK0x0,2211
|
|
20
|
+
abstract_math-0.0.0.32.dist-info/METADATA,sha256=LyysVhRcqa3QM-7mdbJs4WeZqmjW1AzV1Vg3fyBiTz4,3081
|
|
21
|
+
abstract_math-0.0.0.32.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
22
|
+
abstract_math-0.0.0.32.dist-info/top_level.txt,sha256=b7jOgD9c0U-CGH-l7yxhMPukzD40kMEQkQRV_sGyVfE,14
|
|
23
|
+
abstract_math-0.0.0.32.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|