Skip to content

Commit fc93b77

Browse files
committed
numpy 1.20 type hint
modern type annotations require python >= 3.7 for __future__.annotations
1 parent b051765 commit fc93b77

38 files changed

+1003
-700
lines changed

.github/workflows/ci_stdlib_only.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ on:
88

99
jobs:
1010

11-
stdlib_py35:
11+
stdlib_only:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
1515
- uses: actions/setup-python@v2
1616
with:
17-
python-version: 3.5
17+
python-version: 3.7
1818

1919
- run: pip install .[tests]
2020

.mypy.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[mypy]
2-
files = src/
2+
files = src/, Examples/, scripts/
33

44
ignore_missing_imports = True
55
strict_optional = False

Examples/azel2radec.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010

1111
def main():
12-
p = ArgumentParser(description="convert azimuth and elevation to " "right ascension and declination")
12+
p = ArgumentParser(
13+
description="convert azimuth and elevation to " "right ascension and declination"
14+
)
1315
p.add_argument("azimuth", help="azimuth [deg]", type=float)
1416
p.add_argument("elevation", help="elevation [deg]", type=float)
1517
p.add_argument("lat", help="WGS84 obs. lat [deg]", type=float)

Examples/plot_geodetic2ecef.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
11
#!/usr/bin/env python3
2-
import typing
2+
33
import pymap3d as pm
44
import matplotlib.pyplot as mpl
55
import numpy as np
66
import argparse
77

8-
try:
9-
from numpy.typing import ArrayLike
10-
except ImportError:
11-
ArrayLike = typing.Any
128

139
p = argparse.ArgumentParser()
1410
p.add_argument("alt_m", help="altitude [meters]", type=float, default=0.0, nargs="?")
@@ -19,7 +15,7 @@
1915
x, y, z = pm.geodetic2ecef(lat, lon, p.alt_m)
2016

2117

22-
def panel(ax, val: ArrayLike, name: str, cmap: str = None):
18+
def panel(ax, val, name: str, cmap: str = None):
2319
hi = ax.pcolormesh(lon, lat, val, cmap=cmap)
2420
ax.set_title(name)
2521
fg.colorbar(hi, ax=ax).set_label(name + " [m]")

Examples/vdist_poi.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222

