Search in sources :

Example 6 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project Orekit by CS-SI.

the class KalmanEstimatorTest method testKeplerianRangeAndRangeRate.

/**
 * Perfect range and range rate measurements with a perfect start
 * @throws OrekitException
 */
@Test
public void testKeplerianRangeAndRangeRate() throws OrekitException {
    // Create context
    Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
    // Create initial orbit and propagator builder
    final OrbitType orbitType = OrbitType.KEPLERIAN;
    final PositionAngle positionAngle = PositionAngle.TRUE;
    final boolean perfectStart = true;
    final double minStep = 1.e-6;
    final double maxStep = 60.;
    final double dP = 1.;
    final NumericalPropagatorBuilder propagatorBuilder = context.createBuilder(orbitType, positionAngle, perfectStart, minStep, maxStep, dP);
    // Create perfect range & range rate measurements
    final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
    final List<ObservedMeasurement<?>> measurementsRange = EstimationTestUtils.createMeasurements(propagator, new RangeMeasurementCreator(context), 1.0, 3.0, 300.0);
    final List<ObservedMeasurement<?>> measurementsRangeRate = EstimationTestUtils.createMeasurements(propagator, new RangeRateMeasurementCreator(context, false), 1.0, 3.0, 300.0);
    // Concatenate measurements
    final List<ObservedMeasurement<?>> measurements = new ArrayList<ObservedMeasurement<?>>();
    measurements.addAll(measurementsRange);
    measurements.addAll(measurementsRangeRate);
    // Reference propagator for estimation performances
    final NumericalPropagator referencePropagator = propagatorBuilder.buildPropagator(propagatorBuilder.getSelectedNormalizedParameters());
    // Reference position/velocity at last measurement date
    final Orbit refOrbit = referencePropagator.propagate(measurements.get(measurements.size() - 1).getDate()).getOrbit();
    // Cartesian covariance matrix initialization
    // 100m on position / 1e-2m/s on velocity
    final RealMatrix cartesianP = MatrixUtils.createRealDiagonalMatrix(new double[] { 1e-2, 1e-2, 1e-2, 1e-8, 1e-8, 1e-8 });
    // Jacobian of the orbital parameters w/r to Cartesian
    final Orbit initialOrbit = orbitType.convertType(context.initialOrbit);
    final double[][] dYdC = new double[6][6];
    initialOrbit.getJacobianWrtCartesian(PositionAngle.TRUE, dYdC);
    final RealMatrix Jac = MatrixUtils.createRealMatrix(dYdC);
    // Keplerian initial covariance matrix
    final RealMatrix initialP = Jac.multiply(cartesianP.multiply(Jac.transpose()));
    // Process noise matrix
    final RealMatrix cartesianQ = MatrixUtils.createRealDiagonalMatrix(new double[] { 1.e-4, 1.e-4, 1.e-4, 1.e-10, 1.e-10, 1.e-10 });
    final RealMatrix Q = Jac.multiply(cartesianQ.multiply(Jac.transpose()));
    // Build the Kalman filter
    final KalmanEstimatorBuilder kalmanBuilder = new KalmanEstimatorBuilder();
    kalmanBuilder.builder(propagatorBuilder);
    kalmanBuilder.estimatedMeasurementsParameters(new ParameterDriversList());
    kalmanBuilder.initialCovarianceMatrix(initialP);
    kalmanBuilder.processNoiseMatrixProvider(new ConstantProcessNoise(Q));
    final KalmanEstimator kalman = kalmanBuilder.build();
    // Filter the measurements and check the results
    final double expectedDeltaPos = 0.;
    final double posEps = 5.96e-3;
    final double expectedDeltaVel = 0.;
    final double velEps = 2.06e-6;
    final double[] expectedSigmasPos = { 0.341538, 8.175281, 4.634384 };
    final double sigmaPosEps = 1e-6;
    final double[] expectedSigmasVel = { 1.167838e-3, 1.036437e-3, 2.834385e-3 };
    final double sigmaVelEps = 1e-9;
    EstimationTestUtils.checkKalmanFit(context, kalman, measurements, refOrbit, positionAngle, expectedDeltaPos, posEps, expectedDeltaVel, velEps, expectedSigmasPos, sigmaPosEps, expectedSigmasVel, sigmaVelEps);
}
Also used : Context(org.orekit.estimation.Context) Orbit(org.orekit.orbits.Orbit) PositionAngle(org.orekit.orbits.PositionAngle) ArrayList(java.util.ArrayList) RealMatrix(org.hipparchus.linear.RealMatrix) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) ParameterDriversList(org.orekit.utils.ParameterDriversList) NumericalPropagatorBuilder(org.orekit.propagation.conversion.NumericalPropagatorBuilder) Propagator(org.orekit.propagation.Propagator) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) OrbitType(org.orekit.orbits.OrbitType) RangeMeasurementCreator(org.orekit.estimation.measurements.RangeMeasurementCreator) ObservedMeasurement(org.orekit.estimation.measurements.ObservedMeasurement) RangeRateMeasurementCreator(org.orekit.estimation.measurements.RangeRateMeasurementCreator) Test(org.junit.Test)

