File size: 4,109 Bytes
163ce95 | 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 | """Device test for astropy 8.0.1 Android wheels (x86_64 + arm64_v8a).
Generated by RIMI.
Runs on-device via the PythonSTB app Scripts folder after installing, in order:
numpy 2.5.2, pyerfa 2.0.1.5, astropy-iers-data, packaging, PyYAML,
then astropy-8.0.1-cp312-cp312-android_24_<arch>.whl.
Contract: prints [PASS]/[FAIL] per check and exits 0 iff ALL checks pass.
"""
import io
import math
import sys
PASS = 0
FAIL = 0
def check(name, fn):
global PASS, FAIL
try:
fn()
except Exception as e: # noqa: BLE001 - report any failure, never crash
FAIL += 1
print("[FAIL] %s -- %s: %s" % (name, type(e).__name__, e))
else:
PASS += 1
print("[PASS] %s" % name)
def t_import_version():
import astropy
assert astropy.__version__ == "8.0.1", astropy.__version__
def t_native_wcs():
from astropy.wcs import WCS
w = WCS(naxis=2)
w.wcs.ctype = ["RA---TAN", "DEC--TAN"]
assert w.naxis == 2
def t_native_iterparser():
from astropy.utils.xml import _iterparser # noqa: F401
def t_native_convolve():
import numpy as np
from astropy.convolution import convolve
out = convolve(np.ones(9), np.ones(3) / 3.0, boundary="extend")
assert abs(float(out[4]) - 1.0) < 1e-12, out[4]
def t_native_stats():
import numpy as np
from astropy.stats import sigma_clip
r = sigma_clip(np.array([1.0, 1.0, 1.0, 50.0]), sigma=2.0)
assert bool(getattr(r, "mask", [False] * 4)[3]) is True
def t_native_fits():
import numpy as np
from astropy.io import fits
buf = io.BytesIO()
fits.PrimaryHDU(data=np.arange(12, dtype=">i2").reshape(3, 4)).writeto(buf)
buf.seek(0)
with fits.open(buf) as hdul:
assert hdul[0].data.shape == (3, 4)
assert int(hdul[0].data.sum()) == 66
def t_time_object():
from astropy.time import Time
t = Time("2026-01-01T00:00:00", scale="utc")
assert t.iso.startswith("2026-01-01"), t.iso
assert abs(float(t.unix) - 1767225600.0) < 1.0, t.unix
assert str(t.tt.scale) == "tt"
def t_units():
import astropy.units as u
assert abs((1.0 * u.m).to_value(u.km) - 0.001) < 1e-15
assert abs((90.0 * u.deg).to_value(u.rad) - math.pi / 2) < 1e-12
# astrophysical/misc units smoke (solMass, imperial mile, magnitude unit)
assert abs((1.0 * u.solMass).to_value(u.kg) - 1.988409870698051e30) / 1.988409870698051e30 < 1e-9
assert abs((1.0 * u.imperial.mile).to_value(u.m) - 1609.344) < 1e-9
def t_skycoord():
from astropy.coordinates import SkyCoord
import astropy.units as u
a = SkyCoord(0.0 * u.deg, 0.0 * u.deg, frame="icrs")
b = SkyCoord(0.0 * u.deg, 90.0 * u.deg, frame="icrs")
assert abs(a.separation(b).deg - 90.0) < 1e-9
g = SkyCoord("10h00m00s", "+30d00m00s", frame="icrs").galactic
assert hasattr(g, "l") and hasattr(g, "b")
def t_table():
from astropy.table import Table
tab = Table({"a": [1, 2, 3], "b": [4.0, 5.0, 6.0]})
assert len(tab) == 3
assert tab["a"].sum() == 6
def t_votable_ascii():
from astropy.io.votable import parse_single_table # noqa: F401
from astropy.io.ascii import cparser # noqa: F401
CHECKS = [
("import astropy, version 8.0.1", t_import_version),
("native wcs._wcs (WCS object)", t_native_wcs),
("native utils.xml._iterparser import", t_native_iterparser),
("native convolution._convolve", t_native_convolve),
("native stats sigma_clip", t_native_stats),
("native io.fits roundtrip", t_native_fits),
("Time object + unix + scale", t_time_object),
("units m/km, deg/rad, solMass, mile", t_units),
("SkyCoord separation + galactic", t_skycoord),
("Table basics", t_table),
("votable/ascii native imports", t_votable_ascii),
]
def main():
for name, fn in CHECKS:
check(name, fn)
print("SUMMARY: %d PASS, %d FAIL" % (PASS, FAIL))
return 0 if FAIL == 0 else 1
if __name__ == "__main__":
sys.exit(main())
|