def test_HEEQ_creation(): # Smoke test to make sure HEEQ constructors work fine _ = HeliographicStonyhurst(lon=0*u.deg, lat=90*u.deg, obstime=parse_time('2018-12-21')) _ = HeliographicStonyhurst(lon=0*u.deg, lat=90*u.deg, radius=1*u.km, obstime=parse_time('2018-12-21')) _ = HeliographicStonyhurst(x=1*u.km, y=1*u.km, z=1*u.km, obstime=parse_time('2018-12-21'), representation_type='cartesian')
def test_hgs_cart_init(): hpc1 = HeliographicStonyhurst(CartesianRepresentation(0 * u.km, 0 * u.km, 1 * u.Mm)) assert isinstance(hpc1, HeliographicStonyhurst) assert isinstance(hpc1._data, CartesianRepresentation)
def test_hpc_low_precision_float_warning(): hpc = Helioprojective(u.Quantity(0, u.deg, dtype=np.float32), u.Quantity(0, u.arcsec, dtype=np.float16), observer=HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU)) with pytest.raises(SunpyUserWarning, match="Tx is float32, and Ty is float16"): hpc.make_3d()
def test_observer_in_heeq(frame_class): # An observer provided in HGS Cartesian (i.e., HEEQ) should be converted to HGS spherical obs_heeq = HeliographicStonyhurst((3, 4, 12) * u.AU, representation_type='cartesian') frame = frame_class(observer=obs_heeq) assert issubclass(frame.observer.representation_type, SphericalRepresentation) assert_quantity_allclose(frame.observer.radius, 13 * u.AU)
def test_hgs_frame_to_wcs(): frame = HeliographicStonyhurst(obstime='2013-10-28') result_wcs = solar_frame_to_wcs_mapping(frame) assert isinstance(result_wcs, WCS) assert result_wcs.wcs.ctype[0] == 'HGLN-TAN' assert result_wcs.wcs.cunit[0] == 'deg' assert result_wcs.wcs.dateobs == '2013-10-28T00:00:00.000'
def test_observer_not_default_representation(oca): observer = HeliographicStonyhurst((1, 0, 0) * u.AU, representation_type='cartesian', obstime='2001-01-01') result, converted = oca.convert_input(observer) assert isinstance(result, HeliographicStonyhurst) assert issubclass(result.representation_type, SphericalRepresentation) assert result.obstime == observer.obstime assert converted
def test_hgs_frame_to_wcs(): frame = HeliographicStonyhurst(obstime='2013-10-28', rsun=690 * u.Mm) result_wcs = solar_frame_to_wcs_mapping(frame) assert isinstance(result_wcs, WCS) assert result_wcs.wcs.ctype[0] == 'HGLN-TAN' assert result_wcs.wcs.cunit[0] == 'deg' assert result_wcs.wcs.dateobs == '2013-10-28T00:00:00.000' assert result_wcs.wcs.aux.rsun_ref == frame.rsun.to_value(u.m) new_frame = solar_wcs_frame_mapping(result_wcs) assert new_frame.rsun == frame.rsun # Test a frame with no obstime frame = HeliographicStonyhurst() result_wcs = solar_frame_to_wcs_mapping(frame) assert isinstance(result_wcs, WCS) assert result_wcs.wcs.ctype[0] == 'HGLN-TAN' assert result_wcs.wcs.cunit[0] == 'deg' assert result_wcs.wcs.dateobs == ''
def test_hpc_distance_off_limb(): hpc1 = Helioprojective(1500 * u.arcsec, 0 * u.arcsec, observer=HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU)) assert isinstance(hpc1, Helioprojective) # Check that we have a 2D wrap180 representation assert isinstance(hpc1._data, UnitSphericalRepresentation) # Check the attrs are correct assert hpc1.Tx == 1500 * u.arcsec assert hpc1.Ty == 0 * u.arcsec with pytest.warns(SunpyUserWarning, match="is all NaNs"): hpc2 = hpc1.make_3d() assert isinstance(hpc2._data, SphericalRepresentation) # Check the attrs are correct assert hpc2.Tx == 1500 * u.arcsec assert hpc2.Ty == 0 * u.arcsec assert_quantity_allclose(hpc2.distance, u.Quantity(np.nan, u.km))
def test_coord_get(): # Test default (instance=None) obs = Helioprojective.observer assert obs is None # Test get obstime = "2013-04-01" obs = Helioprojective(observer="earth", obstime=obstime).observer earth = get_earth(obstime) assert isinstance(obs, HeliographicStonyhurst) assert_quantity_allclose(obs.lon, earth.lon) assert_quantity_allclose(obs.lat, earth.lat) assert_quantity_allclose(obs.radius, earth.radius) assert hasattr(obs, "object_name") assert obs.object_name == "earth" assert str(obs) == "<HeliographicStonyhurst Coordinate for 'earth'>" # Test get obstime = "2013-04-01" obs = Helioprojective(observer="earth", obstime=obstime).observer earth = get_earth(obstime) assert isinstance(obs, HeliographicStonyhurst) assert_quantity_allclose(obs.lon, earth.lon) assert_quantity_allclose(obs.lat, earth.lat) assert_quantity_allclose(obs.radius, earth.radius) # Test get mars obstime = Time(parse_time("2013-04-01")) obs = Helioprojective(observer="mars", obstime=obstime).observer out_icrs = ICRS(get_body_barycentric("mars", obstime)) mars = out_icrs.transform_to(HeliographicStonyhurst(obstime=obstime)) assert isinstance(obs, HeliographicStonyhurst) assert_quantity_allclose(obs.lon, mars.lon) assert_quantity_allclose(obs.lat, mars.lat) assert_quantity_allclose(obs.radius, mars.radius) assert hasattr(obs, "object_name") assert obs.object_name == "mars" assert str(obs) == "<HeliographicStonyhurst Coordinate for 'mars'>"
def test_hpc_distance(): hpc1 = Helioprojective(0 * u.deg, 0 * u.arcsec, observer=HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU)) assert isinstance(hpc1, Helioprojective) # Check that we have a 2D wrap180 representation assert isinstance(hpc1._data, UnitSphericalRepresentation) # Check the attrs are correct assert hpc1.Tx == 0 * u.arcsec assert hpc1.Ty == 0 * u.arcsec hpc2 = hpc1.make_3d() assert isinstance(hpc2._data, SphericalRepresentation) # Check the attrs are correct assert hpc2.Tx == 0 * u.arcsec assert hpc2.Ty == 0 * u.arcsec assert_quantity_allclose(hpc2.distance, DSUN_METERS - RSUN_METERS)
def test_wcs_frame_mapping_observer_hgc_self(): # Test whether a WCS with HGC coordinates for the observer location uses observer="self" wcs = WCS(naxis=2) wcs.wcs.ctype = ['SOLX', 'SOLY'] wcs.wcs.dateobs = '2001-01-01' wcs.wcs.aux.crln_obs = 10 wcs.wcs.aux.hglt_obs = 20 wcs.wcs.aux.dsun_obs = 1.5e11 # This frame will have the observer location in HGS result = solar_wcs_frame_mapping(wcs) # We perform the desired transformation using observer="self" hgc_obs = HeliographicCarrington(wcs.wcs.aux.crln_obs * u.deg, wcs.wcs.aux.hglt_obs * u.deg, wcs.wcs.aux.dsun_obs * u.m, obstime=wcs.wcs.dateobs, observer="self") hgs_obs = hgc_obs.transform_to( HeliographicStonyhurst(obstime=hgc_obs.obstime)) assert_quantity_allclose(result.observer.lon, hgs_obs.lon) assert_quantity_allclose(result.observer.lat, hgs_obs.lat) assert_quantity_allclose(result.observer.radius, hgs_obs.radius)
def test_hgs_wrapping_off(): hpc1 = HeliographicStonyhurst(350*u.deg, 10*u.deg, wrap_longitude=False) assert_quantity_allclose(hpc1.lon, 350*u.deg) assert_quantity_allclose(hpc1.lon.wrap_angle, 360*u.deg)
def test_hgs_wrapping_on(): hpc1 = HeliographicStonyhurst(350*u.deg, 10*u.deg) assert_quantity_allclose(hpc1.lon, -10*u.deg) assert_quantity_allclose(hpc1.lon.wrap_angle, 180*u.deg)