Files
Aislo/resources/tester/test_344_1_terrain_grid_route.py
eomsangdonandClaude Opus 5.5 11c75f022a refactor(767-1): 안 쓰는 지면 필터 · 서피스 지움 — 필터 넷(CSF · 격자 최저 · PMF · RANSAC) · 표현 셋(TIN + Taubin 평활 · NURBS · meshfree) · 수치지형도 비교 방식 다섯 · 안 부르는 길 정리
- 필터 = 업체 분류 · 점진 TIN · 둘의 다듬기 판만 · 분석 허용 목록 = Ground 등록부(available_filters) 한 벌
- 표현 = DTM · implicit 만 · 평활 = DTM 만 · config 기본 목록 · PRECOMPUTE · 설정 사전 맞춤(설정 지문 바뀜 — 768 에서 다시 지음)
- 등고선 = 격자 · 굳힌 격자만(삼각망 굽기 · 외곽 맞춤 · implicit RBF 폴백 걷음) · 표본기 · 경로 찾기 tin · nurbs · meshfree 갈래 걷음
- 수치지형도 = 라플라스만(TIN 둘 · TPS · ANUDEM형 · 다중해상도 걷음) · B04 단추 하나
- 안 부르는 길 — B04 JSON 점군 GET · ground-stats GET + TS · B07 옛 계획평면도(라이다) 짓기 · lidar_source · LIDAR_ID · plan_lidar 종류 이름 · SOURCE_FILTER_LABELS · MODEL_METHODS(py) · MESH_* 설정
- 옛 manifest 의 지운 갈래 줄은 DB 로 되살리지 않음 · 옛 csf 행은 미리보기 · 등고선 그대로 열림 · 지운 이름 요청 = 400
- 낡은 글 — Ground · Pipeline 머리 · WF1 「없으면 csf」 · B07 음영 기본 「csf」 → 빈 값 · 등고선 폴백 「csf」 → 404 · B04 3D 보기 처음값 · B05 Schema · B06 Prebuild · 씨닝 설명
- 시험 지움 2 — test_b04_contour_raster · test_b04_contour_equivalence(지운 삼각망 굽기 · 없는 프로젝트를 봐 건너뛰던 것)
- 시험 덜어냄 — test_b04_ground_filters CSF · 격자 최저 네 경우(지운 필터)
- 시험 고침 — 허용 목록 · 형 검사에 걸린 csf · tin · grid_min_z · meshfree · tin_sheet 견본을 ptd · implicit · laplace 로(54_22 · 238_1 · 443 · 342_2 · 346_3 · 351_1 · 442_2 · 271 + helper · 344_1 · 133_1 · 343_2 · 637 · 754_1 · 763_1 깨진 tin → 깨진 implicit · 763_3 · b05 둘 · b06 · sheet_surface TIN(도엽선) 경우 지움) · 이름만 바꿈(273_2 · 343_1 · 343_3 · 624_1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 16:35:12 +09:00

172 lines
6.1 KiB
Python

"""PLAN 344-1 — 격자 통로(`/surface/models/{mid}/grid`) · 받을 자리(`terrain-sources` 의 `grid`).
DTM 만 격자 · 평활 고르기 = 서버 표본기 · 첫 요청 때 `.bin` 저장본 · ETag 304 · DTM 아닌 표현 404 ·
주소 서명 = manifest 구성 · 평활 서명.
"""
from __future__ import annotations
import asyncio
import json
from contextlib import asynccontextmanager
from pathlib import Path
import numpy as np
from starlette.requests import Request
from B05_Profile import B05_Profile_Router_Terrain as terrain_router
from common_util.common_util_surface_sampler import dtm_grid_bytes
PID = "1bb0f876-983f-4ca5-9cc7-f59ee1f77e0a"
PARAMS = {"source_filter": "ptd", "method": "dtm", "smooth": True, "contour_interval_m": 1.0}
def _dtm(path: Path, z: float) -> None:
x = np.arange(0.0, 11.0, dtype=np.float32)
np.savez(
path,
x=x,
y=x,
z=np.full((11, 11), z, dtype=np.float32),
valid_mask=np.ones((11, 11), dtype=bool),
)
def _project(tmp_path: Path) -> Path:
models = tmp_path / "B04_PreProcess" / "models"
models.mkdir(parents=True)
_dtm(models / "dtm_ptd.npz", 100.0)
_dtm(models / "dtm_ptd_smooth.npz", 101.0)
manifest = {
"config_signature": "cfg1",
"source_filters": {"ptd": {"methods": {"dtm": {"smooth": {"smoothing_signature": "sm1"}}}}},
}
(models / "manifest.json").write_text(json.dumps(manifest), encoding="utf-8")
return tmp_path
def _patch(monkeypatch, root: Path, row: tuple | None) -> None:
class _Cursor:
async def execute(self, *_args):
return None
async def fetchone(self):
return row
class _Connection:
@asynccontextmanager
async def cursor(self):
yield _Cursor()
class _Pool:
@asynccontextmanager
async def acquire(self):
yield _Connection()
async def stored(_connection, _project_id):
return "x"
monkeypatch.setattr(terrain_router, "get_db_pool", lambda: _Pool())
monkeypatch.setattr(terrain_router, "get_project_storage_relative_path", stored)
monkeypatch.setattr(terrain_router, "resolve_stored_project_path", lambda _s: root)
def _request(etag: str | None = None) -> Request:
headers = [(b"if-none-match", etag.encode())] if etag else []
return Request({"type": "http", "method": "GET", "path": "/", "headers": headers})
def _grid(smooth: bool, etag: str | None = None):
return asyncio.run(terrain_router.read_surface_grid(_request(etag), PID, 7, smooth))
def test_평활_격자를_저장본으로_내고_같은_ETag_면_304(tmp_path, monkeypatch):
root = _project(tmp_path)
models = root / "B04_PreProcess" / "models"
_patch(monkeypatch, root, ("dtm", "B04_PreProcess/models/dtm_ptd.npz"))
response = _grid(True)
assert response.status_code == 200
saved = models / "dtm_ptd_smooth_grid.bin"
assert Path(response.path) == saved
assert saved.read_bytes() == dtm_grid_bytes(models / "dtm_ptd_smooth.npz")
assert _grid(True, response.headers["etag"]).status_code == 304
assert Path(_grid(False).path).name == "dtm_ptd_grid.bin"
def test_DTM_아닌_표현은_404(tmp_path, monkeypatch):
root = _project(tmp_path)
_patch(monkeypatch, root, ("implicit", "B04_PreProcess/models/implicit_ptd.npz"))
assert _grid(True).status_code == 404
_patch(monkeypatch, root, None)
assert _grid(True).status_code == 404
def test_받을_자리_서명은_manifest_구성과_평활(tmp_path):
models = _project(tmp_path) / "B04_PreProcess" / "models"
confirmed = (7, "dtm", "B04_PreProcess/models/dtm_ptd.npz")
grid = terrain_router._design_grid(PARAMS, models, confirmed)
assert grid == {"model_id": 7, "smooth": True, "signature": "cfg1.sm1"}
raw = terrain_router._design_grid({**PARAMS, "smooth": False}, models, confirmed)
assert raw["signature"] == "cfg1."
# 서버 표본기와 다른 파일 · DTM 아닌 표현 · 확정 없음 = 격자 안 냄(서버 표본 길)
assert (
terrain_router._design_grid(
{**PARAMS, "source_filter": "classification"}, models, confirmed
)
is None
)
assert terrain_router._design_grid({**PARAMS, "method": "implicit"}, models, confirmed) is None
assert terrain_router._design_grid(PARAMS, models, None) is None
def test_지반고_자릿수_기본_3_묶음은_6(tmp_path, monkeypatch):
root = tmp_path
models = root / "B04_PreProcess" / "models"
models.mkdir(parents=True)
x = np.arange(0.0, 11.0)
np.savez(
models / "dtm_ptd_smooth.npz",
x=x,
y=x,
z=np.add.outer(x * 0.0, x * 0.1234567),
valid_mask=np.ones((11, 11), dtype=bool),
)
_patch(monkeypatch, root, None)
async def params(_connection, _project_id):
return dict(PARAMS)
monkeypatch.setattr(terrain_router, "get_surface_confirmation_params", params)
ask = terrain_router.ElevationRequest
plain = asyncio.run(terrain_router.read_route_elevations(PID, ask(points=[(5.5, 5.0)])))
fine = asyncio.run(
terrain_router.read_route_elevations(PID, ask(points=[(5.5, 5.0)], decimals=6))
)
assert plain["z"] == [round(5.5 * 0.1234567, 3)]
assert fine["z"] == [round(5.5 * 0.1234567, 6)]
def test_격자_모델은_params_파일_확정_행이_어긋나도(monkeypatch):
"""578-1 — 확정 행(sheet)이 params(ptd)와 어긋나도 서버 표본기와 같은 `dtm_{filter}.npz` 행을 고름."""
rows = [
(9, "dtm", "B04_PreProcess/models/dtm_sheet_laplace.npz"), # 확정(어긋남)
(7, "dtm", "B04_PreProcess/models/dtm_ptd.npz"),
]
class _Cursor:
async def execute(self, *_args):
return None
async def fetchall(self):
return rows
class _Connection:
@asynccontextmanager
async def cursor(self):
yield _Cursor()
pick = asyncio.run(terrain_router._design_model(_Connection(), PID, PARAMS))
assert pick == (7, "dtm", "B04_PreProcess/models/dtm_ptd.npz")
other = {**PARAMS, "source_filter": "classification"}
assert asyncio.run(terrain_router._design_model(_Connection(), PID, other)) is None