|
22 | 22 |
|
23 | 23 | import astropy.units as u |
24 | 24 | from astropy import constants |
25 | | -from astropy.coordinates import ( |
26 | | - EarthLocation, AltAz, SkyCoord, |
27 | | - CartesianRepresentation, UnitSphericalRepresentation) |
| 25 | +from astropy.coordinates import EarthLocation, AltAz, SkyCoord, CartesianRepresentation |
28 | 26 | from astropy.time import Time |
29 | | -from astropy.coordinates.matrix_utilities import rotation_matrix |
30 | 27 | import numpy as np |
31 | 28 | try: |
32 | 29 | from numpy.typing import ArrayLike |
@@ -450,47 +447,26 @@ def test_sample_out( |
450 | 447 | np.testing.assert_array_equal(out, expected) |
451 | 448 |
|
452 | 449 |
|
453 | | -def _skyoffset_matrix(origin: SkyCoord): |
454 | | - """Reproduce the matrix used by :class:`astropy.coordinates.SkyOffsetFrame`. |
455 | | -
|
456 | | - This is the matrix for transforming from a reference frame to an offset |
457 | | - frame. It does not support the rotation attribute of |
458 | | - :class:`astropy.coordinates.SkyOffsetFrame`. |
459 | | - """ |
460 | | - # Based on reference_to_skyoffset in the astropy code. |
461 | | - origin_sph = origin.spherical |
462 | | - maty = rotation_matrix(-origin_sph.lat, 'y') |
463 | | - matz = rotation_matrix(origin_sph.lon, 'z') |
464 | | - return maty @ matz |
465 | | - |
466 | | - |
467 | 450 | def _coords_to_lm(coords: SkyCoord, origin: SkyCoord) -> np.ndarray: |
468 | 451 | """Convert sky coordinates to l/m direction cosines. |
469 | 452 |
|
470 | 453 | The `coords` and `origin` must be in the same frame. |
471 | | -
|
472 | | - This would be simpler with SkyOffsetFrame, but unfortunately |
473 | | - https://github.com/astropy/astropy/issues/11277 makes it break randomly. |
474 | 454 | """ |
| 455 | + # Go via .frame as workaround for https://github.com/astropy/astropy/issues/11277 |
475 | 456 | assert coords.frame.is_equivalent_frame(origin.frame) |
476 | | - mat = _skyoffset_matrix(origin) |
477 | | - offsets = coords.represent_as(CartesianRepresentation).transform(mat) |
478 | | - return offsets.xyz[1:] # astropy spherical (0, 0) at +x, so y, z are l, m |
| 457 | + skyoffset = coords.frame.transform_to(origin.skyoffset_frame()) |
| 458 | + offsets = skyoffset.represent_as(CartesianRepresentation) |
| 459 | + return offsets.xyz[1:] # astropy puts spherical (0, 0) at +x, so y, z are l, m |
479 | 460 |
|
480 | 461 |
|
481 | 462 | def _lm_to_coords(l: ArrayLike, m: ArrayLike, origin: SkyCoord) -> SkyCoord: |
482 | | - """Convert l/m cooordinates relative to an origin into coordinates. |
483 | | -
|
484 | | - This would be simpler with SkyOffsetFrame, but unfortunately |
485 | | - https://github.com/astropy/astropy/issues/11277 makes it break randomly. |
486 | | - """ |
| 463 | + """Convert l/m cooordinates relative to an origin into coordinates.""" |
487 | 464 | l = np.asarray(l) |
488 | 465 | m = np.asarray(m) |
489 | 466 | n = np.sqrt(1 - (l * l + m * m)) |
490 | 467 | nlm = CartesianRepresentation(np.stack([n, l, m])) |
491 | | - mat = _skyoffset_matrix(origin).T # Transposing a rotation matrix inverts it |
492 | | - xyz = nlm.transform(mat) |
493 | | - return SkyCoord(xyz.represent_as(UnitSphericalRepresentation), frame=origin) |
| 468 | + skyoffset = SkyCoord(nlm, frame=origin.skyoffset_frame()) |
| 469 | + return skyoffset.transform_to(origin) |
494 | 470 |
|
495 | 471 |
|
496 | 472 | @pytest.mark.parametrize('lat', [-30 * u.deg, 35 * u.deg]) |
|
0 commit comments