| 1 |
import warnings |
| 2 |
|
| 3 |
import asdf |
| 4 |
import pytest |
| 5 |
from astropy import units as u |
| 6 |
from astropy.coordinates import ICRS, Galactic, SpectralCoord |
| 7 |
from astropy.coordinates.spectral_coordinate import NoVelocityWarning |
| 8 |
|
| 9 |
from asdf_astropy.testing.helpers import assert_spectral_coord_equal |
| 10 |
|
| 11 |
|
| 12 |
def create_spectral_coords(): |
| 13 |
result = [ |
| 14 |
# Scalar |
| 15 |
SpectralCoord(565 * u.nm), |
| 16 |
# Vector |
| 17 |
SpectralCoord([100, 200, 300] * u.GHz), |
| 18 |
] |
| 19 |
|
| 20 |
with warnings.catch_warnings(): |
| 21 |
warnings.simplefilter("ignore", NoVelocityWarning) |
| 22 |
result.append( |
| 23 |
# With observer and target |
| 24 |
SpectralCoord( |
| 25 |
10 * u.GHz, |
| 26 |
observer=ICRS(1 * u.km, 2 * u.km, 3 * u.km, representation_type="cartesian"), |
| 27 |
target=Galactic(10 * u.deg, 20 * u.deg, distance=30 * u.pc), |
| 28 |
), |
| 29 |
) |
| 30 |
|
| 31 |
return result |
| 32 |
|
| 33 |
|
| 34 |
@pytest.mark.filterwarnings("ignore::astropy.coordinates.spectral_coordinate.NoVelocityWarning") |
| 35 |
@pytest.mark.parametrize("coord", create_spectral_coords()) |
| 36 |
def test_serialization(coord, tmp_path): |
| 37 |
file_path = tmp_path / "test.asdf" |
| 38 |
|
| 39 |
with asdf.AsdfFile() as af: |
| 40 |
af["coord"] = coord |
| 41 |
af.write_to(file_path) |
| 42 |
|
| 43 |
with asdf.open(file_path) as af: |
| 44 |
assert_spectral_coord_equal(af["coord"], coord) |