Skip to content

Commit 1178f5d

Browse files
committed
finish adding new functions, apply black code style
1 parent 935f3e4 commit 1178f5d

25 files changed

+524
-550
lines changed

examples/angle_distance.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@
66

77
def main():
88
p = ArgumentParser(description="angular distance between two sky points")
9-
p.add_argument('r0', help='right ascension: first point [deg]', type=float)
10-
p.add_argument('d0', help='declination: first point [deg]', type=float)
11-
p.add_argument('r1', help='right ascension: 2nd point [deg]', type=float)
12-
p.add_argument('d1', help='declination: 2nd point [degrees]', type=float)
9+
p.add_argument("r0", help="right ascension: first point [deg]", type=float)
10+
p.add_argument("d0", help="declination: first point [deg]", type=float)
11+
p.add_argument("r1", help="right ascension: 2nd point [deg]", type=float)
12+
p.add_argument("d1", help="declination: 2nd point [degrees]", type=float)
1313
a = p.parse_args()
1414

1515
dist_deg = anglesep_meeus(a.r0, a.d0, a.r1, a.d1)
1616
dist_deg_astropy = anglesep(a.r0, a.d0, a.r1, a.d1)
1717

18-
print('{:.6f} deg sep'.format(dist_deg))
18+
print("{:.6f} deg sep".format(dist_deg))
1919

2020
assert dist_deg == approx(dist_deg_astropy)
2121

2222

23-
if __name__ == '__main__':
23+
if __name__ == "__main__":
2424
main()

examples/azel2radec.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99

1010

1111
def main():
12-
p = ArgumentParser(description="convert azimuth and elevation to "
13-
"right ascension and declination")
14-
p.add_argument('azimuth', help='azimuth [deg]', type=float)
15-
p.add_argument('elevation', help='elevation [deg]', type=float)
16-
p.add_argument('lat', help='WGS84 obs. lat [deg]', type=float)
17-
p.add_argument('lon', help='WGS84 obs. lon [deg]', type=float)
18-
p.add_argument('time', help='obs. time YYYY-mm-ddTHH:MM:SSZ')
12+
p = ArgumentParser(description="convert azimuth and elevation to " "right ascension and declination")
13+
p.add_argument("azimuth", help="azimuth [deg]", type=float)
14+
p.add_argument("elevation", help="elevation [deg]", type=float)
15+
p.add_argument("lat", help="WGS84 obs. lat [deg]", type=float)
16+
p.add_argument("lon", help="WGS84 obs. lon [deg]", type=float)
17+
p.add_argument("time", help="obs. time YYYY-mm-ddTHH:MM:SSZ")
1918
P = p.parse_args()
2019

2120
ra, dec = azel2radec(P.azimuth, P.elevation, P.lat, P.lon, P.time)
2221

23-
print('ra [deg] ', ra, ' dec [deg] ', dec)
22+
print("ra [deg] ", ra, " dec [deg] ", dec)
2423

2524

2625
if __name__ == "__main__": # pragma: no cover

examples/radec2azel.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@
99

1010

1111
def main():
12-
p = ArgumentParser(description="RightAscension,Declination =>"
13-
"Azimuth,Elevation")
14-
p.add_argument('ra', help='right ascension [degrees]', type=float)
15-
p.add_argument('dec', help='declination [degrees]', type=float)
16-
p.add_argument('lat', help='WGS84 latitude of observer [degrees]',
17-
type=float)
18-
p.add_argument('lon', help='WGS84 latitude of observer [degrees]',
19-
type=float)
20-
p.add_argument('time', help='UTC time of observation YYYY-mm-ddTHH:MM:SSZ')
12+
p = ArgumentParser(description="RightAscension,Declination =>" "Azimuth,Elevation")
13+
p.add_argument("ra", help="right ascension [degrees]", type=float)
14+
p.add_argument("dec", help="declination [degrees]", type=float)
15+
p.add_argument("lat", help="WGS84 latitude of observer [degrees]", type=float)
16+
p.add_argument("lon", help="WGS84 latitude of observer [degrees]", type=float)
17+
p.add_argument("time", help="UTC time of observation YYYY-mm-ddTHH:MM:SSZ")
2118
P = p.parse_args()
2219

