# Faster/more accurate ways to get Earth-Sun vectors in different reference frames than transforming get\_sun results

**URL:** <https://community.openastronomy.org/t/faster-more-accurate-ways-to-get-earth-sun-vectors-in-different-reference-frames-than-transforming-get-sun-results/847>\
**Category:** Astropy\
**Tags:** question\
**Created:** [December 14, 2023, 1:34am UTC](https://community.openastronomy.org/t/faster-more-accurate-ways-to-get-earth-sun-vectors-in-different-reference-frames-than-transforming-get-sun-results/847 "2023-12-14T01:34:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MichaelBonnet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/michaelbonnet/32/484_2.png) [@MichaelBonnet](https://community.openastronomy.org/u/MichaelBonnet)\
**Post date:** [December 14, 2023, 1:34am UTC](https://community.openastronomy.org/t/faster-more-accurate-ways-to-get-earth-sun-vectors-in-different-reference-frames-than-transforming-get-sun-results/847/1 "2023-12-14T01:34:09Z")

</div>

I have a simple function for getting the Earth-Sun position vector in ICRS reference frame at a particular time:

```auto
import datetime
import astropy.units as u
import numpy as np
from astropy.coordinates import ICRS, get_sun
from astropy.time import Time

def get_earth_sun_position_vector_icrs_at_epoch(epoch: datetime.datetime) -> np.ndarray:
    earth_sun_gcrs = get_sun(Time(epoch))
    earth_sun_icrs = earth_sun_gcrs.transform_to(ICRS)
    earth_sun_vector_icrs_at_epoch = earth_sun_icrs.cartesian.xyz.to(u.km).value
    return earth_sun_vector_icrs_at_epoch

```

The conversion from GCRS to ICRS is incredibly expensive, time-wise. 80,000 iterations took over ten minutes.

Is there a faster way to get Earth-Sun vectors at given epochs in different reference frames than this way?

Also - when providing only a Time to get\_sun, is the vector from the center of the Earth to the Sun, or from some other point to the Sun?

---

<div class="post-metadata">

**Author:** ![ayshih](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/ayshih/32/84_2.png) [@ayshih](https://community.openastronomy.org/u/ayshih)\
**Post date:** [December 14, 2023, 4:03am UTC](https://community.openastronomy.org/t/faster-more-accurate-ways-to-get-earth-sun-vectors-in-different-reference-frames-than-transforming-get-sun-results/847/2 "2023-12-14T04:03:21Z")

</div>

First, there is a fundamental error in your code. `earth_sun_gcrs = get_sun(...)` is the location of Sun center in the `GCRS` frame, so `earth_sun_icrs = earth_sun_gcrs.transform_to(ICRS)` is the location of Sun center in the ICRS frame. That is, the vector you return is merely the vector from the origin of ICRS (the solar-system barycenter) to Sun center, with no connection to the Earth at all.

Second, if what you want is the apparent Earth-Sun vector relative to ICRF axes, including the effects of stellar and planetary aberration, then all you need to do is to skip the transformation to ICRS. The origin of `GCRS` is Earth center, so `earth_sun_gcrs.cartesian` is the Earth-Sun vector relative to ICRF axes, including the above observer effects.

Alternatively, if what you want is instead the true/geometric Earth-Sun vector relative to ICRF axes, you shouldn’t use `get_sun()` at all. Instead, you can call `get_body_barycentric()` to get the true location of a solar-system body in ICRS, e.g.:

```python
from astropy.coordinates import get_body_barycentric
epoch = Time(epoch)
earth_icrs = get_body_barycentric('earth', epoch)
sun_icrs = get_body_barycentric('sun', epoch)
earth_sun_vector_icrs_at_epoch = (sun_icrs - earth_icrs).xyz.to_value(u.km)

```

Hope that helps!

---

<div class="post-metadata">

**Author:** ![MichaelBonnet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/michaelbonnet/32/484_2.png) [@MichaelBonnet](https://community.openastronomy.org/u/MichaelBonnet)\
**Post date:** [December 14, 2023, 5:36pm UTC](https://community.openastronomy.org/t/faster-more-accurate-ways-to-get-earth-sun-vectors-in-different-reference-frames-than-transforming-get-sun-results/847/3 "2023-12-14T17:36:47Z")

</div>

It does make sense, thank you.

It does bring up related questions for my project though.

You say ICRF axes use the solar system barycenter - it was my understanding that ICRS is closely analogous to MJ2000 axes/origin. Is that incorrect?

And how might I do the same sort of thing, but getting the TEME earth-sun vector?

---

<div class="post-metadata">

**Author:** ![ayshih](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/ayshih/32/84_2.png) [@ayshih](https://community.openastronomy.org/u/ayshih)\
**Post date:** [December 14, 2023, 6:07pm UTC](https://community.openastronomy.org/t/faster-more-accurate-ways-to-get-earth-sun-vectors-in-different-reference-frames-than-transforming-get-sun-results/847/4 "2023-12-14T18:07:17Z")

</div>

You can use ICRF axes with any origin. Setting aside some details:

- ICRS = ICRF axes with the origin at the solar-system barycenter
- GCRS = ICRF axes with the origin at Earth center
- HCRS = ICRF axes with the origin at Sun center
- etc.

My understanding of MJ2000 is that it’d be very similar to GCRS.

If you have the Sun’s location as a `SkyCoord`, you can transform to Astropy’s `TEME`, which has the origin at Earth center, so the vector will be the Earth-Sun. I’ll caution that there are multiple definitions of TEME, so it’d be prudent for you to confirm whether Astropy’s definition of TEME is what you need.

---

<div class="post-metadata">

**Author:** ![MichaelBonnet](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/michaelbonnet/32/484_2.png) [@MichaelBonnet](https://community.openastronomy.org/u/MichaelBonnet)\
**Post date:** [December 14, 2023, 10:34pm UTC](https://community.openastronomy.org/t/faster-more-accurate-ways-to-get-earth-sun-vectors-in-different-reference-frames-than-transforming-get-sun-results/847/5 "2023-12-14T22:34:16Z")

</div>

This has helped clear up a lot.

The code you have for getting the true/geometric Earth-Sun vector relative to ICRF axes - how might I modify it to use GCRS, to be Earth-centered? Like this?:

```auto
from astropy.coordinates import get_sun
epoch = Time(epoch)
earth_sun_gcrs = get_sun(epoch)
earth_sun_vector_gcrs = earth_sun_gcrs.cartesian

```

---

<div class="post-metadata">

**Author:** ![ayshih](https://dub1.discourse-cdn.com/flex005/user_avatar/community.openastronomy.org/ayshih/32/84_2.png) [@ayshih](https://community.openastronomy.org/u/ayshih)\
**Post date:** [December 21, 2023, 3:02pm UTC](https://community.openastronomy.org/t/faster-more-accurate-ways-to-get-earth-sun-vectors-in-different-reference-frames-than-transforming-get-sun-results/847/6 "2023-12-21T15:02:00Z")

</div>

Again, if what you want is the true/geometric Earth-Sun vector relative to ICRF axes, you shouldn’t use `get_sun()` at all. Note that as the difference of two positions, this vector is the same irrespective of the notion of the coordinate-frame origin, e.g., SSB for ICRS or Earth center for GCRS.

However, if what you want is the Earth-Sun vector relative to ICRF axes, but including the effects of stellar and planetary aberration for an observer at Earth center, then yes, your new code block gives you that.
