OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
orb_interp.py
Go to the documentation of this file.
1 def orb_interp(torb,p,v,t_out):
2  #
3  # orb_interp(torb,p,v,t_out)
4  #
5  # Purpose: Interpolate orbit position and velocity vectors to scan line times
6  #
7  #
8  # Calling Arguments:
9  #
10  # Name Type I/O Description
11  # -------- ---- --- -----------
12  # torb(*) double I Array of orbit vector times in seconds of day
13  # p(*,3) float I Array of orbit position vectors for
14  # each time torb
15  # v(*,3) float I Array of orbit velocity vectors for
16  # each time torb
17  # t_out(*) double I Array of time in seconds of day
18  # for every scan line
19  # posii(*,3) float O Array of interpolated positions
20  # veli(*,3) float O Array of interpolated velocities
21  # orbfl(*) int O Interpolated orbit flags (0=good)
22  #
23  #
24  # By: Frederick S. Patt, GSC, August 10, 1993
25  #
26  # Notes: Method uses cubic polynomial to match positions and velocities
27  # at input data points.
28  #
29  # Modification History:
30  #
31  # Created IDL version from FORTRAN code. F.S. Patt, SAIC, November 29, 2006
32  # python code by Liang Hong, 2018/3/28
33  # updated by Liang Hong, 2020/4/6, converted loop to matrix calculation
34 
35  import numpy as np
36 
37  norb = len(torb)
38  if np.isscalar(t_out):
39  t_out = [t_out]
40  nlines = len(t_out)
41  posi = np.zeros((nlines,3))
42  veli = np.zeros((nlines,3))
43  orbfl = np.zeros(nlines)
44 
45  # find 'Scan line times out of available orbit data'
46  ind = np.searchsorted(torb,t_out)-1
47  ind_invalid = np.where((ind<0 )| (ind>norb-2))
48  ind[ind_invalid] = 0
49 
50  # find direct match of output position & velocity from input without interpolation
51  ind_direct = np.where(t_out[:, None] == torb[None, :])
52  if np.size(ind_direct)>0:
53  posi[ind_direct[0],:] = p[ind_direct[1],:]
54  veli[ind_direct[0],:] = v[ind_direct[1],:]
55  orbfl[ind_direct[0]] = 0
56 
57  # cubic interpolation
58  dt = torb[ind+1] - torb[ind]
59  a0 = p[ind,:]
60  a1 = v[ind,:]*dt[:,None]
61  a2 = 3.0*p[ind+1,:] - 3.0*p[ind,:] - 2.0*v[ind,:]*dt[:,None] - v[ind+1,:]*dt[:,None]
62  a3 = 2.0*p[ind,:] - 2.0*p[ind+1,:] + v[ind,:]*dt[:,None] + v[ind+1,:]*dt[:,None]
63 
64  x = (t_out - torb[ind])/dt
65  x2 = x*x
66  x3 = x2*x
67  posi = a0 + a1*x[:,None] + a2*x2[:,None] + a3*x3[:,None]
68  veli = (a1 + 2.0*a2*x[:,None] + 3.0*a3*x2[:,None])/dt[:,None]
69 
70  posi[ind_invalid,:] = 0.0
71  veli[ind_invalid,:] = 0.0
72  orbfl[ind_invalid] = 1
73 
74  return (posi,veli,orbfl)
75 
def orb_interp(torb, p, v, t_out)
Definition: orb_interp.py:1