Skip to content

Commit 7b06222

Browse files
authored
Merge pull request #63 from CosmicStudioSoftware/meson_move
Meson move
2 parents e322c7a + b264e2c commit 7b06222

18 files changed

Lines changed: 312 additions & 51 deletions

.github/workflows/main.yml

Lines changed: 79 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,39 @@
55

66
name: Pytest with Flake8
77

8-
on: [pull_request, push]
8+
on:
9+
pull_request:
10+
push:
11+
schedule:
12+
- cron: "0 3 * * 1" # Runs 03:00 UT on Mondays
913

1014
jobs:
1115
build:
1216
strategy:
1317
fail-fast: false
1418
matrix:
15-
os: [ubuntu-latest]
16-
python-version: ["3.9", "3.10", "3.11"]
17-
numpy_ver: [latest]
19+
os: ["ubuntu-latest", "windows-latest"]
20+
python-version: ["3.9", "3.10", "3.11", "3.12"]
21+
numpy_ver: ["latest"]
22+
include:
23+
# Support different GA Mac environments
24+
- python-version: "3.9"
25+
os: "macos-13"
26+
numpy_ver: "latest"
27+
- python-version: "3.12"
28+
os: "macos-13"
29+
numpy_ver: "latest"
30+
- python-version: "3.9"
31+
os: "macos-latest"
32+
numpy_ver: "latest"
33+
- python-version: "3.12"
34+
os: "macos-latest"
35+
numpy_ver: "latest"
36+
# NEP29 compliance settings
37+
- python-version: "3.10"
38+
numpy_ver: "1.25"
39+
os: "ubuntu-latest"
40+
test_config: "NEP29"
1841

1942
name: Python ${{ matrix.python-version }} on ${{ matrix.os }} with numpy ${{ matrix.numpy_ver }}
2043
runs-on: ${{ matrix.os }}
@@ -25,6 +48,16 @@ jobs:
2548
with:
2649
python-version: ${{ matrix.python-version }}
2750

51+
- name: Install Windows-specific dependencies for non-pip install
52+
if: ${{ matrix.os == 'windows-latest' }}
53+
run: |
54+
choco install ninja mingw
55+
choco install rtools --no-progress
56+
echo "c:\rtools40\ucrt64\bin;" >> $env:GITHUB_PATH
57+
gfortran --version
58+
pip install flake8 meson-python pytest pytest-cov pytest-xdist scipy
59+
pip install "numpy>=1.19.5"
60+
2861
- name: Install standard dependencies
2962
run: |
3063
python -m pip install --upgrade pip
@@ -47,12 +80,50 @@ jobs:
4780
- name: Evaluate complexity
4881
run: flake8 . --count --exit-zero --max-complexity=10 --statistics
4982

50-
- name: Run OMMBV setup.py
83+
- name: Install on Linux
84+
if: ${{ matrix.os == 'ubuntu-latest' }}
85+
run: |
86+
pip install --upgrade-strategy only-if-needed .
87+
88+
- name: Install on MacOS-13
89+
if: ${{ matrix.os == 'macos-13' }}
90+
run: |
91+
brew reinstall gcc@14
92+
CC=/usr/local/bin/gcc-14 pip install --upgrade-strategy only-if-needed .
93+
94+
- name: Install on MacOS-Latest
95+
if: ${{ matrix.os == 'macos-latest' }}
5196
run: |
52-
python setup.py develop
97+
brew reinstall gcc@14
98+
CC=/opt/homebrew/bin/gcc-14 pip install --upgrade-strategy only-if-needed .
5399
54-
- name: Run unit and integration tests
55-
run: pytest --cov=OMMBV/
100+
- name: Install on Windows
101+
if: ${{ matrix.os == 'windows-latest' }}
102+
run: |
103+
meson setup build
104+
ninja -j 2 -C build
105+
cd build
106+
meson install --destdir=${{ env.Python3_ROOT_DIR }}
107+
108+
- name: Run unit and integration tests Mac/Linux
109+
if: ${{ matrix.os != 'windows-latest' }}
110+
run: |
111+
rm -rf ./OMMBV
112+
cd ..
113+
coverage run -m pytest
114+
coverage report
115+
coverage xml
116+
mv coverage.xml ./OMMBV/.
117+
118+
- name: Run unit and integration tests on Windows
119+
if: ${{ matrix.os == 'windows-latest' }}
120+
run: |
121+
rm ./OMMBV -r -force
122+
cd ..
123+
coverage run -m pytest
124+
coverage report
125+
coverage xml
126+
mv coverage.xml .\OMMBV\.
56127
57128
- name: Publish results to coveralls
58129
env:

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## [1.0.2] - ?????
6+
- Switched away from distutils to Meson for build system
67
- Updated coupling to coveralls
78
- Updated package version for security issue in sphinx
9+
- Added online unit testing for Linux/MacOS/Windows
810

911
## [1.0.1] - 2022-01-04
1012
- Added pyproject.toml to support systems without numpy.

OMMBV/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22
"""init routine for OMMBV."""
33

4-
__version__ = '1.0.1'
4+
__version__ = '1.0.2'
55