Example 7 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project Orekit by CS-SI.

the class KalmanEstimatorTest method testKeplerianPV.

/**
 * Perfect PV measurements with a perfect start
 * Keplerian formalism
 * @throws OrekitException
 */
@Test
public void testKeplerianPV() throws OrekitException {
    // Create context
    Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
    // Create initial orbit and propagator builder
    final OrbitType orbitType = OrbitType.KEPLERIAN;
    final PositionAngle positionAngle = PositionAngle.TRUE;
    final boolean perfectStart = true;
    final double minStep = 1.e-6;
    final double maxStep = 60.;
    final double dP = 1.;
    final NumericalPropagatorBuilder propagatorBuilder = context.createBuilder(orbitType, positionAngle, perfectStart, minStep, maxStep, dP);
    // Create perfect PV measurements
    final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
    final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new PVMeasurementCreator(), 0.0, 3.0, 300.0);
    // Reference propagator for estimation performances
    final NumericalPropagator referencePropagator = propagatorBuilder.buildPropagator(propagatorBuilder.getSelectedNormalizedParameters());
    // Reference position/velocity at last measurement date
    final Orbit refOrbit = referencePropagator.propagate(measurements.get(measurements.size() - 1).getDate()).getOrbit();
    // Covariance matrix initialization
    final RealMatrix initialP = MatrixUtils.createRealDiagonalMatrix(new double[] { 1e-2, 1e-2, 1e-2, 1e-5, 1e-5, 1e-5 });
    // Process noise matrix
    RealMatrix Q = MatrixUtils.createRealDiagonalMatrix(new double[] { 1.e-8, 1.e-8, 1.e-8, 1.e-8, 1.e-8, 1.e-8 });
    // Build the Kalman filter
    final KalmanEstimatorBuilder kalmanBuilder = new KalmanEstimatorBuilder();
    kalmanBuilder.builder(propagatorBuilder);
    kalmanBuilder.estimatedMeasurementsParameters(new ParameterDriversList());
    kalmanBuilder.initialCovarianceMatrix(initialP);
    kalmanBuilder.processNoiseMatrixProvider(new ConstantProcessNoise(Q));
    final KalmanEstimator kalman = kalmanBuilder.build();
    // Filter the measurements and check the results
    final double expectedDeltaPos = 0.;
    final double posEps = 5.80e-8;
    final double expectedDeltaVel = 0.;
    final double velEps = 2.28e-11;
    final double[] expectedsigmasPos = { 0.998872, 0.933655, 0.997516 };
    final double sigmaPosEps = 1e-6;
    final double[] expectedSigmasVel = { 9.478853e-4, 9.910788e-4, 5.0438709e-4 };
    final double sigmaVelEps = 1e-10;
    EstimationTestUtils.checkKalmanFit(context, kalman, measurements, refOrbit, positionAngle, expectedDeltaPos, posEps, expectedDeltaVel, velEps, expectedsigmasPos, sigmaPosEps, expectedSigmasVel, sigmaVelEps);
}
Also used : Context(org.orekit.estimation.Context) Orbit(org.orekit.orbits.Orbit) PositionAngle(org.orekit.orbits.PositionAngle) RealMatrix(org.hipparchus.linear.RealMatrix) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) ParameterDriversList(org.orekit.utils.ParameterDriversList) NumericalPropagatorBuilder(org.orekit.propagation.conversion.NumericalPropagatorBuilder) Propagator(org.orekit.propagation.Propagator) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) OrbitType(org.orekit.orbits.OrbitType) ObservedMeasurement(org.orekit.estimation.measurements.ObservedMeasurement) PVMeasurementCreator(org.orekit.estimation.measurements.PVMeasurementCreator) Test(org.junit.Test)

