added covarage
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.config import get_settings
|
||||
from app.core.atmosphere import atmospheric_loss_between
|
||||
from app.core.diffraction import deygout
|
||||
from app.core.fresnel import LosSample, los_analysis
|
||||
from app.core.geo import GeoPoint, sample_path
|
||||
from app.core.propagation import manual_link_budget
|
||||
from app.core.propagation import itm_loss, manual_link_budget, p452_loss
|
||||
from app.core.raster_sampling import raster_files
|
||||
from app.models.common import DataSources
|
||||
from app.models.link import LinkBudgetRequest, LinkBudgetResponse
|
||||
@@ -14,19 +15,18 @@ from app.services.vegetation import vegetation_loss_along
|
||||
|
||||
|
||||
def link_budget(request: LinkBudgetRequest, db: Session | None = None) -> LinkBudgetResponse:
|
||||
if request.model != "manual":
|
||||
raise NotImplementedError(f"{request.model} link model is implemented in a later stage")
|
||||
|
||||
tx = GeoPoint(lat=request.tx.lat, lon=request.tx.lon)
|
||||
rx = GeoPoint(lat=request.rx.lat, lon=request.rx.lon)
|
||||
points = sample_path(tx, rx, 256)
|
||||
freq_hz = request.frequency_mhz * 1_000_000
|
||||
settings = get_settings()
|
||||
surface_profile = surface_profile_from_points(
|
||||
points,
|
||||
include_buildings=request.include_buildings,
|
||||
include_canopy=False,
|
||||
include_canopy=request.include_canopy,
|
||||
db=db,
|
||||
)
|
||||
elevation_profile = [sample.ground_m for sample in surface_profile.samples]
|
||||
los_result = los_analysis(
|
||||
surface_profile,
|
||||
tx_height_agl=request.tx.height_agl,
|
||||
@@ -45,6 +45,55 @@ def link_budget(request: LinkBudgetRequest, db: Session | None = None) -> LinkBu
|
||||
freq_hz=freq_hz,
|
||||
include_vegetation=request.include_vegetation,
|
||||
)
|
||||
atmospheric_db = atmospheric_loss_between(tx, rx, freq_hz)
|
||||
|
||||
if request.model == "manual":
|
||||
propagation_db = 0.0
|
||||
elif request.model == "itm":
|
||||
propagation_db = (
|
||||
itm_loss(
|
||||
tx,
|
||||
rx,
|
||||
tx_height_agl=request.tx.height_agl,
|
||||
rx_height_agl=request.rx.height_agl,
|
||||
freq_mhz=request.frequency_mhz,
|
||||
elevation_profile_m=elevation_profile,
|
||||
dem_path=str(settings.dem_path),
|
||||
)
|
||||
- manual_link_budget(
|
||||
tx,
|
||||
rx,
|
||||
request.tx.power_dbm,
|
||||
request.tx.gain_dbi,
|
||||
request.rx.gain_dbi,
|
||||
request.rx.sensitivity_dbm,
|
||||
request.frequency_mhz,
|
||||
).fspl_db
|
||||
)
|
||||
elif request.model == "p452":
|
||||
propagation_db = (
|
||||
p452_loss(
|
||||
tx,
|
||||
rx,
|
||||
tx_height_agl=request.tx.height_agl,
|
||||
rx_height_agl=request.rx.height_agl,
|
||||
freq_mhz=request.frequency_mhz,
|
||||
elevation_profile_m=elevation_profile,
|
||||
dem_path=str(settings.dem_path),
|
||||
)
|
||||
- manual_link_budget(
|
||||
tx,
|
||||
rx,
|
||||
request.tx.power_dbm,
|
||||
request.tx.gain_dbi,
|
||||
request.rx.gain_dbi,
|
||||
request.rx.sensitivity_dbm,
|
||||
request.frequency_mhz,
|
||||
).fspl_db
|
||||
)
|
||||
else:
|
||||
raise NotImplementedError(f"{request.model} link model is not supported")
|
||||
|
||||
budget = manual_link_budget(
|
||||
tx=tx,
|
||||
rx=rx,
|
||||
@@ -53,11 +102,11 @@ def link_budget(request: LinkBudgetRequest, db: Session | None = None) -> LinkBu
|
||||
rx_gain_dbi=request.rx.gain_dbi,
|
||||
sensitivity_dbm=request.rx.sensitivity_dbm,
|
||||
frequency_mhz=request.frequency_mhz,
|
||||
diffraction_db=diffraction_db,
|
||||
diffraction_db=diffraction_db + propagation_db,
|
||||
vegetation_db=vegetation_db,
|
||||
atmospheric_db=atmospheric_db,
|
||||
fresnel_clear=los_result.los_clear,
|
||||
)
|
||||
settings = get_settings()
|
||||
geometric_obstructions = [
|
||||
sample for sample in los_result.obstructions if sample.clearance_m < 0
|
||||
]
|
||||
@@ -81,7 +130,7 @@ def link_budget(request: LinkBudgetRequest, db: Session | None = None) -> LinkBu
|
||||
buildings=request.include_buildings and db is not None,
|
||||
landcover=request.include_vegetation
|
||||
and bool(raster_files(settings.landcover_path)),
|
||||
canopy=False,
|
||||
canopy=request.include_canopy and bool(raster_files(settings.canopy_path)),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user