Skip to content

Commit

Permalink
Fixed the signal strength data map to (1) warn the user about the
Browse files Browse the repository at this point in the history
bounding box limitation and (2) gracefully handle invalid distance
errors from the propagation model.
  • Loading branch information
kate-harrison committed Oct 12, 2014
1 parent f5f31ae commit 5b528c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
22 changes: 17 additions & 5 deletions west/data_map_signal_strength.py
@@ -1,4 +1,5 @@
from data_map import DataMap2D
from propagation_model import InvalidDistanceError
from abc import abstractmethod
from geopy.distance import vincenty

Expand Down Expand Up @@ -44,6 +45,13 @@ def add_tv_stations(self, list_of_tv_stations, pathloss_function,
pl_function = lambda *args, **kwargs: pm.get_pathloss_coefficient(*args, curve_enum=PropagationCurve.curve_50_90, **kwargs)
my_signal_map.add_tv_stations(my_tv_stations, pathloss_function=pl_function)
.. warning:: the signal strength will not be calculated outside the \
station's bounding box in order to save on computations.
.. warning:: any InvalidDistanceErrors from the propagation model will \
be ignored and the signal strength at that location (for that station) \
will be zero.
:param list_of_tv_stations: list of \
:class:`protected_entity_tv_station.ProtectedEntityTvStation` objects
:param pathloss_function: the pathloss function to be used when \
Expand Down Expand Up @@ -80,11 +88,15 @@ def _get_station_signal_strength(self, location, tv_station,
tv_location = tv_station.get_location()
distance_km = vincenty(tv_location, location).kilometers
freq = tv_station.get_center_frequency()
pathloss = pathloss_function(distance_km, frequency=freq,
tx_height=tv_station.get_haat_meters(),
rx_height=None, tx_location=tv_location,
rx_location=location)
# TODO: account for rx height?
try:
pathloss = pathloss_function(distance_km, frequency=freq,
tx_height=tv_station.get_haat_meters(),
rx_height=None,
tx_location=tv_location,
rx_location=location)
# TODO: account for rx height?
except InvalidDistanceError:
return 0

return tv_station.get_erp_watts() * pathloss

Expand Down
5 changes: 5 additions & 0 deletions west/propagation_model.py
@@ -1,6 +1,11 @@
from abc import ABCMeta, abstractmethod
from custom_logging import getModuleLogger


class InvalidDistanceError(ValueError):
pass


class PropagationCurve(object):
"""
This class is a poor-man's enum because Python 2 does not support the Enum class.
Expand Down
8 changes: 6 additions & 2 deletions west/propagation_model_fcurves.py
@@ -1,11 +1,10 @@
from propagation_model import PropagationModel, PropagationCurve
from propagation_model import PropagationModel, PropagationCurve, InvalidDistanceError
from configuration import package_directory
from ctypes import *
import os.path
from math import log10



class PropagationModelFcurves(PropagationModel):
"""The FCC's F-curves model.
Expand Down Expand Up @@ -192,6 +191,7 @@ def _initialize_error_codes(self):
"A9": "INVALID 'DISTANCE' VALUE FOR SWITCH = 1.",
" ": None
}
self._invalid_distance_errors = ["A2"]

self._warning_codes = {
"A1": "FREE SPACE EQUATION USED TO FIND REQUESTED ARGUMENT.",
Expand All @@ -216,6 +216,10 @@ def _raise_warning_or_error_if_flag_set(self, flag):


if flag in self._error_codes:
if flag in self._invalid_distance_errors:
raise InvalidDistanceError("Invalid distance for propagation "
"model %r" % self)

error_message = self._error_codes[flag]

if error_message is None:
Expand Down

0 comments on commit 5b528c1

Please sign in to comment.