2323
@functools.lru_cache()
24-
def get_place_coords(place_type: str, latitude: float, longitude: float, search_radius_km: int, keyfn: Path) -> pandas.DataFrame:
24+
def get_place_coords(
25+
place_type: str, latitude: float, longitude: float, search_radius_km: int, keyfn: Path
26+
) -> pandas.DataFrame:
2527
"""
2628
Get places using Google Maps Places API
2729
Requires you to have a Google Cloud account with API key.
@@ -43,7 +45,10 @@ def get_place_coords(place_type: str, latitude: float, longitude: float, search_
4345

4446
place_json = r.json()["results"]
4547

46-
places = pandas.DataFrame(index=[p["name"] for p in place_json], columns=["latitude", "longitude", "distance_km", "vicinity"])
48+
places = pandas.DataFrame(
49+
index=[p["name"] for p in place_json],
50+
columns=["latitude", "longitude", "distance_km", "vicinity"],
51+
)
4752
places["latitude"] = [p["geometry"]["location"]["lat"] for p in place_json]
4853
places["longitude"] = [p["geometry"]["location"]["lng"] for p in place_json]
4954
places["vicinity"] = [p["vicinity"] for p in place_json]
@@ -53,13 +58,20 @@ def get_place_coords(place_type: str, latitude: float, longitude: float, search_
5358

5459
if __name__ == "__main__":
5560
p = ArgumentParser()
56-
p.add_argument("place_type", help="Place type to search: https://developers.google.com/places/supported_types")
57-
p.add_argument("searchloc", help="initial latituude, longitude to search from", nargs=2, type=float)
61+
p.add_argument(
62+
"place_type",
63+
help="Place type to search: https://developers.google.com/places/supported_types",
64+
)
65+
p.add_argument(
66+
"searchloc", help="initial latituude, longitude to search from", nargs=2, type=float
67+
)
5868
p.add_argument("radius", help="search radius (kilometers)", type=int)
5969
p.add_argument("refloc", help="reference location (lat, lon)", nargs=2, type=float)
6070
p.add_argument("-k", "--keyfn", help="Google Places API key file", default="~/googlemaps.key")
6171
a = p.parse_args()
6272

6373
place_coords = get_place_coords(a.place_type, *a.searchloc, a.radius, a.keyfn)
6474

65-
place_coords["distance_km"] = vdist(place_coords["latitude"], place_coords["longitude"], *a.refloc)[0] / 1e3
75+
place_coords["distance_km"] = (
76+
vdist(place_coords["latitude"], place_coords["longitude"], *a.refloc)[0] / 1e3
77+
)

Examples/vdist_stability.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
if eng is None:
1212
eng = matlab.engine.start_matlab("-nojvm")
13-
except Exception as exc:
13+
except ImportError as exc:
1414
print(exc, file=sys.stderr)
1515
eng = None
1616

@@ -25,20 +25,24 @@ def matlab_func(lat1: float, lon1: float, lat2: float, lon2: float) -> typing.Tu
2525
lon1, lon2 = 0.0, 1.0
2626
for i in range(20):
2727
lat1 = lat2 = 10.0 ** (-i)
28-
try:
29-
dist_m, az_deg = vdist(lat1, lon1, lat2, lon2)
30-
except Exception as exc:
31-
print(exc, f"at latitudes {lat1} {lat2}", file=sys.stderr)
32-
continue
28+
29+
dist_m, az_deg = vdist(lat1, lon1, lat2, lon2)
30+
3331
assert dist_m != dlast
3432
assert az_deg != alast
3533
mat_match = True
3634
dist_matlab, az_matlab = matlab_func(lat1, lon1, lat2, lon2)
3735
if not isclose(dist_matlab, dist_m):
3836
mat_match = False
39-
print(f"MISMATCH: latitude {lat1} {lat2}: Python: {dist_m} Matlab: {dist_matlab}", file=sys.stderr)
37+
print(
38+
f"MISMATCH: latitude {lat1} {lat2}: Python: {dist_m} Matlab: {dist_matlab}",
39+
file=sys.stderr,
40+
)
4041
if not isclose(az_matlab, az_deg):
4142
mat_match = False
42-
print(f"MISMATCH: latitude {lat1} {lat2}: Python: {az_matlab} Matlab: {az_deg}", file=sys.stderr)
43+
print(
44+
f"MISMATCH: latitude {lat1} {lat2}: Python: {az_matlab} Matlab: {az_deg}",
45+
file=sys.stderr,
46+
)
4347
if mat_match:
4448
print(f"latitudes {lat1} {lat2}: {dist_m} meters {az_deg} deg azimuth")

Examples/vreckon.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55

66
def main():
7-
p = ArgumentParser(description="Given starting latitude, longitude: find final lat,lon for distance and azimuth")
7+
p = ArgumentParser(
8+
description="Given starting latitude, longitude: find final lat,lon for distance and azimuth"
9+
)
810
p.add_argument("lat", help="latitude WGS-84 [degrees]", type=float)
911
p.add_argument("lon", help="longitude WGS-84 [degrees]", type=float)
1012
p.add_argument("range", help="range from start point [meters]", type=float)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Thanks to our [contributors](./contributors.md).
2727

2828
## Prerequisites
2929

30-
Pymap3d is compatible with Python ≥ 3.5 including PyPy.
30+
Pymap3d is compatible with Python ≥ 3.7 including PyPy.
3131
Numpy and AstroPy are optional; algorithms from Vallado and Meeus are used if AstroPy is not present.
3232

3333
## Install

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
requires = ["setuptools", "wheel"]
33

44
[tool.black]
5-
line-length = 132
5+
line-length = 100
66

77
[tool.pytest.ini_options]
88
addopts = "-ra -v"

scripts/benchmark_vincenty.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ def bench_vdist(N: int) -> float:
5757

5858
if MATLAB:
5959
subprocess.check_call(
60-
f'matlab -batch "f = @() distance({ll0[0]}, {ll0[1]}, rand({N},1), rand({N},1)); t = timeit(f); disp(t)"', timeout=45
60+
f'matlab -batch "f = @() distance({ll0[0]}, {ll0[1]}, rand({N},1), rand({N},1)); t = timeit(f); disp(t)"',
61+
timeout=45,
6162
)

0 commit comments

Comments
 (0)