예제 #1
0
파일: utils.py 프로젝트: zkurtz/astropy
def prepare_earth_position_vel(time):
    """
    Get barycentric position and velocity, and heliocentric position of Earth

    Parameters
    -----------
    time : `~astropy.time.Time`
        time at which to calculate position and velocity of Earth

    Returns
    --------
    earth_pv : `np.ndarray`
        Barycentric position and velocity of Earth, in au and au/day
    earth_helio : `np.ndarray`
        Heliocentric position of Earth in au
    """
    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import (get_body_barycentric,
                                                  get_body_barycentric_posvel)
    # get barycentric position and velocity of earth
    earth_p, earth_v = get_body_barycentric_posvel('earth', time)

    # get heliocentric position of earth, preparing it for passing to erfa.
    sun = get_body_barycentric('sun', time)
    earth_heliocentric = (earth_p - sun).get_xyz(xyz_axis=-1).to_value(u.au)

    # Also prepare earth_pv for passing to erfa, which wants it as
    # a structured dtype.
    earth_pv = erfa.pav2pv(
        earth_p.get_xyz(xyz_axis=-1).to_value(u.au),
        earth_v.get_xyz(xyz_axis=-1).to_value(u.au / u.d))
    return earth_pv, earth_heliocentric
예제 #2
0
파일: utils.py 프로젝트: Cadair/astropy
def prepare_earth_position_vel(time):
    """
    Get barycentric position and velocity, and heliocentric position of Earth

    Parameters
    -----------
    time : `~astropy.time.Time`
        time at which to calculate position and velocity of Earth

    Returns
    --------
    earth_pv : `np.ndarray`
        Barycentric position and velocity of Earth, in au and au/day
    earth_helio : `np.ndarray`
        Heliocentric position of Earth in au
    """
    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import (get_body_barycentric, get_body_barycentric_posvel)
    # get barycentric position and velocity of earth
    earth_p, earth_v = get_body_barycentric_posvel('earth', time)

    # get heliocentric position of earth, preparing it for passing to erfa.
    sun = get_body_barycentric('sun', time)
    earth_heliocentric = (earth_p -
                          sun).get_xyz(xyz_axis=-1).to_value(u.au)

    # Also prepare earth_pv for passing to erfa, which wants it as
    # a structured dtype.
    earth_pv = erfa.pav2pv(
        earth_p.get_xyz(xyz_axis=-1).to_value(u.au),
        earth_v.get_xyz(xyz_axis=-1).to_value(u.au/u.d))
    return earth_pv, earth_heliocentric
예제 #3
0
def icrs_to_iau76_ecliptic(from_coo, to_frame):
    # get barycentric sun coordinate
    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import get_body_barycentric
    bary_sun_pos = get_body_barycentric("sun", to_frame.obstime)

    # now compute the matrix to precess to the right orientation
    rmat = _obliquity_only_rotation_matrix()

    return rmat, (-bary_sun_pos).transform(rmat)
예제 #4
0
def ecliptic_to_iau76_icrs(from_coo, to_frame):
    # first un-precess from ecliptic to ICRS orientation
    rmat = _obliquity_only_rotation_matrix()

    # now offset back to barycentric, which is the correct center for ICRS
    # get barycentric sun coordinate
    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import get_body_barycentric
    bary_sun_pos = get_body_barycentric("sun", from_coo.obstime)

    return matrix_transpose(rmat), bary_sun_pos
