Skip to content

Commit

Permalink
bugfix: don't use np.seterr, use warnings.catch_warnings
Browse files Browse the repository at this point in the history
fixes #79

Co-authored-by: sanguinariojoe <sanguinariojoe@users.noreply.github.com>
  • Loading branch information
scivision and sanguinariojoe committed Mar 2, 2023
1 parent 55e00f4 commit 5802ca3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
4 changes: 0 additions & 4 deletions src/pymap3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@
]

try:
import numpy as np

np.seterr(all="raise")

from .aer import aer2eci, eci2aer
from .azelradec import azel2radec, radec2azel
from .eci import ecef2eci, eci2ecef
Expand Down
9 changes: 7 additions & 2 deletions src/pymap3d/ecef.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
""" Transforms involving ECEF: earth-centered, earth-fixed frame """

from __future__ import annotations

import warnings

try:
from numpy import asarray, finfo, where

Expand Down Expand Up @@ -141,8 +144,10 @@ def ecef2geodetic(

# eqn. 4b
try:
Beta = atan(huE / u * z / hypot(x, y))
except ArithmeticError:
with warnings.catch_warnings(record=True):
warnings.simplefilter("error")
Beta = atan(huE / u * z / hypot(x, y))
except (ArithmeticError, RuntimeWarning):
if isclose(z, 0):
Beta = 0
elif z > 0:
Expand Down
8 changes: 6 additions & 2 deletions src/pymap3d/latitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from __future__ import annotations

import warnings

from math import pi

from . import rcurve
Expand Down Expand Up @@ -343,8 +345,10 @@ def geodetic2conformal(geodetic_lat, ell: Ellipsoid = None, deg: bool = True):

# compute conformal latitudes with correction for points at +90
try:
conformal_lat = 2 * atan(sqrt((f4 / f3) * ((f1 / f2) ** e))) - (pi / 2)
except ArithmeticError:
with warnings.catch_warnings(record=True):
warnings.simplefilter("error")
conformal_lat = 2 * atan(sqrt((f4 / f3) * ((f1 / f2) ** e))) - (pi / 2)
except (ArithmeticError, RuntimeWarning):
conformal_lat = pi / 2

return degrees(conformal_lat) if deg else conformal_lat
Expand Down
2 changes: 1 addition & 1 deletion src/pymap3d/tests/test_vincenty_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
(90, 0, -90, 0, 2.000393145e7, 180),
],
)
def test_unit(lat, lon, lat1, lon1, srange, az):
def test_unit_vdist(lat, lon, lat1, lon1, srange, az):
dist, az1 = vincenty.vdist(lat, lon, lat1, lon1)
assert dist == approx(srange, rel=0.005)
assert az1 == approx(az)
Expand Down
16 changes: 11 additions & 5 deletions src/pymap3d/vincenty.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from __future__ import annotations

import warnings

import logging
from copy import copy
from math import nan, pi
Expand Down Expand Up @@ -184,16 +186,20 @@ def vdist(
sigma = atan2(sinsigma, cossigma)

try:
sinAlpha = cos(U1) * cos(U2) * sin(lamb) / sin(sigma)
with warnings.catch_warnings(record=True):
warnings.simplefilter("error")
sinAlpha = cos(U1) * cos(U2) * sin(lamb) / sin(sigma)

alpha = asin(sinAlpha)
alpha = asin(sinAlpha)
alpha[isnan(sinAlpha)] = 0
alpha[(sinAlpha > 1) | (abs(sinAlpha - 1) < 1e-16)] = pi / 2

except (ArithmeticError, TypeError, ValueError):
except (ArithmeticError, RuntimeWarning, TypeError, ValueError):
try:
sinAlpha = cos(U1) * cos(U2) * sin(lamb) / sin(sigma)
except ArithmeticError:
with warnings.catch_warnings(record=True):
warnings.simplefilter("error")
sinAlpha = cos(U1) * cos(U2) * sin(lamb) / sin(sigma)
except (ArithmeticError, RuntimeWarning):
sinAlpha = 0.0

if isnan(sinAlpha):
Expand Down

0 comments on commit 5802ca3

Please sign in to comment.