Skip to content

Commit

Permalink
Remove expected warnings (#60)
Browse files Browse the repository at this point in the history
* Remove references to np.int and np.float
* Ignore numpy divide by zero errors
* Ignore warning for invalid values in sqrt computing gamma0_approx
* Use None to not limit the column width in pandas
* Remove use of np.power as it doesn't allow for fractional powers
* Catch warnings when testing ITU-676 at low elevation angles
  • Loading branch information
inigodelportillo authored Aug 17, 2021
1 parent d90d2db commit f755a24
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 80 deletions.
3 changes: 3 additions & 0 deletions itur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@

from .__version__ import __version__

# Ignore divide by zero errors
np.seterr(divide='ignore')

AUTHORS = "Inigo del Portillo"


Expand Down
4 changes: 2 additions & 2 deletions itur/models/itu1853.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ def rain_attenuation_synthesis(
# the probability the attenuation Ai (dB) is exceeded where Pi < P_K
p_i = np.array([0.01, 0.02, 0.03, 0.05,
0.1, 0.2, 0.3, 0.5, 1, 2, 3, 5, 10])
Pi = np.array([p for p in p_i if p < P_rain * 100], dtype=np.float)
Ai = np.array([0 for p in p_i if p < P_rain * 100], dtype=np.float)
Pi = np.array([p for p in p_i if p < P_rain * 100], dtype=float)
Ai = np.array([0 for p in p_i if p < P_rain * 100], dtype=float)

for i, p in enumerate(Pi):
Ai[i] = rain_attenuation(lat, lon, f, el, hs, p, tau=tau).value
Expand Down
4 changes: 2 additions & 2 deletions itur/models/itu618.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ def fit_rain_attenuation_to_lognormal(self, lat, lon, f, el, hs, P_k, tau):
# the probability the attenuation Ai (dB) is exceeded where Pi < P_K
p_i = np.array([0.01, 0.02, 0.03, 0.05,
0.1, 0.2, 0.3, 0.5, 1, 2, 3, 5, 10])
Pi = np.array([p for p in p_i if p < P_k], dtype=np.float)
Ai = np.array([0 for p in p_i if p < P_k], dtype=np.float)
Pi = np.array([p for p in p_i if p < P_k], dtype=float)
Ai = np.array([0 for p in p_i if p < P_k], dtype=float)

for i, p in enumerate(Pi):
Ai[i] = self.rain_attenuation(lat, lon, f, el, hs, p, tau=tau)
Expand Down
35 changes: 19 additions & 16 deletions itur/models/itu676.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,15 @@ def gammaw_approx(self, f, p, rho, t):
# Abstract method to compute the specific attenuation due to water
# vapour
fcn = np.vectorize(self.instance.gammaw_approx)
return fcn(f, p, rho, t)
with np.errstate(invalid='ignore'):
return fcn(f, p, rho, t)

def gamma0_approx(self, f, p, rho, t):
# Abstract method to compute the specific attenuation due to dry
# atmoshere
fcn = np.vectorize(self.instance.gamma0_approx)
return fcn(f, p, rho, t)
with np.errstate(invalid='ignore'):
return fcn(f, p, rho, t)


class _ITU676_12_():
Expand Down Expand Up @@ -299,7 +301,7 @@ def gaseous_attenuation_approximation(self, f, el, rho, P, T):
RuntimeWarning(
'The approximated method to compute '
'the gaseous attenuation in recommendation ITU-P 676-11 '
'is only recommended for elevation angles between'
'is only recommended for elevation angles between '
'5 and 90 degrees'))

# Water vapour attenuation (gammaw) computation as in Section 1 of
Expand Down Expand Up @@ -624,7 +626,7 @@ def gaseous_attenuation_approximation(self, f, el, rho, P, T):
RuntimeWarning(
'The approximated method to compute '
'the gaseous attenuation in recommendation ITU-P 676-11 '
'is only recommended for elevation angles between'
'is only recommended for elevation angles between '
'5 and 90 degrees'))

# Water vapour attenuation (gammaw) computation as in Section 1 of
Expand Down Expand Up @@ -870,8 +872,8 @@ def gamma0_approx(self, f, P, rho, T):
rp = P / 1013.0
rt = 288.0 / (T)

def phi(rp, rt, a, b, c, d): return np.power(
rp, a) * np.power(rt, b) * np.exp(c * (1 - rp) + d * (1 - rt))
def phi(rp, rt, a, b, c, d): return (
rp**a * np.power(rt, b) * np.exp(c * (1 - rp) + d * (1 - rt)))

# Dry air attenuation (gamma0) computation as in Section 1 of Annex 2
# of [1]
Expand Down Expand Up @@ -923,19 +925,20 @@ def fcn_rest():
2.91 * rp**2 * rt**1.6)) *
f**2 * rp**2 * rt**3.5 * 1e-3 + delta)