예제 #5
0
def prepare_earth_position_vel(time):
    """
    Get barycentric position and velocity, and heliocentric position of Earth

    Parameters
    -----------
    time : `~astropy.time.Time`
        time at which to calculate position and velocity of Earth

    Returns
    --------
    earth_pv : `np.ndarray`
        Barycentric position and velocity of Earth, in au and au/day
    earth_helio : `np.ndarray`
        Heliocentric position of Earth in au
    """
    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import (
        get_body_barycentric,
        get_body_barycentric_posvel,
        solar_system_ephemeris,
    )
    # get barycentric position and velocity of earth

    ephemeris = solar_system_ephemeris.get()

    # if we are using the builtin erfa based ephemeris,
    # we can use the fact that epv00 already provides all we need.
    # This avoids calling epv00 twice, once
    # in get_body_barycentric_posvel('earth') and once in
    # get_body_barycentric('sun')
    if ephemeris == 'builtin':
        jd1, jd2 = get_jd12(time, 'tdb')
        earth_pv_heliocentric, earth_pv = erfa.epv00(jd1, jd2)
        earth_heliocentric = earth_pv_heliocentric['p']

    # all other ephemeris providers probably don't have a shortcut like this
    else:
        earth_p, earth_v = get_body_barycentric_posvel('earth', time)

        # get heliocentric position of earth, preparing it for passing to erfa.
        sun = get_body_barycentric('sun', time)
        earth_heliocentric = (earth_p - sun).get_xyz(xyz_axis=-1).to_value(
            u.au)

        # Also prepare earth_pv for passing to erfa, which wants it as
        # a structured dtype.
        earth_pv = pav2pv(
            earth_p.get_xyz(xyz_axis=-1).to_value(u.au),
            earth_v.get_xyz(xyz_axis=-1).to_value(u.au / u.d))

    return earth_pv, earth_heliocentric
예제 #6
0
def icrs_to_true_helioecliptic(from_coo, to_frame):
    if not u.m.is_equivalent(from_coo.cartesian.x.unit):
        raise UnitsError(_NEED_ORIGIN_HINT.format(from_coo.__class__.__name__))

    # get barycentric sun coordinate
    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import get_body_barycentric
    bary_sun_pos = get_body_barycentric('sun', to_frame.obstime)

    # now compute the matrix to precess to the right orientation
    rmat = _true_ecliptic_rotation_matrix(to_frame.equinox)

    return rmat, (-bary_sun_pos).transform(rmat)
예제 #7
0
def true_helioecliptic_to_icrs(from_coo, to_frame):
    if not u.m.is_equivalent(from_coo.cartesian.x.unit):
        raise UnitsError(_NEED_ORIGIN_HINT.format(from_coo.__class__.__name__))

    # first un-precess from ecliptic to ICRS orientation
    rmat = _true_ecliptic_rotation_matrix(from_coo.equinox)

    # now offset back to barycentric, which is the correct center for ICRS

    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import get_body_barycentric

    # get barycentric sun coordinate
    bary_sun_pos = get_body_barycentric('sun', from_coo.obstime)

    return matrix_transpose(rmat), bary_sun_pos
예제 #8
0
def icrs_to_helioecliptic(from_coo, to_frame):
    if not u.m.is_equivalent(from_coo.cartesian.x.unit):
        raise UnitsError(_NEED_ORIGIN_HINT.format(from_coo.__class__.__name__))

    # get barycentric sun coordinate
    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import get_body_barycentric
    bary_sun_pos = get_body_barycentric('sun', to_frame.obstime)

    # offset to heliocentric
    heliocart = from_coo.cartesian - bary_sun_pos

    # now compute the matrix to precess to the right orientation
    rmat = _ecliptic_rotation_matrix(to_frame.equinox)

    newrepr = heliocart.transform(rmat)
    return to_frame.realize_frame(newrepr)
예제 #9
0
def icrs_to_hcrs(icrs_coo, hcrs_frame):
    # this is just an origin translation so without a distance it cannot go ahead
    if isinstance(icrs_coo.data, UnitSphericalRepresentation):
        raise u.UnitsError(_NEED_ORIGIN_HINT.format(icrs_coo.__class__.__name__))

    if icrs_coo.data.differentials:
        from astropy.coordinates.solar_system import get_body_barycentric_posvel
        bary_sun_pos, bary_sun_vel = get_body_barycentric_posvel('sun',
                                                                 hcrs_frame.obstime)
        bary_sun_pos = -bary_sun_pos.with_differentials(-bary_sun_vel)

    else:
        from astropy.coordinates.solar_system import get_body_barycentric
        bary_sun_pos = -get_body_barycentric('sun', hcrs_frame.obstime)
        bary_sun_vel = None

    return None, bary_sun_pos
