ppigrf 2.0.0__tar.gz → 2.1.0__tar.gz

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.
@@ -1,18 +1,48 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: ppigrf
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Pure Python IGRF
5
5
  Author: Karl Laundal
6
- Author-email: readme@file.md
7
- Classifier: Development Status :: 4 - Beta
6
+ Maintainer-email: Ashley Smith <ashley.smith@ed.ac.uk>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2021 Karl M. Laundal
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/IAGA-VMOD/ppigrf
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Topic :: Scientific/Engineering
8
32
  Classifier: Intended Audience :: Science/Research
9
- Classifier: Natural Language :: English
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: Operating System :: OS Independent
35
+ Classifier: Programming Language :: Python
10
36
  Classifier: Programming Language :: Python :: 3
37
+ Classifier: Development Status :: 4 - Beta
11
38
  Requires-Python: >=3.6
12
39
  Description-Content-Type: text/markdown
13
40
  License-File: LICENSE
14
- Requires-Dist: numpy>=0.13.1
15
- Requires-Dist: pandas>=1.3.5
41
+ Requires-Dist: numpy>=1.15
42
+ Requires-Dist: pandas>=1.0
43
+ Provides-Extra: dev
44
+ Requires-Dist: pytest; extra == "dev"
45
+ Dynamic: license-file
16
46
 
17
47
  # Pure Python International Geomagnetic Reference Field
