Ejemplo n.º 1
0
def test_differential_rotate(aia171_test_map, all_off_disk_map,
                             all_on_disk_map, straddles_limb_map):

    # Test a map that is entirely off the disk of the Sun
    # Should report an error
    with pytest.raises(ValueError):
        dmap = differential_rotate(all_off_disk_map)

    # Test a full disk map
    new_observer = get_earth(aia171_test_map.date + 6 * u.hr)
    dmap = differential_rotate(aia171_test_map, observer=new_observer)
    assert dmap.data.shape == aia171_test_map.data.shape

    # Test a map that is entirely on disk - triggers sub full disk branches
    # Rotated map should have a smaller extent in the x - direction
    new_observer = get_earth(all_on_disk_map.date - 48 * u.hr)
    dmap = differential_rotate(all_on_disk_map, observer=new_observer)
    assert dmap.data.shape[1] < all_on_disk_map.data.shape[1]

    # This rotated map should have a larger extent in the x direction
    new_observer = get_earth(all_on_disk_map.date + 48 * u.hr)
    dmap = differential_rotate(all_on_disk_map, observer=new_observer)
    assert dmap.data.shape[1] > all_on_disk_map.data.shape[1]

    # Test a map that straddles the limb - triggers sub full disk branches
    # Rotated map should have a smaller extent in the x - direction
    new_observer = get_earth(straddles_limb_map.date + 48 * u.hr)
    dmap = differential_rotate(straddles_limb_map, observer=new_observer)
    assert dmap.data.shape[1] < straddles_limb_map.data.shape[1]

    # The output map should have the positional properties of the observer
    assert dmap.date == new_observer.obstime
    assert dmap.heliographic_latitude == new_observer.lat
    assert dmap.heliographic_longitude == new_observer.lon
Ejemplo n.º 2
0
def test_differential_rotate(aia171_test_map, all_off_disk_map, all_on_disk_map, straddles_limb_map):

    # Test a map that is entirely off the disk of the Sun
    # Should report an error
    with pytest.raises(ValueError):
        dmap = differential_rotate(all_off_disk_map)

    # Test a full disk map
    new_observer = get_earth(aia171_test_map.date + 6*u.hr)
    dmap = differential_rotate(aia171_test_map, observer=new_observer)
    assert dmap.data.shape == aia171_test_map.data.shape

    # Test a map that is entirely on disk - triggers sub full disk branches
    # Rotated map should have a smaller extent in the x - direction
    new_observer = get_earth(all_on_disk_map.date - 48*u.hr)
    dmap = differential_rotate(all_on_disk_map, observer=new_observer)
    assert dmap.data.shape[1] < all_on_disk_map.data.shape[1]

    # This rotated map should have a larger extent in the x direction
    new_observer = get_earth(all_on_disk_map.date + 48*u.hr)
    dmap = differential_rotate(all_on_disk_map, observer=new_observer)
    assert dmap.data.shape[1] > all_on_disk_map.data.shape[1]

    # Test a map that straddles the limb - triggers sub full disk branches
    # Rotated map should have a smaller extent in the x - direction
    new_observer = get_earth(straddles_limb_map.date + 48*u.hr)
    dmap = differential_rotate(straddles_limb_map, observer=new_observer)
    assert dmap.data.shape[1] < straddles_limb_map.data.shape[1]

    # The output map should have the positional properties of the observer
    assert dmap.date == new_observer.obstime
    assert dmap.heliographic_latitude == new_observer.lat
    assert dmap.heliographic_longitude == new_observer.lon
Ejemplo n.º 3
0
def test_solar_rotate_coordinate():
    # Testing along the Sun-Earth line, observer is on the Earth
    obs_time = '2010-09-10 12:34:56'
    observer = get_earth(obs_time)
    c = SkyCoord(-570 * u.arcsec,
                 120 * u.arcsec,
                 obstime=obs_time,
                 observer=observer,
                 frame=frames.Helioprojective)
    new_time = '2010-09-11 12:34:56'
    new_observer = get_earth(new_time)

    # Test that when both the observer and the time are specified, an error is raised.
    with pytest.raises(ValueError):
        d = solar_rotate_coordinate(c, observer=observer, time=new_time)

    # Test that the code properly filters the observer keyword
    with pytest.raises(ValueError):
        d = solar_rotate_coordinate(c, observer='earth')

    # Test that the code properly filters the time keyword
    with pytest.raises(ValueError):
        with pytest.warns(
                UserWarning,
                match="Using 'time' assumes an Earth-based observer"):
            d = solar_rotate_coordinate(c, time='noon')

    # Test that the code gives the same output for multiple different inputs
    # that define the same observer location and time.
    for i, definition in enumerate(
        (1 * u.day, TimeDelta(1 * u.day), new_time, new_observer)):
        if i in (0, 1, 2):
            with pytest.warns(
                    UserWarning,
                    match="Using 'time' assumes an Earth-based observer"):
                d = solar_rotate_coordinate(c, time=definition)
        else:
            d = solar_rotate_coordinate(c, observer=definition)

        # Test that a SkyCoordinate is created
        assert isinstance(d, SkyCoord)

        # Test the coordinate
        np.testing.assert_almost_equal(d.Tx.to(u.arcsec).value,
                                       -371.8885208634674,
                                       decimal=1)
        np.testing.assert_almost_equal(d.Ty.to(u.arcsec).value,
                                       105.35006656251727,
                                       decimal=1)
        np.testing.assert_allclose(d.distance.to(u.km).value,
                                   1.499642e+08,
                                   rtol=1e-5)

        # Test that the SkyCoordinate is Helioprojective
        assert isinstance(d.frame, frames.Helioprojective)
