Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When instantiating a frame, use obstime from observer if obstime not otherwise provided #7186

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/7186.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When creating a coordinate or coordinate frame without specifying ``obstime``, the ``obstime`` value from the ``observer`` frame attribute will be used if present.
12 changes: 0 additions & 12 deletions sunpy/coordinates/ephemeris.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,6 @@ def get_body_heliographic_stonyhurst(body, time='now', observer=None, *, include
(63.03105777, -5.20656151, 1.6251161)
(d_lon, d_lat, d_radius) in (arcsec / s, arcsec / s, km / s)
(-0.02323686, 0.00073376, -1.4798387)>

Transform that same location and velocity of Mars to a different frame using
`~astropy.coordinates.SkyCoord`.

>>> from astropy.coordinates import SkyCoord
>>> from sunpy.coordinates import Helioprojective
>>> SkyCoord(mars).transform_to(Helioprojective(observer=earth))
<SkyCoord (Helioprojective: obstime=2001-02-03T00:00:00.000, rsun=695700.0 km, observer=<HeliographicStonyhurst Coordinate (obstime=2012-06-06T04:07:29.000, rsun=695700.0 km): (lon, lat, radius) in (deg, deg, AU)
(6.2686056e-15, -0.00766698, 1.01475668)>): (Tx, Ty, distance) in (arcsec, arcsec, AU)
(-298654.73268523, -21726.6154073, 1.40134156)
(d_Tx, d_Ty, d_distance) in (arcsec / s, arcsec / s, km / s)
(-0.01663438, -0.00058027, -15.08908184)>
"""
obstime = parse_time(time)

Expand Down
4 changes: 4 additions & 0 deletions sunpy/coordinates/frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ def __init__(self, *args, **kwargs):
if not kwargs.pop('wrap_longitude', True):
self._wrap_angle = None

# If obstime is not provided but observer has an obstime, use that as the obstime
if 'obstime' not in kwargs and 'observer' in kwargs and getattr(kwargs['observer'], 'obstime', None) is not None:
dstansby marked this conversation as resolved.
Show resolved Hide resolved
kwargs['obstime'] = kwargs['observer'].obstime

super().__init__(*args, **kwargs)

# If obstime is specified, treat the default observer (None) as explicitly set
Expand Down
11 changes: 11 additions & 0 deletions sunpy/coordinates/tests/test_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,17 @@ def test_hpc_low_precision_float_warning():
hpc.make_3d()


def test_hpc_obstime_from_observer():
dstansby marked this conversation as resolved.
Show resolved Hide resolved
# Test that observer.obstime is used for obstime if obstime is not provided
observer = HeliographicStonyhurst(obstime='2023-09-08')
hpc = Helioprojective(observer=observer)
assert hpc.obstime == observer.obstime

# Test that obstime is None if observer does not have an obstime
hpc = Helioprojective(observer='earth')
assert hpc.obstime is None


# ==============================================================================
# ## Heliographic Tests
# ==============================================================================
Expand Down