| 1 |
import asdf |
| 2 |
import pytest |
| 3 |
from astropy import units as u |
| 4 |
from astropy.coordinates import EarthLocation, Latitude, Longitude |
| 5 |
from astropy.coordinates.earth import ELLIPSOIDS |
| 6 |
from astropy.units import Quantity |
| 7 |
|
| 8 |
|
| 9 |
def create_earth_locations(): |
| 10 |
longitude = Longitude([0.0, 45.0, 90.0, 135.0, 180.0, -180, -90, -45], u.deg, wrap_angle=180 * u.deg) |
| 11 |
latitude = Latitude([+0.0, 30.0, 60.0, +90.0, -90.0, -60.0, -30.0, 0.0], u.deg) |
| 12 |
height = Quantity([0.1, 0.5, 1.0, -0.5, -1.0, +4.2, -11.0, -0.1], u.m) |
| 13 |
position = (longitude, latitude, height) |
| 14 |
|
| 15 |
result = [ |
| 16 |
EarthLocation(lat=34.4900 * u.deg, lon=-104.221800 * u.deg, height=40 * u.km), |
| 17 |
EarthLocation(*EarthLocation.from_geodetic(*position).to_geocentric()), |
| 18 |
] |
| 19 |
|
| 20 |
result.extend([EarthLocation.from_geodetic(*position, ellipsoid=e) for e in ELLIPSOIDS]) |
| 21 |
|
| 22 |
return result |
| 23 |
|
| 24 |
|
| 25 |
@pytest.mark.parametrize("earth_location", create_earth_locations()) |
| 26 |
def test_serialization(earth_location, tmp_path): |
| 27 |
file_path = tmp_path / "test.asdf" |
| 28 |
with asdf.AsdfFile() as af: |
| 29 |
af["earth_location"] = earth_location |
| 30 |
af.write_to(file_path) |
| 31 |
|
| 32 |
with asdf.open(file_path) as af: |
| 33 |
assert (af["earth_location"] == earth_location).all() |