2320
az_deg, el_deg = radec2azel(P.ra, P.dec, P.lat, P.lon, P.time)
24-
print('azimuth: [deg]', az_deg)
25-
print('elevation [deg]:', el_deg)
21+
print("azimuth: [deg]", az_deg)
22+
print("elevation [deg]:", el_deg)
2623

2724

28-
if __name__ == '__main__':
25+
if __name__ == "__main__":
2926
main()

examples/vdist.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55

66
def main():
7-
p = ArgumentParser(description='vdist distance between WGS-84 coordinates')
8-
p.add_argument('lat1', help='latitude1 WGS-84 [degrees]', type=float)
9-
p.add_argument('lon1', help='longitude1 WGS-84 [degrees]', type=float)
10-
p.add_argument('lat2', help='latitude2 WGS-84 [degrees]', type=float)
11-
p.add_argument('lon2', help='longitude2 WGS-84 [degrees]', type=float)
7+
p = ArgumentParser(description="vdist distance between WGS-84 coordinates")
8+
p.add_argument("lat1", help="latitude1 WGS-84 [degrees]", type=float)
9+
p.add_argument("lon1", help="longitude1 WGS-84 [degrees]", type=float)
10+
p.add_argument("lat2", help="latitude2 WGS-84 [degrees]", type=float)
11+
p.add_argument("lon2", help="longitude2 WGS-84 [degrees]", type=float)
1212
P = p.parse_args()
1313

1414
dist_m = vdist(P.lat1, P.lon1, P.lat2, P.lon2)
1515

16-
print('{:.3f} {:.3f} {:.3f}'.format(*dist_m))
16+
print("{:.3f} {:.3f} {:.3f}".format(*dist_m))
1717

1818

19-
if __name__ == '__main__': # pragma: no cover
19+
if __name__ == "__main__": # pragma: no cover
2020
main()

examples/vdist_poi.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@
1717
from pymap3d.vincenty import vdist
1818

1919

20-
URL = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?'
20+
URL = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
2121

2222