18
48
  [![DOI](https://zenodo.org/badge/352365168.svg)](https://zenodo.org/badge/latestdoi/352365168)
@@ -0,0 +1,47 @@
1
+ [build-system]
2
+ requires = ["setuptools"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ppigrf"
7
+ version = "2.1.0"
8
+ authors = [
9
+ { name = "Karl Laundal" }
10
+ ]
11
+ maintainers = [
12
+ { name = "Ashley Smith", email = "ashley.smith@ed.ac.uk" },
13
+ ]
14
+ license = { file = "LICENSE" }
15
+ description = "Pure Python IGRF"
16
+ readme = "README.md"
17
+ requires-python = ">=3.6"
18
+ classifiers = [
19
+ "License :: OSI Approved :: MIT License",
20
+ "Topic :: Scientific/Engineering",
21
+ "Intended Audience :: Science/Research",
22
+ "Intended Audience :: Developers",
23
+ "Operating System :: OS Independent",
24
+ "Programming Language :: Python",
25
+ "Programming Language :: Python :: 3",
26
+ "Development Status :: 4 - Beta",
27
+ ]
28
+ dependencies = [
29
+ "numpy >= 1.15",
30
+ "pandas >= 1.0",
31
+ ]
32
+
33
+ [project.optional-dependencies]
34
+ dev = [
35
+ "pytest"
36
+ ]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/IAGA-VMOD/ppigrf"
40
+
41
+ [tool.setuptools]
42
+ packages = ["ppigrf"]
43
+ package-dir = {"" = "src"}
44
+ include-package-data = true
45
+
46
+ [tool.setuptools.package-data]
47
+ ppigrf = ["*.shc"]
@@ -1,7 +1,7 @@
1
1
  # IGRF 14
2
2
  # International Geomagnetic Reference Field -- 14th generation
3
- # see https://doi.org/10.5281/zenodo.14012303 for detailed description
4
- 1 13 26 2 1 1900.0 2030.0
3
+ # see https://doi.org/10.5281/zenodo.14012302 for detailed description
4
+ 1 13 27 2 1 1900.0 2030.0
5
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 2030.0
6
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 -29403.41 -29350.0 -29287.0
7
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 -1451.37 -1410.3 -1360.3
@@ -442,7 +442,7 @@ def geoc2geod(theta, r, B_th, B_r):
442
442
 
443
443
 
444
444
 
445
- def igrf_gc(r, theta, phi, date, coeff_fn = shc_fn):
445
+ def igrf_gc(r, theta, phi, date, coeff_fn = shc_fn, min_degree=1, max_degree=13):
446
446
  """
447
447
  Calculate IGRF model components
448
448
 
@@ -467,6 +467,10 @@ def igrf_gc(r, theta, phi, date, coeff_fn = shc_fn):
467
467
  one or more dates to evaluate IGRF coefficients
468
468
  coeff_fn : string, optional
469
469
  filename of .shc file. Default is latest IGRF
470
+ min_degree : int, optional
471
+ lowest degree of expansion min_degree >= 1
472
+ max_degree : int, optional
473
+ highest degree of expansion, 1 <= max_degree <= 13
470
474
 
471
475
  Return
472
476
  ------
@@ -491,6 +495,11 @@ def igrf_gc(r, theta, phi, date, coeff_fn = shc_fn):
491
495
  print('Warning: You provided date(s) not covered by coefficient file \n({} to {})'.format(
492
496
  g.index[0].date(), g.index[-1].date()))
493
497
 
498
+ if min_degree > max_degree:
499
+ print('Warning: Highest degree of expansion must be larger or equal to lowest degree.')
500
+ print('Reset to original range.')
501
+ min_degree, max_degree = 1, 13
502
+
494
503
  # get coordinate arrays to same size and shape
495
504
  r, theta, phi = np.broadcast_arrays(r, theta, phi)
496
505
  shape = r.shape
@@ -524,17 +533,19 @@ def igrf_gc(r, theta, phi, date, coeff_fn = shc_fn):
524
533
  # make versions of n and m that are repeated twice
525
534
  nn, mm = np.tile(n, 2), np.tile(m, 2)
526
535
 
536
+ N_map = ((nn >= min_degree) & (nn <= max_degree)).astype(int)
537
+
527
538
  # calculate Br:
528
- G = (RE / r) ** (nn + 2) * (nn + 1) * np.hstack((P * cosmphi, P * sinmphi))
539
+ G = N_map * (RE / r) ** (nn + 2) * (nn + 1) * np.hstack((P * cosmphi, P * sinmphi))
529
540
  Br = G.dot(np.hstack((g.values, h.values)).T).T # shape (n_times, n_coords)
530
541
 
531
542
  # calculate Btheta:
532
- G = -(RE / r) ** (nn + 1) * np.hstack((dP * cosmphi, dP * sinmphi)) \
543
+ G = - N_map * (RE / r) ** (nn + 1) * np.hstack((dP * cosmphi, dP * sinmphi)) \
533
544
  * RE / r
534
545
  Btheta = G.dot(np.hstack((g.values, h.values)).T).T # shape (n_times, n_coords)
535
546
 
536
547
  # calculate Bphi:
537
- G = -(RE / r) ** (nn + 1) * mm * np.hstack((-P * sinmphi, P * cosmphi)) \
548
+ G = - N_map * (RE / r) ** (nn + 1) * mm * np.hstack((-P * sinmphi, P * cosmphi)) \
538
549
  * RE / r / np.sin(np.radians(theta))
539
550
  Bphi = G.dot(np.hstack((g.values, h.values)).T).T # shape (n_times, n_coords)
540
551
 
@@ -543,7 +554,7 @@ def igrf_gc(r, theta, phi, date, coeff_fn = shc_fn):
543
554
  return Br.reshape(outshape), Btheta.reshape(outshape), Bphi.reshape(outshape)
544
555
 
545
556
 
546
- def igrf(lon, lat, h, date, coeff_fn = shc_fn):
557
+ def igrf(lon, lat, h, date, coeff_fn = shc_fn, min_degree=1, max_degree=13):
547
558
  """
548
559
  Calculate IGRF model components
549
560
 
@@ -568,6 +579,10 @@ def igrf(lon, lat, h, date, coeff_fn = shc_fn):
568
579
  one or more dates to evaluate IGRF coefficients
569
580
  coeff_fn : string, optional
570
581
  filename of .shc file. Default is latest IGRF
582
+ min_degree : int, optional
583
+ lowest degree of expansion, min_degree >= 1
584
+ max_degree : int, optional
585
+ highest degree of expansion, 1 <= max_degree <= 13
571
586
 
572
587
  Return
573
588
  ------
@@ -581,6 +596,11 @@ def igrf(lon, lat, h, date, coeff_fn = shc_fn):
581
596
  ellipsoid
582
597
  """
583
598
 
599
+ if min_degree > max_degree:
600
+ print('Warning: Highest degree of expansion must be larger or equal to lowest degree.')
601
+ print('Reset to original range.')
602
+ min_degree, max_degree = 1, 13
603
+
584
604
  # convert input to arrays and cast to same shape:
585
605
  lon, lat, h = np.broadcast_arrays(lon, lat, h)
586
606
  shape = lon.shape
@@ -591,7 +611,7 @@ def igrf(lon, lat, h, date, coeff_fn = shc_fn):
591
611
  phi = lon
592
612
 
593
613
  # calculate geocentric components of IGRF:
594
- Br, Btheta, Bphi = igrf_gc(r, theta, phi, date, coeff_fn = coeff_fn)
614
+ Br, Btheta, Bphi = igrf_gc(r, theta, phi, date, coeff_fn = coeff_fn, min_degree=min_degree, max_degree=max_degree)
595
615
  Be = Bphi
596
616
 
597
617
  # convert output to geodetic
@@ -602,7 +622,7 @@ def igrf(lon, lat, h, date, coeff_fn = shc_fn):
602
622
  return Be.reshape(outshape), Bn.reshape(outshape), Bu.reshape(outshape)
603
623
 
604
624
 
605
- def igrf_V(r, theta, phi, date, coeff_fn = shc_fn):
625
+ def igrf_V(r, theta, phi, date, coeff_fn = shc_fn, min_degree=1, max_degree=13):
606
626
  """
607
627
  Calculate IGRF magnetic potential
608
628
 
@@ -627,6 +647,11 @@ def igrf_V(r, theta, phi, date, coeff_fn = shc_fn):
627
647
  one or more dates to evaluate IGRF coefficients
628
648
  coeff_fn : string, optional
629
649
  filename of .shc file. Default is latest IGRF
650
+ min_degree : int, optional
651
+ lowest degree of expansion, min_degree >= 1
652
+ max_degree : int, optional
653
+ highest degree of expansion, 1 <= max_degree <= 13
654
+
630
655
 
631
656
  Return
632
657
  ------
@@ -634,6 +659,11 @@ def igrf_V(r, theta, phi, date, coeff_fn = shc_fn):
634
659
  Magnetic potential (unit nT * km)
635
660
  """
636
661
 
662
+ if min_degree > max_degree:
663
+ print('Warning: Highest degree of expansion must be larger or equal to lowest degree.')
664
+ print('Reset to original range.')
665
+ min_degree, max_degree = 1, 13
666
+
637
667
  # read coefficient file:
638
668
  g, h = read_shc(coeff_fn)
639
669
 
@@ -678,8 +708,10 @@ def igrf_V(r, theta, phi, date, coeff_fn = shc_fn):
678
708
  # make versions of n and m that are repeated twice
679
709
  nn, mm = np.tile(n, 2), np.tile(m, 2)
680
710
 
711
+ N_map = ((nn >= min_degree) & (nn <= max_degree)).astype(int)
712
+
681
713
  # calculate Br:
682
- G = RE * (RE / r) ** (nn + 1) * np.hstack((P * cosmphi, P * sinmphi))
714
+ G = N_map * RE * (RE / r) ** (nn + 1) * np.hstack((P * cosmphi, P * sinmphi))
683
715
  V = G.dot(np.hstack((g.values, h.values)).T).T # shape (n_times, n_coords)
684
716
 
685
717
  # reshape and return
@@ -731,14 +763,12 @@ def get_inclination_declination(Be, Bn, Bu, degrees=True):
731
763
  it's returned in radians.
732
764
  """
733
765
  # Compute the horizontal component of B
734
- horizontal_component = np.sqrt(Be**2 + Bn**2)
735
- if horizontal_component == 0:
736
- inclination = -np.sign(Bu) * np.pi /2
737
- declination = 0
738
- else:
739
- # Compute the two angles
740
- inclination = np.arctan(-Bu / horizontal_component)
741
- declination = np.arcsin(Be / horizontal_component)
766
+ H = np.sqrt(Be**2 + Bn**2)
767
+ # Compute the inclination and declination, accounting for special H=0 case
768
+ safe_division = np.divide(-Bu, H, where=H != 0)
769
+ inclination = np.where(H != 0, np.arctan(safe_division), -np.sign(Bu) * np.pi /2)
770
+ safe_division = np.divide(Be, H, where=H != 0)
771
+ declination = np.where(H != 0, np.arcsin(safe_division), 0)
742
772
  # Convert to degrees if needed
743
773
  if degrees:
744
774
  inclination = np.degrees(inclination)
@@ -1,18 +1,48 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.4
2
2
  Name: ppigrf
3
- Version: 2.0.0
3
+ Version: 2.1.0
4
4
  Summary: Pure Python IGRF
5
5
  Author: Karl Laundal
6
- Author-email: readme@file.md
7
- Classifier: Development Status :: 4 - Beta
6
+ Maintainer-email: Ashley Smith <ashley.smith@ed.ac.uk>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2021 Karl M. Laundal
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+
29
+ Project-URL: Homepage, https://github.com/IAGA-VMOD/ppigrf
30
+ Classifier: License :: OSI Approved :: MIT License
31
+ Classifier: Topic :: Scientific/Engineering
8
32
  Classifier: Intended Audience :: Science/Research
9
- Classifier: Natural Language :: English
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: Operating System :: OS Independent
35
+ Classifier: Programming Language :: Python
10
36
  Classifier: Programming Language :: Python :: 3
37
+ Classifier: Development Status :: 4 - Beta
11
38
  Requires-Python: >=3.6
12
39
  Description-Content-Type: text/markdown
13
40
  License-File: LICENSE
14
- Requires-Dist: numpy>=0.13.1
15
- Requires-Dist: pandas>=1.3.5
41
+ Requires-Dist: numpy>=1.15
42
+ Requires-Dist: pandas>=1.0
43
+ Provides-Extra: dev
44
+ Requires-Dist: pytest; extra == "dev"
45
+ Dynamic: license-file
16
46
 
17
47
  # Pure Python International Geomagnetic Reference Field
18
48
  [![DOI](https://zenodo.org/badge/352365168.svg)](https://zenodo.org/badge/latestdoi/352365168)
@@ -1,6 +1,6 @@
1
1
  LICENSE
2
2
  README.md
3
- setup.py
3
+ pyproject.toml
4
4
  src/ppigrf/IGRF13.shc
5
5
  src/ppigrf/IGRF14.shc
6
6
  src/ppigrf/__init__.py
@@ -0,0 +1,5 @@
1
+ numpy>=1.15
2
+ pandas>=1.0
3
+
4
+ [dev]
5
+ pytest
@@ -19,6 +19,12 @@ from ppigrf import get_inclination_declination
19
19
  [(1, 1, -np.sqrt(2)), 45, 45],
20
20
  [(1, 1, np.sqrt(2)), -45, 45],
21
21
  [(-2_938.0, 16_308.1, -52_741.9), 72.5582, -10.2126],
22
+ [(np.array([0, 0, 1, -1, 1, 1, -2_938.0]),
23
+ np.array([0, 0, 1, 1, 1, 1, 16_308.1]),
24
+ np.array([-1, 1, 0, 0, -np.sqrt(2), np.sqrt(2), -52_741.9])),
25
+ np.array([90, -90, 0, 0, 45, -45, 72.5582]),
26
+ np.array([0, 0, 45, -45, 45, 45, -10.2126]),
27
+ ],
22
28
  ],
23
29
  )
24
30
  def test_inclination_declination(degrees, geomagnetic_field, inclination, declination):
ppigrf-2.0.0/setup.py DELETED
@@ -1,40 +0,0 @@
1
- import setuptools
2
-
3
- # Howto
4
- #
5
- #This is how to upload a project to pipy. This is mainly a note to self, as this is the first project I have uplo#aded to pypi:
6
- #
7
- #python3 -m venv /tmp/venv
8
- #source /tmp/venv/bin/activate
9
- #pip install build
10
- #pip install twine
11
- #python3 -m build
12
- #python3 -m twine upload dist/ppigrf-1.0.0.tar.gz
13
-
14
- #Genrate long description using readme file
15
- with open("README.md", "r", encoding="utf-8") as fh:
16
- long_description = fh.read()
17
-
18
- setuptools.setup(
19
- name="ppigrf",
20
- version="2.0.0",
21
- author="Karl Laundal",
22
- author_email="readme@file.md",
23
- description="Pure Python IGRF",
24
- long_description=long_description,
25
- long_description_content_type="text/markdown",
26
- classifiers=[
27
- "Development Status :: 4 - Beta",
28
- "Intended Audience :: Science/Research",
29
- "Natural Language :: English",
30
- "Programming Language :: Python :: 3",
31
- ],
32
- install_requires=[
33
- 'numpy>=0.13.1',
34
- 'pandas>=1.3.5'
35
- ],
36
- package_dir={"": "src"},
37
- package_data={'':['IGRF13.shc', 'IGRF14.shc']},
38
- packages=setuptools.find_packages(where="src"),
39
- python_requires=">=3.6",
40
- )
@@ -1,2 +0,0 @@
1
- numpy>=0.13.1
2
- pandas>=1.3.5
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes