Search in sources :

Example 11 with ParameterDriversList

use of org.orekit.utils.ParameterDriversList in project Orekit by CS-SI.

the class Model method createPropagators.

/**
 * Create the propagators and parameters corresponding to an evaluation point.
 * @param point evaluation point
 * @return an array of new propagators
 * @exception OrekitException if orbit cannot be created with the current point
 */
public NumericalPropagator[] createPropagators(final RealVector point) throws OrekitException {
    final NumericalPropagator[] propagators = new NumericalPropagator[builders.length];
    // Set up the propagators
    for (int i = 0; i < builders.length; ++i) {
        // Get the number of selected orbital drivers in the builder
        final int nbOrb = orbitsEndColumns[i] - orbitsStartColumns[i];
        // Get the list of selected propagation drivers in the builder and its size
        final ParameterDriversList selectedPropagationDrivers = getSelectedPropagationDriversForBuilder(i);
        final int nbParams = selectedPropagationDrivers.getNbParams();
        // Init the array of normalized parameters for the builder
        final double[] propagatorArray = new double[nbOrb + nbParams];
        // Add the orbital drivers normalized values
        for (int j = 0; j < nbOrb; ++j) {
            propagatorArray[j] = point.getEntry(orbitsStartColumns[i] + j);
        }
        // Add the propagation drivers normalized values
        for (int j = 0; j < nbParams; ++j) {
            propagatorArray[nbOrb + j] = point.getEntry(propagationParameterColumns.get(selectedPropagationDrivers.getDrivers().get(j).getName()));
        }
        // Build the propagator
        propagators[i] = builders[i].buildPropagator(propagatorArray);
    }
    return propagators;
}
Also used : NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) ParameterDriversList(org.orekit.utils.ParameterDriversList)

Example 12 with ParameterDriversList

use of org.orekit.utils.ParameterDriversList in project Orekit by CS-SI.

the class BatchLSEstimator method estimate.

/**
 * Estimate the orbital, propagation and measurements parameters.
 * <p>
 * The initial guess for all parameters must have been set before calling this method
 * using {@link #getOrbitalParametersDrivers(boolean)}, {@link #getPropagatorParametersDrivers(boolean)},
 * and {@link #getMeasurementsParametersDrivers(boolean)} and then {@link ParameterDriver#setValue(double)
 * setting the values} of the parameters.
 * </p>
 * <p>
 * For parameters whose reference date has not been set to a non-null date beforehand (i.e.
 * the parameters for which {@link ParameterDriver#getReferenceDate()} returns {@code null},
 * a default reference date will be set automatically at the start of the estimation to the
 * {@link NumericalPropagatorBuilder#getInitialOrbitDate() initial orbit date} of the first
 * propagator builder. For parameters whose reference date has been set to a non-null date,
 * this reference date is untouched.
 * </p>
 * <p>
 * After this method returns, the estimated parameters can be retrieved using
 * {@link #getOrbitalParametersDrivers(boolean)}, {@link #getPropagatorParametersDrivers(boolean)},
 * and {@link #getMeasurementsParametersDrivers(boolean)} and then {@link ParameterDriver#getValue()
 * getting the values} of the parameters.
 * </p>
 * <p>
 * As a convenience, the method also returns a fully configured and ready to use
 * propagator set up with all the estimated values.
 * </p>
 * <p>
 * For even more in-depth information, the {@link #getOptimum()} method provides detailed
 * elements (covariance matrix, estimated parameters standard deviation, weighted Jacobian, RMS,
 * χ², residuals and more).
 * </p>
 * @return propagators configured with estimated orbits as initial states, and all
 * propagators estimated parameters also set
 * @exception OrekitException if there is a conflict in parameters names
 * or if orbit cannot be determined
 */
