Generate the time-variable mass input

lro_mass.py
 1### ------------------------------------------------------------------------------------------------------- ###
 2
 3#									  LRO MASS OBJECT BUILDING
 4
 5# Example purpose:
 6# The spacecraft mass must be defined to compute non-gravitational accelerations.
 7# It can be a float, int or an xarray.
 8# Here we show how to store the spacecraft mass as an xarray.
 9
10# To compute accelerations, the mass is interpolated by simply returning the previous value of the point.
11
12### ------------------------------------------------------------------------------------------------------- ###
13
14import spiceypy as sp
15import xarray as xr
16import numpy as np
17from pyRTX.core.analysis_utils import epochRange2
18
19ref_epc		=  "2010 may 10 09:25:00"
20duration    =  50000  									  # seconds
21timestep    =  100
22METAKR      = '../example_data/LRO/metakernel_lro.tm'     # metakernel
23
24sp.furnsh(METAKR)
25
26# Define epochs (they must be sorted)
27epc_et0 = sp.str2et( ref_epc )
28epc_et1 = epc_et0 + duration
29times   = epochRange2(startEpoch = epc_et0, endEpoch = epc_et1, step = timestep)
30
31# Define values (here we use a constant value in kg for every epoch)
32values = [2000.] * len(times)
33
34# Create the xarray
35MASS = xr.Dataset(
36    data_vars = dict( mass=("time", values),),
37    coords = dict(time = times,),
38    attrs = dict(description="LRO mass related data."),	
39	)
40
41# Save 
42MASS.to_netcdf('mass/lro_mass.nc', encoding = MASS.encoding.update({'zlib': True, 'complevel': 1}))
43
44sp.unload(METAKR)
45
46### ------------------------------------------------------------------------------------------------------- ###