OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
tle2orb.py
Go to the documentation of this file.
1 def tle2orb(TLEline1,TLEline2,t_start,t_end,t_interval):
2  # derived from sgp4_rot which rotateS the SGP4 orbit vectors to the ECR frame
3  # converted from: sgp4_rot.f
4  # inherited from TLE2ECR.py
5  # Liang Hong, 2/26/2020
6  # input: TLEline1,TLEline2, two lines from the TLE file
7  # e.g. 1 43820U 18099BQ 20019.13664524 .00000344 00000-0 36192-4 0 9993
8  # 2 43820 97.7183 93.1246 0011684 330.0533 30.0019 14.95507336 60873
9  # input: t_start, in UTC
10  # input: t_end, in UTC
11  # input: t_interval, in seconds
12  # output: orb, ECR data [doy.partialDay pos[0-2], vel[0-2]]
13  # Liang Hong, 4/8/2020
14 
15  import sgp4
16  import time
17  import numpy as np
18  import datetime
19  from sgp4.api import Satrec
20  from sgp4.api import jday
21  from hawknav.jd import jd
22 
23  OMEGAE = 7.29211585494e-5
24 
25  satellite = Satrec.twoline2rv(TLEline1,TLEline2)
26  time_tuple = time.gmtime(t_start)
27  jd, fr = jday(time_tuple.tm_year, time_tuple.tm_mon, time_tuple.tm_mday, time_tuple.tm_hour, time_tuple.tm_min, time_tuple.tm_sec)
28  ts = np.arange(t_start,t_end,t_interval) # time stamps in UTC seconds
29  dt_array = (ts-t_start)/86400.0
30  fr_array = fr+dt_array
31  jd_array = jd*np.ones(np.size(fr_array))
32  jd_array = jd_array + np.modf(fr_array)[1]
33  fr_array = np.modf(fr_array)[0]
34  e, r, v = satellite.sgp4_array(jd_array, fr_array)
35  nrec = np.size(jd_array)
36 
37  # Compute days since J2000
38  t = jd_array - 2451545 + fr_array
39 
40  # Compute Greenwich Mean Sidereal Time (degrees)
41  gmst = 100.4606184 + 0.9856473663*t + 2.908e-13*t*t
42 
43  # Add time-of-day to get GHA
44  gha = gmst + fr_array*360
45  gha = np.mod(gha,360)
46 
47  # Rotate position and velocity vectors
48  cogha = np.cos(np.deg2rad(gha))
49  sigha = np.sin(np.deg2rad(gha))
50  posr = np.zeros((nrec,3))
51  posr[:,0] = r[:,0]*cogha + r[:,1]*sigha
52  posr[:,1] = r[:,1]*cogha - r[:,0]*sigha
53  posr[:,2] = r[:,2]
54 
55  # Include Earth rotation rate in velocity
56  velr = np.zeros((nrec,3))
57  velr[:,0] = v[:,0]*cogha + v[:,1]*sigha + OMEGAE*posr[:,1]
58  velr[:,1] = v[:,1]*cogha - v[:,0]*sigha - OMEGAE*posr[:,0]
59  velr[:,2] = v[:,2]
60 
61  yd = [datetime.datetime.utcfromtimestamp(t).timetuple().tm_yday for t in ts]
62  tt = yd + fr_array
63 
64  orb = np.concatenate((tt[:,None],posr,velr),axis=1)
65  return orb
int32_t jday(int16_t i, int16_t j, int16_t k)
Definition: jday.c:4
def tle2orb(TLEline1, TLEline2, t_start, t_end, t_interval)
Definition: tle2orb.py:1