public NumericalPropagator[] estimate() throws OrekitException {
    // set reference date for all parameters that lack one (including the not estimated parameters)
    for (final ParameterDriver driver : getOrbitalParametersDrivers(false).getDrivers()) {
        if (driver.getReferenceDate() == null) {
            driver.setReferenceDate(builders[0].getInitialOrbitDate());
        }
    }
    for (final ParameterDriver driver : getPropagatorParametersDrivers(false).getDrivers()) {
        if (driver.getReferenceDate() == null) {
            driver.setReferenceDate(builders[0].getInitialOrbitDate());
        }
    }
    for (final ParameterDriver driver : getMeasurementsParametersDrivers(false).getDrivers()) {
        if (driver.getReferenceDate() == null) {
            driver.setReferenceDate(builders[0].getInitialOrbitDate());
        }
    }
    // get all estimated parameters
    final ParameterDriversList estimatedOrbitalParameters = getOrbitalParametersDrivers(true);
    final ParameterDriversList estimatedPropagatorParameters = getPropagatorParametersDrivers(true);
    final ParameterDriversList estimatedMeasurementsParameters = getMeasurementsParametersDrivers(true);
    // create start point
    final double[] start = new double[estimatedOrbitalParameters.getNbParams() + estimatedPropagatorParameters.getNbParams() + estimatedMeasurementsParameters.getNbParams()];
    int iStart = 0;
    for (final ParameterDriver driver : estimatedOrbitalParameters.getDrivers()) {
        start[iStart++] = driver.getNormalizedValue();
    }
    for (final ParameterDriver driver : estimatedPropagatorParameters.getDrivers()) {
        start[iStart++] = driver.getNormalizedValue();
    }
    for (final ParameterDriver driver : estimatedMeasurementsParameters.getDrivers()) {
        start[iStart++] = driver.getNormalizedValue();
    }
    lsBuilder.start(start);
    // create target (which is an array set to 0, as we compute weighted residuals ourselves)
    int p = 0;
    for (final ObservedMeasurement<?> measurement : measurements) {
        if (measurement.isEnabled()) {
            p += measurement.getDimension();
        }
    }
    final double[] target = new double[p];
    lsBuilder.target(target);
    // set up the model
    final ModelObserver modelObserver = new ModelObserver() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void modelCalled(final Orbit[] newOrbits, final Map<ObservedMeasurement<?>, EstimatedMeasurement<?>> newEstimations) {
            BatchLSEstimator.this.orbits = newOrbits;
            BatchLSEstimator.this.estimations = newEstimations;
        }
    };
    final Model model = new Model(builders, measurements, estimatedMeasurementsParameters, modelObserver);
    lsBuilder.model(model);
    // add a validator for orbital parameters
    lsBuilder.parameterValidator(new Validator(estimatedOrbitalParameters, estimatedPropagatorParameters, estimatedMeasurementsParameters));
    lsBuilder.checker(new ConvergenceChecker<LeastSquaresProblem.Evaluation>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean converged(final int iteration, final LeastSquaresProblem.Evaluation previous, final LeastSquaresProblem.Evaluation current) {
            final double lInf = current.getPoint().getLInfDistance(previous.getPoint());
            return lInf <= parametersConvergenceThreshold;
        }
    });
    // set up the problem to solve
    final LeastSquaresProblem problem = new TappedLSProblem(lsBuilder.build(), model, estimatedOrbitalParameters, estimatedPropagatorParameters, estimatedMeasurementsParameters);
    try {
        // solve the problem
        optimum = optimizer.optimize(problem);
        // create a new configured propagator with all estimated parameters
        return model.createPropagators(optimum.getPoint());
    } catch (MathRuntimeException mrte) {
        throw new OrekitException(mrte);
    } catch (OrekitExceptionWrapper oew) {
        throw oew.getException();
    }
}
Also used : MathRuntimeException(org.hipparchus.exception.MathRuntimeException) OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) ParameterDriver(org.orekit.utils.ParameterDriver) ParameterDriversList(org.orekit.utils.ParameterDriversList) LeastSquaresProblem(org.hipparchus.optim.nonlinear.vector.leastsquares.LeastSquaresProblem) OrekitException(org.orekit.errors.OrekitException) Map(java.util.Map) ParameterValidator(org.hipparchus.optim.nonlinear.vector.leastsquares.ParameterValidator)

Example 13 with ParameterDriversList

use of org.orekit.utils.ParameterDriversList in project Orekit by CS-SI.

the class FiniteDifferencePropagatorConverterTest method testGetObjectiveFunctionParametersOnlyScaledOnce.

/**
 * Test case for bug #362. Check that scaling is only applied once.
 *
 * @throws OrekitException on error.
 */
@Test
public void testGetObjectiveFunctionParametersOnlyScaledOnce() throws OrekitException {
    // setup
    // create some arbitrary sample data to run with
    Frame eci = FramesFactory.getGCRF();
    double gm = Constants.EIGEN5C_EARTH_MU;
    AbsoluteDate date = AbsoluteDate.J2000_EPOCH;
    Propagator source = new KeplerianPropagator(new KeplerianOrbit(6878137, 0, 0, 0, 0, 0, PositionAngle.TRUE, eci, date, gm));
    // Create a mock builder that allows us to check the values passed to it
    PropagatorBuilder builder = Mockito.mock(PropagatorBuilder.class);
    ParameterDriversList list = new ParameterDriversList();
    list.add(new ParameterDriver("p1", 0, 1e-3, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY));
    Mockito.when(builder.getOrbitalParametersDrivers()).thenReturn(list);
    Mockito.when(builder.getPropagationParametersDrivers()).thenReturn(new ParameterDriversList());
    Mockito.when(builder.getFrame()).thenReturn(eci);
    Mockito.when(builder.getSelectedNormalizedParameters()).thenReturn(new double[1]);
    Mockito.when(builder.buildPropagator(Mockito.any(double[].class))).thenReturn(source);
    // subject under test
    FiniteDifferencePropagatorConverter converter = new FiniteDifferencePropagatorConverter(builder, 1, 100);
    // set some internal variables in FDPC that are not settable using another
    // interface
    converter.convert(source, 1, 2);
    // Forget all the side effect of the call to convert()
    Mockito.clearInvocations(builder);
    // action
    converter.getModel().value(new ArrayRealVector(1));
    // verify
    Mockito.verify(builder).buildPropagator(new double[] { 0 });
    Mockito.verify(builder).buildPropagator(new double[] { 1 });
}
Also used : KeplerianPropagator(org.orekit.propagation.analytical.KeplerianPropagator) Frame(org.orekit.frames.Frame) ParameterDriversList(org.orekit.utils.ParameterDriversList) Propagator(org.orekit.propagation.Propagator) KeplerianPropagator(org.orekit.propagation.analytical.KeplerianPropagator) ArrayRealVector(org.hipparchus.linear.ArrayRealVector) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) ParameterDriver(org.orekit.utils.ParameterDriver) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 14 with ParameterDriversList

