def orbit_trajectory(x1_new, x2_new, time): ''' Tool for checking if the motion of the sallite is retrogade or counter - clock wise Args: x1 (numpy array): time and position for point 1 [time1,x1,y1,z1] x2 (numpy array): time and position for point 2 [time2,x2,y2,z2] time (float): time difference between the 2 points Returns: bool: true if we want to keep retrogade, False if we want counter-clock wise ''' l = pkp.lambert_problem(x1_new, x2_new, time, 398600.4405, False, 0) # only one revolution is needed v1 = l.get_v1()[0] v1 = np.asarray(v1) #v1 = np.reshape(v1, 3) x1_new = np.asarray(x1_new) kep1 = state_kep.state_kep(x1_new, v1) if kep1[0] < 0.0: traj = True elif kep1[1] > 1.0: traj = True else: traj = False return traj
def test_statekep_kepstate(): # Initial state vector which is going to be transformed into keplerian elements and then back to the initial state kep = np.array([[15711.578566], [0.377617], [90.0], [0.887383], [0.0], [28.357744]]) y = kep_state.kep_state(kep) expected = np.ravel(kep) r_given = np.array([y[0, 0], y[1, 0], y[2, 0]]) v_given = np.array([y[3, 0], y[4, 0], y[5, 0]]) npt.assert_almost_equal(state_kep.state_kep(r_given, v_given), expected, decimal=10)
def propagate_state(r,v,t0,tf,bstar=0.21109E-4): """Propagates a state vector Args: r(1x3 numpy array): the position vector at epoch v(1x3 numpy array): the velocity vector at epoch t0(float): initial time (epoch) tf(float): final time Returns: pos(1x3 numpy array): the position at tf vel(1x3 numpy array): the velocity at tf """ kep = state_kep(r,v) return propagate_kep(kep,t0,tf,bstar)
def main(data_points): ''' Apply the whole process of interpolation for keplerian element computation Args: data_points (numpy array): positional data set in format of (time, x, y, z) Returns: numpy array: computed keplerian elements for every point of the orbit ''' velocity_vectors = [] keplerians = [] #for index in range(len(data_points)-1): for index in range(1, 100): # Take a pair of points from data_points spline_input = data_points[index:index + 2] # Calculate spline corresponding to these two points spline = cubic_spline(spline_input) # Calculate velocity corresponding 1st of the 2 points of spline_input velocity = compute_velocity(spline, spline_input[0:, 1:4][0]) # Calculate keplerian elements correspong to the state vector(position, velocity) orbital_elements = state_kep.state_kep(spline_input[0:, 1:4][0], velocity) velocity_vectors.append(velocity) keplerians.append(orbital_elements) # Uncomment the below statement to save the velocity vectors in a csv file. # np.savetxt('velo.csv', velocity_vectors, delimiter=",") # Take average of the keplerian elements corresponding to all the state vectors # orbit = np.array(keplerians).mean(axis=0) keplerians = np.asarray(keplerians) return keplerians
def create_kep(my_data): ''' Computes all the keplerian elements for every point of the orbit you provide using Lambert's solution It implements a tool for deleting all the points that give extremely jittery state vectors Args: data(numpy array) : contains the positional data set in (Time, x, y, z) Format Returns: numpy array: array containing all the keplerian elements computed for the orbit given in [semi major axis (a), eccentricity (e), inclination (i), argument of perigee (ω), right ascension of the ascending node (Ω), true anomaly (v)] format ''' v_hold = np.zeros((len(my_data), 3)) # v_abs1 = np.empty([len(my_data)]) x1_new = [1, 1, 1] x1_new[:] = my_data[0, 1:4] x2_new = [1, 1, 1] x2_new[:] = my_data[1, 1:4] time = my_data[1, 0] - my_data[0, 0] traj = orbit_trajectory(x1_new, x2_new, time) v1, v2, ratio = lm.lamberts_method(x1_new, x2_new, time, traj) v_hold[0] = v1 # Produce all the 2 consecutive pairs and find the velocity with lamberts() method for i in range(1, (len(my_data) - 1)): j = i + 1 x1_new = [1, 1, 1] x1_new[:] = my_data[i, 1:4] x2_new = [1, 1, 1] x2_new[:] = my_data[j, 1:4] time = my_data[j, 0] - my_data[i, 0] v1, v2, ratio = lm.lamberts_method(x1_new, x2_new, time, traj) v_hold[i] = v1 # compute the absolute value of the velocity vector for every point # v_abs1[i] = (v1[0] ** 2 + v1[1] ** 2 + v1[2] ** 2) ** (0.5) # If the value of v_abs(i) > v_abs(0) * 10, then we dont keep that value v(i) because it is propably a bad jiitery product # if v_abs1[i] > (10 * v_abs1[0]): # v_hold[i] = v1 # else: # v_hold[i] = v1 # we know have lots of [0, 0, 0] inside our numpy array v(vx, vy, vz) and we dont want them because they produce a bug # when we'll try to transform these products to keplerian elements bo = list() store_i = list() for i in range(0, len(v_hold)): bo.append(np.all(v_hold[i, :] == 0.0)) for i in range(0, len(v_hold)): if bo[i] == False: store_i.append(i) # keeping only the rows with values and throwing all the [0, 0, 0] arrays final_v = np.zeros((len(store_i), 3)) j = 0 for i in store_i: final_v[j] = (v_hold[i]) j += 1 # collecting the position vector r(x ,y, z) that come along with the velocities kept above final_r = np.zeros((len(store_i), 3)) j = 0 for i in store_i: final_r[j] = my_data[i, 1:4] j += 1 # finally we transform the state vectors = position vectors + velocity vectors into keplerian elements kep = np.zeros((len(store_i), 6)) for i in range(0, len(final_r)): kep[i] = np.ravel(state_kep.state_kep(final_r[i], final_v[i])) kep = check_keplerian(kep) return kep