def test_read_write_bsp( plot = False ): ''' Propagate a 30 degree inclination orbit (20 periods), write BSP kernel, then read back the BSP kernel, ensuring that latitudes are within +-30 degrees before and after writing kernel ''' spice.furnsh( sd.pck00010 ) sc = SC( { 'coes' : [ 8000.0, 0.01, 30.0, 0, 0, 0 ], 'tspan': '20' } ) ''' Ensure latitudes are +-30 degrees ''' sc.calc_latlons() assert np.all( sc.latlons[ :, 2 ] <= 30.0 ) assert np.all( sc.latlons[ :, 2 ] >= -30.0 ) ''' spice.spkopn will error if a bsp with the requested filename already exists ''' filename = 'test_read_write_bsp.bsp' if os.path.isfile( filename ): os.remove( filename ) ''' Write bsp with all the default arguments except filename ''' st.write_bsp( sc.ets, sc.states[ :, :6 ], { 'bsp_fn': filename } ) ''' Now read back the bsp and ensure that latitudes are still within +-30 degrees ''' spice.furnsh( filename ) states = st.calc_ephemeris( -999, sc.ets, 'IAU_EARTH', 399 ) latlons = nt.cart2lat( states[ :, :3 ] ) assert np.all( latlons[ :, 2 ] <= 30.0 ) assert np.all( latlons[ :, 2 ] >= -30.0 ) os.remove( filename )
states_list.append(states) ets += spice.str2et('2021-12-26') pt.plot_orbits( states_list, { 'labels': ['0', '45', '75', '100'], 'colors': ['crimson', 'lime', 'c', 'm'], 'traj_lws': 2, 'show': True }) latlons = [] for states in states_list: latlons.append( nt.cart2lat(states[:1000, :3], 'J2000', 'IAU_EARTH', ets)) pt.plot_groundtracks( latlons, { 'labels': ['0', '45', '75', '100'], 'colors': ['crimson', 'lime', 'c', 'm'], 'show': True }) ''' This part is outside the scope of this lesson, but for those who are curious this is how to write the trajectory to a SPICE .bsp kernel to then use in Cosmographia In general, it is bad practice to have imports in this part of the code, so don't try this at home! ''' if False:
# AWP libraries from Spacecraft import Spacecraft as SC import numerical_tools as nt import plotting_tools as pt import spice_data as sd from planetary_data import earth if __name__ == '__main__': spice.furnsh(sd.pck00010) ER = earth['radius'] coes0 = [ER + 400, 0.01, 45.0, 0, 0.0, 0] # LEO coes1 = [42164.0, 0.2, 55.0, 0, -80, 0] # geosync coes2 = [ER + 890.0, 0.0, 99.0, 0, 0, 0] # sunsync coes3 = [ER + 500, 0.01, 135.0, 0, 0, 0] # retrograde latlons = [] sc_config = {'tspan': '3', 'dense_output': True} for coes in [coes0, coes1, coes2, coes3]: sc_config['coes'] = coes sc = SC(sc_config) ets = arange(sc.ets[0], sc.ets[-1], 15.0) rs = sc.ode_sol.sol(ets).T[:, :3] latlons.append(nt.cart2lat(rs, 'J2000', 'IAU_EARTH', ets)) pt.plot_groundtracks( latlons, { 'labels': ['LEO', 'Geosynchronous', 'Sun Sync', 'Retrograde'], 'show': True })