Example #1
0
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 )
Example #2
0
    n_states = 1350
    tas = np.zeros(n_states)
    for n in range(n_states):
        tas[n] = oc.state2coes(states[n])[3]

    plt.figure(figsize=(14, 8))
    plt.plot(ets[:n_states] / 3600.0, tas, 'm', linewidth=3)
    plt.grid(linestyle='dotted')
    plt.yticks(range(0, 390, 30), fontsize=15)
    plt.xticks(fontsize=15)
    plt.ylim([0, 360])
    plt.xlabel('Time (hours)', fontsize=15)
    plt.ylabel(r'True Anomaly $\Theta^{\circ}$', fontsize=15)
    plt.show()
    '''
	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.
	'''
    if False:
        import spiceypy as spice
        import spice_data as sd
        import spice_tools as st
        spice.furnsh(sd.leapseconds_kernel)

        ets += spice.str2et('2021-12-26')

        st.write_bsp(ets, states, {'bsp_fn': fp + 'equatorial-elliptical.bsp'})
Example #3
0
    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:
        import spice_tools as st
        spice.furnsh(sd.leapseconds_kernel)

        st.write_bsp(ets, states_list[0], {'bsp_fn': fp + 'raans.bsp'})

        for n in [1]:
            st.write_bsp(ets, states_list[n], {
                'bsp_fn': fp + 'raans.bsp',
                'spice_id': -999 + n,
                'new': False
            })
Example #4
0
# 3rd party libraries
import spiceypy as spice

if __name__ == '__main__':
    spice.furnsh(sd.leapseconds_kernel)
    spice.furnsh(sd.de432)
    spice.furnsh(sd.pck00010)

    sc = SC({
        'date0': '2021-03-03 22:10:35 TDB',
        'coes': [7480.0, 0.09, 5.5, 6.26, 5.95, 0.2],
        'tspan': '40',
    })

    st.write_bsp(sc.ets, sc.states[:, :6], {'bsp_fn': 'leo.bsp'})
    spice.furnsh('leo.bsp')

    et0 = spice.str2et('2021-03-03 22:10:40 TDB')
    etf = spice.str2et('2021-03-04 TDB')

    timecell = spice.utils.support_types.SPICEDOUBLE_CELL(2)
    spice.appndd(et0, timecell)
    spice.appndd(etf, timecell)

    cell = spice.gfoclt('ANY', '399', 'ELLIPSOID', 'IAU_EARTH', '10',
                        'ELLIPSOID', 'IAU_SUN', 'LT', '-999', 120.0, timecell)
    ets_SPICE = spice.wnfetd(cell, 0)
    cal0 = spice.et2utc(ets_SPICE[0], 'C', 1)
    cal1 = spice.et2utc(ets_SPICE[1], 'C', 1)
    print('\n*** SPICE RESULTS ***')
Example #5
0
        latlons.append(
            nt.cart2lat(states[:3000, :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:
        import spice_tools as st
        spice.furnsh(sd.leapseconds_kernel)

        st.write_bsp(ets, states_list[0],
                     {'bsp_fn': fp + 'cosmo/many-orbits.bsp'})

        for n in [1, 2, 3]:
            st.write_bsp(
                ets, states_list[n], {
                    'bsp_fn': fp + 'cosmo/many-orbits.bsp',
                    'spice_id': -999 + n,
                    'new': False
                })