Files
RadioPropagationApi/api/app/services/vegetation.py
T
2026-06-23 13:14:27 +03:00

40 lines
1.1 KiB
Python

from __future__ import annotations
from pathlib import Path
from app.config import get_settings
from app.core.geo import PathPoint
from app.core.landcover import LandcoverNotConfiguredError, landcover_path
from app.core.vegetation import P833Coefficients, p833_attenuation
def vegetation_loss_along(
points: list[PathPoint],
freq_hz: float,
include_vegetation: bool,
landcover_path_dir: str | Path | None = None,
canopy_path_dir: str | Path | None = None,
) -> float:
if not include_vegetation:
return 0.0
settings = get_settings()
landcover_dir = landcover_path_dir or settings.landcover_path
canopy_dir = canopy_path_dir or settings.canopy_path
try:
path = landcover_path(points, landcover_dir, canopy_dir)
except LandcoverNotConfiguredError:
return 0.0
coefficients = P833Coefficients(
gamma_db_per_m=settings.p833_gamma_db_per_m,
max_attenuation_db=settings.p833_max_attenuation_db,
)
return p833_attenuation(
depth_m=path.vegetation_depth_m,
freq_hz=freq_hz,
forest_type="unknown",
coefficients=coefficients,
)