예제 #10
0
def hcrs_to_icrs(hcrs_coo, icrs_frame):
    # this is just an origin translation so without a distance it cannot go ahead
    if isinstance(hcrs_coo.data, UnitSphericalRepresentation):
        raise u.UnitsError(_NEED_ORIGIN_HINT.format(hcrs_coo.__class__.__name__))

    if hcrs_coo.data.differentials:
        from astropy.coordinates.solar_system import get_body_barycentric_posvel
        bary_sun_pos, bary_sun_vel = get_body_barycentric_posvel('sun',
                                                                 hcrs_coo.obstime)
        bary_sun_vel = bary_sun_vel.represent_as(CartesianDifferential)
        bary_sun_pos = bary_sun_pos.with_differentials(bary_sun_vel)

    else:
        from astropy.coordinates.solar_system import get_body_barycentric
        bary_sun_pos = get_body_barycentric('sun', hcrs_coo.obstime)
        bary_sun_vel = None

    return None, bary_sun_pos
예제 #11
0
def helioecliptic_to_icrs(from_coo, to_frame):
    if not u.m.is_equivalent(from_coo.cartesian.x.unit):
        raise UnitsError(_NEED_ORIGIN_HINT.format(from_coo.__class__.__name__))

    # first un-precess from ecliptic to ICRS orientation
    rmat = _ecliptic_rotation_matrix(from_coo.equinox)
    intermed_repr = from_coo.cartesian.transform(matrix_transpose(rmat))

    # now offset back to barycentric, which is the correct center for ICRS

    # this goes here to avoid circular import errors
    from astropy.coordinates.solar_system import get_body_barycentric

    # get barycentric sun coordinate
    bary_sun_pos = get_body_barycentric('sun', from_coo.obstime)

    newrepr = intermed_repr + bary_sun_pos
    return to_frame.realize_frame(newrepr)
예제 #12
0
def get_offset_sun_from_barycenter(time,
                                   include_velocity=False,
                                   reverse=False):
    """
    Returns the offset of the Sun center from the solar-system barycenter (SSB).

    Parameters
    ----------
    time : `~astropy.time.Time`
        Time at which to calculate the offset
    include_velocity : `bool`
        If ``True``, attach the velocity as a differential.  Defaults to ``False``.
    reverse : `bool`
        If ``True``, return the offset of the barycenter from the Sun.  Defaults to ``False``.

    Returns
    -------
    `~astropy.coordinates.CartesianRepresentation`
        The offset
    """
    if include_velocity:
        # Import here to avoid a circular import
        from astropy.coordinates.solar_system import get_body_barycentric_posvel
        offset_pos, offset_vel = get_body_barycentric_posvel('sun', time)
        if reverse:
            offset_pos, offset_vel = -offset_pos, -offset_vel
        offset_vel = offset_vel.represent_as(CartesianDifferential)
        offset_pos = offset_pos.with_differentials(offset_vel)

    else:
        # Import here to avoid a circular import
        from astropy.coordinates.solar_system import get_body_barycentric
        offset_pos = get_body_barycentric('sun', time)
        if reverse:
            offset_pos = -offset_pos

    return offset_pos
예제 #13
0
def test_barycentric_pos_posvel_same():
    # Check that the two routines give identical results.
    ep1 = get_body_barycentric('earth', Time('2016-03-20T12:30:00'))
    ep2, _ = get_body_barycentric_posvel('earth', Time('2016-03-20T12:30:00'))
    assert np.all(ep1.xyz == ep2.xyz)
예제 #14
0
def test_barycentric_pos_posvel_same():
    # Check that the two routines give identical results.
    ep1 = get_body_barycentric('earth', Time('2016-03-20T12:30:00'))
    ep2, _ = get_body_barycentric_posvel('earth', Time('2016-03-20T12:30:00'))
    assert np.all(ep1.xyz == ep2.xyz)