gamma0 = \
np.where(
f <= 54, fcn_le_54(),
with np.errstate(invalid='ignore'):
gamma0 = \
np.where(
np.logical_and(54 < f, f <= 60), fcn_le_60(),
f <= 54, fcn_le_54(),
np.where(
np.logical_and(60 < f, f <= 62), fcn_le_62(),
np.logical_and(54 < f, f <= 60), fcn_le_60(),
np.where(
np.logical_and(62 < f, f <= 66), fcn_le_66(),
np.logical_and(60 < f, f <= 62), fcn_le_62(),
np.where(
np.logical_and(66 < f, f <= 120),
fcn_le_120(),
fcn_rest())))))
np.logical_and(62 < f, f <= 66), fcn_le_66(),
np.where(
np.logical_and(66 < f, f <= 120),
fcn_le_120(),
fcn_rest())))))

return gamma0

Expand Down Expand Up @@ -969,7 +972,7 @@ def gaseous_attenuation_approximation(self, f, el, rho, P, T):
RuntimeWarning(
'The approximated method to compute '
'the gaseous attenuation in recommendation ITU-P 676-11 '
'is only recommended for elevation angles between'
'is only recommended for elevation angles between '
'5 and 90 degrees'))

# Water vapour attenuation (gammaw) computation as in Section 1 of
Expand Down
80 changes: 40 additions & 40 deletions itur/models/itu835.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,26 @@ def standard_temperature(h, T_0=288.15):
"""
h_p = 6356.766 * h / (6356.766 + h)
T = np.where(h_p <= 11, 288.15 - 6.5 * h_p,
np.where(np.logical_and(11 < h_p, h_p <= 20),
216.65,
np.where(np.logical_and(20 < h_p, h_p <= 32),
216.65 + (h_p - 20),
np.where(np.logical_and(32 < h_p, h_p <= 47),
228.65 + 2.8 * (h_p - 32),
np.where(np.logical_and(47 < h_p, h_p <= 51),
270.65,
np.where(np.logical_and(51 < h_p, h_p <= 71),
270.65 - 2.8 * (h_p - 51),
np.where(np.logical_and(71 < h_p, h_p <= 84.852),
214.65 - 2.0 * (h_p - 71),
np.where(np.logical_and(86 <= h, h <= 91),
186.8673,
np.where(np.logical_and(91 < h, h <= 100),
263.1905 - 76.3232 * np.sqrt((1 - ((h - 91)/19.9429)**2)),
195.08134433524688)))))))))
# Warnings because of sqrt are expected
with np.errstate(invalid='ignore'):
T = np.where(h_p <= 11, 288.15 - 6.5 * h_p,
np.where(np.logical_and(11 < h_p, h_p <= 20),
216.65,
np.where(np.logical_and(20 < h_p, h_p <= 32),
216.65 + (h_p - 20),
np.where(np.logical_and(32 < h_p, h_p <= 47),
228.65 + 2.8 * (h_p - 32),
np.where(np.logical_and(47 < h_p, h_p <= 51),
270.65,
np.where(np.logical_and(51 < h_p, h_p <= 71),
270.65 - 2.8 * (h_p - 51),
np.where(np.logical_and(71 < h_p, h_p <= 84.852),
214.65 - 2.0 * (h_p - 71),
np.where(np.logical_and(86 <= h, h <= 91),
186.8673,
np.where(np.logical_and(91 < h, h <= 100),
263.1905 - 76.3232 * np.sqrt((1 - ((h - 91)/19.9429)**2)),
195.08134)))))))))

return T

Expand All @@ -113,28 +115,26 @@ def standard_pressure(h, T_0=None, P_0=None):
"""
h_p = 6356.766 * h / (6356.766 + h)
P = np.where(h_p <= 11,
1013.25 * np.power((288.15 / (288.15 - 6.5 * h_p)),
(-34.1632 / 6.5)),
np.where(np.logical_and(11 < h_p, h_p <= 20),
226.3226 * np.exp(-34.1632 * (h_p - 11) / 216.65),
np.where(np.logical_and(20 < h_p, h_p <= 32),
54.74980 * (216.65 / (216.65 + (h_p - 20))) ** 34.1632,
np.where(np.logical_and(32 < h_p, h_p <= 47),
8.680422 * (228.65 / (228.65 + 2.8 * (h_p - 32))) **
(34.1632 / 2.8),
np.where(np.logical_and(47 < h_p, h_p <= 51),
1.109106 * np.exp(-34.1632 * (h_p - 47) / 270.65),
np.where(np.logical_and(51 < h_p, h_p <= 71),
0.6694167 * np.power((270.65 / (270.65 - 2.8 * (h_p - 51))),
(-34.1632 / 2.8)),
np.where(np.logical_and(71 < h_p, h_p <= 84.852),
0.03956649 * np.power((214.65 / (214.65 - 2.0 * (h_p - 71))),
(-34.1632 / 2.0)),
np.where(np.logical_and(86 <= h, h <= 100),
np.exp(95.571899 -4.011801 * h + 6.424731e-2 * h**2 -
4.789660e-4 * h**3 + 1.340543e-6 * h**4),
1e-62)))))))).astype(float)
with np.errstate(invalid='ignore'):
P = np.where(h_p <= 11,
1013.25 * (288.15 / (288.15 - 6.5 * h_p))**(-34.1632 / 6.5),
np.where(np.logical_and(11 < h_p, h_p <= 20),
226.3226 * np.exp(-34.1632 * (h_p - 11) / 216.65),
np.where(np.logical_and(20 < h_p, h_p <= 32),
54.74980 * (216.65 / (216.65 + (h_p - 20))) ** 34.1632,
np.where(np.logical_and(32 < h_p, h_p <= 47),
8.680422 * (228.65 / (228.65 + 2.8 * (h_p - 32))) **
(34.1632 / 2.8),
np.where(np.logical_and(47 < h_p, h_p <= 51),
1.109106 * np.exp(-34.1632 * (h_p - 47) / 270.65),
np.where(np.logical_and(51 < h_p, h_p <= 71),
0.6694167 * (270.65 / (270.65 - 2.8 * (h_p - 51)))**(-34.1632 / 2.8),
np.where(np.logical_and(71 < h_p, h_p <= 84.852),
0.03956649 *(214.65 / (214.65 - 2.0 * (h_p - 71)))**(-34.1632 / 2.0),
np.where(np.logical_and(86 <= h, h <= 100),
np.exp(95.571899 -4.011801 * h + 6.424731e-2 * h**2 -
4.789660e-4 * h**3 + 1.340543e-6 * h**4),
1e-62)))))))).astype(float)

