def test_rotated_time_to_duration(): r1 = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-02'), rotated_time='2001-01-03') assert_quantity_allclose(r1.duration, 1 * u.day) r2 = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-02'), rotated_time='2001-01-01') assert_quantity_allclose(r2.duration, -1 * u.day)
def test_rotated_time_property(): r1 = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-02'), duration=1 * u.day) assert r1.rotated_time == Time('2001-01-03') r2 = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-02'), duration=-1 * u.day) assert r2.rotated_time == Time('2001-01-01')
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 rot_hci(): return (f.HeliocentricInertial, RotatedSunFrame(lon=1 * u.deg, lat=2 * u.deg, distance=3 * u.AU, base=f.HeliocentricInertial(obstime='2001-01-01'), duration=4 * u.day))
def test_consistency_with_rotatedsunframe(): old_observer = frames.HeliographicStonyhurst(10 * u.deg, 20 * u.deg, 1 * u.AU, obstime='2001-01-01') new_observer = frames.HeliographicStonyhurst(30 * u.deg, 40 * u.deg, 2 * u.AU, obstime='2001-01-08') hpc_coord = SkyCoord(100 * u.arcsec, 200 * u.arcsec, frame='helioprojective', observer=old_observer, obstime=old_observer.obstime) # Perform the differential rotation using solar_rotate_coordinate() result1 = solar_rotate_coordinate(hpc_coord, observer=new_observer) # Perform the differential rotation using RotatedSunFrame, with translational motion of the Sun # ignored using transform_with_sun_center() rsf_coord = RotatedSunFrame(base=hpc_coord, rotated_time=new_observer.obstime) with transform_with_sun_center(): result2 = rsf_coord.transform_to(result1.replicate_without_data()) assert_quantity_allclose(result1.Tx, result2.Tx) assert_quantity_allclose(result1.Ty, result2.Ty) assert_quantity_allclose(result1.distance, result2.distance)
def rot_hgs(): return (f.HeliographicStonyhurst, RotatedSunFrame( lon=1 * u.deg, lat=2 * u.deg, radius=3 * u.AU, base=f.HeliographicStonyhurst(obstime='2001-01-01'), duration=4 * u.day))
def rot_hgc(): return (f.HeliographicCarrington, RotatedSunFrame(lon=1 * u.deg, lat=2 * u.deg, radius=3 * u.AU, base=f.HeliographicCarrington( observer='earth', obstime='2001-01-01'), duration=4 * u.day))
def rot_hcc(): return (f.Heliocentric, RotatedSunFrame(x=1 * u.AU, y=2 * u.AU, z=3 * u.AU, base=f.Heliocentric(observer='earth', obstime='2001-01-01'), duration=4 * u.day))
def rot_hpc(): return (f.Helioprojective, RotatedSunFrame(Tx=1 * u.deg, Ty=2 * u.deg, distance=3 * u.AU, base=f.Helioprojective(observer='earth', obstime='2001-01-01'), duration=4 * u.day))
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 base = frame(lon=lon, lat=lat, obstime=obstime) # 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) # 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) # 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) # Use the `spherical` property since the name of the component varies with frame assert_quantity_allclose(result3.spherical.distance, result1.spherical.distance)
def rot_hme(): return (HeliocentricMeanEcliptic, RotatedSunFrame(lon=1 * u.deg, lat=2 * u.deg, distance=3 * u.AU, base=HeliocentricMeanEcliptic( obstime='2001-01-01', equinox='2001-01-01'), duration=4 * u.day))
def test_scalar_base_and_array_duration(): scalar_base = f.HeliographicStonyhurst(1*u.deg, 2*u.deg, obstime='2001-01-02') array_duration = [1, -1]*u.day r = RotatedSunFrame(base=scalar_base, duration=array_duration) assert not r.data.isscalar assert r.data.shape == array_duration.shape assert_quantity_allclose(r.cartesian[0].xyz, scalar_base.cartesian.xyz) assert_quantity_allclose(r.cartesian[1].xyz, scalar_base.cartesian.xyz)
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_default_rotation_model(): r = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-01')) assert r.rotation_model == "howard"
def test_no_sunpy_frame(): with pytest.raises(TypeError): RotatedSunFrame(base=BaseCoordinateFrame)
def test_no_base(): with pytest.raises(TypeError): RotatedSunFrame()
def test_no_obstime(): with pytest.raises(ValueError): RotatedSunFrame(base=f.HeliographicStonyhurst(obstime=None))
def test_default_duration(): r = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-01')) assert_quantity_allclose(r.duration, 0 * u.day)
def test_alternate_rotation_model(): r = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-01'), rotation_model="allen") assert r.rotation_model == "allen"