2323
@functools.lru_cache()
24-
def get_place_coords(place_type: str,
25-
latitude: float, longitude: float,
26-
search_radius_km: int,
27-
keyfn: Path) -> pandas.DataFrame:
24+
def get_place_coords(place_type: str, latitude: float, longitude: float, search_radius_km: int, keyfn: Path) -> pandas.DataFrame:
2825
"""
2926
Get places using Google Maps Places API
3027
Requires you to have a Google Cloud account with API key.
@@ -33,37 +30,36 @@ def get_place_coords(place_type: str,
3330
keyfn = Path(keyfn).expanduser()
3431
key = keyfn.read_text()
3532

36-
stub = URL + 'location={},{}'.format(latitude, longitude)
33+
stub = URL + "location={},{}".format(latitude, longitude)
3734

38-
stub += '&radius={}'.format(search_radius_km * 1000)
35+
stub += "&radius={}".format(search_radius_km * 1000)
3936

40-
stub += '&types={}'.format(place_type)
37+
stub += "&types={}".format(place_type)
4138

42-
stub += '&key={}'.format(key)
39+
stub += "&key={}".format(key)
4340

4441
r = requests.get(stub)
4542
r.raise_for_status()
4643

47-
place_json = r.json()['results']
44+
place_json = r.json()["results"]
4845

49-
places = pandas.DataFrame(index=[p['name'] for p in place_json],
50-
columns=['latitude', 'longitude', 'distance_km', 'vicinity'])
51-
places['latitude'] = [p['geometry']['location']['lat'] for p in place_json]
52-
places['longitude'] = [p['geometry']['location']['lng'] for p in place_json]
53-
places['vicinity'] = [p['vicinity'] for p in place_json]
46+
places = pandas.DataFrame(index=[p["name"] for p in place_json], columns=["latitude", "longitude", "distance_km", "vicinity"])
47+
places["latitude"] = [p["geometry"]["location"]["lat"] for p in place_json]
48+
places["longitude"] = [p["geometry"]["location"]["lng"] for p in place_json]
49+
places["vicinity"] = [p["vicinity"] for p in place_json]
5450

5551
return places
5652

5753

58-
if __name__ == '__main__':
54+
if __name__ == "__main__":
5955
p = ArgumentParser()
60-
p.add_argument('place_type', help='Place type to search: https://developers.google.com/places/supported_types')
61-
p.add_argument('searchloc', help='initial latituude, longitude to search from', nargs=2, type=float)
62-
p.add_argument('radius', help='search radius (kilometers)', type=int)
63-
p.add_argument('refloc', help='reference location (lat, lon)', nargs=2, type=float)
64-
p.add_argument('-k', '--keyfn', help='Google Places API key file', default='~/googlemaps.key')
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)
58+
p.add_argument("radius", help="search radius (kilometers)", type=int)
59+
p.add_argument("refloc", help="reference location (lat, lon)", nargs=2, type=float)
60+
p.add_argument("-k", "--keyfn", help="Google Places API key file", default="~/googlemaps.key")
6561
a = p.parse_args()
6662

6763
place_coords = get_place_coords(a.place_type, *a.searchloc, a.radius, a.keyfn)
6864

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

examples/vreckon.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55

66
def main():
7-
p = ArgumentParser(description='Given starting latitude, longitude: find final lat,lon for distance and azimuth')
8-
p.add_argument('lat', help='latitude WGS-84 [degrees]', type=float)
9-
p.add_argument('lon', help='longitude WGS-84 [degrees]', type=float)
10-
p.add_argument('range', help='range from start point [meters]', type=float)
11-
p.add_argument('azimuth', help='clockwise from north: azimuth to start [degrees]', type=float)
7+
p = ArgumentParser(description="Given starting latitude, longitude: find final lat,lon for distance and azimuth")
8+
p.add_argument("lat", help="latitude WGS-84 [degrees]", type=float)
9+
p.add_argument("lon", help="longitude WGS-84 [degrees]", type=float)
10+
p.add_argument("range", help="range from start point [meters]", type=float)
11+
p.add_argument("azimuth", help="clockwise from north: azimuth to start [degrees]", type=float)
1212
P = p.parse_args()
1313

1414
lat2, lon2, a21 = vreckon(P.lat, P.lon, P.range, P.azimuth)
1515

16-
print('{:.4f} {:.4f}'.format(lat2, lon2))
17-
print('{:.1f}'.format(a21))
16+
print("{:.4f} {:.4f}".format(lat2, lon2))
17+
print("{:.1f}".format(a21))
1818

1919

20-
if __name__ == '__main__': # pragma: no cover
20+
if __name__ == "__main__": # pragma: no cover
2121
main()

pymap3d/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,16 @@
5252
parametric2geodetic,
5353
)
5454
from .rcurve import rcurve_parallel, rcurve_meridian, rcurve_transverse
55-
from .rsphere import rsphere_eqavol, rsphere_authalic, rsphere_rectifying, rsphere_euler, rsphere_curve, rsphere_triaxial, rsphere_biaxial
56-
from .lox import isometric, meridian_dist, loxodrome_inverse
55+
from .rsphere import (
56+
rsphere_eqavol,
57+
rsphere_authalic,
58+
rsphere_rectifying,
59+
rsphere_euler,
60+
rsphere_curve,
61+
rsphere_triaxial,
62+
rsphere_biaxial,
63+
)
64+
from .lox import meridian_arc, meridian_dist, loxodrome_inverse, loxodrome_direct, departure, meanm
5765
from .los import lookAtSpheroid
5866
from .timeconv import str2dt
5967

pymap3d/aer.py

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
from .ecef import ecef2enu, geodetic2ecef, ecef2geodetic, enu2uvw
66
from .enu import geodetic2enu, aer2enu, enu2aer
77
from .ellipsoid import Ellipsoid
8+
89
try:
910
from .eci import eci2ecef, ecef2eci
1011
except ImportError:
1112
eci2ecef = ecef2eci = None
1213

13-
__all__ = ['aer2ecef', 'ecef2aer', 'geodetic2aer', 'aer2geodetic']
14+
__all__ = ["aer2ecef", "ecef2aer", "geodetic2aer", "aer2geodetic"]
1415

1516

16-
def ecef2aer(x: float, y: float, z: float,
17-
lat0: float, lon0: float, h0: float,
18-
ell: Ellipsoid = None, deg: bool = True) -> Tuple[float, float, float]:
17+
def ecef2aer(
18+
x: float, y: float, z: float, lat0: float, lon0: float, h0: float, ell: Ellipsoid = None, deg: bool = True
19+
) -> Tuple[float, float, float]:
1920
"""
2021
gives azimuth, elevation and slant range from an Observer to a Point with ECEF coordinates.
2122
@@ -55,9 +56,9 @@ def ecef2aer(x: float, y: float, z: float,
5556
return enu2aer(xEast, yNorth, zUp, deg=deg)
5657

5758

58-
def geodetic2aer(lat: float, lon: float, h: float,
59-
lat0: float, lon0: float, h0: float,
60-
ell: Ellipsoid = None, deg: bool = True) -> Tuple[float, float, float]:
59+
def geodetic2aer(
60+
lat: float, lon: float, h: float, lat0: float, lon0: float, h0: float, ell: Ellipsoid = None, deg: bool = True
61+
) -> Tuple[float, float, float]:
6162
"""
6263
gives azimuth, elevation and slant range from an Observer to a Point with geodetic coordinates.
6364
@@ -96,10 +97,9 @@ def geodetic2aer(lat: float, lon: float, h: float,
9697
return enu2aer(e, n, u, deg=deg)
9798

9899

99-
def aer2geodetic(az: float, el: float, srange: float,
100-
lat0: float, lon0: float, h0: float,
101-
ell: Ellipsoid = None,
102-
deg: bool = True) -> Tuple[float, float, float]:
100+
def aer2geodetic(
101+
az: float, el: float, srange: float, lat0: float, lon0: float, h0: float, ell: Ellipsoid = None, deg: bool = True
102+
) -> Tuple[float, float, float]:
103103
"""
104104
gives geodetic coordinates of a point with az, el, range
105105
from an observer at lat0, lon0, h0
@@ -140,10 +140,9 @@ def aer2geodetic(az: float, el: float, srange: float,
140140
return ecef2geodetic(x, y, z, ell=ell, deg=deg)
141141

142142

143-
def eci2aer(x: float, y: float, z: float,
144-
lat0: float, lon0: float, h0: float,
145-
t: datetime,
146-
useastropy: bool = True) -> Tuple[float, float, float]:
143+
def eci2aer(
144+
x: float, y: float, z: float, lat0: float, lon0: float, h0: float, t: datetime, useastropy: bool = True
145+
) -> Tuple[float, float, float]:
147146
"""
148147
takes ECI coordinates of point and gives az, el, slant range from Observer
149148
@@ -183,10 +182,18 @@ def eci2aer(x: float, y: float, z: float,
183182
return ecef2aer(xecef, yecef, zecef, lat0, lon0, h0)
184183

185184

186-
def aer2eci(az: float, el: float, srange: float,
187-
lat0: float, lon0: float, h0: float, t: datetime,
188-
ell=None, deg: bool = True,
189-
useastropy: bool = True) -> Tuple[float, float, float]:
185+
def aer2eci(
186+
az: float,
187+
el: float,
188+
srange: float,
189+
lat0: float,
190+
lon0: float,
191+
h0: float,
192+
t: datetime,
193+
ell=None,
194+
deg: bool = True,
195+
useastropy: bool = True,
196+
) -> Tuple[float, float, float]:
190197
"""
191198
gives ECI of a point from an observer at az, el, slant range
192199
@@ -231,9 +238,9 @@ def aer2eci(az: float, el: float, srange: float,
231238
return ecef2eci(x, y, z, t, useastropy=useastropy)
232239

233240

234-
def aer2ecef(az: float, el: float, srange: float,
235-
lat0: float, lon0: float, alt0: float,
236-
ell: Ellipsoid = None, deg: bool = True) -> Tuple[float, float, float]:
241+
def aer2ecef(
242+
az: float, el: float, srange: float, lat0: float, lon0: float, alt0: float, ell: Ellipsoid = None, deg: bool = True
243+
) -> Tuple[float, float, float]:
237244
"""
238245
converts target azimuth, elevation, range from observer at lat0,lon0,alt0 to ECEF coordinates.
239246

pymap3d/azelradec.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from datetime import datetime
66
from .vallado import azel2radec as vazel2radec, radec2azel as vradec2azel
77
from .timeconv import str2dt # astropy can't handle xarray times (yet)
8+
89
try:
910
from astropy.time import Time
1011
from astropy import units as u
@@ -13,9 +14,9 @@
1314
Time = None
1415

1516

16-
def azel2radec(az_deg: float, el_deg: float,
17-
lat_deg: float, lon_deg: float,
18-
time: datetime, usevallado: bool = False) -> Tuple[float, float]:
17+
def azel2radec(
18+
az_deg: float, el_deg: float, lat_deg: float, lon_deg: float, time: datetime, usevallado: bool = False
19+
) -> Tuple[float, float]:
1920
"""
2021
viewing angle (az, el) to sky coordinates (ra, dec)
2122
@@ -47,17 +48,16 @@ def azel2radec(az_deg: float, el_deg: float,
4748

4849
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
4950

50-
direc = AltAz(location=obs, obstime=Time(str2dt(time)),
51-
az=az_deg * u.deg, alt=el_deg * u.deg)
51+
direc = AltAz(location=obs, obstime=Time(str2dt(time)), az=az_deg * u.deg, alt=el_deg * u.deg)
5252

5353
sky = SkyCoord(direc.transform_to(ICRS()))
5454

5555
return sky.ra.deg, sky.dec.deg
5656

5757

58-
def radec2azel(ra_deg: float, dec_deg: float,
59-
lat_deg: float, lon_deg: float,
60-
time: datetime, usevallado: bool = False) -> Tuple[float, float]:
58+
def radec2azel(
59+
ra_deg: float, dec_deg: float, lat_deg: float, lon_deg: float, time: datetime, usevallado: bool = False
60+
) -> Tuple[float, float]:
6161
"""
6262
sky coordinates (ra, dec) to viewing angle (az, el)
6363
@@ -87,12 +87,9 @@ def radec2azel(ra_deg: float, dec_deg: float,
8787
if usevallado or Time is None:
8888
return vradec2azel(ra_deg, dec_deg, lat_deg, lon_deg, time)
8989

90-
obs = EarthLocation(lat=lat_deg * u.deg,
91-
lon=lon_deg * u.deg)
90+
obs = EarthLocation(lat=lat_deg * u.deg, lon=lon_deg * u.deg)
9291

93-
points = SkyCoord(Angle(ra_deg, unit=u.deg),
94-
Angle(dec_deg, unit=u.deg),
95-
equinox='J2000.0')
92+
points = SkyCoord(Angle(ra_deg, unit=u.deg), Angle(dec_deg, unit=u.deg), equinox="J2000.0")
9693

9794
altaz = points.transform_to(AltAz(location=obs, obstime=Time(str2dt(time))))
9895

0 commit comments

Comments
 (0)