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)
示例#2
0
def test_great_arc_calculable(start, end):
    c = SkyCoord(start[0]*u.degree, start[1]*u.degree, frame=frames.HeliographicStonyhurst,
                 observer=frames.HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU))
    d = SkyCoord(end[0]*u.degree, end[1]*u.degree, frame=frames.HeliographicStonyhurst,
                 observer=frames.HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU))
    gc = GreatArc(c, d)

    c_trans = c.transform_to(frames.Heliocentric)
    assert gc.start.x == c_trans.x
    assert gc.start.y == c_trans.y
    assert gc.start.z == c_trans.z
    assert gc.start.observer.lat == 0*u.deg
    assert gc.start.observer.lon == 0*u.deg
    assert gc.start.observer.radius == 1 * u.AU

    d_trans = d.transform_to(frames.Heliocentric(observer=c.observer))
    assert gc.end.x == d_trans.x
    assert gc.end.y == d_trans.y
    assert gc.end.z == d_trans.z
    assert gc.end.observer.lat == 0*u.deg
    assert gc.end.observer.lon == 0*u.deg
    assert gc.end.observer.radius == 1 * u.AU

    np.testing.assert_almost_equal(gc.inner_angle.to('deg').value, 45.0)
    np.testing.assert_almost_equal(gc.radius.to('km').value, sun.constants.radius.to('km').value)
    np.testing.assert_almost_equal(gc.distance.to(
        'km').value, sun.constants.radius.to('km').value * 2 * np.pi/8, decimal=1)
示例#3
0
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)
示例#4
0
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')
示例#5
0
def test_great_arc_calculable(start, end):
    c = SkyCoord(start[0]*u.degree, start[1]*u.degree, frame=frames.HeliographicStonyhurst,
                 observer=frames.HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU))
    d = SkyCoord(end[0]*u.degree, end[1]*u.degree, frame=frames.HeliographicStonyhurst,
                 observer=frames.HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU))
    gc = GreatArc(c, d)

    assert gc.start == c
    assert gc.end == d
    np.testing.assert_almost_equal(gc.inner_angle.to('deg').value, 45.0)
    np.testing.assert_almost_equal(gc.radius.to('km').value, sun.constants.radius.to('km').value)
    np.testing.assert_almost_equal(gc.distance.to('km').value, sun.constants.radius.to('km').value * 2 * np.pi/8, decimal=1)
示例#6
0
def get_observer_meta(observer, rsun: (u.Mm, None) = None):
    """
    Function to get observer meta from coordinate frame.

    Parameters
    ----------
    coordinate : `~astropy.coordinates.BaseCoordinateFrame`
        The coordinate of the observer, must be transformable to Heliographic
        Stonyhurst.
    rsun : `astropy.units.Quantity`, optional
        The radius of the Sun. If ``None``, the RSUN_OBS and RSUN_REF keys are
        not set.

    Returns
    -------
    coord_meta : `dict`
        WCS metadata, with the keys ``['hgln_obs', 'hglt_obs', 'dsun_obs']``,
        and additionally if ``rsun`` is given ``['rsun_obs', 'rsun_ref']``.
    """
    observer = observer.transform_to(
        frames.HeliographicStonyhurst(obstime=observer.obstime))
    coord_meta = {}

    coord_meta['hgln_obs'] = observer.lon.to_value(u.deg)
    coord_meta['hglt_obs'] = observer.lat.to_value(u.deg)
    coord_meta['dsun_obs'] = observer.radius.to_value(u.m)
    if rsun is not None:
        coord_meta['rsun_ref'] = rsun.to_value(u.m)
        coord_meta['rsun_obs'] = sun._angular_radius(
            rsun, observer.radius).to_value(u.arcsec)

    return coord_meta
示例#7
0
def test_default_observer_transform_hpc():
    center = frames.HeliographicStonyhurst(0 * u.deg,
                                           0 * u.deg,
                                           obstime="2017-07-11 15:00")
    hpc = center.transform_to(frames.Helioprojective)

    assert_quantity_allclose(hpc.Ty, -66.04425197 * u.arcsec)