66
try:
77
from OMMBV import igrf
@@ -22,4 +22,5 @@
2222

2323
from OMMBV import heritage
2424

25-
__all__ = ['heritage', 'satellite', 'trace', 'trans', 'utils', 'vector']
25+
__all__ = ['igrf', 'fortran_coords', 'sources', 'satellite',
26+
'trace', 'trans', 'utils', 'vector', 'heritage']

OMMBV/_core.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
from OMMBV import vector
1111

1212

13-
def calculate_geomagnetic_basis(latitude, longitude, altitude, datetimes):
13+
def calculate_geomagnetic_basis(latitude, longitude, altitude, datetimes,
14+
**kwargs):
1415
"""Calculate local geomagnetic basis vectors and mapping scalars.
1516
1617
Parameters
@@ -58,7 +59,8 @@ def calculate_geomagnetic_basis(latitude, longitude, altitude, datetimes):
5859
mx, my, mz,
5960
info) = calculate_mag_drift_unit_vectors_ecef(latitude, longitude,
6061
altitude, datetimes,
61-
full_output=True)
62+
full_output=True,
63+
**kwargs)
6264

6365
d_zon_mag = np.sqrt(info['d_zon_x']**2 + info['d_zon_y']**2
6466
+ info['d_zon_z']**2)
@@ -290,6 +292,13 @@ def calculate_mag_drift_unit_vectors_ecef(latitude, longitude, altitude,
290292
ecef_x, ecef_y, ecef_z = trans.geodetic_to_ecef(latitude, longitude,
291293
altitude)
292294

295+
# This shouldn't have been pushed to the repo
296+
# idx, = np.where(np.isnan(ecef_x))
297+
# if len(idx) > 0:
298+
# print("Encountered nan starting ecef locations ", ecef_x[idx],
299+
# ecef_y[idx], ecef_z[idx], latitude[idx], longitude[idx],
300+
# altitude[idx])
301+
293302
# Begin method calculation.
294303

295304
# Magnetic field at root location
@@ -348,6 +357,14 @@ def calculate_mag_drift_unit_vectors_ecef(latitude, longitude, altitude,
348357
return_geodetic=True,
349358
ecef_input=True,
350359
**step_kwargs)
360+
361+
# This shouldn't be here
362+
# idx, = np.where(np.isnan(tzx))
363+
# if len(idx) > 0:
364+
# print("Encountered nan tzx values ", idx, ecef_x[idx],
365+
# ecef_y[idx], ecef_z[idx], tzx[idx], tzy[idx], tzz[idx],
366+
# latitude[idx], longitude[idx], altitude[idx])
367+
351368
if centered_diff:
352369
# Negative step
353370
ecef_xz2, ecef_yz2, ecef_zz2 = (ecef_x - step_size * tzx,
@@ -418,6 +435,15 @@ def calculate_mag_drift_unit_vectors_ecef(latitude, longitude, altitude,
418435
& (loop_num + 1 >= min_loops):
419436
# Reached terminating conditions
420437
repeat_flag = False
438+
# print('Using position ', location_info(ecef_xz, ecef_yz, ecef_zz,
439+
# datetimes,
440+
# return_geodetic=True,
441+
# ecef_input=True,
442+
# **step_kwargs)[3:], loop_num)
443+
# idx, = np.where(np.isnan(ecef_xz))
444+
# if len(idx) > 0:
445+
# print("Encountered nan apex locations ", ecef_xz[idx],
446+
# ecef_yz[idx], ecef_zz[idx])
421447
else:
422448
# Store info into calculation vectors to refine next loop
423449
tzx, tzy, tzz = tzx2, tzy2, tzz2
@@ -665,6 +691,7 @@ def step_along_mag_unit_vector(x, y, z, date, direction, num_steps=1,
665691

666692
if direction == 'meridional':
667693
centered_diff = True
694+
# print("False")
668695
else:
669696
centered_diff = False
670697

meson.build

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
project('OMMBV', 'c',
2+
version : '1.0.2',
3+
license: 'BSD-3',
4+
meson_version: '>=0.64.0',
5+
default_options : [
6+
'warning_level=2',
7+
'c_args=-Wno-unused-parameter -Wno-cast-function-type -Wno-missing-field-initializers',
8+
'fortran_args=-Wno-line-truncation -Wno-conversion -Wno-unused-variable -Wno-maybe-uninitialized -Wno-unused-dummy-argument -Wno-compare-reals',
9+
'fortran_std=legacy'],
10+
)
11+
12+
add_languages('fortran', native: false)
13+
14+
py_mod = import('python')
15+
py = py_mod.find_installation(pure: false)
16+
py_dep = py.dependency()
17+
18+
incdir_numpy = run_command(py,
19+
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
20+
check : true
21+
).stdout().strip()
22+
23+
incdir_f2py = run_command(py,
24+
['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'],
25+
check : true
26+
).stdout().strip()
27+
28+
inc_np = include_directories(incdir_numpy, incdir_f2py)
29+
30+
# Unlike distutils, meson doesn't yet include some of the f2py stuff
31+
fortranobject_c = incdir_f2py / 'fortranobject.c'
32+
33+
fortranobject_lib = static_library('_fortranobject',
34+
fortranobject_c,
35+
dependencies: py_dep,
36+
include_directories: [incdir_numpy, incdir_f2py])
37+
38+
fortranobject_dep = declare_dependency(
39+
link_with: fortranobject_lib,
40+
include_directories: [incdir_numpy, incdir_f2py])
41+
42+
43+
igrf_source = custom_target('igrfmodule.c',
44+
input : ['OMMBV/igrf13.f'], # .f so no F90 wrappers
45+
output : ['igrfmodule.c', 'igrf-f2pywrappers.f'],
46+
command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'igrf', '--lower']
47+
)
48+
py.extension_module('igrf',
49+
[
50+
'OMMBV/igrf13.f',
51+
igrf_source,
52+
fortranobject_c
53+
],
54+
include_directories: inc_np,
55+
link_with: fortranobject_lib,
56+
dependencies : [py_dep, fortranobject_dep],
57+
subdir: 'OMMBV',
58+
install : true
59+
)
60+
61+
62+
sources_source = custom_target('sourcesmodule.c',
63+
input : ['OMMBV/sources.f', 'OMMBV/igrf13.f'], # .f so no F90 wrappers
64+
output : ['sourcesmodule.c', 'sources-f2pywrappers.f'],
65+
command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'sources', '--lower']
66+
)
67+
py.extension_module('sources',
68+
[
69+
'OMMBV/sources.f',
70+
'OMMBV/igrf13.f',
71+
sources_source,
72+
fortranobject_c
73+
],
74+
include_directories: inc_np,
75+
link_with: fortranobject_lib,
76+
dependencies : [py_dep, fortranobject_dep],
77+
subdir: 'OMMBV',
78+
install : true
79+
)
80+
81+
82+
fcoords_source = custom_target('fortran_coordsmodule.c',
83+
input : ['OMMBV/_coords.f'], # .f so no F90 wrappers
84+
output : ['fortran_coordsmodule.c', 'fortran_coords-f2pywrappers.f'],
85+
command : [py, '-m', 'numpy.f2py', '@INPUT@', '-m', 'fortran_coords', '--lower']
86+
)
87+
py.extension_module('fortran_coords',
88+
[
89+
'OMMBV/_coords.f',
90+
fcoords_source,
91+
fortranobject_c
92+
],
93+
include_directories: inc_np,
94+
link_with: fortranobject_lib,
95+
dependencies : [py_dep, fortranobject_dep],
96+
subdir: 'OMMBV',
97+
install : true
98+
)
99+
100+
py.install_sources(
101+
'OMMBV/_core.py',
102+
'OMMBV/heritage.py',
103+
'OMMBV/satellite.py',
104+
'OMMBV/trace.py',
105+
'OMMBV/trans.py',
106+
'OMMBV/utils.py',
107+
'OMMBV/vector.py',
108+
'OMMBV/__init__.py',
109+
pure: false,
110+
subdir: 'OMMBV'
111+
)

pyproject.toml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,59 @@
11
[build-system]
2-
requires = ["setuptools", "wheel", "Cython", "numpy"]
2+
build-backend = 'mesonpy'
3+
requires = [
4+
"wheel",
5+
"meson-python>=0.12.0",
6+
"setuptools<60.0", # Do not increase, 60.0 enables vendored distutils
7+
"Cython>=0.29.21",
8+
"ninja",
9+
"numpy"
10+
]
11+
12+
[project]
13+
name = "OMMBV"
14+
version = "1.0.2"
15+
license = {file = "LICENSE"}
16+
description = "Orthogonal geomagnetic vector basis and field-line mapping for multipole magnetic fields."
17+
maintainers = [
18+
{name = "Russell Stoneback", email = "contact@cosmicstudio.io"}
19+
]
20+
requires-python = ">=3.9"
21+
dependencies = [
22+
"numpy",
23+
"pysat",
24+
"scipy"
25+
]
26+
readme = "README.md"
27+
classifiers = [
28+
"Development Status :: 5 - Production/Stable",
29+
"Topic :: Scientific/Engineering :: Physics",
30+
"Intended Audience :: Science/Research",
31+
"License :: OSI Approved :: BSD License",
32+
"Natural Language :: English",
33+
"Programming Language :: Python :: 3",
34+
"Programming Language :: Python :: 3.9",
35+
"Programming Language :: Python :: 3.10",
36+
"Programming Language :: Python :: 3.11",
37+
"Programming Language :: Python :: 3.12",
38+
"Operating System :: POSIX :: Linux",
39+
"Operating System :: POSIX",
40+
"Operating System :: MacOS"
41+
]
42+
keywords = [
43+
"vector-basis",
44+
"geomagnetic-field",
45+
"magnetic-fields",
46+
"field-line-tracing",
47+
"meridional",
48+
"zonal",
49+
"field-aligned",
50+
"satellite",
51+
"electric-field-mapping",
52+
"ion-drift-mapping",
53+
"multipole",
54+
"electrodynamics",
55+
"plasma"
56+
]
57+
58+
59+

0 commit comments

Comments
 (0)