ppigrf 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ppigrf/IGRF13.shc +200 -0
- ppigrf/__init__.py +1 -0
- ppigrf/ppigrf.py +769 -0
- ppigrf-1.0.0.dist-info/LICENSE +21 -0
- ppigrf-1.0.0.dist-info/METADATA +117 -0
- ppigrf-1.0.0.dist-info/RECORD +8 -0
- ppigrf-1.0.0.dist-info/WHEEL +5 -0
- ppigrf-1.0.0.dist-info/top_level.txt +1 -0
ppigrf/IGRF13.shc
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
# IGRF 13
|
|
2
|
+
# International Geomagnetic Reference Field -- 13th generation
|
|
3
|
+
# see http://www.ngdc.noaa.gov/IAGA/vmod/igrf.html for detailed description
|
|
4
|
+
1 13 26 2 1 1900.0 2025.0
|
|
5
|
+
1900.0 1905.0 1910.0 1915.0 1920.0 1925.0 1930.0 1935.0 1940.0 1945.0 1950.0 1955.0 1960.0 1965.0 1970.0 1975.0 1980.0 1985.0 1990.0 1995.0 2000.0 2005.0 2010.0 2015.0 2020.0 2025.0
|
|
6
|
+
1 0 -31543 -31464 -31354 -31212 -31060 -30926 -30805 -30715 -30654 -30594 -30554 -30500 -30421 -30334 -30220 -30100 -29992 -29873 -29775 -29692 -29619.4 -29554.63 -29496.57 -29441.46 -29404.8 -29376.2
|
|
7
|
+
1 1 -2298 -2298 -2297 -2306 -2317 -2318 -2316 -2306 -2292 -2285 -2250 -2215 -2169 -2119 -2068 -2013 -1956 -1905 -1848 -1784 -1728.2 -1669.05 -1586.42 -1501.77 -1450.9 -1413.8
|
|
8
|
+
1 -1 5922 5909 5898 5875 5845 5817 5808 5812 5821 5810 5815 5820 5791 5776 5737 5675 5604 5500 5406 5306 5186.1 5077.99 4944.26 4795.99 4652.5 4523.0
|
|
9
|
+
2 0 -677 -728 -769 -802 -839 -893 -951 -1018 -1106 -1244 -1341 -1440 -1555 -1662 -1781 -1902 -1997 -2072 -2131 -2200 -2267.7 -2337.24 -2396.06 -2445.88 -2499.6 -2554.5
|
|
10
|
+
2 1 2905 2928 2948 2956 2959 2969 2980 2984 2981 2990 2998 3003 3002 2997 3000 3010 3027 3044 3059 3070 3068.4 3047.69 3026.34 3012.20 2982.0 2947.2
|
|
11
|
+
2 -1 -1061 -1086 -1128 -1191 -1259 -1334 -1424 -1520 -1614 -1702 -1810 -1898 -1967 -2016 -2047 -2067 -2129 -2197 -2279 -2366 -2481.6 -2594.50 -2708.54 -2845.41 -2991.6 -3142.5
|
|
12
|
+
2 2 924 1041 1176 1309 1407 1471 1517 1550 1566 1578 1576 1581 1590 1594 1611 1632 1663 1687 1686 1681 1670.9 1657.76 1668.17 1676.35 1677.0 1666.2
|
|
13
|
+
2 -2 1121 1065 1000 917 823 728 644 586 528 477 381 291 206 114 25 -68 -200 -306 -373 -413 -458.0 -515.43 -575.73 -642.17 -734.6 -846.6
|
|
14
|
+
3 0 1022 1037 1058 1084 1111 1140 1172 1206 1240 1282 1297 1302 1302 1297 1287 1276 1281 1296 1314 1335 1339.6 1336.30 1339.85 1350.33 1363.2 1374.2
|
|
15
|
+
3 1 -1469 -1494 -1524 -1559 -1600 -1645 -1692 -1740 -1790 -1834 -1889 -1944 -1992 -2038 -2091 -2144 -2180 -2208 -2239 -2267 -2288.0 -2305.83 -2326.54 -2352.26 -2381.2 -2410.6
|
|
16
|
+
3 -1 -330 -357 -389 -421 -445 -462 -480 -494 -499 -499 -476 -462 -414 -404 -366 -333 -336 -310 -284 -262 -227.6 -198.86 -160.40 -115.29 -82.1 -52.0
|
|
17
|
+
3 2 1256 1239 1223 1212 1205 1202 1205 1215 1232 1255 1274 1288 1289 1292 1278 1260 1251 1247 1248 1249 1252.1 1246.39 1232.10 1225.85 1236.2 1251.5
|
|
18
|
+
3 -2 3 34 62 84 103 119 133 146 163 186 206 216 224 240 251 262 271 284 293 302 293.4 269.72 251.75 245.04 241.8 236.4
|
|
19
|
+
3 3 572 635 705 778 839 881 907 918 916 913 896 882 878 856 838 830 833 829 802 759 714.5 672.51 633.73 581.69 525.7 465.5
|
|
20
|
+
3 -3 523 480 425 360 293 229 166 101 43 -11 -46 -83 -130 -165 -196 -223 -252 -297 -352 -427 -491.1 -524.72 -537.03 -538.70 -543.4 -541.1
|
|
21
|
+
4 0 876 880 884 887 889 891 896 903 914 944 954 958 957 957 952 946 938 936 939 940 932.3 920.55 912.66 907.42 903.0 897.0
|
|
22
|
+
4 1 628 643 660 678 695 711 727 744 762 776 792 796 800 804 800 791 782 780 780 780 786.8 797.96 808.97 813.68 809.5 801.8
|
|
23
|
+
4 -1 195 203 211 218 220 216 205 188 169 144 136 133 135 148 167 191 212 232 247 262 272.6 282.07 286.48 283.54 281.9 281.3
|
|
24
|
+
4 2 660 653 644 631 616 601 584 565 550 544 528 510 504 479 461 438 398 361 325 290 250.0 210.65 166.58 120.49 86.3 56.6
|
|
25
|
+
4 -2 -69 -77 -90 -109 -134 -163 -195 -226 -252 -276 -278 -274 -278 -269 -266 -265 -257 -249 -240 -236 -231.9 -225.23 -211.03 -188.43 -158.4 -126.0
|
|
26
|
+
4 3 -361 -380 -400 -416 -424 -426 -422 -415 -405 -421 -408 -397 -394 -390 -395 -405 -419 -424 -423 -418 -403.0 -379.86 -356.83 -334.85 -309.4 -283.4
|
|
27
|
+
4 -3 -210 -201 -189 -173 -153 -130 -109 -90 -72 -55 -37 -23 3 13 26 39 53 69 84 97 119.8 145.15 164.46 180.95 199.7 217.4
|
|
28
|
+
4 4 134 146 160 178 199 217 234 249 265 304 303 290 269 252 234 216 199 170 141 122 111.3 100.00 89.40 70.38 48.0 22.5
|
|
29
|
+
4 -4 -75 -65 -55 -51 -57 -70 -90 -114 -141 -178 -210 -230 -255 -269 -279 -288 -297 -297 -299 -306 -303.8 -305.36 -309.72 -329.23 -349.7 -374.5
|
|
30
|
+
5 0 -184 -192 -201 -211 -221 -230 -237 -241 -241 -253 -240 -229 -222 -219 -216 -218 -218 -214 -214 -214 -218.8 -227.00 -230.87 -232.91 -234.3 -235.7
|
|
31
|
+
5 1 328 328 327 327 326 326 327 329 334 346 349 360 362 358 359 356 357 355 353 352 351.4 354.41 357.29 360.14 363.2 365.7
|
|
32
|
+
5 -1 -210 -193 -172 -148 -122 -96 -72 -51 -33 -12 3 15 16 19 26 31 46 47 46 46 43.8 42.72 44.58 46.98 47.7 47.6
|
|
33
|
+
5 2 264 259 253 245 236 226 218 211 208 194 211 230 242 254 262 264 261 253 245 235 222.3 208.95 200.26 192.35 187.8 184.8
|
|
34
|
+
5 -2 53 56 57 58 58 58 60 64 71 95 103 110 125 128 139 148 150 150 154 165 171.9 180.25 189.01 196.98 208.3 220.6
|
|
35
|
+
5 3 5 -1 -9 -16 -23 -28 -32 -33 -33 -20 -20 -23 -26 -31 -42 -59 -74 -93 -109 -118 -130.4 -136.54 -141.05 -140.94 -140.7 -139.7
|
|
36
|
+
5 -3 -33 -32 -33 -34 -38 -44 -53 -64 -75 -67 -87 -98 -117 -126 -139 -152 -151 -154 -153 -143 -133.1 -123.45 -118.06 -119.14 -121.2 -124.0
|
|
37
|
+
5 4 -86 -93 -102 -111 -119 -125 -131 -136 -141 -142 -147 -152 -156 -157 -160 -159 -162 -164 -165 -166 -168.6 -168.05 -163.17 -157.40 -151.2 -144.8
|
|
38
|
+
5 -4 -124 -125 -126 -126 -125 -122 -118 -115 -113 -119 -122 -121 -114 -97 -91 -83 -78 -75 -69 -55 -39.3 -19.57 -0.01 15.98 32.3 47.2
|
|
39
|
+
5 5 -16 -26 -38 -51 -62 -69 -74 -76 -76 -82 -76 -69 -63 -62 -56 -49 -48 -46 -36 -17 -12.9 -13.55 -8.03 4.30 13.5 17.8
|
|
40
|
+
5 -5 3 11 21 32 43 51 58 64 69 82 80 78 81 81 83 88 92 95 97 107 106.3 103.85 101.04 100.12 98.8 100.2
|
|
41
|
+
6 0 63 62 62 61 61 61 60 59 57 59 54 47 46 45 43 45 48 53 61 68 72.3 73.60 72.78 69.55 66.0 63.3
|
|
42
|
+
6 1 61 60 58 57 55 54 53 53 54 57 57 57 58 61 64 66 66 65 65 67 68.2 69.56 68.69 67.57 65.5 63.8
|
|
43
|
+
6 -1 -9 -7 -5 -2 0 3 4 4 4 6 -1 -9 -10 -11 -12 -13 -15 -16 -16 -17 -17.4 -20.33 -20.90 -20.61 -19.1 -18.9
|
|
44
|
+
6 2 -11 -11 -11 -10 -10 -9 -9 -8 -7 6 4 3 1 8 15 28 42 51 59 68 74.2 76.74 75.92 72.79 72.9 74.9
|
|
45
|
+
6 -2 83 86 89 93 96 99 102 104 105 100 99 96 99 100 100 99 93 88 82 72 63.7 54.75 44.18 33.30 25.1 17.0
|
|
46
|
+
6 3 -217 -221 -224 -228 -233 -238 -242 -246 -249 -246 -247 -247 -237 -228 -212 -198 -192 -185 -178 -170 -160.9 -151.34 -141.40 -129.85 -121.5 -115.0
|
|
47
|
+
6 -3 2 4 5 8 11 14 19 25 33 16 33 48 60 68 72 75 71 69 69 67 65.1 63.63 61.54 58.74 52.8 46.1
|
|
48
|
+
6 4 -58 -57 -54 -51 -46 -40 -32 -25 -18 -25 -16 -8 -1 4 2 1 4 4 3 -1 -5.9 -14.58 -22.83 -28.93 -36.2 -43.2
|
|
49
|
+
6 -4 -35 -32 -29 -26 -22 -18 -16 -15 -15 -9 -12 -16 -20 -32 -37 -41 -43 -48 -52 -58 -61.2 -63.53 -66.26 -66.64 -64.5 -60.4
|
|
50
|
+
6 5 59 57 54 49 44 39 32 25 18 21 12 7 -2 1 3 6 14 16 18 19 16.9 14.58 13.10 13.14 13.5 13.4
|
|
51
|
+
6 -5 36 32 28 23 18 13 8 4 0 -16 -12 -12 -11 -8 -6 -4 -2 -1 1 1 0.7 0.24 3.02 7.35 8.9 9.0
|
|
52
|
+
6 6 -90 -92 -95 -98 -101 -103 -104 -106 -107 -104 -105 -107 -113 -111 -112 -111 -108 -102 -96 -93 -90.4 -86.36 -78.09 -70.85 -64.7 -60.2
|
|
53
|
+
6 -6 -69 -67 -65 -62 -57 -52 -46 -40 -33 -39 -30 -24 -17 -7 1 11 17 21 24 36 43.8 50.94 55.40 62.41 68.1 72.9
|
|
54
|
+
7 0 70 70 71 72 73 73 74 74 74 70 65 65 67 75 72 71 72 74 77 77 79.0 79.88 80.44 81.29 80.6 79.9
|
|
55
|
+
7 1 -55 -54 -54 -54 -54 -54 -54 -53 -53 -40 -55 -56 -56 -57 -57 -56 -59 -62 -64 -72 -74.0 -74.46 -75.00 -75.99 -76.7 -77.4
|
|
56
|
+
7 -1 -45 -46 -47 -48 -49 -50 -51 -52 -52 -45 -35 -50 -55 -61 -70 -77 -82 -83 -80 -69 -64.6 -61.14 -57.80 -54.27 -51.5 -48.4
|
|
57
|
+
7 2 0 0 1 2 2 3 4 4 4 0 2 2 5 4 1 1 2 3 2 1 0.0 -1.65 -4.55 -6.79 -8.2 -8.4
|
|
58
|
+
7 -2 -13 -14 -14 -14 -14 -14 -15 -17 -18 -18 -17 -24 -28 -27 -27 -26 -27 -27 -26 -25 -24.2 -22.57 -21.20 -19.53 -16.9 -14.0
|
|
59
|
+
7 3 34 33 32 31 29 27 25 23 20 0 1 10 15 13 14 16 21 24 26 28 33.3 38.73 45.24 51.82 56.5 59.9
|
|
60
|
+
7 -3 -10 -11 -12 -12 -13 -14 -14 -14 -14 2 0 -4 -6 -2 -4 -5 -5 -2 0 4 6.2 6.82 6.54 5.59 2.2 -1.5
|
|
61
|
+
7 4 -41 -41 -40 -38 -37 -35 -34 -33 -31 -29 -40 -32 -32 -26 -22 -14 -12 -6 -1 5 9.1 12.30 14.00 15.07 15.8 16.2
|
|
62
|
+
7 -4 -1 0 1 2 4 5 6 7 7 6 10 8 7 6 8 10 16 20 21 24 24.0 25.35 24.96 24.45 23.5 22.3
|
|
63
|
+
7 5 -21 -20 -19 -18 -16 -14 -12 -11 -9 -10 -7 -11 -7 -6 -2 0 1 4 5 4 6.9 9.37 10.46 9.32 6.4 3.7
|
|
64
|
+
7 -5 28 28 28 28 28 29 29 29 29 28 36 28 23 26 23 22 18 17 17 17 14.8 10.93 7.03 3.27 -2.2 -7.7
|
|
65
|
+
7 6 18 18 18 19 19 19 18 18 17 15 5 9 17 13 13 12 11 10 9 8 7.3 5.42 1.64 -2.88 -7.2 -11.0
|
|
66
|
+
7 -6 -12 -12 -13 -15 -16 -17 -18 -19 -20 -17 -18 -20 -18 -23 -23 -23 -23 -23 -23 -24 -25.4 -26.32 -27.61 -27.50 -27.2 -26.5
|
|
67
|
+
7 7 6 6 6 6 6 6 6 6 5 29 19 18 8 1 -2 -5 -2 0 0 -2 -1.2 1.94 4.92 6.61 9.8 13.6
|
|
68
|
+
7 -7 -22 -22 -22 -22 -22 -21 -20 -19 -19 -22 -16 -18 -17 -12 -11 -12 -10 -7 -4 -6 -5.8 -4.64 -3.28 -2.32 -1.8 -0.3
|
|
69
|
+
8 0 11 11 11 11 11 11 11 11 11 13 22 11 15 13 14 14 18 21 23 25 24.4 24.80 24.41 23.98 23.7 23.6
|
|
70
|
+
8 1 8 8 8 8 7 7 7 7 7 7 15 9 6 5 6 6 6 6 5 6 6.6 7.62 8.21 8.89 9.7 10.4
|
|
71
|
+
8 -1 8 8 8 8 8 8 8 8 8 12 5 10 11 7 7 6 7 8 10 11 11.9 11.20 10.84 10.04 8.4 7.2
|
|
72
|
+
8 2 -4 -4 -4 -4 -3 -3 -3 -3 -3 -8 -4 -6 -4 -4 -2 -1 0 0 -1 -6 -9.2 -11.73 -14.50 -16.78 -17.6 -17.8
|
|
73
|
+
8 -2 -14 -15 -15 -15 -15 -15 -15 -15 -14 -21 -22 -15 -14 -12 -15 -16 -18 -19 -19 -21 -21.5 -20.88 -20.03 -18.26 -15.3 -12.3
|
|
74
|
+
8 3 -9 -9 -9 -9 -9 -9 -9 -9 -10 -5 -1 -14 -11 -14 -13 -12 -11 -11 -10 -9 -7.9 -6.88 -5.59 -3.16 -0.5 1.7
|
|
75
|
+
8 -3 7 7 6 6 6 6 5 5 5 -12 0 5 7 9 6 4 4 5 6 8 8.5 9.83 11.83 13.18 12.8 12.0
|
|
76
|
+
8 4 1 1 1 2 2 2 2 1 1 9 11 6 2 0 -3 -8 -7 -9 -12 -14 -16.6 -18.11 -19.34 -20.56 -21.1 -21.4
|
|
77
|
+
8 -4 -13 -13 -13 -13 -14 -14 -14 -15 -15 -7 -21 -23 -18 -16 -17 -19 -22 -23 -22 -23 -21.5 -19.71 -17.41 -14.60 -11.7 -9.1
|
|
78
|
+
8 5 2 2 2 3 4 4 5 6 6 7 15 10 10 8 5 4 4 4 3 9 9.1 10.17 11.61 13.33 15.3 17.4
|
|
79
|
+
8 -5 5 5 5 5 5 5 5 5 5 2 -8 3 4 4 6 6 9 11 12 15 15.5 16.22 16.71 16.16 14.9 13.5
|
|
80
|
+
8 6 -9 -8 -8 -8 -7 -7 -6 -6 -5 -10 -13 -7 -5 -1 0 0 3 4 4 6 7.0 9.36 10.85 11.76 13.7 15.2
|
|
81
|
+
8 -6 16 16 16 16 17 17 18 18 19 18 17 23 23 24 21 18 16 14 12 11 8.9 7.61 6.96 5.69 3.6 1.4
|
|
82
|
+
8 7 5 5 5 6 6 7 8 8 9 7 5 6 10 11 11 10 6 4 2 -5 -7.9 -11.25 -14.05 -15.98 -16.5 -16.9
|
|
83
|
+
8 -7 -5 -5 -5 -5 -5 -5 -5 -5 -5 3 -4 -4 1 -3 -6 -10 -13 -15 -16 -16 -14.9 -12.76 -10.74 -9.10 -6.9 -4.4
|
|
84
|
+
8 8 8 8 8 8 8 8 8 7 7 2 -1 9 8 4 3 1 -1 -4 -6 -7 -7.0 -4.87 -3.54 -2.02 -0.3 1.6
|
|
85
|
+
8 -8 -18 -18 -18 -18 -19 -19 -19 -19 -19 -11 -17 -13 -20 -17 -16 -17 -15 -11 -10 -4 -2.1 -0.06 1.64 2.26 2.8 3.0
|
|
86
|
+
9 0 8 8 8 8 8 8 8 8 8 5 3 4 4 8 8 7 5 5 4 4 5.0 5.58 5.50 5.33 5.0 5.0
|
|
87
|
+
9 1 10 10 10 10 10 10 10 10 10 -21 -7 9 6 10 10 10 10 10 9 9 9.4 9.76 9.45 8.83 8.4 8.4
|
|
88
|
+
9 -1 -20 -20 -20 -20 -20 -20 -20 -20 -21 -27 -24 -11 -18 -22 -21 -21 -21 -21 -20 -20 -19.7 -20.11 -20.54 -21.77 -23.4 -23.4
|
|
89
|
+
9 2 1 1 1 1 1 1 1 1 1 1 -1 -4 0 2 2 2 1 1 1 3 3.0 3.58 3.45 3.02 2.9 2.9
|
|
90
|
+
9 -2 14 14 14 14 14 14 14 15 15 17 19 12 12 15 16 16 16 15 15 15 13.4 12.69 11.51 10.76 11.0 11.0
|
|
91
|
+
9 3 -11 -11 -11 -11 -11 -11 -12 -12 -12 -11 -25 -5 -9 -13 -12 -12 -12 -12 -12 -10 -8.4 -6.94 -5.27 -3.22 -1.5 -1.5
|
|
92
|
+
9 -3 5 5 5 5 5 5 5 5 5 29 12 7 2 7 6 7 9 9 11 12 12.5 12.67 12.75 11.74 9.8 9.8
|
|
93
|
+
9 4 12 12 12 12 12 12 12 11 11 3 10 2 1 10 10 10 9 9 9 8 6.3 5.01 3.13 0.67 -1.1 -1.1
|
|
94
|
+
9 -4 -3 -3 -3 -3 -3 -3 -3 -3 -3 -9 2 6 0 -4 -4 -4 -5 -6 -7 -6 -6.2 -6.72 -7.14 -6.74 -5.1 -5.1
|
|
95
|
+
9 5 1 1 1 1 1 1 1 1 1 16 5 4 4 -1 -1 -1 -3 -3 -4 -8 -8.9 -10.76 -12.38 -13.20 -13.2 -13.2
|
|
96
|
+
9 -5 -2 -2 -2 -2 -2 -2 -2 -3 -3 4 2 -2 -3 -5 -5 -5 -6 -6 -7 -8 -8.4 -8.16 -7.42 -6.88 -6.3 -6.3
|
|
97
|
+
9 6 -2 -2 -2 -2 -2 -2 -2 -2 -2 -3 -5 1 -1 -1 0 -1 -1 -1 -2 -1 -1.5 -1.25 -0.76 -0.10 1.1 1.1
|
|
98
|
+
9 -6 8 8 8 8 9 9 9 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 0 0 0 0 0 0 0 0 0 0 0 0 -0.2 -0.22 -0.25 -0.30 -0.4 -0.4
|
|
197
|
+
13 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.0 -0.10 -0.26 -0.35 -0.5 -0.5
|
|
198
|
+
13 -12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.5 -0.57 -0.53 -0.43 -0.3 -0.3
|
|
199
|
+
13 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.1 -0.18 -0.26 -0.36 -0.4 -0.4
|
|
200
|
+
13 -13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -0.9 -0.82 -0.79 -0.71 -0.6 -0.6
|
ppigrf/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .ppigrf import igrf, igrf_gc, get_inclination_declination
|
ppigrf/ppigrf.py
ADDED
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
"""
|
|
2
|
+
MIT License
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2021 Karl M. Laundal
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
Pure Python implementation of IGRF.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
Example usage:
|
|
29
|
+
--------------
|
|
30
|
+
import numpy as np
|
|
31
|
+
from datetime import datetime
|
|
32
|
+
import ppigrf
|
|
33
|
+
|
|
34
|
+
# GEODETIC
|
|
35
|
+
lon = 5.32415 # degrees east
|
|
36
|
+
lat = 60.39299 # degrees north
|
|
37
|
+
h = 0 # kilometers above sea level
|
|
38
|
+
date = datetime(2021, 3, 28)
|
|
39
|
+
Be, Bn, Bu = ppigrf.igrf(lon, lat, h, date) # returns east, north, up
|
|
40
|
+
|
|
41
|
+
# GEOCENTRIC
|
|
42
|
+
r = 6500 # kilometers from center of Earht
|
|
43
|
+
theta = 30 # colatitude in degrees
|
|
44
|
+
phi = 4 # degrees east (same as lon)
|
|
45
|
+
Br, Btheta, Bphi = ppigrf.igrf_gc(r, theta, phi, date) # returns radial, south, east
|
|
46
|
+
|
|
47
|
+
# GRID
|
|
48
|
+
lon = np.array([20, 120, 220])
|
|
49
|
+
lat = np.array([[60, 60, 60], [-60, -60, -60]])
|
|
50
|
+
h = 0
|
|
51
|
+
dates = [datetime(y, 1, 1) for y in np.arange(1960, 2021, 20)]
|
|
52
|
+
Be, Bn, Bu = ppigrf.igrf(lon, lat, h, dates)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
This script contains all code needed to calculate IGRF model values.
|
|
57
|
+
Here is a list of functions:
|
|
58
|
+
|
|
59
|
+
Helper functions
|
|
60
|
+
----------------
|
|
61
|
+
is_leapyear - Check if year is leapyear
|
|
62
|
+
yearfrac_to_datetime - Convert fraction of year to datetime
|
|
63
|
+
get_legendre - Calculate Legendre functions
|
|
64
|
+
read_shc - Read spherical harmonic coefficient file
|
|
65
|
+
geod2geoc - Convert from geodetic to geocentric coordinates
|
|
66
|
+
geoc2geod - Convert from geocentric to geodetic coordinates
|
|
67
|
+
|
|
68
|
+
Main functions
|
|
69
|
+
--------------
|
|
70
|
+
igrf_gc - Calculate IGRF model values (geocentric input/output)
|
|
71
|
+
igrf - Calculate IGRF model values (geodetic input/output)
|
|
72
|
+
|
|
73
|
+
"""
|
|
74
|
+
|
|
75
|
+
import numpy as np
|
|
76
|
+
import pandas as pd
|
|
77
|
+
import os
|
|
78
|
+
|
|
79
|
+
basepath = os.path.dirname(__file__)
|
|
80
|
+
shc_fn = basepath + '/IGRF13.shc' # Default shc file
|
|
81
|
+
|
|
82
|
+
# Geomagnetic reference radius:
|
|
83
|
+
RE = 6371.2 # km
|
|
84
|
+
|
|
85
|
+
# World Geodetic System 84 parameters:
|
|
86
|
+
WGS84_e2 = 0.00669437999014
|
|
87
|
+
WGS84_a = 6378.137 # km
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def is_leapyear(year):
|
|
92
|
+
""" Check for leapyear (handles arrays and preserves shape)
|
|
93
|
+
|
|
94
|
+
"""
|
|
95
|
+
|
|
96
|
+
# if array:
|
|
97
|
+
if type(year) is np.ndarray:
|
|
98
|
+
out = np.full_like(year, False, dtype = bool)
|
|
99
|
+
|
|
100
|
+
out[ year % 4 == 0] = True
|
|
101
|
+
out[ year % 100 == 0] = False
|
|
102
|
+
out[ year % 400 == 0] = True
|
|
103
|
+
|
|
104
|
+
return out
|
|
105
|
+
|
|
106
|
+
# if scalar:
|
|
107
|
+
if year % 400 == 0:
|
|
108
|
+
return True
|
|
109
|
+
|
|
110
|
+
if year % 100 == 0:
|
|
111
|
+
return False
|
|
112
|
+
|
|
113
|
+
if year % 4 == 0:
|
|
114
|
+
return True
|
|
115
|
+
|
|
116
|
+
else:
|
|
117
|
+
return False
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def yearfrac_to_datetime(fracyear):
|
|
121
|
+
"""
|
|
122
|
+
Convert fraction of year to datetime
|
|
123
|
+
|
|
124
|
+
Parameters
|
|
125
|
+
----------
|
|
126
|
+
fracyear : iterable
|
|
127
|
+
Date(s) in decimal year. E.g., 2021-03-28 is 2021.2377
|
|
128
|
+
Must be an array, list or similar.
|
|
129
|
+
|
|
130
|
+
Returns
|
|
131
|
+
-------
|
|
132
|
+
datetimes : array
|
|
133
|
+
Array of datetimes
|
|
134
|
+
"""
|
|
135
|
+
|
|
136
|
+
year = np.uint16(fracyear) # truncate fracyear to get year
|
|
137
|
+
# use pandas to_timedelta to represent time since beginning of year:
|
|
138
|
+
delta_year = pd.to_timedelta((fracyear - year)*(365 + is_leapyear(year)), unit = 'D')
|
|
139
|
+
# and DatetimeIndex to represent beginning of years:
|
|
140
|
+
start_year = pd.DatetimeIndex(list(map(str, year)))
|
|
141
|
+
|
|
142
|
+
# adding them produces the datetime:
|
|
143
|
+
return (start_year + delta_year).to_pydatetime()
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def get_legendre(theta, keys):
|
|
147
|
+
"""
|
|
148
|
+
Calculate Schmidt semi-normalized associated Legendre functions
|
|
149
|
+
|
|
150
|
+
Calculations based on recursive algorithm found in "Spacecraft Attitude Determination and Control" by James Richard Wertz
|
|
151
|
+
|
|
152
|
+
Parameters
|
|
153
|
+
----------
|
|
154
|
+
theta : array
|
|
155
|
+
Array of colatitudes in degrees
|
|
156
|
+
keys: iterable
|
|
157
|
+
list of spherical harmnoic degree and order, tuple (n, m) for each
|
|
158
|
+
term in the expansion
|
|
159
|
+
|
|
160
|
+
Returns
|
|
161
|
+
-------
|
|
162
|
+
P : array
|
|
163
|
+
Array of Legendre functions, with shape (theta.size, len(keys)).
|
|
164
|
+
dP : array
|
|
165
|
+
Array of dP/dtheta, with shape (theta.size, len(keys))
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
# get maximum N and maximum M:
|
|
169
|
+
n, m = np.array([k for k in keys]).T
|
|
170
|
+
nmax, mmax = np.max(n), np.max(m)
|
|
171
|
+
|
|
172
|
+
theta = theta.flatten()[:, np.newaxis]
|
|
173
|
+
theta_rad = np.radians(theta)
|
|
174
|
+
|
|
175
|
+
P = {}
|
|
176
|
+
dP = {}
|
|
177
|
+
sinth = np.sin(theta_rad)
|
|
178
|
+
costh = np.cos(theta_rad)
|
|
179
|
+
|
|
180
|
+
# Initialize Schmidt normalization
|
|
181
|
+
S = {}
|
|
182
|
+
S[0, 0] = 1.
|
|
183
|
+
|
|
184
|
+
# initialize the functions:
|
|
185
|
+
for n in range(nmax +1):
|
|
186
|
+
for m in range(nmax + 1):
|
|
187
|
+
P[n, m] = np.zeros_like(theta, dtype = np.float64)
|
|
188
|
+
dP[n, m] = np.zeros_like(theta, dtype = np.float64)
|
|
189
|
+
|
|
190
|
+
P[0, 0] = np.ones_like(theta, dtype = np.float64)
|
|
191
|
+
for n in range(1, nmax +1):
|
|
192
|
+
for m in range(0, min([n + 1, mmax + 1])):
|
|
193
|
+
# do the legendre polynomials and derivatives
|
|
194
|
+
if n == m:
|
|
195
|
+
P[n, n] = sinth * P[n - 1, m - 1]
|
|
196
|
+
dP[n, n] = sinth * dP[n - 1, m - 1] + costh * P[n - 1, n - 1]
|
|
197
|
+
else:
|
|
198
|
+
|
|
199
|
+
if n == 1:
|
|
200
|
+
Knm = 0.
|
|
201
|
+
P[n, m] = costh * P[n -1, m]
|
|
202
|
+
dP[n, m] = costh * dP[n - 1, m] - sinth * P[n - 1, m]
|
|
203
|
+
|
|
204
|
+
elif n > 1:
|
|
205
|
+
Knm = ((n - 1)**2 - m**2) / ((2*n - 1)*(2*n - 3))
|
|
206
|
+
P[n, m] = costh * P[n -1, m] - Knm*P[n - 2, m]
|
|
207
|
+
dP[n, m] = costh * dP[n - 1, m] - sinth * P[n - 1, m] - Knm * dP[n - 2, m]
|
|
208
|
+
|
|
209
|
+
# compute Schmidt normalization
|
|
210
|
+
if m == 0:
|
|
211
|
+
S[n, 0] = S[n - 1, 0] * (2.*n - 1)/n
|
|
212
|
+
else:
|
|
213
|
+
S[n, m] = S[n, m - 1] * np.sqrt((n - m + 1)*(int(m == 1) + 1.)/(n + m))
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
# now apply Schmidt normalization
|
|
217
|
+
for n in range(1, nmax + 1):
|
|
218
|
+
for m in range(0, min([n + 1, mmax + 1])):
|
|
219
|
+
P[n, m] *= S[n, m]
|
|
220
|
+
dP[n, m] *= S[n, m]
|
|
221
|
+
|
|
222
|
+
Pmat = np.hstack(tuple(P[key] for key in keys))
|
|
223
|
+
dPmat = np.hstack(tuple(dP[key] for key in keys))
|
|
224
|
+
return Pmat, dPmat
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def read_shc(filename = shc_fn):
|
|
228
|
+
"""
|
|
229
|
+
Read .shc (spherical harmonic coefficient) file
|
|
230
|
+
|
|
231
|
+
The function produces data frames that have time as index and
|
|
232
|
+
spherical harmonic degree and order as columns. In the case of IGRF,
|
|
233
|
+
the times will correspond to the different models 5 years apart
|
|
234
|
+
|
|
235
|
+
Parameters
|
|
236
|
+
----------
|
|
237
|
+
filename : string
|
|
238
|
+
filename of .shc file
|
|
239
|
+
|
|
240
|
+
Returns
|
|
241
|
+
-------
|
|
242
|
+
g : DataFrame
|
|
243
|
+
pandas DataFrame of gauss coefficients for cos terms.
|
|
244
|
+
h : DataFrame
|
|
245
|
+
pandas DataFrame of gauss coefficients for sin terms.
|
|
246
|
+
|
|
247
|
+
Note
|
|
248
|
+
----
|
|
249
|
+
This code has no special treatment of "secular variation" coefficients.
|
|
250
|
+
Instead, the SV coefficients of IGRF should be used to make gauss
|
|
251
|
+
coefficients. This must be done prior to this code (when making the
|
|
252
|
+
.shc file).
|
|
253
|
+
"""
|
|
254
|
+
|
|
255
|
+
header = 2
|
|
256
|
+
coeffdict = {}
|
|
257
|
+
with open(filename, 'r') as f:
|
|
258
|
+
for line in f.readlines():
|
|
259
|
+
|
|
260
|
+
if line.startswith('#'): # this is a header that we don't read
|
|
261
|
+
continue
|
|
262
|
+
|
|
263
|
+
if header == 2: # read parameters (could be skipped...)
|
|
264
|
+
N_MIN, N_MAX, NTIMES, SP_ORDER, N_STEPS = list(map(int, line.split()[:5]))
|
|
265
|
+
header -= 1
|
|
266
|
+
continue
|
|
267
|
+
|
|
268
|
+
if header == 1: # read years
|
|
269
|
+
times = yearfrac_to_datetime(list(map(float, line.split())) )
|
|
270
|
+
header -= 1
|
|
271
|
+
continue
|
|
272
|
+
|
|
273
|
+
key = tuple(map(int, line.split()[:2]))
|
|
274
|
+
coeffdict[key] = np.array(list(map(float, line.split()[2:])))
|
|
275
|
+
|
|
276
|
+
g = {key:coeffdict[key] for key in coeffdict.keys() if key[1] >= 0}
|
|
277
|
+
h = {(key[0], -key[1]):coeffdict[key] for key in coeffdict.keys() if key[1] < 0 }
|
|
278
|
+
for key in [k for k in g.keys() if k[1] == 0]: # add zero coefficients for m = 0 in h dictionary
|
|
279
|
+
h[key] = 0
|
|
280
|
+
|
|
281
|
+
# this must be true:
|
|
282
|
+
assert len(g.keys()) == len(h.keys())
|
|
283
|
+
|
|
284
|
+
gdf = pd.DataFrame(g, index = times)
|
|
285
|
+
hdf = pd.DataFrame(h, index = times)
|
|
286
|
+
|
|
287
|
+
# make sure that the column keys of h are in same order as in g:
|
|
288
|
+
hdf = hdf[gdf.columns]
|
|
289
|
+
|
|
290
|
+
return gdf, hdf
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
def geod2geoc(gdlat, height, Bn, Bu):
|
|
295
|
+
"""
|
|
296
|
+
Convert from geocentric to geodetic coordinates
|
|
297
|
+
|
|
298
|
+
Example:
|
|
299
|
+
--------
|
|
300
|
+
theta, r, B_th, B_r = geod2lat(gdlat, height, Bn, Bu)
|
|
301
|
+
|
|
302
|
+
Parameters
|
|
303
|
+
----------
|
|
304
|
+
gdlat : array
|
|
305
|
+
Geodetic latitude [degrees]
|
|
306
|
+
h : array
|
|
307
|
+
Height above ellipsoid [km]
|
|
308
|
+
Bn : array
|
|
309
|
+
Vector in northward direction, relative to ellipsoid
|
|
310
|
+
Bu : array
|
|
311
|
+
Vector in upward direction, relative to ellipsoid
|
|
312
|
+
|
|
313
|
+
Returns
|
|
314
|
+
-------
|
|
315
|
+
theta : array
|
|
316
|
+
Colatitudes [degrees]
|
|
317
|
+
r : array
|
|
318
|
+
Radius [km]
|
|
319
|
+
B_th : array
|
|
320
|
+
Vector component in theta direction
|
|
321
|
+
B_r : array
|
|
322
|
+
Vector component in radial direction
|
|
323
|
+
"""
|
|
324
|
+
|
|
325
|
+
a = WGS84_a
|
|
326
|
+
b = a*np.sqrt(1 - WGS84_e2)
|
|
327
|
+
|
|
328
|
+
# Convert geodetic latitude angles to radians
|
|
329
|
+
gdlat_rad = np.radians(gdlat)
|
|
330
|
+
|
|
331
|
+
sin_alpha_2 = np.sin(gdlat_rad)**2
|
|
332
|
+
cos_alpha_2 = np.cos(gdlat_rad)**2
|
|
333
|
+
|
|
334
|
+
# calculate geocentric latitude and radius
|
|
335
|
+
tmp = height * np.sqrt(a**2 * cos_alpha_2 + b**2 * sin_alpha_2)
|
|
336
|
+
beta = np.arctan((tmp + b**2)/(tmp + a**2) * np.tan(gdlat_rad))
|
|
337
|
+
theta = np.pi/2 - beta
|
|
338
|
+
r = np.sqrt(height**2 + 2 * tmp + a**2 * (1 - (1 - (b/a)**4) * sin_alpha_2) / (1 - (1 - (b/a)**2) * sin_alpha_2))
|
|
339
|
+
|
|
340
|
+
# calculate geocentric components
|
|
341
|
+
psi = np.sin(gdlat_rad) * np.sin(theta) - np.cos(gdlat_rad) * np.cos(theta)
|
|
342
|
+
|
|
343
|
+
B_r = -np.sin(psi) * Bn + np.cos(psi) * Bu
|
|
344
|
+
B_th = -np.cos(psi) * Bn - np.sin(psi) * Bu
|
|
345
|
+
|
|
346
|
+
# Convert theta to degrees
|
|
347
|
+
theta = np.degrees(theta)
|
|
348
|
+
|
|
349
|
+
return theta, r, B_th, B_r
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def geoc2geod(theta, r, B_th, B_r):
|
|
353
|
+
"""
|
|
354
|
+
Convert from geodetic to geocentric coordinates
|
|
355
|
+
|
|
356
|
+
Based on Matlab code by Nils Olsen, DTU
|
|
357
|
+
|
|
358
|
+
Example:
|
|
359
|
+
--------
|
|
360
|
+
gdlat, height, Bn, Bu = geod2lat(theta, r, B_th, B_r)
|
|
361
|
+
|
|
362
|
+
Parameters
|
|
363
|
+
----------
|
|
364
|
+
theta : array
|
|
365
|
+
Colatitudes [degrees]
|
|
366
|
+
r : array
|
|
367
|
+
Radius [km]
|
|
368
|
+
B_th : array
|
|
369
|
+
Vector component in theta direction
|
|
370
|
+
B_r : array
|
|
371
|
+
Vector component in radial direction
|
|
372
|
+
|
|
373
|
+
Returns
|
|
374
|
+
-------
|
|
375
|
+
gdlat : array
|
|
376
|
+
Geodetic latitude [degrees]
|
|
377
|
+
h : array
|
|
378
|
+
Height above ellipsoid [km]
|
|
379
|
+
Bn : array
|
|
380
|
+
Vector in northward direction, relative to ellipsoid
|
|
381
|
+
Bu : array
|
|
382
|
+
Vector in upward direction, relative to ellipsoid
|
|
383
|
+
"""
|
|
384
|
+
|
|
385
|
+
a = WGS84_a
|
|
386
|
+
b = a*np.sqrt(1 - WGS84_e2)
|
|
387
|
+
|
|
388
|
+
E2 = 1.-(b/a)**2
|
|
389
|
+
E4 = E2*E2
|
|
390
|
+
E6 = E4*E2
|
|
391
|
+
E8 = E4*E4
|
|
392
|
+
OME2REQ = (1.-E2)*a
|
|
393
|
+
A21 = (512.*E2 + 128.*E4 + 60.*E6 + 35.*E8)/1024.
|
|
394
|
+
A22 = ( E6 + E8)/ 32.
|
|
395
|
+
A23 = -3.*( 4.*E6 + 3.*E8)/ 256.
|
|
396
|
+
A41 = -( 64.*E4 + 48.*E6 + 35.*E8)/1024.
|
|
397
|
+
A42 = ( 4.*E4 + 2.*E6 + E8)/ 16.
|
|
398
|
+
A43 = 15.*E8 / 256.
|
|
399
|
+
A44 = -E8 / 16.
|
|
400
|
+
A61 = 3.*( 4.*E6 + 5.*E8)/1024.
|
|
401
|
+
A62 = -3.*( E6 + E8)/ 32.
|
|
402
|
+
A63 = 35.*( 4.*E6 + 3.*E8)/ 768.
|
|
403
|
+
A81 = -5.*E8 /2048.
|
|
404
|
+
A82 = 64.*E8 /2048.
|
|
405
|
+
A83 = -252.*E8 /2048.
|
|
406
|
+
A84 = 320.*E8 /2048.
|
|
407
|
+
|
|
408
|
+
GCLAT = (90-theta)
|
|
409
|
+
SCL = np.sin(np.radians(GCLAT))
|
|
410
|
+
|
|
411
|
+
RI = a/r
|
|
412
|
+
A2 = RI*(A21 + RI * (A22 + RI* A23))
|
|
413
|
+
A4 = RI*(A41 + RI * (A42 + RI*(A43+RI*A44)))
|
|
414
|
+
A6 = RI*(A61 + RI * (A62 + RI* A63))
|
|
415
|
+
A8 = RI*(A81 + RI * (A82 + RI*(A83+RI*A84)))
|
|
416
|
+
|
|
417
|
+
CCL = np.sqrt(1-SCL**2)
|
|
418
|
+
S2CL = 2.*SCL * CCL
|
|
419
|
+
C2CL = 2.*CCL * CCL-1.
|
|
420
|
+
S4CL = 2.*S2CL * C2CL
|
|
421
|
+
C4CL = 2.*C2CL * C2CL-1.
|
|
422
|
+
S8CL = 2.*S4CL * C4CL
|
|
423
|
+
S6CL = S2CL * C4CL + C2CL * S4CL
|
|
424
|
+
|
|
425
|
+
DLTCL = S2CL * A2 + S4CL * A4 + S6CL * A6 + S8CL * A8
|
|
426
|
+
gdlat = DLTCL + np.radians(GCLAT)
|
|
427
|
+
height = r * np.cos(DLTCL)- a * np.sqrt(1 - E2 * np.sin(gdlat) ** 2)
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
# magnetic components
|
|
431
|
+
theta_rad = np.radians(theta)
|
|
432
|
+
psi = np.sin(gdlat) * np.sin(theta_rad) - np.cos(gdlat) * np.cos(theta_rad)
|
|
433
|
+
Bn = -np.cos(psi) * B_th - np.sin(psi) * B_r
|
|
434
|
+
Bu = -np.sin(psi) * B_th + np.cos(psi) * B_r
|
|
435
|
+
|
|
436
|
+
# Convert gdlat to degrees
|
|
437
|
+
gdlat = np.degrees(gdlat)
|
|
438
|
+
|
|
439
|
+
return gdlat, height, Bn, Bu
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def igrf_gc(r, theta, phi, date, coeff_fn = shc_fn):
|
|
444
|
+
"""
|
|
445
|
+
Calculate IGRF model components
|
|
446
|
+
|
|
447
|
+
Input and output in geocentric coordinates
|
|
448
|
+
|
|
449
|
+
Broadcasting rules apply for coordinate arrays, and the
|
|
450
|
+
combined shape will be preserved. The dates are kept out
|
|
451
|
+
of the broadcasting, so that the output will have shape
|
|
452
|
+
(N, ...) where N is the number of dates, and ... represents
|
|
453
|
+
the combined shape of the coordinates. If you pass scalars,
|
|
454
|
+
the output will be arrays of shape (1,)
|
|
455
|
+
|
|
456
|
+
Parameters
|
|
457
|
+
----------
|
|
458
|
+
r : array
|
|
459
|
+
radius [km] of IGRF calculation
|
|
460
|
+
theta : array
|
|
461
|
+
colatitude [deg] of IGRF calculation
|
|
462
|
+
phi : array
|
|
463
|
+
longitude [deg], positive east, of IGRF claculation
|
|
464
|
+
date : date(s)
|
|
465
|
+
one or more dates to evaluate IGRF coefficients
|
|
466
|
+
coeff_fn : string, optional
|
|
467
|
+
filename of .shc file. Default is latest IGRF
|
|
468
|
+
|
|
469
|
+
Return
|
|
470
|
+
------
|
|
471
|
+
Br : array
|
|
472
|
+
Magnetic field [nT] in radial direction
|
|
473
|
+
Btheta : array
|
|
474
|
+
Magnetic field [nT] in theta direction (south on an
|
|
475
|
+
Earth-centered sphere with radius r)
|
|
476
|
+
Bphi : array
|
|
477
|
+
Magnetic field [nT] in eastward direction
|
|
478
|
+
"""
|
|
479
|
+
|
|
480
|
+
# read coefficient file:
|
|
481
|
+
g, h = read_shc(coeff_fn)
|
|
482
|
+
|
|
483
|
+
if not hasattr(date, '__iter__'):
|
|
484
|
+
date = np.array([date])
|
|
485
|
+
else:
|
|
486
|
+
date = np.array(date)
|
|
487
|
+
|
|
488
|
+
if np.any(date > g.index[-1]) or np.any(date < g.index[0]):
|
|
489
|
+
print('Warning: You provided date(s) not covered by coefficient file \n({} to {})'.format(
|
|
490
|
+
g.index[0].date(), g.index[-1].date()))
|
|
491
|
+
|
|
492
|
+
# get coordinate arrays to same size and shape
|
|
493
|
+
r, theta, phi = np.broadcast_arrays(r, theta, phi)
|
|
494
|
+
shape = r.shape
|
|
495
|
+
r, theta, phi = map(lambda x: x.flatten().reshape((-1 ,1)), [r, theta, phi]) # column vectors
|
|
496
|
+
|
|
497
|
+
# make row vectors of wave numbers n and m:
|
|
498
|
+
n, m = np.array([k for k in g.columns]).T
|
|
499
|
+
n, m = n.reshape((1, -1)), m.reshape((1, -1))
|
|
500
|
+
|
|
501
|
+
# get maximum N and maximum M:
|
|
502
|
+
N, M = np.max(n), np.max(m)
|
|
503
|
+
|
|
504
|
+
# get the legendre functions
|
|
505
|
+
P, dP = get_legendre(theta, g.keys())
|
|
506
|
+
|
|
507
|
+
# Append coefficients at desired times (skip if index is already in coefficient data frame):
|
|
508
|
+
index = g.index.union(date)
|
|
509
|
+
|
|
510
|
+
g = g.reindex(index).groupby(index).first() # reindex and skip duplicates
|
|
511
|
+
h = h.reindex(index).groupby(index).first() # reindex and skip duplicates
|
|
512
|
+
|
|
513
|
+
# interpolate and collect the coefficients at desired times:
|
|
514
|
+
g = g.interpolate(method = 'time').loc[date, :]
|
|
515
|
+
h = h.interpolate(method = 'time').loc[date, :]
|
|
516
|
+
|
|
517
|
+
# compute cosmlon and sinmlon:
|
|
518
|
+
phi_rad = np.radians(phi)
|
|
519
|
+
cosmphi = np.cos(phi_rad * m) # shape (n_coords x n_model_params/2)
|
|
520
|
+
sinmphi = np.sin(phi_rad * m)
|
|
521
|
+
|
|
522
|
+
# make versions of n and m that are repeated twice
|
|
523
|
+
nn, mm = np.tile(n, 2), np.tile(m, 2)
|
|
524
|
+
|
|
525
|
+
# calculate Br:
|
|
526
|
+
G = (RE / r) ** (nn + 2) * (nn + 1) * np.hstack((P * cosmphi, P * sinmphi))
|
|
527
|
+
Br = G.dot(np.hstack((g.values, h.values)).T).T # shape (n_times, n_coords)
|
|
528
|
+
|
|
529
|
+
# calculate Btheta:
|
|
530
|
+
G = -(RE / r) ** (nn + 1) * np.hstack((dP * cosmphi, dP * sinmphi)) \
|
|
531
|
+
* RE / r
|
|
532
|
+
Btheta = G.dot(np.hstack((g.values, h.values)).T).T # shape (n_times, n_coords)
|
|
533
|
+
|
|
534
|
+
# calculate Bphi:
|
|
535
|
+
G = -(RE / r) ** (nn + 1) * mm * np.hstack((-P * sinmphi, P * cosmphi)) \
|
|
536
|
+
* RE / r / np.sin(np.radians(theta))
|
|
537
|
+
Bphi = G.dot(np.hstack((g.values, h.values)).T).T # shape (n_times, n_coords)
|
|
538
|
+
|
|
539
|
+
# reshape and return
|
|
540
|
+
outshape = tuple([Bphi.shape[0]] + list(shape))
|
|
541
|
+
return Br.reshape(outshape), Btheta.reshape(outshape), Bphi.reshape(outshape)
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
def igrf(lon, lat, h, date, coeff_fn = shc_fn):
|
|
545
|
+
"""
|
|
546
|
+
Calculate IGRF model components
|
|
547
|
+
|
|
548
|
+
Input and output in geodetic coordinates
|
|
549
|
+
|
|
550
|
+
Broadcasting rules apply for coordinate arrays, and the
|
|
551
|
+
combined shape will be preserved. The dates are kept out
|
|
552
|
+
of the broadcasting, so that the output will have shape
|
|
553
|
+
(N, ...) where N is the number of dates, and ... represents
|
|
554
|
+
the combined shape of the coordinates. If you pass scalars,
|
|
555
|
+
the output will be arrays of shape (1,)
|
|
556
|
+
|
|
557
|
+
Parameters
|
|
558
|
+
----------
|
|
559
|
+
lon : array
|
|
560
|
+
longitude [deg], postiive east, of IGRF calculation
|
|
561
|
+
lat : array
|
|
562
|
+
geodetic latitude [deg] of IGRF calculation
|
|
563
|
+
h : array
|
|
564
|
+
height [km] above ellipsoid for IGRF calculation
|
|
565
|
+
date : date(s)
|
|
566
|
+
one or more dates to evaluate IGRF coefficients
|
|
567
|
+
coeff_fn : string, optional
|
|
568
|
+
filename of .shc file. Default is latest IGRF
|
|
569
|
+
|
|
570
|
+
Return
|
|
571
|
+
------
|
|
572
|
+
Be : array
|
|
573
|
+
Magnetic field [nT] in eastward direction
|
|
574
|
+
Bn : array
|
|
575
|
+
Magnetic field [nT] in northward direction, relative to
|
|
576
|
+
ellipsoid
|
|
577
|
+
Bu : array
|
|
578
|
+
Magnetic field [nT] in upward direction, relative to
|
|
579
|
+
ellipsoid
|
|
580
|
+
"""
|
|
581
|
+
|
|
582
|
+
# convert input to arrays and cast to same shape:
|
|
583
|
+
lon, lat, h = np.broadcast_arrays(lon, lat, h)
|
|
584
|
+
shape = lon.shape
|
|
585
|
+
lon, lat, h = map(lambda x: x.flatten(), [lon, lat, h])
|
|
586
|
+
|
|
587
|
+
# convert to geocentric:
|
|
588
|
+
theta, r, _, __ = geod2geoc(lat, h, h, h)
|
|
589
|
+
phi = lon
|
|
590
|
+
|
|
591
|
+
# calculate geocentric components of IGRF:
|
|
592
|
+
Br, Btheta, Bphi = igrf_gc(r, theta, phi, date, coeff_fn = coeff_fn)
|
|
593
|
+
Be = Bphi
|
|
594
|
+
|
|
595
|
+
# convert output to geodetic
|
|
596
|
+
lat_, h_, Bn, Bu = geoc2geod(theta, r, Btheta, Br)
|
|
597
|
+
|
|
598
|
+
# return with shapes implied by input
|
|
599
|
+
outshape = tuple([Be.shape[0]] + list(shape))
|
|
600
|
+
return Be.reshape(outshape), Bn.reshape(outshape), Bu.reshape(outshape)
|
|
601
|
+
|
|
602
|
+
|
|
603
|
+
def igrf_V(r, theta, phi, date, coeff_fn = shc_fn):
|
|
604
|
+
"""
|
|
605
|
+
Calculate IGRF magnetic potential
|
|
606
|
+
|
|
607
|
+
Input and output in geocentric coordinates
|
|
608
|
+
|
|
609
|
+
Broadcasting rules apply for coordinate arrays, and the
|
|
610
|
+
combined shape will be preserved. The dates are kept out
|
|
611
|
+
of the broadcasting, so that the output will have shape
|
|
612
|
+
(N, ...) where N is the number of dates, and ... represents
|
|
613
|
+
the combined shape of the coordinates. If you pass scalars,
|
|
614
|
+
the output will be arrays of shape (1,)
|
|
615
|
+
|
|
616
|
+
Parameters
|
|
617
|
+
----------
|
|
618
|
+
r : array
|
|
619
|
+
radius [km] of IGRF calculation
|
|
620
|
+
theta : array
|
|
621
|
+
colatitude [deg] of IGRF calculation
|
|
622
|
+
phi : array
|
|
623
|
+
longitude [deg], positive east, of IGRF claculation
|
|
624
|
+
date : date(s)
|
|
625
|
+
one or more dates to evaluate IGRF coefficients
|
|
626
|
+
coeff_fn : string, optional
|
|
627
|
+
filename of .shc file. Default is latest IGRF
|
|
628
|
+
|
|
629
|
+
Return
|
|
630
|
+
------
|
|
631
|
+
V : array
|
|
632
|
+
Magnetic potential (unit nT * km)
|
|
633
|
+
"""
|
|
634
|
+
|
|
635
|
+
# read coefficient file:
|
|
636
|
+
g, h = read_shc(coeff_fn)
|
|
637
|
+
|
|
638
|
+
if not hasattr(date, '__iter__'):
|
|
639
|
+
date = np.array([date])
|
|
640
|
+
else:
|
|
641
|
+
date = np.array(date)
|
|
642
|
+
|
|
643
|
+
if np.any(date > g.index[-1]) or np.any(date < g.index[0]):
|
|
644
|
+
print('Warning: You provided date(s) not covered by coefficient file \n({} to {})'.format(
|
|
645
|
+
g.index[0].date(), g.index[-1].date()))
|
|
646
|
+
|
|
647
|
+
# convert input to arrays in case they aren't
|
|
648
|
+
r, theta, phi = np.broadcast_arrays(r, theta, phi)
|
|
649
|
+
shape = r.shape
|
|
650
|
+
r, theta, phi = map(lambda x: x.flatten().reshape((-1 ,1)), [r, theta, phi]) # column vectors
|
|
651
|
+
|
|
652
|
+
# make row vectors of wave numbers n and m:
|
|
653
|
+
n, m = np.array([k for k in g.columns]).T
|
|
654
|
+
n, m = n.reshape((1, -1)), m.reshape((1, -1))
|
|
655
|
+
|
|
656
|
+
# get maximum N and maximum M:
|
|
657
|
+
N, M = np.max(n), np.max(m)
|
|
658
|
+
|
|
659
|
+
# get the legendre functions
|
|
660
|
+
P, dP = get_legendre(theta, g.keys())
|
|
661
|
+
|
|
662
|
+
# Append coefficients at desired times (skip if index is already in coefficient data frame):
|
|
663
|
+
index = g.index.union(date)
|
|
664
|
+
|
|
665
|
+
g = g.reindex(index).groupby(index).first() # reindex and skip duplicates
|
|
666
|
+
h = h.reindex(index).groupby(index).first() # reindex and skip duplicates
|
|
667
|
+
|
|
668
|
+
# interpolate and collect the coefficients at desired times:
|
|
669
|
+
g = g.interpolate(method = 'time').loc[date, :]
|
|
670
|
+
h = h.interpolate(method = 'time').loc[date, :]
|
|
671
|
+
|
|
672
|
+
# compute cosmlon and sinmlon:
|
|
673
|
+
cosmphi = np.cos(np.deg2rad(phi * m)) # shape (n_coords x n_model_params/2)
|
|
674
|
+
sinmphi = np.sin(np.deg2rad(phi * m))
|
|
675
|
+
|
|
676
|
+
# make versions of n and m that are repeated twice
|
|
677
|
+
nn, mm = np.tile(n, 2), np.tile(m, 2)
|
|
678
|
+
|
|
679
|
+
# calculate Br:
|
|
680
|
+
G = RE * (RE / r) ** (nn + 1) * np.hstack((P * cosmphi, P * sinmphi))
|
|
681
|
+
V = G.dot(np.hstack((g.values, h.values)).T).T # shape (n_times, n_coords)
|
|
682
|
+
|
|
683
|
+
# reshape and return
|
|
684
|
+
outshape = tuple([V.shape[0]] + list(shape))
|
|
685
|
+
return V.reshape(outshape)
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
def get_inclination_declination(Be, Bn, Bu, degrees=True):
|
|
689
|
+
r"""
|
|
690
|
+
Compute the inclination and declination angles of the IGRF
|
|
691
|
+
|
|
692
|
+
The inclination angle is defined as the angle between the magnetic field
|
|
693
|
+
vector and the horizontal plane:
|
|
694
|
+
|
|
695
|
+
.. math::
|
|
696
|
+
|
|
697
|
+
I = \arctan \frac{-B_u}{\sqrt{B_e^2 + B_n^2}}
|
|
698
|
+
|
|
699
|
+
And the declination angle is defined as the azimuth of the projection of
|
|
700
|
+
the magnetic field vector onto the horizontal plane (starting from the
|
|
701
|
+
northing direction, positive to the east and negative to the west):
|
|
702
|
+
|
|
703
|
+
.. math::
|
|
704
|
+
|
|
705
|
+
D = \arcsin \frac{B_e}{\sqrt{B_e^2 + B_n^2}}
|
|
706
|
+
|
|
707
|
+
Parameters
|
|
708
|
+
----------
|
|
709
|
+
Be : float or array
|
|
710
|
+
Easting component of the IGRF magnetic vector.
|
|
711
|
+
Bn : float or array
|
|
712
|
+
Northing component of the IGRF magnetic vector.
|
|
713
|
+
Bu : float or array
|
|
714
|
+
Upward component of the IGRF magnetic vector.
|
|
715
|
+
degrees : bool (optional)
|
|
716
|
+
If True, the angles are returned in degrees.
|
|
717
|
+
If False, the angles are returned in radians.
|
|
718
|
+
Default True.
|
|
719
|
+
|
|
720
|
+
Returns
|
|
721
|
+
-------
|
|
722
|
+
inclination : float or array
|
|
723
|
+
Inclination angle of the IGRF magnetic vector. If ``degrees`` is True,
|
|
724
|
+
then the angle is returned in degrees. If ``degrees`` is False, then
|
|
725
|
+
it's returned in radians.
|
|
726
|
+
declination : float or array
|
|
727
|
+
Declination angle of the IGRF magnetic vector. If ``degrees`` is True,
|
|
728
|
+
then the angle is returned in degrees. If ``degrees`` is False, then
|
|
729
|
+
it's returned in radians.
|
|
730
|
+
"""
|
|
731
|
+
# Compute the horizontal component of B
|
|
732
|
+
horizontal_component = np.sqrt(Be**2 + Bn**2)
|
|
733
|
+
if horizontal_component == 0:
|
|
734
|
+
inclination = -np.sign(Bu) * np.pi /2
|
|
735
|
+
declination = 0
|
|
736
|
+
else:
|
|
737
|
+
# Compute the two angles
|
|
738
|
+
inclination = np.arctan(-Bu / horizontal_component)
|
|
739
|
+
declination = np.arcsin(Be / horizontal_component)
|
|
740
|
+
# Convert to degrees if needed
|
|
741
|
+
if degrees:
|
|
742
|
+
inclination = np.degrees(inclination)
|
|
743
|
+
declination = np.degrees(declination)
|
|
744
|
+
return inclination, declination
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
if __name__ == '__main__':
|
|
748
|
+
|
|
749
|
+
from datetime import datetime
|
|
750
|
+
|
|
751
|
+
# GEODETIC
|
|
752
|
+
lon = 5.32415 # degrees east
|
|
753
|
+
lat = 60.39299 # degrees north
|
|
754
|
+
h = 0 # kilometers above sea level
|
|
755
|
+
date = datetime(2021, 3, 28)
|
|
756
|
+
Be, Bn, Bu = igrf(lon, lat, h, date) # returns east, north, up
|
|
757
|
+
|
|
758
|
+
# GEOCENTRIC
|
|
759
|
+
r = 6500 # kilometers from center of Earht
|
|
760
|
+
theta = 30 # colatitude in degrees
|
|
761
|
+
phi = 4 # degrees east (same as lon)
|
|
762
|
+
Br, Btheta, Bphi = igrf_gc(r, theta, phi, date) # returns radial, south, east
|
|
763
|
+
|
|
764
|
+
# GRID
|
|
765
|
+
lon = np.array([20, 120, 220])
|
|
766
|
+
lat = np.array([[60, 60, 60], [-60, -60, -60]])
|
|
767
|
+
h = 0
|
|
768
|
+
dates = [datetime(y, 1, 1) for y in np.arange(1960, 2021, 20)]
|
|
769
|
+
Be, Bn, Bu = igrf(lon, lat, h, dates)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Karl M. Laundal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ppigrf
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Pure Python IGRF
|
|
5
|
+
Author: Karl Laundal
|
|
6
|
+
Author-email: readme@file.md
|
|
7
|
+
Classifier: Development Status :: 4 - Beta
|
|
8
|
+
Classifier: Intended Audience :: Science/Research
|
|
9
|
+
Classifier: Natural Language :: English
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: numpy >=0.13.1
|
|
15
|
+
Requires-Dist: pandas >=1.3.5
|
|
16
|
+
|
|
17
|
+
# Pure Python International Geomagnetic Reference Field
|
|
18
|
+
[](https://zenodo.org/badge/latestdoi/352365168)
|
|
19
|
+
|
|
20
|
+
Pure Python code to calculate IGRF model predictions. The IGRF is a model of the Earth's main magnetic field that is updated every 5 years.
|
|
21
|
+
See https://www.ngdc.noaa.gov/IAGA/vmod/igrf.html for details and https://doi.org/10.1186/s40623-020-01163-9 for even more details.
|
|
22
|
+
|
|
23
|
+
The code is vectorized, so calculations should be pretty fast.
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
The only dependencies are Numpy and Pandas. Install by either
|
|
28
|
+
```
|
|
29
|
+
pip install ppigrf
|
|
30
|
+
```
|
|
31
|
+
or clone the repository and run
|
|
32
|
+
```
|
|
33
|
+
python setup.py install
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Also, if you don't want to install a module but use the code in your project, just grap ppigrf.py and the .shc file (from src/ppigrf) and place it in your working directory. That's all.
|
|
37
|
+
|
|
38
|
+
## Example
|
|
39
|
+
All the above choices should enable you to import like this:
|
|
40
|
+
```python
|
|
41
|
+
import ppigrf
|
|
42
|
+
```
|
|
43
|
+
IGRF model values depend on time and position. Time can be given as one or more datetimes. The position can be specified in either geodetic or geocentric coordinates. Example with geodetic coordinates:
|
|
44
|
+
```python
|
|
45
|
+
from datetime import datetime
|
|
46
|
+
lon = 5.32415 # degrees east
|
|
47
|
+
lat = 60.39299 # degrees north
|
|
48
|
+
h = 0 # kilometers above sea level
|
|
49
|
+
date = datetime(2021, 3, 28)
|
|
50
|
+
|
|
51
|
+
Be, Bn, Bu = ppigrf.igrf(lon, lat, h, date) # returns east, north, up
|
|
52
|
+
```
|
|
53
|
+
Geodetic coordinates take the ellipsoidal shape of the Earth into account. The northward component returned by the igrf function is tangential to the ellipsoid, and in general not tangential to an Earth centered sphere. The upward component is perpendicular to the ellipsoid, and in general not perpendicular to the sphere.
|
|
54
|
+
|
|
55
|
+
In some cases it is more convenient to work in geocentric coordinates, which are purely spherical. To do that, use the igrf_gc function:
|
|
56
|
+
```python
|
|
57
|
+
r = 6500 # kilometers from center of Earht
|
|
58
|
+
theta = 30 # colatitude in degrees
|
|
59
|
+
phi = 4 # degrees east (same as lon)
|
|
60
|
+
|
|
61
|
+
Br, Btheta, Bphi = ppigrf.igrf_gc(r, theta, phi, date) # returns radial, south, east
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
It is also possible to calculate magnetic field values on a grid. The code uses broadcasting rules for the coordinate inputs. You can also pass multiple dates. If you pass `K` time stamps, together with coordinates with a combined shape of e.g., `(L, M, N)`, the output will have shape `(K, L, M, N)`. Example:
|
|
65
|
+
```python
|
|
66
|
+
lon = np.array([20, 120, 220])
|
|
67
|
+
lat = np.array([[60, 60, 60], [-60, -60, -60]])
|
|
68
|
+
h = 0
|
|
69
|
+
dates = [datetime(y, 1, 1) for y in np.arange(1960, 2021, 20)]
|
|
70
|
+
Be, Bn, Bu = ppigrf.igrf(lon, lat, h, dates)
|
|
71
|
+
```
|
|
72
|
+
The output will have shape `(4, 2, 3)`.
|
|
73
|
+
|
|
74
|
+
## How to test?
|
|
75
|
+
|
|
76
|
+
It is possible to run some tests that corroborates that `ppigrf` works as
|
|
77
|
+
expected. To do so you need to install [`pytest`](https://docs.pytest.org). You
|
|
78
|
+
can do so through `pip`:
|
|
79
|
+
|
|
80
|
+
```
|
|
81
|
+
pip install pytest
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Then you need to clone this repository and install `ppigrf`:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
python setup.py install
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Finally you can test the installed version of `ppigrf` with:
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
pytest -v
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## Why?
|
|
98
|
+
There are lots of Python modules that can calculate IGRF values. Most are wrappers of Fortran code, which can be tricky to compile. This version is pure Python. For most applications it is still quite fast. I also prefer the ppigrf interface over the alternatives.
|
|
99
|
+
|
|
100
|
+
The code is also super portable: Just copy ppigrf.py and the .shc file to your project and you're done.
|
|
101
|
+
|
|
102
|
+
## Notes
|
|
103
|
+
The model coefficients are read from an .shc file. This is a file format that is used for certain spherical harmonic magnetic field models. See a selection of .shc model files here:
|
|
104
|
+
https://github.com/ESA-VirES/MagneticModel/blob/staging/eoxmagmod/eoxmagmod/data/
|
|
105
|
+
|
|
106
|
+
It should be straightforward to swap the IGRF .shc file with another model, but keep in mind that the time dependence may be implemented differently in other models. IGRF, and this code, uses linear interpolation between model updates, and changing the model file will not change the ppigrf interpolation setup.
|
|
107
|
+
|
|
108
|
+
The code is vectorized, so it will be quite fast, but probably not as fast as compiled Fortran code. One application which may require more optimization is field line tracing: In the current implementation, the coefficients are loaded and interpolated in time for every function call, which gives a lot of unnecessary overhead.
|
|
109
|
+
|
|
110
|
+
Thanks to Juha Vierinen for the setup script, and for making ppigrf available via PyPI.
|
|
111
|
+
|
|
112
|
+
## Contact
|
|
113
|
+
If you find errors, please let me know!
|
|
114
|
+
|
|
115
|
+
You don't need permission to copy or use this code, but I would be happy to know if it is useful for anyone else.
|
|
116
|
+
|
|
117
|
+
karl.laundal at uib.no
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
ppigrf/IGRF13.shc,sha256=NXU2FSu29yztPriG3vhPkaWSUSRlw2fKWre9pMNsNSI,40160
|
|
2
|
+
ppigrf/__init__.py,sha256=e0wyc42KAAkE8QlDfMmkLlBlkLL8OOk36lOoTmcl8L8,63
|
|
3
|
+
ppigrf/ppigrf.py,sha256=cG0aLieYWAh1bfrlHZ_GpXAhDipWeph2ZA1JQePSZrg,24193
|
|
4
|
+
ppigrf-1.0.0.dist-info/LICENSE,sha256=y6VnzUe8aX9XTY55HLsmjaQrnILQnWWoHDJ3lwVyvcc,1072
|
|
5
|
+
ppigrf-1.0.0.dist-info/METADATA,sha256=yw8aluqLeY5T_3kJbLJaliY8TKSEmzDX3Co5f9w-p3o,5081
|
|
6
|
+
ppigrf-1.0.0.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
|
7
|
+
ppigrf-1.0.0.dist-info/top_level.txt,sha256=w8RyBzIe6uNefRw2rbMacU5lUHNCZV2P1G0p5dKy7ec,7
|
|
8
|
+
ppigrf-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ppigrf
|