use of org.orekit.propagation.sampling.OrekitStepInterpolator in project Orekit by CS-SI.
the class RangeAnalyticTest method genericTestValues.
/**
* Generic test function for values of the range
* @param printResults Print the results ?
* @throws OrekitException
*/
void genericTestValues(final boolean printResults) throws OrekitException {
Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
final NumericalPropagatorBuilder propagatorBuilder = context.createBuilder(OrbitType.KEPLERIAN, PositionAngle.TRUE, true, 1.0e-6, 60.0, 0.001);
// Create perfect range measurements
final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new RangeMeasurementCreator(context), 1.0, 3.0, 300.0);
// Lists for results' storage - Used only for derivatives with respect to state
// "final" value to be seen by "handleStep" function of the propagator
final List<Double> absoluteErrors = new ArrayList<Double>();
final List<Double> relativeErrors = new ArrayList<Double>();
// Set master mode
// Use a lambda function to implement "handleStep" function
propagator.setMasterMode((OrekitStepInterpolator interpolator, boolean isLast) -> {
for (final ObservedMeasurement<?> measurement : measurements) {
// Play test if the measurement date is between interpolator previous and current date
if ((measurement.getDate().durationFrom(interpolator.getPreviousState().getDate()) > 0.) && (measurement.getDate().durationFrom(interpolator.getCurrentState().getDate()) <= 0.)) {
// We intentionally propagate to a date which is close to the
// real spacecraft state but is *not* the accurate date, by
// compensating only part of the downlink delay. This is done
// in order to validate the partial derivatives with respect
// to velocity. If we had chosen the proper state date, the
// range would have depended only on the current position but
// not on the current velocity.
final double meanDelay = measurement.getObservedValue()[0] / Constants.SPEED_OF_LIGHT;
final AbsoluteDate date = measurement.getDate().shiftedBy(-0.75 * meanDelay);
final SpacecraftState state = interpolator.getInterpolatedState(date);
// Values of the RangeAnalytic & errors
final double RangeObserved = measurement.getObservedValue()[0];
final double RangeEstimated = new RangeAnalytic((Range) measurement).theoreticalEvaluationAnalytic(0, 0, state).getEstimatedValue()[0];
final double absoluteError = RangeEstimated - RangeObserved;
absoluteErrors.add(absoluteError);
relativeErrors.add(FastMath.abs(absoluteError) / FastMath.abs(RangeObserved));
// Print results on console ?
if (printResults) {
final AbsoluteDate measurementDate = measurement.getDate();
String stationName = ((Range) measurement).getStation().getBaseFrame().getName();
System.out.format(Locale.US, "%-15s %-23s %-23s %19.6f %19.6f %13.6e %13.6e%n", stationName, measurementDate, date, RangeObserved, RangeEstimated, FastMath.abs(RangeEstimated - RangeObserved), FastMath.abs((RangeEstimated - RangeObserved) / RangeObserved));
}
}
// End if measurement date between previous and current interpolator step
}
// End for loop on the measurements
});
// Print results on console ? Header
if (printResults) {
System.out.format(Locale.US, "%-15s %-23s %-23s %19s %19s %13s %13s%n", "Station", "Measurement Date", "State Date", "Range observed [m]", "Range estimated [m]", "ΔRange [m]", "rel ΔRange");
}
// Rewind the propagator to initial date
propagator.propagate(context.initialOrbit.getDate());
// Sort measurements chronologically
measurements.sort(new ChronologicalComparator());
// Propagate to final measurement's date
propagator.propagate(measurements.get(measurements.size() - 1).getDate());
// Convert lists to double array
final double[] absErrors = absoluteErrors.stream().mapToDouble(Double::doubleValue).toArray();
final double[] relErrors = relativeErrors.stream().mapToDouble(Double::doubleValue).toArray();
// Statistics' assertion
final double absErrorsMedian = new Median().evaluate(absErrors);
final double absErrorsMin = new Min().evaluate(absErrors);
final double absErrorsMax = new Max().evaluate(absErrors);
final double relErrorsMedian = new Median().evaluate(relErrors);
final double relErrorsMax = new Max().evaluate(relErrors);
// Print the results on console ? Final results
if (printResults) {
System.out.println();
System.out.println("Absolute errors median: " + absErrorsMedian);
System.out.println("Absolute errors min : " + absErrorsMin);
System.out.println("Absolute errors max : " + absErrorsMax);
System.out.println("Relative errors median: " + relErrorsMedian);
System.out.println("Relative errors max : " + relErrorsMax);
}
Assert.assertEquals(0.0, absErrorsMedian, 3.8e-08);
Assert.assertEquals(0.0, absErrorsMin, 2.0e-07);
Assert.assertEquals(0.0, absErrorsMax, 2.3e-07);
Assert.assertEquals(0.0, relErrorsMedian, 6.5e-15);
Assert.assertEquals(0.0, relErrorsMax, 2.4e-14);
}
use of org.orekit.propagation.sampling.OrekitStepInterpolator in project Orekit by CS-SI.
the class RangeTest method genericTestStateDerivatives.
void genericTestStateDerivatives(final boolean isModifier, final boolean printResults, final double refErrorsPMedian, final double refErrorsPMean, final double refErrorsPMax, final double refErrorsVMedian, final double refErrorsVMean, final double refErrorsVMax) throws OrekitException {
Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
final NumericalPropagatorBuilder propagatorBuilder = context.createBuilder(OrbitType.KEPLERIAN, PositionAngle.TRUE, true, 1.0e-6, 60.0, 0.001);
// Create perfect range measurements
final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new RangeMeasurementCreator(context), 1.0, 3.0, 300.0);
// Lists for results' storage - Used only for derivatives with respect to state
// "final" value to be seen by "handleStep" function of the propagator
final List<Double> errorsP = new ArrayList<Double>();
final List<Double> errorsV = new ArrayList<Double>();
// Set master mode
// Use a lambda function to implement "handleStep" function
propagator.setMasterMode((OrekitStepInterpolator interpolator, boolean isLast) -> {
for (final ObservedMeasurement<?> measurement : measurements) {
// Play test if the measurement date is between interpolator previous and current date
if ((measurement.getDate().durationFrom(interpolator.getPreviousState().getDate()) > 0.) && (measurement.getDate().durationFrom(interpolator.getCurrentState().getDate()) <= 0.)) {
// Add modifiers if test implies it
final RangeTroposphericDelayModifier modifier = new RangeTroposphericDelayModifier(SaastamoinenModel.getStandardModel());
if (isModifier) {
((Range) measurement).addModifier(modifier);
}
// We intentionally propagate to a date which is close to the
// real spacecraft state but is *not* the accurate date, by
// compensating only part of the downlink delay. This is done
// in order to validate the partial derivatives with respect
// to velocity. If we had chosen the proper state date, the
// range would have depended only on the current position but
// not on the current velocity.
final double meanDelay = measurement.getObservedValue()[0] / Constants.SPEED_OF_LIGHT;
final AbsoluteDate date = measurement.getDate().shiftedBy(-0.75 * meanDelay);
final SpacecraftState state = interpolator.getInterpolatedState(date);
final double[][] jacobian = measurement.estimate(0, 0, new SpacecraftState[] { state }).getStateDerivatives(0);
// Jacobian reference value
final double[][] jacobianRef;
// Compute a reference value using finite differences
jacobianRef = Differentiation.differentiate(new StateFunction() {
public double[] value(final SpacecraftState state) throws OrekitException {
return measurement.estimate(0, 0, new SpacecraftState[] { state }).getEstimatedValue();
}
}, measurement.getDimension(), propagator.getAttitudeProvider(), OrbitType.CARTESIAN, PositionAngle.TRUE, 2.0, 3).value(state);
Assert.assertEquals(jacobianRef.length, jacobian.length);
Assert.assertEquals(jacobianRef[0].length, jacobian[0].length);
// Errors & relative errors on the Jacobian
double[][] dJacobian = new double[jacobian.length][jacobian[0].length];
double[][] dJacobianRelative = new double[jacobian.length][jacobian[0].length];
for (int i = 0; i < jacobian.length; ++i) {
for (int j = 0; j < jacobian[i].length; ++j) {
dJacobian[i][j] = jacobian[i][j] - jacobianRef[i][j];
dJacobianRelative[i][j] = FastMath.abs(dJacobian[i][j] / jacobianRef[i][j]);
if (j < 3) {
errorsP.add(dJacobianRelative[i][j]);
} else {
errorsV.add(dJacobianRelative[i][j]);
}
}
}
// Print values in console ?
if (printResults) {
String stationName = ((Range) measurement).getStation().getBaseFrame().getName();
System.out.format(Locale.US, "%-15s %-23s %-23s " + "%10.3e %10.3e %10.3e " + "%10.3e %10.3e %10.3e " + "%10.3e %10.3e %10.3e " + "%10.3e %10.3e %10.3e%n", stationName, measurement.getDate(), date, dJacobian[0][0], dJacobian[0][1], dJacobian[0][2], dJacobian[0][3], dJacobian[0][4], dJacobian[0][5], dJacobianRelative[0][0], dJacobianRelative[0][1], dJacobianRelative[0][2], dJacobianRelative[0][3], dJacobianRelative[0][4], dJacobianRelative[0][5]);
}
}
// End if measurement date between previous and current interpolator step
}
// End for loop on the measurements
});
// Print results on console ?
if (printResults) {
System.out.format(Locale.US, "%-15s %-23s %-23s " + "%10s %10s %10s " + "%10s %10s %10s " + "%10s %10s %10s " + "%10s %10s %10s%n", "Station", "Measurement Date", "State Date", "ΔdPx", "ΔdPy", "ΔdPz", "ΔdVx", "ΔdVy", "ΔdVz", "rel ΔdPx", "rel ΔdPy", "rel ΔdPz", "rel ΔdVx", "rel ΔdVy", "rel ΔdVz");
}
// Rewind the propagator to initial date
propagator.propagate(context.initialOrbit.getDate());
// Sort measurements chronologically
measurements.sort(new ChronologicalComparator());
// Propagate to final measurement's date
propagator.propagate(measurements.get(measurements.size() - 1).getDate());
// Convert lists to double[] and evaluate some statistics
final double[] relErrorsP = errorsP.stream().mapToDouble(Double::doubleValue).toArray();
final double[] relErrorsV = errorsV.stream().mapToDouble(Double::doubleValue).toArray();
final double errorsPMedian = new Median().evaluate(relErrorsP);
final double errorsPMean = new Mean().evaluate(relErrorsP);
final double errorsPMax = new Max().evaluate(relErrorsP);
final double errorsVMedian = new Median().evaluate(relErrorsV);
final double errorsVMean = new Mean().evaluate(relErrorsV);
final double errorsVMax = new Max().evaluate(relErrorsV);
// Print the results on console ?
if (printResults) {
System.out.println();
System.out.format(Locale.US, "Relative errors dR/dP -> Median: %6.3e / Mean: %6.3e / Max: %6.3e%n", errorsPMedian, errorsPMean, errorsPMax);
System.out.format(Locale.US, "Relative errors dR/dV -> Median: %6.3e / Mean: %6.3e / Max: %6.3e%n", errorsVMedian, errorsVMean, errorsVMax);
}
Assert.assertEquals(0.0, errorsPMedian, refErrorsPMedian);
Assert.assertEquals(0.0, errorsPMean, refErrorsPMean);
Assert.assertEquals(0.0, errorsPMax, refErrorsPMax);
Assert.assertEquals(0.0, errorsVMedian, refErrorsVMedian);
Assert.assertEquals(0.0, errorsVMean, refErrorsVMean);
Assert.assertEquals(0.0, errorsVMax, refErrorsVMax);
}
use of org.orekit.propagation.sampling.OrekitStepInterpolator in project Orekit by CS-SI.
the class NumericalPropagatorTest method testException.
@Test(expected = OrekitException.class)
public void testException() throws OrekitException {
propagator.setMasterMode(new OrekitStepHandler() {
private int countDown = 3;
private AbsoluteDate previousCall = null;
public void init(SpacecraftState s0, AbsoluteDate t) {
}
public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) throws OrekitException {
if (previousCall != null) {
Assert.assertTrue(interpolator.getCurrentState().getDate().compareTo(previousCall) < 0);
}
if (--countDown == 0) {
throw new OrekitException(LocalizedCoreFormats.SIMPLE_MESSAGE, "dummy error");
}
}
});
propagator.propagate(initDate.shiftedBy(-3600));
}
use of org.orekit.propagation.sampling.OrekitStepInterpolator in project Orekit by CS-SI.
the class IntegratedEphemerisTest method testPartialDerivativesIssue16.
@Test
public void testPartialDerivativesIssue16() throws OrekitException {
final String eqName = "derivatives";
numericalPropagator.setEphemerisMode();
numericalPropagator.setOrbitType(OrbitType.CARTESIAN);
final PartialDerivativesEquations derivatives = new PartialDerivativesEquations(eqName, numericalPropagator);
final SpacecraftState initialState = derivatives.setInitialJacobians(new SpacecraftState(initialOrbit));
final JacobiansMapper mapper = derivatives.getMapper();
numericalPropagator.setInitialState(initialState);
numericalPropagator.propagate(initialOrbit.getDate().shiftedBy(3600.0));
BoundedPropagator ephemeris = numericalPropagator.getGeneratedEphemeris();
ephemeris.setMasterMode(new OrekitStepHandler() {
private final Array2DRowRealMatrix dYdY0 = new Array2DRowRealMatrix(6, 6);
public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) throws OrekitException {
SpacecraftState state = interpolator.getCurrentState();
Assert.assertEquals(mapper.getAdditionalStateDimension(), state.getAdditionalState(eqName).length);
mapper.getStateJacobian(state, dYdY0.getDataRef());
// no parameters, this is a no-op and should work
mapper.getParametersJacobian(state, null);
RealMatrix deltaId = dYdY0.subtract(MatrixUtils.createRealIdentityMatrix(6));
Assert.assertTrue(deltaId.getNorm() > 100);
Assert.assertTrue(deltaId.getNorm() < 3100);
}
});
ephemeris.propagate(initialOrbit.getDate().shiftedBy(1800.0));
}
use of org.orekit.propagation.sampling.OrekitStepInterpolator in project Orekit by CS-SI.
the class KeplerianPropagatorTest method testStepException.
@Test(expected = OrekitException.class)
public void testStepException() throws OrekitException {
final KeplerianOrbit orbit = new KeplerianOrbit(7.8e6, 0.032, 0.4, 0.1, 0.2, 0.3, PositionAngle.TRUE, FramesFactory.getEME2000(), AbsoluteDate.J2000_EPOCH, 3.986004415e14);
KeplerianPropagator propagator = new KeplerianPropagator(orbit);
OrekitStepHandlerMultiplexer multiplexer = new OrekitStepHandlerMultiplexer();
propagator.setMasterMode(multiplexer);
multiplexer.add(new OrekitStepHandler() {
public void init(SpacecraftState s0, AbsoluteDate t) {
}
public void handleStep(OrekitStepInterpolator interpolator, boolean isLast) throws OrekitException {
if (isLast) {
throw new OrekitException((Throwable) null, new DummyLocalizable("dummy error"));
}
}
});
propagator.propagate(orbit.getDate().shiftedBy(-3600));
}
Aggregations