-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mag2geo.py
60 lines (42 loc) · 1.44 KB
/
mag2geo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python
"""
demo converting millions of points / second with Apex
"""
import numpy as np
import argparse
import typing as T
import apexpy3
try:
from matplotlib.pyplot import figure, show
except ImportError:
figure = show = None
def main():
p = argparse.ArgumentParser()
p.add_argument("yeardec", help="decimal year e.g. 2020.352", type=float)
P = p.parse_args()
# demoing a grid
gmlat = np.arange(-90, 90, 1)
gmlon = np.arange(0, 360, 2)
gmlat, gmlon = np.meshgrid(gmlat, gmlon)
dat = apexpy3.mag2geo(P.yeardec, gmlat, gmlon)
dat.update({"gmlat": gmlat, "gmlon": gmlon, "date": P.yeardec})
if show is None:
return
mag_contour(dat)
def mag_contour(dat: T.Dict[str, np.ndarray]):
print("Converted", dat["gmlat"].shape, "points")
fg = figure()
ax = fg.subplots(1, 2, sharey=True)
fg.suptitle("WMM2020 {}".format(dat["date"]))
h = ax[0].contour(dat["gmlon"], dat["gmlat"], dat["glat"], range(-90, 90 + 20, 20))
ax[0].clabel(h, inline=True, fmt="%0.1f")
ax[0].set_title("Geographic latitude [degrees]")
h = ax[1].contour(dat["gmlon"], dat["gmlat"], dat["glon"], range(-90, 90 + 20, 20))
ax[1].clabel(h, inline=True, fmt="%0.1f")
ax[1].set_title("Geographic longitude [degrees]")
ax[0].set_ylabel("Magnetic latitude (deg)")
for a in ax:
a.set_xlabel("Magnetic longitude (deg)")
show()
if __name__ == "__main__":
main()