示例#8
0
def test_default_observer_transform_hcc():
    center = frames.HeliographicStonyhurst(0 * u.deg,
                                           0 * u.deg,
                                           obstime="2017-07-11 15:00")
    hpc = center.transform_to(frames.Heliocentric(obstime="2017-07-11 15:00"))

    assert_quantity_allclose(hpc.y, -48471.1283979 * u.km)
示例#9
0
def get_observer_meta(observer, rsun: (u.Mm, None)):
    """
    Function to get observer meta from coordinate frame.

    Parameters
    ----------
    coordinate : ~`astropy.coordinates.BaseFrame`
        The coordinate of the observer, must be transformable to Heliographic
        Stonyhurst.
    rsun : `astropy.units.Quantity`
        The radius of the Sun.

    Returns
    -------
    `dict`
        Containing the WCS meta information
            * hgln_obs, hglt_obs
            * dsun_obs
            * rsun_obs
            * rsun_ref
    """
    observer = observer.transform_to(
        frames.HeliographicStonyhurst(obstime=observer.obstime))
    coord_meta = {}

    coord_meta['hgln_obs'] = observer.lon.to_value(u.deg)
    coord_meta['hglt_obs'] = observer.lat.to_value(u.deg)
    coord_meta['dsun_obs'] = observer.radius.to_value(u.m)
    if rsun:
        coord_meta['rsun_ref'] = rsun.to_value(u.m)
        coord_meta['rsun_obs'] = np.arctan(rsun / observer.radius).to_value(
            u.arcsec)

    return coord_meta
示例#10
0
def test_tranformation_to_nonobserver_frame(indirect_fixture):
    base_class, rot_frame = indirect_fixture

    hgs_frame = f.HeliographicStonyhurst(obstime='2020-01-01')
    hgs_coord = rot_frame.transform_to(hgs_frame)

    assert hgs_coord.obstime == hgs_frame.obstime
示例#11
0
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))
示例#12
0
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)
示例#13
0
def test_hcc_observer_version(tmpdir):
    """
    This test verifies that the heliocentric frame has an upto date list of
    the HGS schema versions by ensuring that a HPC frame with a instantiated
    HGS frame as the observer round trips correctly.
    """
    time = "2021-10-13T11:08"
    obs = frames.HeliographicStonyhurst(0*u.deg, 0*u.deg, 1*u.AU, obstime=time)
    coord = frames.Heliocentric(1*u.Mm, 1*u.Mm, 1*u.Mm, obstime=time, observer=obs)
    assert_round_trip_frame(coord)
示例#14
0
def test_transform():
    # Check that field lines can be transformed into different coordinates
    obstime = Time('1992-12-21')
    stonyhurst = sunframes.HeliographicStonyhurst(
        12 * u.deg, 0 * u.deg, obstime=obstime)
    fline = FieldLine([1, 2.5], [0, 0], [0, 0], None, None)
    # Check field line transform
    fline.coords.transform_to(stonyhurst)

    # Check footpoint transform
    fline.solar_footpoint.transform_to(stonyhurst)
示例#15
0
def semi_circular_loop(length: u.cm, latitude: u.deg = 0 * u.deg):
    """
    Return HGS coordinates for a semi-circular loop
    """
    angles = np.linspace(0, 1, 1000) * np.pi * u.rad
    z = length / np.pi * np.sin(angles)
    x = length / np.pi * np.cos(angles)
    hcc_frame = frames.Heliocentric(observer=frames.HeliographicStonyhurst(
        lon=0 * u.deg, lat=latitude, radius=constants.au))

    return SkyCoord(x=x,
                    y=np.zeros_like(x),
                    z=z + constants.radius,
                    frame=hcc_frame)
示例#16
0
def test_hpc_observer_version(tmpdir):
    """
    This test verifies that the helioprojective frame has an upto date list of
    the HGS schema versions by ensuring that a HPC frame with a instantiated
    HGS frame as the observer round trips correctly.
    """
    time = "2021-10-13T11:08"
    obs = frames.HeliographicStonyhurst(0 * u.deg,
                                        0 * u.deg,
                                        1 * u.AU,
                                        obstime=time)
    coord = frames.Helioprojective(10 * u.arcsec,
                                   10 * u.arcsec,
                                   obstime=time,
                                   observer=obs)
    tree = {'coord': coord}
    assert_roundtrip_tree(tree, tmpdir)
