JuliaSpace / SatelliteToolbox.jl

A toolbox for satellite analysis written in julia language.
MIT License
248 stars 33 forks source link

ITRF to TEME transformation #93

Closed trufanov-nok closed 1 year ago

trufanov-nok commented 1 year ago

Hello!
I don't know julia language so may be missing something...
I would like to try to propagate a State Vector obtained from GPS with SGP4. Thus I need to construct a TLE (with help of RV2TLE tool) with state vector in TEME. So I would like to convert it from ITRF (GPS) to TEME. My code is:

using SatelliteToolbox
using StaticArrays
import Dates

# Position vector [m].
r = SVector{3, Float64}(4.311678750265122e+06, -3.090624111700405e+06, 4.284610045293988e+06)
# Velocity vector [m/s].
v = SVector{3, Float64}(3.147249615634850e+03, -3.764293063945658e+03, -5.865605641177310e+03)
# Acceleration vector [m/s²]
a = SVector{3, Float64}(0,0,0)

# Epoch in [s] since J2000 epoch Terrestrial Time
t = 732341388.184000
# UnxTime
t = 946728000 + t
# Epoch [Julian Day].
t = Dates.unix2datetime(t)
t = DatetoJD(t)

sv = OrbitStateVector(t,r,v,a)

eop = get_iers_eop()
LOD = eop.LOD[sv.t]

svECEFtoECI(sv, ITRF(), TEME(), sv.t, LOD)

Unfortunately I'm getting ERROR: MethodError: no method matching sv_ecef_to_eci(::OrbitStateVector{Float64, Float64}, ::Val{:ITRF}, ::Val{:TEME}, ::Float64, ::Float64).
Am I missing something or direct conversion between ITRF and TEME is not supported?

ronisbr commented 1 year ago

Hi @trufanov-nok !

You need to pass all the EOP data instead of just the LOD:

using SatelliteToolbox
using Dates

r = [4.311678750265122e+06, -3.090624111700405e+06, 4.284610045293988e+06]
v = [3.147249615634850e+03, -3.764293063945658e+03, -5.865605641177310e+03]

# Epoch in [s] since J2000 epoch Terrestrial Time
t = 732341388.184000
t = 946728000 + t
t = Dates.unix2datetime(t)
t = datetime2julian(t)

sv = orbsv(t, r, v)

eop = get_iers_eop()

sv_ecef_to_eci(sv, ITRF(), TEME(), t, eop)
  epoch : 2.46002e6 (2023-03-17T16:09:48.184)
      r : [4925.69, 1969.78, 4284.61]   km
      v : [4.72293, 0.984993, -5.8656]  km/s

I have two important points:

  1. The conversion from ECEF to ECI using the state vector considers that the velocity in ECEF is also measured in the ECEF, meaning that the Earth rotation rate will be subtracted.
  2. Do you know that we have here a tool to convert the RV measurements from GPS to TLE? We used this tool for some applications in a satellite developed here in Brazil. See the functions rv_to_mean_elements_sgp4 and rv_to_tle.
trufanov-nok commented 1 year ago

The conversion from ECEF to ECI using the state vector considers that the velocity in ECEF is also measured in the ECEF, meaning that the Earth rotation rate will be subtracted.

Is this subtraction performed automatically?

Do you know that we have here a tool to convert the RV measurements from GPS to TLE? We used this tool for some applications in a satellite developed here in Brazil. See the functions rv_to_mean_elements_sgp4 and rv_to_tle.

Great to hear! I didn't know that, thank you. At least I don't need to run DOS program on linux machine anymore.
Both functions seems to expect vectors represented in TEME reference frame, so I still need sv_ecef_to_eci.

ronisbr commented 1 year ago

Is this subtraction performed automatically?

Yes! It will always remove the Earth rotation rate if you use sv_ecef_to_eci.

Great to hear! I didn't know that, thank you. At least I don't need to run DOS program on linux machine anymore. Both functions seems to expect vectors represented in TEME reference frame, so I still need sv_ecef_to_eci.

Yes! Indeed, you need to pass vectors represented in TEME. If you want a code snipped how to use the TLE estimation, take a look a this test file: https://github.com/JuliaSpace/SatelliteToolbox.jl/blob/master/test/orbit/mean_elements/sgp4.jl

ronisbr commented 1 year ago

Ah! Notice that rv_to_tle actually estimates and orbit. It is not just a conversion from a state vector to SGP4 mean elements. You can provide a list of vectors (like GPS measurements), and it returns the mean elements obtained by a least square algorithm.