def test_obstime_change_loopback(indirect_fixture): base_class, rot_frame = indirect_fixture # Doing a explicit loopback transformation through an intermediate frame with a different # obstime should get back to the original coordinate int_frame = base_class(obstime='2001-01-31') loopback = rot_frame.transform_to(int_frame).transform_to(rot_frame) assert_longitude_allclose(loopback.lon, rot_frame.lon, atol=1e-10 * u.deg)
def test_as_base(rot_hgs): # Check the as_base() method a = rot_hgs[1].as_base() assert type(a) == type(rot_hgs[1].base) assert_longitude_allclose(a.lon, rot_hgs[1].lon) assert_quantity_allclose(a.lat, rot_hgs[1].lat) assert_quantity_allclose(a.radius, rot_hgs[1].radius)
def test_transform(lon, lat): """ Test that the north pole in the new frame transforms back to the given north argument. """ north = SkyCoord(lon=lon, lat=lat, frame='heliographic_stonyhurst') off = NorthOffsetFrame(north=north) t_north = SkyCoord(lon=0 * u.deg, lat=90 * u.deg, frame=off) t_north = t_north.transform_to('heliographic_stonyhurst') assert_longitude_allclose(north.lon, t_north.lon, atol=1e-6 * u.deg) assert_quantity_allclose(north.lat, t_north.lat, atol=1e-6 * u.deg)
def test_obstime_change(indirect_fixture): base_class, rot_frame = indirect_fixture # Transforming a RotatedSun coordinate to a different obstime should give the same answer # as first transforming to its base and then transforming to the different obstime new_frame = base_class(obstime='2001-01-31') new_implicit = rot_frame.transform_to(new_frame) new_explicit = rot_frame.transform_to( rot_frame.base).transform_to(new_frame) assert_longitude_allclose(new_implicit.lon, new_explicit.lon, atol=1e-10 * u.deg)
def test_cartesian(): # Test a north pole specified in Cartesian coordinates s = SkyCoord(1, 2, 3, unit=u.m, representation_type='cartesian', frame='heliographic_stonyhurst') off = NorthOffsetFrame(north=s) assert_longitude_allclose(off.origin.lon, np.arctan2(s.y, s.x)) assert_quantity_allclose( off.origin.lat, np.arctan2(s.z, np.sqrt(s.x**2 + s.y**2)) - 90 * u.deg)
def test_base_skycoord(rot_hgs): # Check that RotatedSunFrame can be instantiated from a SkyCoord s = SkyCoord(1 * u.deg, 2 * u.deg, 3 * u.AU, frame=f.HeliographicStonyhurst, obstime='2001-01-01') r = RotatedSunFrame(base=s) assert type(r) == type(rot_hgs[1]) assert r.has_data assert not r.base.has_data assert_longitude_allclose(r.lon, s.lon) assert_quantity_allclose(r.lat, s.lat) assert_quantity_allclose(r.radius, s.radius)
def test_rotatedsun_transforms(frame, lon, lat, obstime, rotated_time1, rotated_time2): # Tests the transformations (to, from, and loopback) for consistency with `diff_rot` output if hasattr(frame, 'observer'): base = frame(lon=lon, lat=lat, observer='earth', obstime=obstime) else: base = frame(lon=lon, lat=lat, obstime=obstime) # Map any 2D coordinate to the surface of the Sun if base.spherical.distance.unit is u.one and u.allclose( base.spherical.distance, 1 * u.one): newrepr = base.spherical * constants.radius base = base.realize_frame(newrepr) # Test the RotatedSunFrame->base transformation rsf1 = RotatedSunFrame(base=base, rotated_time=rotated_time1) result1 = rsf1.transform_to(base) desired_delta_lon1 = diff_rot((rotated_time1 - obstime).to(u.day), lat) assert_longitude_allclose(result1.lon, rsf1.lon + desired_delta_lon1, atol=1e-5 * u.deg) assert_quantity_allclose(base.lat, result1.lat, atol=1e-10 * u.deg) # Use the `spherical` property since the name of the component varies with frame assert_quantity_allclose(base.spherical.distance, result1.spherical.distance) # Test the base->RotatedSunFrame transformation rsf2 = RotatedSunFrame(base=base, rotated_time=rotated_time2) result2 = base.transform_to(rsf2) desired_delta_lon2 = -diff_rot((rotated_time2 - obstime).to(u.day), lat) assert_longitude_allclose(result2.lon, rsf2.lon + desired_delta_lon2, atol=1e-5 * u.deg) assert_quantity_allclose(base.lat, result2.lat, atol=1e-10 * u.deg) # Use the `spherical` property since the name of the component varies with frame assert_quantity_allclose(base.spherical.distance, result2.spherical.distance) # Test the RotatedSunFrame->RotatedSunFrame transformation result3 = rsf1.transform_to(rsf2) desired_delta_lon3 = desired_delta_lon1 + desired_delta_lon2 assert_longitude_allclose(result3.lon, rsf1.lon + desired_delta_lon3, atol=1e-5 * u.deg) assert_quantity_allclose(result3.lat, result1.lat, atol=1e-10 * u.deg) # Use the `spherical` property since the name of the component varies with frame assert_quantity_allclose(result3.spherical.distance, result1.spherical.distance)
def test_south_pole(): s = SkyCoord(-10 * u.deg, 0 * u.deg, frame='heliographic_stonyhurst') off = NorthOffsetFrame(north=s) assert_longitude_allclose(off.origin.lon, 170 * u.deg) assert_quantity_allclose(off.origin.lat, -90 * u.deg)