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generated by RIMI.
|
| 4 |
+
|
| 5 |
+
Runs on-device via the PythonSTB app Scripts folder after installing, in order:
|
| 6 |
+
numpy 2.5.2, pyerfa 2.0.1.5, astropy-iers-data, packaging, PyYAML,
|
| 7 |
+
then astropy-8.0.1-cp312-cp312-android_24_<arch>.whl.
|
| 8 |
+
|
| 9 |
+
Contract: prints [PASS]/[FAIL] per check and exits 0 iff ALL checks pass.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import io
|
| 13 |
+
import math
|
| 14 |
+
import sys
|
| 15 |
+
|
| 16 |
+
PASS = 0
|
| 17 |
+
FAIL = 0
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def check(name, fn):
|
| 21 |
+
global PASS, FAIL
|
| 22 |
+
try:
|
| 23 |
+
fn()
|
| 24 |
+
except Exception as e: # noqa: BLE001 - report any failure, never crash
|
| 25 |
+
FAIL += 1
|
| 26 |
+
print("[FAIL] %s -- %s: %s" % (name, type(e).__name__, e))
|
| 27 |
+
else:
|
| 28 |
+
PASS += 1
|
| 29 |
+
print("[PASS] %s" % name)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def t_import_version():
|
| 33 |
+
import astropy
|
| 34 |
+
|
| 35 |
+
assert astropy.__version__ == "8.0.1", astropy.__version__
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def t_native_wcs():
|
| 39 |
+
from astropy.wcs import WCS
|
| 40 |
+
|
| 41 |
+
w = WCS(naxis=2)
|
| 42 |
+
w.wcs.ctype = ["RA---TAN", "DEC--TAN"]
|
| 43 |
+
assert w.naxis == 2
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def t_native_iterparser():
|
| 47 |
+
from astropy.utils.xml import _iterparser # noqa: F401
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def t_native_convolve():
|
| 51 |
+
import numpy as np
|
| 52 |
+
from astropy.convolution import convolve
|
| 53 |
+
|
| 54 |
+
out = convolve(np.ones(9), np.ones(3) / 3.0, boundary="extend")
|
| 55 |
+
assert abs(float(out[4]) - 1.0) < 1e-12, out[4]
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def t_native_stats():
|
| 59 |
+
import numpy as np
|
| 60 |
+
from astropy.stats import sigma_clip
|
| 61 |
+
|
| 62 |
+
r = sigma_clip(np.array([1.0, 1.0, 1.0, 50.0]), sigma=2.0)
|
| 63 |
+
assert bool(getattr(r, "mask", [False] * 4)[3]) is True
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def t_native_fits():
|
| 67 |
+
import numpy as np
|
| 68 |
+
from astropy.io import fits
|
| 69 |
+
|
| 70 |
+
buf = io.BytesIO()
|
| 71 |
+
fits.PrimaryHDU(data=np.arange(12, dtype=">i2").reshape(3, 4)).writeto(buf)
|
| 72 |
+
buf.seek(0)
|
| 73 |
+
with fits.open(buf) as hdul:
|
| 74 |
+
assert hdul[0].data.shape == (3, 4)
|
| 75 |
+
assert int(hdul[0].data.sum()) == 66
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def t_time_object():
|
| 79 |
+
from astropy.time import Time
|
| 80 |
+
|
| 81 |
+
t = Time("2026-01-01T00:00:00", scale="utc")
|
| 82 |
+
assert t.iso.startswith("2026-01-01"), t.iso
|
| 83 |
+
assert abs(float(t.unix) - 1767225600.0) < 1.0, t.unix
|
| 84 |
+
assert str(t.tt.scale) == "tt"
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def t_units():
|
| 88 |
+
import astropy.units as u
|
| 89 |
+
|
| 90 |
+
assert abs((1.0 * u.m).to_value(u.km) - 0.001) < 1e-15
|
| 91 |
+
assert abs((90.0 * u.deg).to_value(u.rad) - math.pi / 2) < 1e-12
|
| 92 |
+
# astrophysical/misc units smoke (solMass, imperial mile, magnitude unit)
|
| 93 |
+
assert abs((1.0 * u.solMass).to_value(u.kg) - 1.988409870698051e30) / 1.988409870698051e30 < 1e-9
|
| 94 |
+
assert abs((1.0 * u.imperial.mile).to_value(u.m) - 1609.344) < 1e-9
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def t_skycoord():
|
| 98 |
+
from astropy.coordinates import SkyCoord
|
| 99 |
+
import astropy.units as u
|
| 100 |
+
|
| 101 |
+
a = SkyCoord(0.0 * u.deg, 0.0 * u.deg, frame="icrs")
|
| 102 |
+
b = SkyCoord(0.0 * u.deg, 90.0 * u.deg, frame="icrs")
|
| 103 |
+
assert abs(a.separation(b).deg - 90.0) < 1e-9
|
| 104 |
+
g = SkyCoord("10h00m00s", "+30d00m00s", frame="icrs").galactic
|
| 105 |
+
assert hasattr(g, "l") and hasattr(g, "b")
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def t_table():
|
| 109 |
+
from astropy.table import Table
|
| 110 |
+
|
| 111 |
+
tab = Table({"a": [1, 2, 3], "b": [4.0, 5.0, 6.0]})
|
| 112 |
+
assert len(tab) == 3
|
| 113 |
+
assert tab["a"].sum() == 6
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def t_votable_ascii():
|
| 117 |
+
from astropy.io.votable import parse_single_table # noqa: F401
|
| 118 |
+
from astropy.io.ascii import cparser # noqa: F401
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
CHECKS = [
|
| 122 |
+
("import astropy, version 8.0.1", t_import_version),
|
| 123 |
+
("native wcs._wcs (WCS object)", t_native_wcs),
|
| 124 |
+
("native utils.xml._iterparser import", t_native_iterparser),
|
| 125 |
+
("native convolution._convolve", t_native_convolve),
|
| 126 |
+
("native stats sigma_clip", t_native_stats),
|
| 127 |
+
("native io.fits roundtrip", t_native_fits),
|
| 128 |
+
("Time object + unix + scale", t_time_object),
|
| 129 |
+
("units m/km, deg/rad, solMass, mile", t_units),
|
| 130 |
+
("SkyCoord separation + galactic", t_skycoord),
|
| 131 |
+
("Table basics", t_table),
|
| 132 |
+
("votable/ascii native imports", t_votable_ascii),
|
| 133 |
+
]
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def main():
|
| 137 |
+
for name, fn in CHECKS:
|
| 138 |
+
check(name, fn)
|
| 139 |
+
print("SUMMARY: %d PASS, %d FAIL" % (PASS, FAIL))
|
| 140 |
+
return 0 if FAIL == 0 else 1
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
if __name__ == "__main__":
|
| 144 |
+
sys.exit(main())
|