Spaces:
Build error
Build error
File size: 2,413 Bytes
4fa8bcb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# config.py
from typing import List
from video_sequencer.simulate_physics import PhysicsSimulator
import os
# --- Input Normalization Configs ---
physics_input_configs = {
"projectile_motion": {
"fields": ["initial_velocity", "angle", "gravity"],
"normalize": lambda v0, a, g: [
v0 / 20.0,
a / 90.0,
g / 20.0
],
"denormalize": lambda x: (
x[0] * 20.0,
x[1] * 90.0,
x[2] * 20.0
)
},
"ball_motion": {
"fields": ["mass", "angle", "friction"],
"normalize": lambda m, a, f: [
m / 5.0,
(a - 10.0) / 35.0,
(f - 0.05) / 0.45
],
"denormalize": lambda x: (
x[0] * 5.0,
x[1] * 35.0 + 10.0,
x[2] * 0.45 + 0.05
)
}
}
# --- Shared Accessor Functions ---
def get_physics_types() -> List[str]:
return list(physics_input_configs.keys())
def normalize_input(physics_type: str, *inputs: float) -> List[float]:
if physics_type not in physics_input_configs:
raise ValueError(f"Unsupported physics type: {physics_type}")
return physics_input_configs[physics_type]["normalize"](*inputs)
def denormalize_input(physics_type: str, inputs: List[float]) -> List[float]:
if physics_type not in physics_input_configs:
raise ValueError(f"Unsupported physics type: {physics_type}")
return physics_input_configs[physics_type]["denormalize"](inputs)
def get_input_fields(physics_type: str) -> List[str]:
if physics_type not in physics_input_configs:
raise ValueError(f"Unsupported physics type: {physics_type}")
return physics_input_configs[physics_type]["fields"]
def get_simulation_fn(physics_type):
sim = PhysicsSimulator()
return {
"ball_motion": sim.simulate_ball_motion,
"projectile_motion": sim.simulate_projectile_motion
}.get(physics_type)
def get_param_ranges(physics_type):
if physics_type == "ball_motion":
return {
"mass": (0.5, 5.0),
"angle": (10.0, 45.0),
"friction": (0.05, 0.5),
}
elif physics_type == "projectile_motion":
return {
"initial_velocity": (25.0, 50.0),
"angle": (45.0, 75.0),
"gravity": (9.5, 10.5),
}
else:
raise ValueError(f"Unknown physics type: {physics_type}") |