use of org.orekit.estimation.Context in project Orekit by CS-SI.
the class TurnAroundRangeTest method genericTestParameterDerivatives.
void genericTestParameterDerivatives(final boolean isModifier, final boolean printResults, final double refErrorQMMedian, final double refErrorQMMean, final double refErrorQMMax, final double refErrorQSMedian, final double refErrorQSMean, final double refErrorQSMax) 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 TAR measurements
for (Map.Entry<GroundStation, GroundStation> entry : context.TARstations.entrySet()) {
final GroundStation masterStation = entry.getKey();
final GroundStation slaveStation = entry.getValue();
masterStation.getEastOffsetDriver().setSelected(true);
masterStation.getNorthOffsetDriver().setSelected(true);
masterStation.getZenithOffsetDriver().setSelected(true);
slaveStation.getEastOffsetDriver().setSelected(true);
slaveStation.getNorthOffsetDriver().setSelected(true);
slaveStation.getZenithOffsetDriver().setSelected(true);
}
final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new TurnAroundRangeMeasurementCreator(context), 1.0, 3.0, 300.0);
propagator.setSlaveMode();
// Print results on console ? Header
if (printResults) {
System.out.format(Locale.US, "%-15s %-15s %-23s %-23s " + "%10s %10s %10s " + "%10s %10s %10s " + "%10s %10s %10s " + "%10s %10s %10s%n", "Master Station", "Slave Station", "Measurement Date", "State Date", "ΔdQMx", "rel ΔdQMx", "ΔdQMy", "rel ΔdQMy", "ΔdQMz", "rel ΔdQMz", "ΔdQSx", "rel ΔdQSx", "ΔdQSy", "rel ΔdQSy", "ΔdQSz", "rel ΔdQSz");
}
// List to store the results for master and slave station
final List<Double> relErrorQMList = new ArrayList<Double>();
final List<Double> relErrorQSList = new ArrayList<Double>();
// Loop on the measurements
for (final ObservedMeasurement<?> measurement : measurements) {
// Add modifiers if test implies it
final TurnAroundRangeTroposphericDelayModifier modifier = new TurnAroundRangeTroposphericDelayModifier(SaastamoinenModel.getStandardModel());
if (isModifier) {
((TurnAroundRange) measurement).addModifier(modifier);
}
// parameter corresponding to station position offset
final GroundStation masterStationParameter = ((TurnAroundRange) measurement).getMasterStation();
final GroundStation slaveStationParameter = ((TurnAroundRange) measurement).getSlaveStation();
// 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 = propagator.propagate(date);
final ParameterDriver[] drivers = new ParameterDriver[] { masterStationParameter.getEastOffsetDriver(), masterStationParameter.getNorthOffsetDriver(), masterStationParameter.getZenithOffsetDriver(), slaveStationParameter.getEastOffsetDriver(), slaveStationParameter.getNorthOffsetDriver(), slaveStationParameter.getZenithOffsetDriver() };
// Print results on console ? Stations' names
if (printResults) {
String masterStationName = masterStationParameter.getBaseFrame().getName();
String slaveStationName = slaveStationParameter.getBaseFrame().getName();
System.out.format(Locale.US, "%-15s %-15s %-23s %-23s ", masterStationName, slaveStationName, measurement.getDate(), date);
}
// Loop on the parameters
for (int i = 0; i < 6; ++i) {
final double[] gradient = measurement.estimate(0, 0, new SpacecraftState[] { state }).getParameterDerivatives(drivers[i]);
Assert.assertEquals(1, measurement.getDimension());
Assert.assertEquals(1, gradient.length);
// Compute a reference value using finite differences
final ParameterFunction dMkdP = Differentiation.differentiate(new ParameterFunction() {
/**
* {@inheritDoc}
*/
@Override
public double value(final ParameterDriver parameterDriver) throws OrekitException {
return measurement.estimate(0, 0, new SpacecraftState[] { state }).getEstimatedValue()[0];
}
}, drivers[i], 3, 20.0);
final double ref = dMkdP.value(drivers[i]);
// Deltas
double dGradient = gradient[0] - ref;
double dGradientRelative = FastMath.abs(dGradient / ref);
// Print results on console ? Gradient difference
if (printResults) {
System.out.format(Locale.US, "%10.3e %10.3e ", dGradient, dGradientRelative);
}
// Add relative error to the list
if (i < 3) {
relErrorQMList.add(dGradientRelative);
} else {
relErrorQSList.add(dGradientRelative);
}
}
// End for loop on the parameters
if (printResults) {
System.out.format(Locale.US, "%n");
}
}
// End for loop on the measurements
// Convert error list to double[]
final double[] relErrorQM = relErrorQMList.stream().mapToDouble(Double::doubleValue).toArray();
final double[] relErrorQS = relErrorQSList.stream().mapToDouble(Double::doubleValue).toArray();
// Compute statistics
final double relErrorsQMMedian = new Median().evaluate(relErrorQM);
final double relErrorsQMMean = new Mean().evaluate(relErrorQM);
final double relErrorsQMMax = new Max().evaluate(relErrorQM);
final double relErrorsQSMedian = new Median().evaluate(relErrorQS);
final double relErrorsQSMean = new Mean().evaluate(relErrorQS);
final double relErrorsQSMax = new Max().evaluate(relErrorQS);
// Print the results on console ?
if (printResults) {
System.out.println();
System.out.format(Locale.US, "Relative errors dR/dQ master station -> Median: %6.3e / Mean: %6.3e / Max: %6.3e%n", relErrorsQMMedian, relErrorsQMMean, relErrorsQMMax);
System.out.format(Locale.US, "Relative errors dR/dQ slave station -> Median: %6.3e / Mean: %6.3e / Max: %6.3e%n", relErrorsQSMedian, relErrorsQSMean, relErrorsQSMax);
}
// Check values
Assert.assertEquals(0.0, relErrorsQMMedian, refErrorQMMedian);
Assert.assertEquals(0.0, relErrorsQMMean, refErrorQMMean);
Assert.assertEquals(0.0, relErrorsQMMax, refErrorQMMax);
Assert.assertEquals(0.0, relErrorsQSMedian, refErrorQSMedian);
Assert.assertEquals(0.0, relErrorsQSMean, refErrorQSMean);
Assert.assertEquals(0.0, relErrorsQSMax, refErrorQSMax);
}
use of org.orekit.estimation.Context in project Orekit by CS-SI.
the class BiasTest method testEstimateBias.
@SuppressWarnings("unchecked")
@Test
public void testEstimateBias() 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);
// create range biases: one bias for each station
final RandomGenerator random = new Well19937a(0x0c4b69da5d64b35al);
final Bias<?>[] stationsRangeBiases = new Bias<?>[context.stations.size()];
final double[] realStationsBiases = new double[context.stations.size()];
for (int i = 0; i < context.stations.size(); ++i) {
final TopocentricFrame base = context.stations.get(i).getBaseFrame();
stationsRangeBiases[i] = new Bias<Range>(new String[] { base.getName() + " range bias" }, new double[] { 0.0 }, new double[] { 1.0 }, new double[] { Double.NEGATIVE_INFINITY }, new double[] { Double.POSITIVE_INFINITY });
realStationsBiases[i] = 2 * random.nextDouble() - 1;
}
// create orbit estimator
final BatchLSEstimator estimator = new BatchLSEstimator(new LevenbergMarquardtOptimizer(), propagatorBuilder);
// add the measurements, with both spacecraft and stations biases
for (final ObservedMeasurement<?> measurement : measurements) {
final Range range = (Range) measurement;
for (int i = 0; i < context.stations.size(); ++i) {
if (range.getStation() == context.stations.get(i)) {
double biasedRange = range.getObservedValue()[0] + realStationsBiases[i];
final Range m = new Range(range.getStation(), range.getDate(), biasedRange, range.getTheoreticalStandardDeviation()[0], range.getBaseWeight()[0]);
m.addModifier((Bias<Range>) stationsRangeBiases[i]);
estimator.addMeasurement(m);
}
}
}
estimator.setParametersConvergenceThreshold(1.0e-3);
estimator.setMaxIterations(10);
estimator.setMaxEvaluations(20);
// we want to estimate the biases
for (Bias<?> bias : stationsRangeBiases) {
for (final ParameterDriver driver : bias.getParametersDrivers()) {
driver.setSelected(true);
}
}
EstimationTestUtils.checkFit(context, estimator, 2, 3, 0.0, 7.2e-7, 0.0, 2.1e-6, 0.0, 3.7e-7, 0.0, 1.7e-10);
for (int i = 0; i < stationsRangeBiases.length; ++i) {
Assert.assertEquals(realStationsBiases[i], stationsRangeBiases[i].getParametersDrivers().get(0).getValue(), 3.3e-6);
}
}
use of org.orekit.estimation.Context in project Orekit by CS-SI.
the class IonoModifierTest method testRangeIonoModifier.
@Test
public void testRangeIonoModifier() 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
for (final GroundStation station : context.stations) {
station.getEastOffsetDriver().setSelected(true);
station.getNorthOffsetDriver().setSelected(true);
station.getZenithOffsetDriver().setSelected(true);
}
final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new RangeMeasurementCreator(context), 1.0, 3.0, 300.0);
propagator.setSlaveMode();
final RangeIonosphericDelayModifier modifier = new RangeIonosphericDelayModifier(model);
for (final ObservedMeasurement<?> measurement : measurements) {
final AbsoluteDate date = measurement.getDate();
final SpacecraftState refstate = propagator.propagate(date);
Range range = (Range) measurement;
EstimatedMeasurement<Range> evalNoMod = range.estimate(12, 17, new SpacecraftState[] { refstate });
Assert.assertEquals(12, evalNoMod.getIteration());
Assert.assertEquals(17, evalNoMod.getCount());
// add modifier
range.addModifier(modifier);
boolean found = false;
for (final EstimationModifier<Range> existing : range.getModifiers()) {
found = found || existing == modifier;
}
Assert.assertTrue(found);
//
EstimatedMeasurement<Range> eval = range.estimate(0, 0, new SpacecraftState[] { refstate });
Assert.assertEquals(evalNoMod.getStatus(), eval.getStatus());
eval.setStatus(EstimatedMeasurement.Status.REJECTED);
Assert.assertEquals(EstimatedMeasurement.Status.REJECTED, eval.getStatus());
eval.setStatus(evalNoMod.getStatus());
try {
eval.getParameterDerivatives(new ParameterDriver("extra", 0, 1, -1, +1));
Assert.fail("an exception should have been thrown");
} catch (OrekitIllegalArgumentException oiae) {
Assert.assertEquals(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, oiae.getSpecifier());
}
final double diffMeters = eval.getEstimatedValue()[0] - evalNoMod.getEstimatedValue()[0];
// TODO: check threshold
Assert.assertEquals(0.0, diffMeters, 30.0);
}
}
use of org.orekit.estimation.Context in project Orekit by CS-SI.
the class IonoModifierTest method testKlobucharIonoModel.
@Test
public void testKlobucharIonoModel() 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
for (final GroundStation station : context.stations) {
station.getEastOffsetDriver().setSelected(true);
station.getNorthOffsetDriver().setSelected(true);
station.getZenithOffsetDriver().setSelected(true);
}
final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new RangeMeasurementCreator(context), 1.0, 3.0, 300.0);
propagator.setSlaveMode();
for (final ObservedMeasurement<?> measurement : measurements) {
// parameter corresponding to station position offset
final GroundStation station = ((Range) measurement).getStation();
final AbsoluteDate date = ((Range) measurement).getDate();
final SpacecraftState state = propagator.propagate(date);
final Vector3D position = state.getPVCoordinates().getPosition();
//
final GeodeticPoint geo = station.getBaseFrame().getPoint();
// elevation
final double elevation = station.getBaseFrame().getElevation(position, state.getFrame(), state.getDate());
// elevation
final double azimuth = station.getBaseFrame().getAzimuth(position, state.getFrame(), state.getDate());
double delayMeters = model.pathDelay(date, geo, elevation, azimuth);
final double epsilon = 1e-6;
Assert.assertTrue(Precision.compareTo(delayMeters, 15., epsilon) < 0);
Assert.assertTrue(Precision.compareTo(delayMeters, 0., epsilon) > 0);
}
}
use of org.orekit.estimation.Context in project Orekit by CS-SI.
the class OnBoardAntennaInterSatellitesRangeModifierTest method testEffect.
@Test
public void testEffect() 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);
propagatorBuilder.setAttitudeProvider(new LofOffset(propagatorBuilder.getFrame(), LOFType.LVLH));
// create perfect inter-satellites range measurements without antenna offset
final TimeStampedPVCoordinates original = context.initialOrbit.getPVCoordinates();
final Orbit closeOrbit = new CartesianOrbit(new TimeStampedPVCoordinates(context.initialOrbit.getDate(), original.getPosition().add(new Vector3D(1000, 2000, 3000)), original.getVelocity().add(new Vector3D(-0.03, 0.01, 0.02))), context.initialOrbit.getFrame(), context.initialOrbit.getMu());
final Propagator closePropagator = EstimationTestUtils.createPropagator(closeOrbit, propagatorBuilder);
closePropagator.setEphemerisMode();
closePropagator.propagate(context.initialOrbit.getDate().shiftedBy(3.5 * closeOrbit.getKeplerianPeriod()));
final BoundedPropagator ephemeris = closePropagator.getGeneratedEphemeris();
final Propagator p1 = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
final List<ObservedMeasurement<?>> spacecraftCenteredMeasurements = EstimationTestUtils.createMeasurements(p1, new InterSatellitesRangeMeasurementCreator(ephemeris, Vector3D.ZERO, Vector3D.ZERO), 1.0, 3.0, 300.0);
// create perfect inter-satellites range measurements with antenna offset
final Vector3D apc1 = new Vector3D(-2.5, 0.0, 0);
final Vector3D apc2 = new Vector3D(0.0, 0.8, 0);
final Propagator p2 = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
final List<ObservedMeasurement<?>> antennaCenteredMeasurements = EstimationTestUtils.createMeasurements(p2, new InterSatellitesRangeMeasurementCreator(ephemeris, apc1, apc2), 1.0, 3.0, 300.0);
final Propagator p3 = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
OnBoardAntennaInterSatellitesRangeModifier modifier = new OnBoardAntennaInterSatellitesRangeModifier(apc1, apc2);
for (int i = 0; i < spacecraftCenteredMeasurements.size(); ++i) {
InterSatellitesRange sr = (InterSatellitesRange) spacecraftCenteredMeasurements.get(i);
sr.addModifier(modifier);
EstimatedMeasurement<InterSatellitesRange> estimated = sr.estimate(0, 0, new SpacecraftState[] { p3.propagate(sr.getDate()), ephemeris.propagate(sr.getDate()) });
InterSatellitesRange ar = (InterSatellitesRange) antennaCenteredMeasurements.get(i);
Assert.assertEquals(0.0, sr.getDate().durationFrom(ar.getDate()), 2.0e-8);
Assert.assertEquals(ar.getObservedValue()[0], estimated.getEstimatedValue()[0], 2.0e-5);
}
}
Aggregations