Download tests/test_obstacles.py from kimjunhan/vkgs-sim: direct link, hf CLI and curl.
- Browser
- Download file 2.85 kB
-
https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/tests/test_obstacles.py
- Command line
-
hf download hf://kimjunhan/vkgs-sim/tests/test_obstacles.py
-
curl -L -o test_obstacles.py https://huggingface.co/kimjunhan/vkgs-sim/resolve/main/tests/test_obstacles.py
2.85 kB
| import numpy as np | |
| from nusim.sim.obstacles import RES, obstacle_grid | |
| def _cell(grid, x0, y0, x, y): | |
| return grid[int((y - y0) / RES), int((x - x0) / RES)] | |
| def test_wall_blocks_but_curb_and_canopy_do_not(): | |
| rng = np.random.default_rng(0) | |
| ground = np.c_[rng.uniform(-20, 20, (40000, 2)), rng.normal(0.0, 0.01, 40000)] | |
| # ๋ฒฝ: x = 5 m, ๋์ด 0~3 m | |
| wall = np.c_[np.full(3000, 5.05), rng.uniform(-3, 3, 3000), rng.uniform(0, 3, 3000)] | |
| # ์ฐ์: x = -5 m, ๋์ด 0.15 m โ ์ฐจ์ฒด์ ๊ฑธ๋ฆฌ์ง ์๋๋ค (์ฃผํ๊ฐ๋ฅ์์ญ ๊ฒฝ๊ณ๊ฐ ๋ฐ๋ก ๋งก๋๋ค) | |
| curb = np.c_[np.full(3000, -5.05), rng.uniform(-3, 3, 3000), np.full(3000, 0.15)] | |
| # ๊ฐ๋ก์ ์๊ด: ๋์ด 4 m โ ์ฐจ๊ฐ ๋ฐ์ผ๋ก ์ง๋๊ฐ๋ค | |
| canopy = np.c_[rng.uniform(-1, 1, (3000, 2)) + [0, 10], np.full(3000, 4.0)] | |
| # ์ธํจ์ด ์ก์ ์ ๋ฌด๋๊ธฐ ํ ์นธ | |
| noise = np.tile([[12.05, 12.05, 1.0]], (10, 1)) | |
| grid, x0, y0 = obstacle_grid(np.vstack([ground, wall, curb, canopy, noise]), np.zeros(2), 20.0) | |
| assert _cell(grid, x0, y0, 5.05, 0.0) == 255 | |
| assert _cell(grid, x0, y0, -5.05, 0.0) == 0 | |
| assert _cell(grid, x0, y0, 0.0, 10.0) == 0 | |
| assert _cell(grid, x0, y0, 12.05, 12.05) == 0 # ์ด์ ์๋ ์นธ์ ์ง์ด๋ค | |
| assert _cell(grid, x0, y0, 0.0, 0.0) == 0 | |
| def test_ground_follows_slope(): | |
| """๋นํ(๊ฒฝ์ฌ 10%)์์๋ ๋ ธ๋ฉด์ด ์ฅ์ ๋ฌผ์ด ๋์ง ์๋๋ค โ ์ง๋ฉด ๋์ด๋ฅผ ์นธ๋ง๋ค ์ฐ๋ค.""" | |
| rng = np.random.default_rng(1) | |
| xy = rng.uniform(-20, 20, (60000, 2)) | |
| pts = np.c_[xy, 0.1 * xy[:, 0]] | |
| grid, _, _ = obstacle_grid(pts, np.zeros(2), 20.0) | |
| assert grid.sum() == 0 | |
| def test_smeared_road_and_canopy_not_obstacle(): | |
| """๊ธด ์ฌ: ๋จผ sweep ์ ๋ ธ๋ฉด ์ ์ด ์๋๋ก ๋ฒ์ง๊ณ (์ง๋ฉด์ด ๋ฎ๊ฒ ์กํ๋ ๋ฌธ์ ), ๋ ธ๋ฉด ์๋ก ๊ฐ๋ก์ ์๊ด์ด ๋๋ฆฌ์ด๋ค | |
| (๊ฐ์ฅ ๋์ ์ ๊ธฐ์ค์ด๋ฉด '์์ ๊ตฌ์กฐ๋ฌผ' ๋ก ๋จ๋ ๋ฌธ์ ) โ scene-0402, 2026-10-09.""" | |
| from nusim.sim.obstacles import TALL_BAND | |
| rng = np.random.default_rng(0) | |
| n = 200_000 | |
| xy = rng.uniform(-10, 10, (n, 2)) | |
| z = np.where(rng.random(n) < 0.7, rng.normal(-0.2, 0.01, n), rng.uniform(-0.65, -0.2, n)) # ๋ ธ๋ฉด + ์๋ ๋ฒ์ง 30% | |
| road = np.c_[xy, z] | |
| canopy = np.c_[rng.uniform(-5, 5, (20_000, 2)), rng.uniform(6, 15, 20_000)] | |
| pole = np.c_[rng.normal(7, 0.03, (3000, 2)), rng.uniform(-0.2, 6, 3000)] | |
| grid, x0, y0, tall = obstacle_grid(np.vstack([road, canopy, pole]), np.zeros(2), 12.0, with_top=True) | |
| ix = lambda v: int((v - x0) / 0.2) | |
| assert grid[ix(-8):ix(5), ix(-8):ix(5)].sum() == 0 # ๋ ธ๋ฉด์ ๋น์ด ์๋ค | |
| assert not tall[ix(-4):ix(4), ix(-4):ix(4)].any() # ์๊ด ์๋๋ '์์ ๊ตฌ์กฐ๋ฌผ' ์ด ์๋๋ค | |
| assert grid[ix(7), ix(7)] and tall[ix(7), ix(7)] # ๊ธฐ๋ฅ์ ์ฅ์ ๋ฌผ์ด๊ณ ๋ ธ๋ฉด์์๋ ๋จ๋๋ค | |
| assert TALL_BAND[1] <= 3.0 | |