Example 8 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project Orekit by CS-SI.

the class KalmanOrbitDeterminationTest method testLageos2.

@Test
public // Orbit determination for Lageos2 based on SLR (range) measurements
void testLageos2() throws URISyntaxException, IllegalArgumentException, IOException, OrekitException, ParseException {
    // Print results on console
    final boolean print = false;
    // input in tutorial resources directory/output
    final String inputPath = KalmanOrbitDeterminationTest.class.getClassLoader().getResource("orbit-determination/Lageos2/od_test_Lageos2.in").toURI().getPath();
    final File input = new File(inputPath);
    // configure Orekit data acces
    Utils.setDataRoot("orbit-determination/Lageos2:potential/icgem-format");
    GravityFieldFactory.addPotentialCoefficientsReader(new ICGEMFormatReader("eigen-6s-truncated", true));
    // Choice of an orbit type to use
    // Default for test is Cartesian
    final OrbitType orbitType = OrbitType.CARTESIAN;
    // Initial orbital Cartesian covariance matrix
    // These covariances are derived from the deltas between initial and reference orbits
    // So in a way they are "perfect"...
    // Cartesian covariance matrix initialization
    final RealMatrix cartesianOrbitalP = MatrixUtils.createRealDiagonalMatrix(new double[] { 1e4, 4e3, 1, 5e-3, 6e-5, 1e-4 });
    // Orbital Cartesian process noise matrix (Q)
    final RealMatrix cartesianOrbitalQ = MatrixUtils.createRealDiagonalMatrix(new double[] { 1.e-4, 1.e-4, 1.e-4, 1.e-10, 1.e-10, 1.e-10 });
    // Initial measurement covariance matrix and process noise matrix
    final RealMatrix measurementP = MatrixUtils.createRealDiagonalMatrix(new double[] { 1., 1., 1., 1. });
    final RealMatrix measurementQ = MatrixUtils.createRealDiagonalMatrix(new double[] { 1e-6, 1e-6, 1e-6, 1e-6 });
    // Kalman orbit determination run.
    ResultKalman kalmanLageos2 = run(input, orbitType, print, cartesianOrbitalP, cartesianOrbitalQ, null, null, measurementP, measurementQ);
    // Definition of the accuracy for the test
    final double distanceAccuracy = 0.86;
    final double velocityAccuracy = 4.12e-3;
    // Tests
    // Note: The reference initial orbit is the same as in the batch LS tests
    // -----
    // Number of measurements processed
    final int numberOfMeas = 258;
    Assert.assertEquals(numberOfMeas, kalmanLageos2.getNumberOfMeasurements());
    // Estimated position and velocity
    final Vector3D estimatedPos = kalmanLageos2.getEstimatedPV().getPosition();
    final Vector3D estimatedVel = kalmanLageos2.getEstimatedPV().getVelocity();
    // Reference position and velocity at initial date (same as in batch LS test)
    final Vector3D refPos0 = new Vector3D(-5532131.956902, 10025696.592156, -3578940.040009);
    final Vector3D refVel0 = new Vector3D(-3871.275109, -607.880985, 4280.972530);
    // Run the reference until Kalman last date
    final Orbit refOrbit = runReference(input, orbitType, refPos0, refVel0, null, kalmanLageos2.getEstimatedPV().getDate());
    final Vector3D refPos = refOrbit.getPVCoordinates().getPosition();
    final Vector3D refVel = refOrbit.getPVCoordinates().getVelocity();
    // Check distances
    final double dP = Vector3D.distance(refPos, estimatedPos);
    final double dV = Vector3D.distance(refVel, estimatedVel);
    Assert.assertEquals(0.0, dP, distanceAccuracy);
    Assert.assertEquals(0.0, dV, velocityAccuracy);
    // Print orbit deltas
    if (print) {
        System.out.println("Test performances:");
        System.out.format("\t%-30s\n", "ΔEstimated / Reference");
        System.out.format(Locale.US, "\t%-10s %20.6f\n", "ΔP [m]", dP);
        System.out.format(Locale.US, "\t%-10s %20.6f\n", "ΔV [m/s]", dV);
    }
    // Test on measurements parameters
    final List<DelegatingDriver> list = new ArrayList<DelegatingDriver>();
    list.addAll(kalmanLageos2.measurementsParameters.getDrivers());
    sortParametersChanges(list);
    // Batch LS values
    // final double[] stationOffSet = { 1.659203,  0.861250,  -0.885352 };
    // final double rangeBias = -0.286275;
    final double[] stationOffSet = { 0.298867, -0.137456, 0.013315 };
    final double rangeBias = 0.002390;
    Assert.assertEquals(stationOffSet[0], list.get(0).getValue(), distanceAccuracy);
    Assert.assertEquals(stationOffSet[1], list.get(1).getValue(), distanceAccuracy);
    Assert.assertEquals(stationOffSet[2], list.get(2).getValue(), distanceAccuracy);
    Assert.assertEquals(rangeBias, list.get(3).getValue(), distanceAccuracy);
    // test on statistic for the range residuals
    final long nbRange = 258;
    // Batch LS values
    // final double[] RefStatRange = { -2.431135, 2.218644, 0.038483, 0.982017 };
    final double[] RefStatRange = { -23.561314, 20.436464, 0.964164, 5.687187 };
    Assert.assertEquals(nbRange, kalmanLageos2.getRangeStat().getN());
    Assert.assertEquals(RefStatRange[0], kalmanLageos2.getRangeStat().getMin(), distanceAccuracy);
    Assert.assertEquals(RefStatRange[1], kalmanLageos2.getRangeStat().getMax(), distanceAccuracy);
    Assert.assertEquals(RefStatRange[2], kalmanLageos2.getRangeStat().getMean(), distanceAccuracy);
    Assert.assertEquals(RefStatRange[3], kalmanLageos2.getRangeStat().getStandardDeviation(), distanceAccuracy);
}
Also used : ICGEMFormatReader(org.orekit.forces.gravity.potential.ICGEMFormatReader) EquinoctialOrbit(org.orekit.orbits.EquinoctialOrbit) CartesianOrbit(org.orekit.orbits.CartesianOrbit) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Orbit(org.orekit.orbits.Orbit) CircularOrbit(org.orekit.orbits.CircularOrbit) ArrayList(java.util.ArrayList) GeodeticPoint(org.orekit.bodies.GeodeticPoint) RealMatrix(org.hipparchus.linear.RealMatrix) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) OrbitType(org.orekit.orbits.OrbitType) DelegatingDriver(org.orekit.utils.ParameterDriversList.DelegatingDriver) File(java.io.File) Test(org.junit.Test)

