I am writing a script to convert an OEM into an OCM. After parsing the OEM I use OemSegment.getCoordinates() to eventually get a list of SpacecraftState, and use OemSegment.getCovarianceMatrices() to get a list of CartesianCovariance. The two issues I encountered are as follows:
- In the OEM itself, states are in km & km/s, and covariance is in km^2, km^2/s, & km^2/s^2. If I pull the covariance matrix itself from a
CartesianCovarianceI see that is has been converted to SI units. So 2.090280011336369E-8 km^2 → 2.090280011336369E-2 m^2. Similarly the states are converted into m & m/s. However, when building theOrbitCovarianceobject for the OCM, putting in the LTM string covariance from these values has the OCM output thinking they are already in km. Additionally, this method of building OCM covariance through LTM strings is a bit clunky - would be much easier if it could acceptCartesianCovarianceorStateCovarianceor even just aRealMatrix(and then do the conversion to km later) - When trying to remedy the covariance to get it into km for the OCM output, I ran into another funky issue with
CartesianCovariance. In this case, pulled out the covariance matrix as aRealMatrixviagetCovarianceMatrix(), then looped through element by element and divided each value by 1e6 (m^2 → km^2) and then placed it back into theCartesianCovarianceusingsetCovarianceMatrixEntry(). Since covariance is symmetrical, element 0,1 would be the same as 1,0 - but theRealMatrixshouldn’t know this. When looping through, I would divide by 1e6, and the symmetric element would also get divided, which meant that then I got to that element, it would get divided again. See below for the loop iteration printout example:
# Example 2x2 covariance
cart_cov = <CartesianCovariance>
cov_matrix = cart_cov.getCovarianceMatrix() # Assume RealMatrix([[5, 3], [3, 5]])
# Loop
for i in range(2):
for j in range(2):
# Get the covariance entry by index from the cov_matrix
cov_entry_m2 = cov_matrix.getEntry(i, j)
# Convert to km2 for OCM
cov_entry_km2 = cov_entry_m2 / 1e6
# Set the CartesianCovariance element to the new value
cart_cov.setCovarianceMatrixEntry(i, j, cov_entry_km2)
# Print at each step
print(i, j, cart_cov.getCovarianceMatrix())
# Below is what is printed
0, 0, [[5e-6, 3], [3, 5]]
0, 1, [[5e-6, 3e-6], [3e-6, 5]]
1, 0, [[5e-6, 3e-12], [3e-12, 5]]
1, 1, [[5e-6, 3e-12], [3e-12, 5e-6]]