return P

Expand Down
4 changes: 2 additions & 2 deletions itur/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

# Define numeric types including numpy types
__NUMERIC_TYPES__ = [numbers.Number, int, float, complex,
np.float, np.float16, np.float32, np.float64,
np.int, np.int8, np.int16, np.int32, np.int64]
np.float16, np.float32, np.float64,
np.int8, np.int16, np.int32, np.int64]

# Define the geodetic system using the WSG-84 ellipsoid
__wgs84_geod__ = Geod(ellps='WGS84')
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
Expand Down
6 changes: 5 additions & 1 deletion test/ITU_validation_report_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
from itur import atmospheric_attenuation_slant_path


pd.set_option('display.max_colwidth', -1)
if sys.version[:3] <= '3.5':
pd.set_option('display.max_colwidth', -1)
else:
pd.set_option('display.max_colwidth', None)

basepath = path.dirname(path.realpath(__file__))
test_data = path.join(basepath, 'test_data')
html_path = path.join(basepath, '../docs/validation')
Expand Down
31 changes: 16 additions & 15 deletions test/itur_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def test_all_functions_676():

r = 5 * itur.u.km
f = 29 * itur.u.GHz
el = 31
el = 71
el_low = 4
rho = 7.5
P = 1013 * itur.u.hPa
Expand Down Expand Up @@ -671,20 +671,21 @@ def test_all_functions_676():
models.itu676.gaseous_attenuation_inclined_path(
f, el, rho, P, T, h1=h1, h2=h2, mode='exact')

models.itu676.gaseous_attenuation_inclined_path(
f, el_low, rho, P, T, h1=h1, h2=h2, mode='approx')
models.itu676.gaseous_attenuation_inclined_path(
f, el_low, rho, P, T, h1=h1, h2=h2, mode='exact')
models.itu676.gaseous_attenuation_inclined_path(
[f, f], [el_low, el_low], [rho, rho], [P, P], [T, T],
h1=h1, h2=h2, mode='approx')
models.itu676.gaseous_attenuation_inclined_path(
[f, f], [el_low, el_low], [rho, rho], [P, P], [T, T],
h1=h1, h2=h2, mode='exact')
models.itu676.gaseous_attenuation_inclined_path(
f, el_low, rho, P, T, h1=h1, h2=h2, mode='approx')
models.itu676.gaseous_attenuation_inclined_path(
f, el_low, rho, P, T, h1=h1, h2=h2, mode='exact')
with warnings.catch_warnings(record=True) as w:
models.itu676.gaseous_attenuation_inclined_path(
f, el_low, rho, P, T, h1=h1, h2=h2, mode='approx')
models.itu676.gaseous_attenuation_inclined_path(
f, el_low, rho, P, T, h1=h1, h2=h2, mode='exact')
models.itu676.gaseous_attenuation_inclined_path(
[f, f], [el_low, el_low], [rho, rho], [P, P], [T, T],
h1=h1, h2=h2, mode='approx')
models.itu676.gaseous_attenuation_inclined_path(
[f, f], [el_low, el_low], [rho, rho], [P, P], [T, T],
h1=h1, h2=h2, mode='exact')
models.itu676.gaseous_attenuation_inclined_path(
f, el_low, rho, P, T, h1=h1, h2=h2, mode='approx')
models.itu676.gaseous_attenuation_inclined_path(
f, el_low, rho, P, T, h1=h1, h2=h2, mode='exact')

models.itu676.gaseous_attenuation_slant_path(
f, el, rho, P, T, V_t=None, h=None, mode='approx')
Expand Down

0 comments on commit f755a24

Please sign in to comment.