Example 9 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project Orekit by CS-SI.

the class EstimationTestUtils method checkKalmanFit.

/**
 * Checker for Kalman estimator validation
 * @param context context used for the test
 * @param kalman Kalman filter
 * @param measurements List of observed measurements to be processed by the Kalman
 * @param refOrbit Reference orbit at last measurement date
 * @param expectedDeltaPos Expected position difference between estimated orbit and reference orbit
 * @param posEps Tolerance on expected position difference
 * @param expectedDeltaVel Expected velocity difference between estimated orbit and reference orbit
 * @param velEps Tolerance on expected velocity difference
 * @param expectedSigmasPos Expected values for covariance matrix on position
 * @param sigmaPosEps Tolerance on expected covariance matrix on position
 * @param expectedSigmasVel Expected values for covariance matrix on velocity
 * @param sigmaVelEps Tolerance on expected covariance matrix on velocity
 * @throws OrekitException
 */
public static void checkKalmanFit(final Context context, final KalmanEstimator kalman, final List<ObservedMeasurement<?>> measurements, final Orbit refOrbit, final PositionAngle positionAngle, final double expectedDeltaPos, final double posEps, final double expectedDeltaVel, final double velEps, final double[] expectedSigmasPos, final double sigmaPosEps, final double[] expectedSigmasVel, final double sigmaVelEps) throws OrekitException {
    // Add the measurements to the Kalman filter
    NumericalPropagator estimated = kalman.processMeasurements(measurements);
    // Check the number of measurements processed by the filter
    Assert.assertEquals(measurements.size(), kalman.getCurrentMeasurementNumber());
    // Get the last estimation
    final Orbit estimatedOrbit = estimated.getInitialState().getOrbit();
    final Vector3D estimatedPosition = estimatedOrbit.getPVCoordinates().getPosition();
    final Vector3D estimatedVelocity = estimatedOrbit.getPVCoordinates().getVelocity();
    // Get the last covariance matrix estimation
    final RealMatrix estimatedP = kalman.getPhysicalEstimatedCovarianceMatrix();
    // Convert the orbital part to Cartesian formalism
    // Assuming all 6 orbital parameters are estimated by the filter
    final double[][] dCdY = new double[6][6];
    estimatedOrbit.getJacobianWrtParameters(positionAngle, dCdY);
    final RealMatrix Jacobian = MatrixUtils.createRealMatrix(dCdY);
    final RealMatrix estimatedCartesianP = Jacobian.multiply(estimatedP.getSubMatrix(0, 5, 0, 5)).multiply(Jacobian.transpose());
    // Get the final sigmas (ie.sqrt of the diagonal of the Cartesian orbital covariance matrix)
    final double[] sigmas = new double[6];
    for (int i = 0; i < 6; i++) {
        sigmas[i] = FastMath.sqrt(estimatedCartesianP.getEntry(i, i));
    }
    // // FIXME: debug
    // final double dPos = Vector3D.distance(refOrbit.getPVCoordinates().getPosition(), estimatedPosition);
    // final double dVel = Vector3D.distance(refOrbit.getPVCoordinates().getVelocity(), estimatedVelocity);
    // System.out.println("Nb Meas = " + kalman.getCurrentMeasurementNumber());
    // System.out.println("dPos    = " + dPos + " m");
    // System.out.println("dVel    = " + dVel + " m/s");
    // System.out.println("sigmas  = " + sigmas[0] + " "
    // + sigmas[1] + " "
    // + sigmas[2] + " "
    // + sigmas[3] + " "
    // + sigmas[4] + " "
    // + sigmas[5]);
    // //debug
    // Check the final orbit estimation & PV sigmas
    Assert.assertEquals(expectedDeltaPos, Vector3D.distance(refOrbit.getPVCoordinates().getPosition(), estimatedPosition), posEps);
    Assert.assertEquals(expectedDeltaVel, Vector3D.distance(refOrbit.getPVCoordinates().getVelocity(), estimatedVelocity), velEps);
    for (int i = 0; i < 3; i++) {
        Assert.assertEquals(expectedSigmasPos[i], sigmas[i], sigmaPosEps);
        Assert.assertEquals(expectedSigmasVel[i], sigmas[i + 3], sigmaVelEps);
    }
}
Also used : KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) Orbit(org.orekit.orbits.Orbit) RealMatrix(org.hipparchus.linear.RealMatrix) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D)