示例#17
0
def set_observer_coord(m, observer_coord):
    """
    Set observer coordinate.

    Parameters
    ----------
    m : `~sunpy.map.GenericMap`
        Input map.
    observer_coord : astropy.coordiantes.SkyCoord
        Observer coordinate.
    """
    from sunpy.coordinates import frames
    new_obs_frame = frames.HeliographicStonyhurst(obstime=m.date)
    observer_coord = observer_coord.transform_to(new_obs_frame)

    new_meta = remove_obs_keywords(m.meta)
    new_meta['hglt_obs'] = observer_coord.lat.to_value(u.deg)
    new_meta['hgln_obs'] = observer_coord.lon.to_value(u.deg)
    new_meta['dsun_obs'] = observer_coord.radius.to_value(u.m)
    return sunpy.map.Map(m.data, new_meta)
示例#18
0
def make_map_ipa(file):
    """
    Function to make a sunpy.map.GenericMap from a NoRH fits file.
    This function fixes the header keywords so that it works within
    map.

    Parameters
    ----------
    file : `str`
        path of NoRH fits file to read into a map

    Returns
    -------
    `sunpy.map.GenericMap

    """
    hdu = fits.open(file)[0]
    header = hdu.header
    data = hdu.data

    header['CUNIT1'], header['CUNIT2'] = 'arcsec', 'arcsec'
    header['CTYPE1'], header['CTYPE2'] = 'HPLN-TAN', 'HPLT-TAN'
    header['date-obs'] = header['date-obs'] + 'T' + header['time-obs']

    # get observer location
    observer = get_earth(header['date-obs'])
    observer = observer.transform_to(
        frames.HeliographicStonyhurst(obstime=observer.obstime))

    header['hgln_obs'] = observer.lon.to_value(u.deg)
    header['hglt_obs'] = observer.lat.to_value(u.deg)
    header['dsun_obs'] = observer.radius.to_value(u.m)

    header['rsun_obs'] = sun.angular_radius(
        header['date-obs']).to('arcsec').value

    norh_map = sunpy.map.Map(data, header)
    norh_map.plot_settings['cmap'] = 'BuPu'
    #norh_map.plot_settings['norm'] = LogNorm()

    return norh_map
示例#19
0
def semi_circular_loop(length: u.m, latitude: u.deg = 0 * u.deg):
    """
    Return a Heliographic Stonyhurst coordinate object with points of a semi circular loop in it.
    """
    r_sun = constants.radius

    def r_2_func(x):
        return np.arccos(0.5 * x / r_sun.to(u.cm).value) - np.pi + length.to(
            u.cm).value / 2. / x

    # Find the loop radius corresponding to the loop length
    r_2 = scipy.optimize.bisect(r_2_func,
                                length.to(u.cm).value / (2 * np.pi),
                                length.to(u.cm).value / np.pi) * u.cm
    alpha = np.arccos(0.5 * (r_2 / r_sun))
    phi = np.linspace(-np.pi * u.rad + alpha, np.pi * u.rad - alpha, 2000)

    hcc_frame = frames.Heliocentric(observer=frames.HeliographicStonyhurst(
        lon=0 * u.deg, lat=latitude, radius=1 * u.AU))

    return SkyCoord(x=r_2 * np.sin(phi),
                    y=0 * u.cm,
                    z=r_2 * np.cos(phi) + r_sun,
                    frame=hcc_frame).transform_to('heliographic_stonyhurst')
示例#20
0
def test_no_obstime():
    with pytest.raises(ValueError):
        RotatedSunFrame(base=f.HeliographicStonyhurst(obstime=None))
示例#21
0
def test_alternate_rotation_model():
    r = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-01'),
                        rotation_model="allen")
    assert r.rotation_model == "allen"
示例#22
0
def test_default_rotation_model():
    r = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-01'))
    assert r.rotation_model == "howard"
示例#23
0
def test_default_duration():
    r = RotatedSunFrame(base=f.HeliographicStonyhurst(obstime='2001-01-01'))
    assert_quantity_allclose(r.duration, 0 * u.day)