-
Notifications
You must be signed in to change notification settings - Fork 10
160 lines (128 loc) · 4.91 KB
/
ci.yaml
File metadata and controls
160 lines (128 loc) · 4.91 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: Continuous Integration
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
use-cache: false
- name: Download FITS file
run: |
curl -o ${{ github.workspace }}/test/table.fits http://data.astropy.org/tutorials/FITS-tables/chandra_events.fits
working-directory: ${{ github.workspace }}
- name: Run `test`
run: zig build test --summary all
working-directory: ${{ github.workspace }}
fmt:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
use-cache: false
- name: Run `fmt`
run: zig build fmt
python:
name: Python ${{ matrix.python }} bindings
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ['3.10', '3.11', '3.12', '3.13', '3.14']
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- name: Set up Zig
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
use-cache: false
- name: Build Python bindings
run: |
PYTHON_INCLUDE=$(python -c "import sysconfig; print(sysconfig.get_path('include'))")
PYTHON_LIBDIR=$(python -c "import sysconfig; print(sysconfig.get_config_var('LIBDIR'))")
PYTHON_LIB=$(python -c "import sys; print(f'python{sys.version_info.major}.{sys.version_info.minor}')")
echo "Python include: $PYTHON_INCLUDE"
echo "Python libdir: $PYTHON_LIBDIR"
zig build python-bindings \
-Dpython-include="$PYTHON_INCLUDE" \
-Dpython-lib="$PYTHON_LIB" \
-Dpython-lib-path="$PYTHON_LIBDIR" \
-Doptimize=ReleaseFast
- name: Copy built library
run: |
# Zig builds lib_astroz.so, but Python expects _astroz.so
cp zig-out/bindings/python/astroz/lib_astroz.so bindings/python/astroz/_astroz.so
- name: Install package
run: |
pip install numpy
pip install -e bindings/python
- name: Test import and basic functionality
run: |
python -c "from astroz import Tle, Constellation, propagate, __version__; print(f'astroz {__version__}')"
python -c "
from astroz import Tle, propagate
import numpy as np
tle_text = '1 25544U 98067A 24127.82853009 .00015698 00000+0 27310-3 0 9995\n2 25544 51.6393 160.4574 0003580 140.6673 205.7250 15.50957674452123'
# Test TLE parsing
tle = Tle(tle_text)
print(f'Satellite: {tle.satellite_number}')
# Test propagation
times = np.arange(100, dtype=np.float64)
positions = propagate(tle_text, times)
print(f'Batch: {positions.shape}')
"
- name: Test python-sgp4 compatible API
run: |
pip install sgp4
python -c "
from astroz.api import Satrec, SatrecArray, jday, WGS72
from sgp4.api import Satrec as Sgp4Satrec, jday as sgp4_jday, WGS72 as SGP4_WGS72
import numpy as np
line1 = '1 25544U 98067A 24127.82853009 .00015698 00000+0 27310-3 0 9995'
line2 = '2 25544 51.6393 160.4574 0003580 140.6673 205.7250 15.50957674452123'
# Test Satrec
sat = Satrec.twoline2rv(line1, line2, WGS72)
print(f'Satrec: satnum={sat.satnum}, error={sat.error}')
# Test jday
jd, fr = jday(2024, 5, 6, 12, 0, 0.0)
print(f'jday: {jd} + {fr}')
# Test sgp4
e, r, v = sat.sgp4(jd, fr)
print(f'sgp4: error={e}, pos=({r[0]:.1f}, {r[1]:.1f}, {r[2]:.1f})')
# Test sgp4_array
jd_arr = np.full(100, jd)
fr_arr = fr + np.arange(100) / 1440.0
e, r, v = sat.sgp4_array(jd_arr, fr_arr)
print(f'sgp4_array: shape={r.shape}')
# Test SatrecArray
arr = SatrecArray([sat])
e, r, v = arr.sgp4(jd_arr, fr_arr)
print(f'SatrecArray: shape={r.shape}')
# Accuracy test vs python-sgp4
sgp4_sat = Sgp4Satrec.twoline2rv(line1, line2, SGP4_WGS72)
az_e, az_r, az_v = sat.sgp4(jd, fr)
sg_e, sg_r, sg_v = sgp4_sat.sgp4(jd, fr)
pos_diff = np.linalg.norm(np.array(az_r) - np.array(sg_r))
assert pos_diff < 0.001, f'Position error {pos_diff*1000:.1f}m exceeds 1mm'
print(f'Accuracy: {pos_diff*1000:.3f}mm (< 1mm OK)')
"
- name: Run Python example
run: python examples/python_sgp4.py