Example 10 with RealMatrix

use of org.hipparchus.linear.RealMatrix in project Orekit by CS-SI.

the class BatchLSEstimatorTest method testKeplerPVBackward.

/**
 * Test PV measurements generation and backward propagation in least-square orbit determination.
 */
@Test
public void testKeplerPVBackward() 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, 1.0);
    // create perfect PV measurements
    final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
    final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new PVMeasurementCreator(), 0.0, -1.0, 300.0);
    // create orbit estimator
    final BatchLSEstimator estimator = new BatchLSEstimator(new LevenbergMarquardtOptimizer(), propagatorBuilder);
    for (final ObservedMeasurement<?> measurement : measurements) {
        estimator.addMeasurement(measurement);
    }
    estimator.setParametersConvergenceThreshold(1.0e-2);
    estimator.setMaxIterations(10);
    estimator.setMaxEvaluations(20);
    EstimationTestUtils.checkFit(context, estimator, 1, 2, 0.0, 8.3e-9, 0.0, 5.3e-8, 0.0, 5.6e-9, 0.0, 1.6e-12);
    RealMatrix normalizedCovariances = estimator.getOptimum().getCovariances(1.0e-10);
    RealMatrix physicalCovariances = estimator.getPhysicalCovariances(1.0e-10);
    Assert.assertEquals(6, normalizedCovariances.getRowDimension());
    Assert.assertEquals(6, normalizedCovariances.getColumnDimension());
    Assert.assertEquals(6, physicalCovariances.getRowDimension());
    Assert.assertEquals(6, physicalCovariances.getColumnDimension());
    Assert.assertEquals(0.00258, physicalCovariances.getEntry(0, 0), 1.0e-5);
}
Also used : Context(org.orekit.estimation.Context) LevenbergMarquardtOptimizer(org.hipparchus.optim.nonlinear.vector.leastsquares.LevenbergMarquardtOptimizer) RealMatrix(org.hipparchus.linear.RealMatrix) NumericalPropagatorBuilder(org.orekit.propagation.conversion.NumericalPropagatorBuilder) BoundedPropagator(org.orekit.propagation.BoundedPropagator) Propagator(org.orekit.propagation.Propagator) ObservedMeasurement(org.orekit.estimation.measurements.ObservedMeasurement) PVMeasurementCreator(org.orekit.estimation.measurements.PVMeasurementCreator) Test(org.junit.Test)

Aggregations

RealMatrix (org.hipparchus.linear.RealMatrix)44 Test (org.junit.Test)17 Orbit (org.orekit.orbits.Orbit)14 Propagator (org.orekit.propagation.Propagator)14 NumericalPropagatorBuilder (org.orekit.propagation.conversion.NumericalPropagatorBuilder)13 ParameterDriversList (org.orekit.utils.ParameterDriversList)13 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)12 Array2DRowRealMatrix (org.hipparchus.linear.Array2DRowRealMatrix)12 Context (org.orekit.estimation.Context)12 ObservedMeasurement (org.orekit.estimation.measurements.ObservedMeasurement)12 OrbitType (org.orekit.orbits.OrbitType)10 NumericalPropagator (org.orekit.propagation.numerical.NumericalPropagator)10 ParameterDriver (org.orekit.utils.ParameterDriver)10 RealVector (org.hipparchus.linear.RealVector)8 PositionAngle (org.orekit.orbits.PositionAngle)8 ArrayList (java.util.ArrayList)7 GeodeticPoint (org.orekit.bodies.GeodeticPoint)6 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)5 OrekitException (org.orekit.errors.OrekitException)5 DelegatingDriver (org.orekit.utils.ParameterDriversList.DelegatingDriver)5