Ejemplo n.º 4
0
def test_get_earth():
    # Validate against published values from the Astronomical Almanac (2013)
    e1 = get_earth('2013-Jan-01')
    assert e1.lon == 0 * u.deg
    assert_quantity_allclose(e1.lat, -3.03 * u.deg, atol=5e-3 * u.deg)
    assert_quantity_allclose(e1.radius, 0.9832947 * u.AU, atol=5e-7 * u.AU)

    e2 = get_earth('2013-Sep-01')
    assert e2.lon == 0 * u.deg
    assert_quantity_allclose(e2.lat, 7.19 * u.deg, atol=5e-3 * u.deg)
    assert_quantity_allclose(e2.radius, 1.0092561 * u.AU, atol=5e-7 * u.AU)
Ejemplo n.º 5
0
def test_differential_rotate_observer_all_on_disk(all_on_disk_map):
    # Test a map that is entirely on disk - triggers sub full disk branches
    # Rotated map should have a smaller extent in the x - direction
    new_observer = get_earth(all_on_disk_map.date - 48 * u.hr)
    dmap = differential_rotate(all_on_disk_map, observer=new_observer)
    assert dmap.data.shape[1] < all_on_disk_map.data.shape[1]
    # This rotated map should have a larger extent in the x direction
    new_observer = get_earth(all_on_disk_map.date + 48 * u.hr)
    dmap = differential_rotate(all_on_disk_map, observer=new_observer)
    assert dmap.data.shape[1] > all_on_disk_map.data.shape[1]
    assert dmap.date.isot == new_observer.obstime.isot
    assert dmap.heliographic_latitude == new_observer.lat
    assert dmap.heliographic_longitude == new_observer.lon
def test_solar_rotate_coordinate():
    # Testing along the Sun-Earth line, observer is on the Earth
    obstime = '2010-09-10 12:34:56'
    newtime = '2010-09-10 13:34:56'
    c = SkyCoord(-570*u.arcsec, 120*u.arcsec, obstime=obstime, observer=get_earth(obstime),
                 frame=frames.Helioprojective)
    d = solar_rotate_coordinate(c, newtime)

    # Test that a SkyCoordinate is created
    assert isinstance(d, SkyCoord)

    # Test the coordinate
    np.testing.assert_almost_equal(d.Tx.to(u.arcsec).value, -562.3768, decimal=1)
    np.testing.assert_almost_equal(d.Ty.to(u.arcsec).value, 119.2684, decimal=1)
    np.testing.assert_almost_equal(d.distance.to(u.km).value, 150083151.97246578, decimal=1)

    # Test that the SkyCoordinate is Helioprojective
    assert isinstance(d.frame, frames.Helioprojective)

    # Test the observer
    assert d.observer.obstime == Time(parse_time(newtime), scale='utc')
    np.testing.assert_almost_equal(d.observer.lon.to(u.deg).value, 0.0, decimal=5)
    np.testing.assert_almost_equal(d.observer.lat.to(u.deg).value, 7.248, decimal=3)
    np.testing.assert_almost_equal(d.observer.radius.to(u.AU).value, 1.006954, decimal=6)
    assert isinstance(d.observer, frames.HeliographicStonyhurst)
Ejemplo n.º 7
0
def test_solar_rotate_coordinate():
    # Testing along the Sun-Earth line, observer is on the Earth
    obstime = '2010-09-10 12:34:56'
    newtime = '2010-09-10 13:34:56'
    c = SkyCoord(-570*u.arcsec, 120*u.arcsec, obstime=obstime, observer=get_earth(obstime),
                 frame=frames.Helioprojective)
    d = solar_rotate_coordinate(c, newtime)

    # Test that a SkyCoordinate is created
    assert isinstance(d, SkyCoord)

    # Test the coordinate
    np.testing.assert_almost_equal(d.Tx.to(u.arcsec).value, -562.3768, decimal=1)
    np.testing.assert_almost_equal(d.Ty.to(u.arcsec).value, 119.2684, decimal=1)
    np.testing.assert_almost_equal(d.distance.to(u.km).value, 150083151.97246578, decimal=1)

    # Test that the SkyCoordinate is Helioprojective
    assert isinstance(d.frame, frames.Helioprojective)

    # Test the observer
    assert d.observer.obstime == Time(parse_time(newtime), scale='utc')
    np.testing.assert_almost_equal(d.observer.lon.to(u.deg).value, 0.0, decimal=5)
    np.testing.assert_almost_equal(d.observer.lat.to(u.deg).value, 7.248, decimal=3)
    np.testing.assert_almost_equal(d.observer.radius.to(u.AU).value, 1.006954, decimal=6)
    assert isinstance(d.observer, frames.HeliographicStonyhurst)