use of org.orekit.utils.ParameterDriversList in project Orekit by CS-SI.

the class PartialDerivativesEquations method freezeParametersSelection.

/**
 * Freeze the selected parameters from the force models.
 * @exception OrekitException if an existing driver for a
 * parameter throws one when its value is reset using the value
 * from another driver managing the same parameter
 */
private void freezeParametersSelection() throws OrekitException {
    if (selected == null) {
        // first pass: gather all parameters, binding similar names together
        selected = new ParameterDriversList();
        for (final ForceModel provider : propagator.getAllForceModels()) {
            for (final ParameterDriver driver : provider.getParametersDrivers()) {
                selected.add(driver);
            }
        }
        // second pass: now that shared parameter names are bound together,
        // their selections status have been synchronized, we can filter them
        selected.filter(true);
        // third pass: sort parameters lexicographically
        selected.sort();
        // fourth pass: set up a map between parameters drivers and matrices columns
        map = new IdentityHashMap<ParameterDriver, Integer>();
        int parameterIndex = 0;
        for (final ParameterDriver selectedDriver : selected.getDrivers()) {
            for (final ForceModel provider : propagator.getAllForceModels()) {
                for (final ParameterDriver driver : provider.getParametersDrivers()) {
                    if (driver.getName().equals(selectedDriver.getName())) {
                        map.put(driver, parameterIndex);
                    }
                }
            }
            ++parameterIndex;
        }
    }
}
Also used : ForceModel(org.orekit.forces.ForceModel) ParameterDriversList(org.orekit.utils.ParameterDriversList) ParameterDriver(org.orekit.utils.ParameterDriver)

Example 15 with ParameterDriversList

use of org.orekit.utils.ParameterDriversList in project Orekit by CS-SI.

the class KalmanEstimatorTest method testCartesianRangeRate.

/**
 * Perfect range rate measurements with a perfect start
 * Cartesian formalism
 * @throws OrekitException
 */
@Test
public void testCartesianRangeRate() throws OrekitException {
    // Create context
    Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
    // Create initial orbit and propagator builder
    final OrbitType orbitType = OrbitType.CARTESIAN;
    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 measurements
    final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
    final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new RangeRateMeasurementCreator(context, false), 1.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();
    // Cartesian covariance matrix initialization
    // 100m on position / 1e-2m/s on velocity
    final RealMatrix cartesianP = MatrixUtils.createRealDiagonalMatrix(new double[] { 1e-4, 1e-4, 1e-4, 1e-10, 1e-10, 1e-10 });
    // 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);
    // Initial covariance matrix
    final RealMatrix initialP = Jac.multiply(cartesianP.multiply(Jac.transpose()));
    // Process noise matrix
    final RealMatrix cartesianQ = MatrixUtils.createRealDiagonalMatrix(new double[] { 1.e-6, 1.e-6, 1.e-6, 1.e-12, 1.e-12, 1.e-12 });
    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 = 9.50e-4;
    final double expectedDeltaVel = 0.;
    final double velEps = 3.49e-7;
    final double[] expectedSigmasPos = { 0.324398, 1.347031, 1.743310 };
    final double sigmaPosEps = 1e-6;
    final double[] expectedSigmasVel = { 2.856883e-4, 5.765844e-4, 5.056186e-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) RangeRateMeasurementCreator(org.orekit.estimation.measurements.RangeRateMeasurementCreator) Test(org.junit.Test)

Aggregations

ParameterDriversList (org.orekit.utils.ParameterDriversList)29 ObservedMeasurement (org.orekit.estimation.measurements.ObservedMeasurement)19 Orbit (org.orekit.orbits.Orbit)19 NumericalPropagatorBuilder (org.orekit.propagation.conversion.NumericalPropagatorBuilder)19 Test (org.junit.Test)18 Propagator (org.orekit.propagation.Propagator)17 ParameterDriver (org.orekit.utils.ParameterDriver)17 Context (org.orekit.estimation.Context)16 RealMatrix (org.hipparchus.linear.RealMatrix)13 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)11 OrbitType (org.orekit.orbits.OrbitType)11 NumericalPropagator (org.orekit.propagation.numerical.NumericalPropagator)11 RangeMeasurementCreator (org.orekit.estimation.measurements.RangeMeasurementCreator)10 PositionAngle (org.orekit.orbits.PositionAngle)10 CartesianOrbit (org.orekit.orbits.CartesianOrbit)9 OrekitException (org.orekit.errors.OrekitException)7 EstimationsProvider (org.orekit.estimation.measurements.EstimationsProvider)7 ArrayList (java.util.ArrayList)6 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)6 Map (java.util.Map)5