Ejemplo n.º 8
0
def test_rotate_submap_edge(aia171_test_map, all_off_disk_map, all_on_disk_map, straddles_limb_map):

    observer = get_earth(aia171_test_map.date + 2*u.day)

    # For a map that has all the edges off disk, the function should
    # return just the edges of the map - no solar rotation applied.
    for this_map in (aia171_test_map, all_off_disk_map):
        edges = map_edges(this_map)
        for this_edge in range(0, 4):
            pixels = edges[this_edge]
            res = _rotate_submap_edge(this_map, pixels, observer)
            assert all(res.Tx == (this_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
            assert all(res.Ty == (this_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)

    # For an on disk map, all the edges should change
    edges = map_edges(all_on_disk_map)
    for this_edge in range(0, 4):
        pixels = edges[this_edge]
        res = _rotate_submap_edge(all_on_disk_map, pixels, observer)
        assert all(res.Tx != (all_on_disk_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
        assert all(res.Ty != (all_on_disk_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)

    # For the limb map, two of the edges move and two do not
    edges = map_edges(straddles_limb_map)
    for this_edge in (0, 3):  # Top and right edges do not move
        pixels = edges[this_edge]
        res = _rotate_submap_edge(straddles_limb_map, pixels, observer)
        assert all(res.Tx == (straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
        assert all(res.Ty == (straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)

    for this_edge in (1, 2):  # Bottom and left edges do move
        pixels = edges[this_edge]
        res = _rotate_submap_edge(straddles_limb_map, pixels, observer)
        assert all(res.Tx != (straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
        assert all(res.Ty != (straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)
def test_rotate_submap_edge(aia171_test_map, all_off_disk_map, all_on_disk_map, straddles_limb_map):

    observer = get_earth(aia171_test_map.date + 2*u.day)

    # For a map that has all the edges off disk, the function should
    # return just the edges of the map - no solar rotation applied.
    for this_map in (aia171_test_map, all_off_disk_map):
        edges = map_edges(this_map)
        for this_edge in range(0, 4):
            pixels = edges[this_edge]
            res = _rotate_submap_edge(this_map, pixels, observer)
            assert all(res.Tx == (this_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
            assert all(res.Ty == (this_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)

    # For an on disk map, all the edges should change
    edges = map_edges(all_on_disk_map)
    for this_edge in range(0, 4):
        pixels = edges[this_edge]
        res = _rotate_submap_edge(all_on_disk_map, pixels, observer)
        assert all(res.Tx != (all_on_disk_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
        assert all(res.Ty != (all_on_disk_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)

    # For the limb map, two of the edges move and two do not
    edges = map_edges(straddles_limb_map)
    for this_edge in (0, 3):  # Top and right edges do not move
        pixels = edges[this_edge]
        res = _rotate_submap_edge(straddles_limb_map, pixels, observer)
        assert all(res.Tx == (straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
        assert all(res.Ty == (straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)

    for this_edge in (1, 2):  # Bottom and left edges do move
        pixels = edges[this_edge]
        res = _rotate_submap_edge(straddles_limb_map, pixels, observer)
        assert all(res.Tx != (straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
        assert all(res.Ty != (straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)
def calc_ci(MAPCUBE, xdim, ydim, LOCS, id):
	c1 = SkyCoord(LOCS[id].Tx - xdim/2.0,
				  LOCS[id].Ty - ydim/2.0,
				  frame = MAPCUBE[id].coordinate_frame)

	c2 = SkyCoord(LOCS[id].Tx + xdim/2.0,
				  LOCS[id].Ty + ydim/2.0,
				  frame = MAPCUBE[id].coordinate_frame)

	CUTOUT = MAPCUBE[id].submap(c1, c2)
	DATA = CUTOUT.data
	THRESHOLD = np.amax(DATA) - 500

	for i in range(len(DATA)):

		for j in range(len(DATA[0])):

			if DATA[i][j] < THRESHOLD:
				DATA[i][j] = 0

	ci = list(ndimage.measurements.center_of_mass(DATA))
	ci = [int(ci[1] + 0.5) * u.pixel, int(ci[0] + 0.5) * u.pixel]

 	COORD = CUTOUT.pixel_to_world(ci[0], ci[1])

 	return SkyCoord(COORD.Tx,
 					COORD.Ty,
 					obstime = str(MAPCUBE[id].date),
 					observer = get_earth(MAPCUBE[id].date),
 					frame = frames.Helioprojective)
Ejemplo n.º 11
0
def map_rot_correct(mmap,refx,refy,reftime):
    """
    Correct the solar rotation.
    
    Parameters
    ----------
    mmap : sunpy.map.GenericMap
        Single map class.
    refx : astropy.units.Quantity
        Horizontal wcs information of reference frame.
    refy : astropy.units.Quantity
        Vertical wcs information of reference frame.
    reftime : astropy.time.Time
        Time for the reference frame.
    
    Returns
    -------
    smap : sunpy.map.GenericMap
        Solar rotation corrected map class.
    
    """
    
    refc = SkyCoord(refx, refy, obstime= reftime,
                    observer= get_earth(reftime),
                    frame= frames.Helioprojective)
    
    date = mmap.date
    res = solar_rotate_coordinate(refc, date ,frame_time= 'synodic')
    x = res.Tx.value
    y = res.Ty.value
    
    sx = x - refx.value
    sy = y - refy.value
    smap = mmap.shift(-sx,-sy)
    return smap
Ejemplo n.º 12
0
def test_get_body_heliographic_stonyhurst_light_travel_time():
    # Tests whether the apparent position of the Sun accounts for light travel time
    t = Time('2012-06-05 22:34:48.350')  # An arbitrary test time

    # Use the implemented correction for light travel time
    implementation = get_body_heliographic_stonyhurst('sun',
                                                      t,
                                                      observer=get_earth(t))
    implementation_icrs = SkyCoord(implementation).icrs.cartesian

    # Use a manual correction for light travel time
    light_travel_time = get_earth(t).radius / speed_of_light
    manual = get_body_heliographic_stonyhurst('sun', t - light_travel_time)
    manual_icrs = SkyCoord(manual).icrs.cartesian

    difference = (implementation_icrs - manual_icrs).norm()
    assert_quantity_allclose(difference, 0 * u.m, atol=1 * u.m)
Ejemplo n.º 13
0
def test_differential_rotate_observer_full_disk(aia171_test_map):
    # Test a full disk map
    new_observer = get_earth(aia171_test_map.date + 6 * u.hr)
    dmap = differential_rotate(aia171_test_map, observer=new_observer)
    assert dmap.data.shape == aia171_test_map.data.shape
    assert dmap.date.isot == new_observer.obstime.isot
    assert dmap.heliographic_latitude == new_observer.lat
    assert dmap.heliographic_longitude == new_observer.lon
Ejemplo n.º 14
0
def test_get_body_heliographic_stonyhurst_light_travel_time_array():
    # Tests whether requesting an array of locations returns the same answers as individually
    t1 = Time('2001-02-03 04:05:06')
    t2 = Time('2011-12-13 14:15:16')

    venus1 = get_body_heliographic_stonyhurst('venus',
                                              t1,
                                              observer=get_earth(t1))
    venus2 = get_body_heliographic_stonyhurst('venus',
                                              t2,
                                              observer=get_earth(t2))
    both = get_body_heliographic_stonyhurst('venus', [t1, t2],
                                            observer=get_earth([t1, t2]))

    assert_quantity_allclose(venus1.lon, both[0].lon)
    assert_quantity_allclose(venus1.lat, both[0].lat)
    assert_quantity_allclose(venus1.radius, both[0].radius)
    assert_quantity_allclose(venus2.lon, both[1].lon)
    assert_quantity_allclose(venus2.lat, both[1].lat)
    assert_quantity_allclose(venus2.radius, both[1].radius)
Ejemplo n.º 15
0
def test_get_bounding_coordinates():
    coords = SkyCoord([-1, 0, 1] * u.arcsec, [-2, 0, 2] * u.arcsec, frame=frames.Helioprojective,
                      observer=get_earth("1999-09-13 00:00:00"))
    bl, tr = _get_bounding_coordinates(coords)

    assert bl.Tx == -1*u.arcsec
    assert bl.Ty == -2*u.arcsec
    assert bl.observer == coords[0].observer

    assert tr.Tx == 1*u.arcsec
    assert tr.Ty == 2*u.arcsec
    assert tr.observer == coords[0].observer
Ejemplo n.º 16
0
def test_get_bounding_coordinates():
    coords = SkyCoord([-1, 0, 1] * u.arcsec, [-2, 0, 2] * u.arcsec, frame=frames.Helioprojective,
                      observer=get_earth("1999-09-13 00:00:00"))
    bl, tr = _get_bounding_coordinates(coords)

    assert bl.Tx == -1*u.arcsec
    assert bl.Ty == -2*u.arcsec
    assert bl.observer == coords[0].observer

    assert tr.Tx == 1*u.arcsec
    assert tr.Ty == 2*u.arcsec
    assert tr.observer == coords[0].observer
Ejemplo n.º 17
0
def test_rotate_submap_edge(aia171_test_map, all_off_disk_map, all_on_disk_map,
                            straddles_limb_map):

    observer = get_earth(aia171_test_map.date + 2 * u.day)

    # For a map that has all the edges off disk, the function should
    # return just the edges of the map - no solar rotation applied.
    for this_map in (aia171_test_map, all_off_disk_map):
        edges = map_edges(this_map)
        for this_edge in range(0, 4):
            pixels = edges[this_edge]
            res = _rotate_submap_edge(this_map, pixels, observer)
            assert all(
                res.Tx == (this_map.pixel_to_world(pixels[:,
                                                          0], pixels[:,
                                                                     1])).Tx)
            assert all(
                res.Ty == (this_map.pixel_to_world(pixels[:,
                                                          0], pixels[:,
                                                                     1])).Ty)

    # For an on disk map, all the edges should change
    edges = map_edges(all_on_disk_map)
    for this_edge in range(0, 4):
        pixels = edges[this_edge]
        res = _rotate_submap_edge(all_on_disk_map, pixels, observer)
        assert all(res.Tx != (
            all_on_disk_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
        assert all(res.Ty != (
            all_on_disk_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)

    # For the limb map, two of the edges move and two do not
    edges = map_edges(straddles_limb_map)
    for this_edge in (0, 3):  # Top and right edges do not move
        pixels = edges[this_edge]
        res = _rotate_submap_edge(straddles_limb_map, pixels, observer)
        assert all(res.Tx == (
            straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Tx)
        assert all(res.Ty == (
            straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:, 1])).Ty)

    for this_edge in (1, 2):  # Bottom and left edges do move
        pixels = edges[this_edge]
        res = _rotate_submap_edge(straddles_limb_map, pixels, observer)
        # Ignore some invalid NaN comparisions within astropy
        # (fixed in astropy 4.0.1 https://github.com/astropy/astropy/pull/9843)
        with np.errstate(invalid='ignore'):
            assert all(res.Tx != (
                straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:,
                                                                       1])).Tx)
            assert all(res.Ty != (
                straddles_limb_map.pixel_to_world(pixels[:, 0], pixels[:,
                                                                       1])).Ty)
Ejemplo n.º 18
0
def test_consistency_with_horizons(astropy_ephemeris_de432s, obstime):
    # get_horizons_coord() depends on astroquery
    pytest.importorskip("astroquery")

    # Check whether the location of Earth is the same between Astropy and JPL HORIZONS
    e1 = get_earth(obstime)
    e2 = get_horizons_coord('Geocenter', obstime)
    assert_quantity_allclose(e2.separation_3d(e1), 0 * u.km, atol=50 * u.m)

    # Check whether the location of Mars is the same between Astropy and JPL HORIZONS
    e1 = get_body_heliographic_stonyhurst('mars', obstime)
    e2 = get_horizons_coord('Mars barycenter', obstime)
    assert_quantity_allclose(e2.separation_3d(e1), 0 * u.km, atol=500 * u.m)
Ejemplo n.º 19
0
def test_differential_rotate_observer_straddles_limb(straddles_limb_map):
    # Test a map that straddles the limb - triggers sub full disk branches
    # Rotated map should have a smaller extent in the x - direction
    new_observer = get_earth(straddles_limb_map.date + 48 * u.hr)
    # Ignore some invalid NaN comparisons within astropy
    # (fixed in astropy 4.0.1 https://github.com/astropy/astropy/pull/9843)
    with np.errstate(invalid='ignore'):
        dmap = differential_rotate(straddles_limb_map, observer=new_observer)
    assert dmap.data.shape[1] < straddles_limb_map.data.shape[1]
    # The output map should have the positional properties of the observer
    assert dmap.date.isot == new_observer.obstime.isot
    assert dmap.heliographic_latitude == new_observer.lat
    assert dmap.heliographic_longitude == new_observer.lon
Ejemplo n.º 20
0
def test_consistency_with_horizons(use_DE440s, obstime):
    # Check that the high-accuracy Astropy ephemeris has been set
    assert solar_system_ephemeris.get() == 'de440s'

    # Check whether the location of Earth is the same between Astropy and JPL HORIZONS
    e1 = get_earth(obstime)
    e2 = get_horizons_coord('Geocenter', obstime)
    assert_quantity_allclose(e2.separation_3d(e1), 0 * u.km, atol=50 * u.m)

    # Check whether the location of Mars is the same between Astropy and JPL HORIZONS
    e1 = get_body_heliographic_stonyhurst('mars', obstime)
    e2 = get_horizons_coord('Mars barycenter', obstime)
    assert_quantity_allclose(e2.separation_3d(e1), 0 * u.km, atol=500 * u.m)
Ejemplo n.º 21
0
def test_solar_rotate_coordinate():
    # Testing along the Sun-Earth line, observer is on the Earth
    obs_time = '2010-09-10 12:34:56'
    observer = get_earth(obs_time)
    c = SkyCoord(-570*u.arcsec, 120*u.arcsec, obstime=obs_time, observer=observer, frame=frames.Helioprojective)
    new_time = '2010-09-11 12:34:56'
    new_observer = get_earth(new_time)

    # Test that when both the observer and the time are specified, an error is raised.
    with pytest.raises(ValueError):
        d = solar_rotate_coordinate(c, observer=observer, time=new_time)

    # Test that the code properly filters the observer keyword
    with pytest.raises(ValueError):
        d = solar_rotate_coordinate(c, observer='earth')

    # Test that the code properly filters the time keyword
    with pytest.raises(ValueError):
        d = solar_rotate_coordinate(c, time='noon')

    # Test that the code gives the same output for multiple different inputs
    # that define the same observer location and time.
    for i, definition in enumerate((1 * u.day, TimeDelta(1*u.day), new_time, new_observer)):
        if i in (0, 1, 2):
            d = solar_rotate_coordinate(c, time=definition)
        else:
            d = solar_rotate_coordinate(c, observer=definition)

        # Test that a SkyCoordinate is created
        assert isinstance(d, SkyCoord)

        # Test the coordinate
        np.testing.assert_almost_equal(d.Tx.to(u.arcsec).value, -371.8885208634674, decimal=1)
        np.testing.assert_almost_equal(d.Ty.to(u.arcsec).value, 105.35006656251727, decimal=1)
        np.testing.assert_allclose(d.distance.to(u.km).value, 1.499642e+08, rtol=1e-5)

        # Test that the SkyCoordinate is Helioprojective
        assert isinstance(d.frame, frames.Helioprojective)
Ejemplo n.º 22
0
def test_velocity_hgs_hci():
    # HGS and HCI share the same origin and Z axis, so the induced velocity is entirely angular
    obstime = Time(['2021-01-01', '2021-04-01', '2021-07-01', '2021-10-01'])
    venus_hgs = get_body_heliographic_stonyhurst('venus', obstime, include_velocity=True)
    venus_hci = venus_hgs.transform_to(HeliocentricInertial(obstime=obstime))

    # The induced velocity is the longitude component of Earth's velocity, ~360 deg/yr
    induced_dlon = get_earth(obstime, include_velocity=True).heliocentricinertial.d_lon
    assert_quantity_allclose(induced_dlon, 360*u.deg/u.yr, rtol=0.05)

    # The HCI velocity should be the same as the HGS velocity except for the induced velocity
    assert_quantity_allclose(venus_hci.d_distance, venus_hgs.d_radius, rtol=1e-5)
    assert_quantity_allclose(venus_hci.d_lon, venus_hgs.d_lon + induced_dlon, rtol=1e-6)
    assert_quantity_allclose(venus_hci.d_lat, venus_hgs.d_lat)
Ejemplo n.º 23
0
def test_warp_sun_coordinates(all_on_disk_map):
    # Define an observer
    new_observer = get_earth(all_on_disk_map.date + 6 * u.hr)

    dummy_array = np.zeros((500, 2))

    # Call the warp
    xy2 = _warp_sun_coordinates(dummy_array, all_on_disk_map, new_observer)

    # Test the properties of the output
    assert xy2.shape == dummy_array.shape
    assert isinstance(xy2, np.ndarray)

    # Test the values - values are not independently found
    # We are passing in 500 pairs of (0,0) so all the output pixels should be the same
    np.testing.assert_almost_equal(xy2[:, 0], -2.08384686, decimal=2)
    np.testing.assert_almost_equal(xy2[:, 1], -0.23927568, decimal=2)
Ejemplo n.º 24
0
def test_get_new_observer(aia171_test_map):
    initial_obstime = aia171_test_map.date
    rotation_interval = 2 * u.day
    new_time = initial_obstime + rotation_interval
    time_delta = new_time - initial_obstime
    observer = get_earth(initial_obstime + rotation_interval)

    # The observer time is set along with other definitions of time
    for time in (rotation_interval, new_time, time_delta):
        with pytest.raises(ValueError):
            new_observer = _get_new_observer(initial_obstime, observer, time)

    # Obstime property is present but the value is None
    observer_obstime_is_none = SkyCoord(12*u.deg, 46*u.deg, frame=frames.HeliographicStonyhurst)
    with pytest.raises(ValueError):
        new_observer = _get_new_observer(None, observer_obstime_is_none, None)

    # When the observer is set, it gets passed back out
    new_observer = _get_new_observer(initial_obstime, observer, None)
    assert isinstance(new_observer, SkyCoord)
    np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).lon.to(u.deg).value,
                                   observer.transform_to(frames.HeliographicStonyhurst).lon.to(u.deg).value, decimal=3)
    np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).lat.to(u.deg).value,
                                   observer.transform_to(frames.HeliographicStonyhurst).lat.to(u.deg).value, decimal=3)
    np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).radius.to(u.au).value,
                                   observer.transform_to(frames.HeliographicStonyhurst).radius.to(u.au).value, decimal=3)

    # When the time is set, a coordinate for Earth comes back out
    for time in (rotation_interval, new_time, time_delta):
        with pytest.warns(UserWarning, match="Using 'time' assumes an Earth-based observer"):
            new_observer = _get_new_observer(initial_obstime, None, time)
        assert isinstance(new_observer, SkyCoord)

        np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).lon.to(u.deg).value,
                                       observer.transform_to(frames.HeliographicStonyhurst).lon.to(u.deg).value, decimal=3)
        np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).lat.to(u.deg).value,
                                       observer.transform_to(frames.HeliographicStonyhurst).lat.to(u.deg).value, decimal=3)
        np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).radius.to(u.au).value,
                                       observer.transform_to(frames.HeliographicStonyhurst).radius.to(u.au).value, decimal=3)

    # The observer and the time cannot both be None
    with pytest.raises(ValueError):
        new_observer = _get_new_observer(initial_obstime, None, None)
Ejemplo n.º 25
0
def test_get_new_observer(aia171_test_map):
    initial_obstime = aia171_test_map.date
    rotation_interval = 2 * u.day
    new_time = initial_obstime + rotation_interval
    time_delta = new_time - initial_obstime
    observer = get_earth(initial_obstime + rotation_interval)

    # The observer time is set along with other definitions of time
    for time in (rotation_interval, new_time, time_delta):
        with pytest.raises(ValueError):
            new_observer = _get_new_observer(initial_obstime, observer, time)

    # Obstime property is present but the value is None
    observer_obstime_is_none = SkyCoord(12*u.deg, 46*u.deg, frame=frames.HeliographicStonyhurst)
    with pytest.raises(ValueError):
        new_observer = _get_new_observer(None, observer_obstime_is_none, None)

    # When the observer is set, it gets passed back out
    new_observer = _get_new_observer(initial_obstime, observer, None)
    assert isinstance(new_observer, SkyCoord)
    np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).lon.to(u.deg).value,
                                   observer.transform_to(frames.HeliographicStonyhurst).lon.to(u.deg).value, decimal=3)
    np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).lat.to(u.deg).value,
                                   observer.transform_to(frames.HeliographicStonyhurst).lat.to(u.deg).value, decimal=3)
    np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).radius.to(u.au).value,
                                   observer.transform_to(frames.HeliographicStonyhurst).radius.to(u.au).value, decimal=3)

    # When the time is set, a coordinate for Earth comes back out
    for time in (rotation_interval, new_time, time_delta):
        new_observer = _get_new_observer(initial_obstime, None, time)
        assert isinstance(new_observer, SkyCoord)

        np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).lon.to(u.deg).value,
                                       observer.transform_to(frames.HeliographicStonyhurst).lon.to(u.deg).value, decimal=3)
        np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).lat.to(u.deg).value,
                                       observer.transform_to(frames.HeliographicStonyhurst).lat.to(u.deg).value, decimal=3)
        np.testing.assert_almost_equal(new_observer.transform_to(frames.HeliographicStonyhurst).radius.to(u.au).value,
                                       observer.transform_to(frames.HeliographicStonyhurst).radius.to(u.au).value, decimal=3)

    # The observer and the time cannot both be None
    with pytest.raises(ValueError):
        new_observer = _get_new_observer(initial_obstime, None, None)
Ejemplo n.º 26
0
def test_warp_sun_coordinates(all_on_disk_map):
    # Define an observer
    new_observer = get_earth(all_on_disk_map.date + 6*u.hr)

    # This array is not used in the function but is part of the signature
    dummy_array = np.zeros(10)

    # Call the warp
    xy2 = _warp_sun_coordinates(dummy_array, all_on_disk_map, new_observer)

    # Test the properties of the output
    shape = all_on_disk_map.data.shape
    assert xy2.shape == (shape[0]*shape[1], 2)
    assert isinstance(xy2, np.ma.core.MaskedArray)

    # Test the values - values are not independently found
    np.testing.assert_almost_equal(xy2[0, 0], -2.063284482734346, decimal=2)
    np.testing.assert_almost_equal(xy2[0, 1], -0.23511899658107005, decimal=2)
    np.testing.assert_almost_equal(xy2[499, 0], 16.396007639829428, decimal=2)
    np.testing.assert_almost_equal(xy2[499, 1], 23.87553530074777, decimal=2)
Ejemplo n.º 27
0
def test_warp_sun_coordinates(all_on_disk_map):
    # Define an observer
    new_observer = get_earth(all_on_disk_map.date + 6 * u.hr)

    # This array is not used in the function but is part of the signature
    dummy_array = np.zeros(10)

    # Call the warp
    xy2 = _warp_sun_coordinates(dummy_array, all_on_disk_map, new_observer)

    # Test the properties of the output
    shape = all_on_disk_map.data.shape
    assert xy2.shape == (shape[0] * shape[1], 2)
    assert isinstance(xy2, np.ma.core.MaskedArray)

    # Test the values - values are not independently found
    np.testing.assert_almost_equal(xy2[0, 0], -2.063284482734346, decimal=2)
    np.testing.assert_almost_equal(xy2[0, 1], -0.23511899658107005, decimal=2)
    np.testing.assert_almost_equal(xy2[499, 0], 16.396007639829428, decimal=2)
    np.testing.assert_almost_equal(xy2[499, 1], 23.87553530074777, decimal=2)
Ejemplo n.º 28
0
def update_fiss_header(file,alignfile,**kwargs):
    """
    Create the new FISS data with update header.
    
    Parameters
    ----------
    file : list
        FISS fts file list
    alignfile : str
        Aligned information binary (.npz) file.
    sil : (optional) bool
        If False, it print the ongoing time index.
            * Default is True.
    sol_rot : (optional) bool
        If True, correct the solar rotation when update the file header.
            * Default is False.
        
    Returns
    -------
    mfts : file
        List of files which updated the header.
        
    Notes
    -----
        Name of saved fits data file is added 'm' to 
        the first character of original data name.
    """
    sil=kwargs.pop('sil',False)
    sol_rot=kwargs.pop('sol_rot',False)
    
    if not sil:
        print('Add the align information to the haeder.')
    level=alignfile[-8:-4]
    inform=np.load(alignfile)
    fissht=[getheader(i) for i in file]
    fissh=[fits.getheader(i) for i in file]
    tlist=[i['date'] for i in fissht]
    
    time=Time(tlist,format='isot',scale='ut1')
    angle=inform['angle']
    ny=fissht[0]['naxis2']
    nx=fissht[0]['naxis3']
    x=np.array((0,nx-1,nx-1,0))
    y=np.array((0,0,ny-1,ny-1))
    xc=inform['xc'].item()
    yc=inform['yc'].item()
    dx=inform['dx']
    dy=inform['dy']
    
    xt1,yt1=rot_trans(x,y,xc,yc,angle.max())
    xt2,yt2=rot_trans(x,y,xc,yc,angle.min())
    
    tmpx=np.concatenate((xt1,xt2))
    tmpy=np.concatenate((yt1,yt2))
    
    xmargin=int(np.abs(np.round(tmpx.min()+dx.min())))+1
    ymargin=int(np.abs(np.around(tmpy.min()+dy.min())))+1
    
    if level=='lev0':
        for i,h in enumerate(fissh):
            h['alignl']=(0,'Alignment level')
            h['reflect']=(False,'Mirror reverse')
            h['reffr']=(inform['reffr'].item(),'Reference frame in alignment')
            h['reffi']=(inform['reffi'].item(),'Reference file name in alignment')
            h['cdelt2']=(0.16,'arcsec per pixel')
            h['cdelt3']=(0.16,'arcsec per pixel')
            h['crota2']=(angle[i],
                        'Roation angle about reference pixel')
            h['crpix3']=(inform['xc'].item(),'Reference pixel in data axis 3')
            h['shift3']=(inform['dx'][i],
                        'Shifting pixel value along data axis 2')
            h['crpix2']=(inform['yc'].item(),'Reference pixel in data axis 2')
            h['shift2']=(inform['dy'][i],
                        'Shifting pixel value along data axis 3')
            h['margin2']=(ymargin,'Rotation margin in axis 2')
            h['margin3']=(xmargin,'Rotation margin in axis 3')
            
            h['history']='FISS aligned (lev0)'
    elif level=='lev1':
        wcsx=inform['wcsx']
        wcsy=inform['wcsy']
        xref=wcsx*u.arcsec
        yref=wcsy*u.arcsec
        reffr=inform['reffr']
        for i,h in enumerate(fissh):
            if sol_rot:
                refc = SkyCoord(xref, yref, obstime = time[reffr],
                                observer= get_earth(time[reffr]),
                                frame= frames.Helioprojective)
                res = solar_rotate_coordinate(refc, time[i],
                                              frame_time= 'synodic')
                wcsx = res.Tx.value
                wcsy = res.Ty.value
                h['crval3']=(wcsx.value,
                            'Location of ref pixel x (arcsec)')
                h['crval2']=(wcsy.value,
                            'Location of ref pixel y (arcsec)')
            else:
                h['crval3']=(wcsx.item(),
                            'Location of ref pixel for ref frame x (arcsec)')
                h['crval2']=(wcsy.item(),
                            'Location of ref pixel for ref frame y (arcsec)')

            h['alignl']=(1,'Alignment level')
            h['reflect']=(inform['reflect'].item(),'Mirror reverse')
            h['reffr']=(inform['reffr'].item(),'Reference frame in alignment')
            h['reffi']=(inform['reffi'].item(),'Reference file name in alignment')
            h['cdelt2']=(0.16,'arcsec per pixel')
            h['cdelt3']=(0.16,'arcsec per pixel')
            h['crota1']=(inform['sdo_angle'].item(),
                        'Rotation angle of reference frame (radian)')
            h['crota2']=(inform['angle'][i],
                        'Rotation angle about reference pixel (radian)')
            h['crpix3']=(inform['xc'].item(),'Reference pixel in data axis 3')
            h['shift3']=(inform['dx'][i],
                        'Shifting pixel value along data axis 3')
            h['crpix2']=(inform['yc'].item(),'Reference pixel in data axis 2')

            h['shift2']=(inform['dy'][i],
                        'Shifting pixel value along data axis 2')
            h['margin2']=(ymargin,'Rotation margin in axis 2')
            h['margin3']=(xmargin,'Rotation margin in axis 3')
            h['srot']=(True,'Solar Rotation correction')
            h['history']='FISS aligned and matched wcs (lev1)'
    else:
        raise ValueError('The level of alignfile is neither lev0 or lev1.')
    
    data=[fits.getdata(i) for i in file]
    
    odirname=os.path.dirname(file[0])
    if not odirname:
        odirname=os.getcwd()
    dirname = os.path.join(odirname, 'match')
    
    try:
        os.mkdir(dirname)
    except:
        pass
    
    for i,oname in enumerate(file):
        name='m'+os.path.basename(oname)
        fits.writeto(os.path.join(dirname, name),data[i],fissh[i])
    try:
        pfilelist=[i['pfile'] for i in fissh]
        pfileset=set(pfilelist)
        for i in pfileset:
            copy2(os.path.join(odirname, i),os.path.join(dirname,i))
    except:
        pass
    
    if not sil:
        print("The align information is updated to the header, "
              "and new fts file is locate %s the file name is 'mFISS*.fts'"%dirname)
	else:
		INIT_COORD = cutout_selection(MAPCUBE)
		auto_sel = False

	#########################

	PRINTER.line()
	INIT_TIME = str(MAPCUBE[0].date)
	PRINTER.display_item("Initial time", INIT_TIME)

	#########################

	INIT_LOC = SkyCoord(INIT_COORD.Tx,
						INIT_COORD.Ty,
						obstime = INIT_TIME,
						observer = get_earth(INIT_TIME),
						frame = frames.Helioprojective)

	PRINTER.display_item("Initial location", "(%s arcsec, %s arcsec)" % (INIT_LOC.Tx, INIT_LOC.Ty))

	#########################

	PRINTER.info_text("Calculating future coordinates")
	LOCS = [solar_rotate_coordinate(INIT_LOC, MAPCUBE[i].date) for i in range(len(MAPCUBE))]

#########################

if ask_to_change_default_settings:

	if(PRINTER.input_text("Use default settings (low scale 0, high scale 40000)? [y/n]") == "n"):
		default_low_scale = int(PRINTER.input_text("Enter low scale"))