use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class RangeRateTest method testParameterDerivativesOneWay.
@Test
public void testParameterDerivativesOneWay() 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 rate 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 RangeRateMeasurementCreator(context, false), 1.0, 3.0, 300.0);
propagator.setSlaveMode();
double maxRelativeError = 0;
for (final ObservedMeasurement<?> measurement : measurements) {
// parameter corresponding to station position offset
final GroundStation stationParameter = ((RangeRate) measurement).getStation();
// 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[] { stationParameter.getEastOffsetDriver(), stationParameter.getNorthOffsetDriver(), stationParameter.getZenithOffsetDriver() };
for (int i = 0; i < 3; ++i) {
final double[] gradient = measurement.estimate(0, 0, new SpacecraftState[] { state }).getParameterDerivatives(drivers[i]);
Assert.assertEquals(1, measurement.getDimension());
Assert.assertEquals(1, gradient.length);
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]);
maxRelativeError = FastMath.max(maxRelativeError, FastMath.abs((ref - gradient[0]) / ref));
}
}
Assert.assertEquals(0, maxRelativeError, 1.2e-6);
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class RangeRateTest method testParameterDerivativesTwoWays.
@Test
public void testParameterDerivativesTwoWays() 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 rate 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 RangeRateMeasurementCreator(context, true), 1.0, 3.0, 300.0);
propagator.setSlaveMode();
double maxRelativeError = 0;
for (final ObservedMeasurement<?> measurement : measurements) {
// parameter corresponding to station position offset
final GroundStation stationParameter = ((RangeRate) measurement).getStation();
// 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[] { stationParameter.getEastOffsetDriver(), stationParameter.getNorthOffsetDriver(), stationParameter.getZenithOffsetDriver() };
for (int i = 0; i < 3; ++i) {
final double[] gradient = measurement.estimate(0, 0, new SpacecraftState[] { state }).getParameterDerivatives(drivers[i]);
Assert.assertEquals(1, measurement.getDimension());
Assert.assertEquals(1, gradient.length);
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]);
maxRelativeError = FastMath.max(maxRelativeError, FastMath.abs((ref - gradient[0]) / ref));
}
}
Assert.assertEquals(0, maxRelativeError, 5.2e-5);
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class RangeTest method genericTestParameterDerivatives.
void genericTestParameterDerivatives(final boolean isModifier, final boolean printResults, final double refErrorsMedian, final double refErrorsMean, final double refErrorsMax) 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);
// List to store the results
final List<Double> relErrorList = 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);
}
// Parameter corresponding to station position offset
final GroundStation stationParameter = ((Range) measurement).getStation();
// 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 ParameterDriver[] drivers = new ParameterDriver[] { stationParameter.getEastOffsetDriver(), stationParameter.getNorthOffsetDriver(), stationParameter.getZenithOffsetDriver() };
if (printResults) {
String stationName = ((Range) measurement).getStation().getBaseFrame().getName();
System.out.format(Locale.US, "%-15s %-23s %-23s ", stationName, measurement.getDate(), date);
}
for (int i = 0; i < 3; ++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]);
if (printResults) {
System.out.format(Locale.US, "%10.3e %10.3e ", gradient[0] - ref, FastMath.abs((gradient[0] - ref) / ref));
}
final double relError = FastMath.abs((ref - gradient[0]) / ref);
relErrorList.add(relError);
// Assert.assertEquals(ref, gradient[0], 6.1e-5 * FastMath.abs(ref));
}
if (printResults) {
System.out.format(Locale.US, "%n");
}
}
// End if measurement date between previous and current interpolator step
}
// End for loop on the measurements
});
// Rewind the propagator to initial date
propagator.propagate(context.initialOrbit.getDate());
// Sort measurements chronologically
measurements.sort(new ChronologicalComparator());
// Print results ? Header
if (printResults) {
System.out.format(Locale.US, "%-15s %-23s %-23s " + "%10s %10s %10s " + "%10s %10s %10s%n", "Station", "Measurement Date", "State Date", "ΔdQx", "rel ΔdQx", "ΔdQy", "rel ΔdQy", "ΔdQz", "rel ΔdQz");
}
// Propagate to final measurement's date
propagator.propagate(measurements.get(measurements.size() - 1).getDate());
// Convert error list to double[]
final double[] relErrors = relErrorList.stream().mapToDouble(Double::doubleValue).toArray();
// Compute statistics
final double relErrorsMedian = new Median().evaluate(relErrors);
final double relErrorsMean = new Mean().evaluate(relErrors);
final double relErrorsMax = new Max().evaluate(relErrors);
// Print the results on console ?
if (printResults) {
System.out.println();
System.out.format(Locale.US, "Relative errors dR/dQ -> Median: %6.3e / Mean: %6.3e / Max: %6.3e%n", relErrorsMedian, relErrorsMean, relErrorsMax);
}
Assert.assertEquals(0.0, relErrorsMedian, refErrorsMedian);
Assert.assertEquals(0.0, relErrorsMean, refErrorsMean);
Assert.assertEquals(0.0, relErrorsMax, refErrorsMax);
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class PoissonSeriesParserTest method testMissingTerms.
@Test
public void testMissingTerms() throws OrekitException {
try {
String data = " 0.0 + 0.0 x - 0.0 x^2 - 0.0 x^3 - 0.0 x^4 + 0.0 x^5\n" + "j = 0 Nb of terms = 1\n" + "1 1.0 0.0 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n" + "j = 1 Nb of terms = 3\n" + "2 1.0 0.0 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n" + "3 1.0 0.0 0 0 0 0 0 2 0 0 0 0 0 0 0 0\n" + "j = 2 Nb of terms = 1\n" + "4 1.0 0.0 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n";
new PoissonSeriesParser(17).withPolynomialPart('x', PolynomialParser.Unit.NO_UNITS).withFirstDelaunay(4).withFirstPlanetary(9).withSinCos(0, 2, 1.0, 3, 1.0).parse(new ByteArrayInputStream(data.getBytes()), "");
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.NOT_A_SUPPORTED_IERS_DATA_FILE, oe.getSpecifier());
}
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class PoissonSeriesParserTest method testWrongIndex.
@Test
public void testWrongIndex() throws OrekitException {
String data = "Expression for the X coordinate of the CIP in the GCRS based on the IAU2000A\n" + "precession-nutation model\n" + "\n" + "\n" + "----------------------------------------------------------------------\n" + "\n" + "X = polynomial part + non-polynomial part\n" + "\n" + "----------------------------------------------------------------------\n" + "\n" + "Polynomial part (unit microarcsecond)\n" + "\n" + " -16616.99 + 2004191742.88 t - 427219.05 t^2 - 198620.54 t^3 - 46.05 t^4 + 5.98 t^5\n" + "\n" + "----------------------------------------------------------------------\n" + "\n" + "Non-polynomial part (unit microarcsecond)\n" + "(ARG being for various combination of the fundamental arguments of the nutation theory)\n" + "\n" + " Sum_i[a_{s,0})_i * sin(ARG) + a_{c,0})_i * cos(ARG)] \n" + "\n" + "+ Sum_i)j=1,4 [a_{s,j})_i * t^j * sin(ARG) + a_{c,j})_i * cos(ARG)] * t^j]\n" + "\n" + "The Table below provides the values for a_{s,j})_i and a_{c,j})_i\n" + "\n" + "The expressions for the fundamental arguments appearing in columns 4 to 8 (luni-solar part) \n" + "and in columns 6 to 17 (planetary part) are those of the IERS Conventions 2000\n" + "\n" + "----------------------------------------------------------------------\n" + "\n" + " i a_{s,j})_i a_{c,j})_i l l' F D Om L_Me L_Ve L_E L_Ma L_J L_Sa L_U L_Ne p_A\n" + "\n" + "----------------------------------------------------------------------\n" + "-16616.99 + 2004191742.88 t - 427219.05 t^2 - 198620.54 t^3 - 46.05 t^4 + 5.98 t^5\n" + "j = 0 Nb of terms = 2\n" + "\n" + " 1 -6844318.44 1328.67 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n" + " 2 0.11 0.00 0 0 4 -4 4 0 0 0 0 0 0 0 0 0\n" + "\n" + "j = 1 Nb of terms = 2\n" + "\n" + " 3 -3328.48 205833.15 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n" + " 4 0.00 -0.10 1 -1 -2 -2 -1 0 0 0 0 0 0 0 0 0\n" + "\n" + " j = 2 Nb of terms = 2\n" + "\n" + " 5 2038.00 82.26 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n" + " 6 -0.12 0.00 1 0 -2 -2 -1 0 0 0 0 0 0 0 0 0\n" + " \n" + " j = 3 Nb of terms = 2\n" + "\n" + " 7 1.76 -20.39 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n" + " 999 0.00 0.20 0 0 0 0 2 0 0 0 0 0 0 0 0 0\n" + "\n" + " j = 4 Nb of terms = 1\n" + " \n" + " 9 -0.10 -0.02 0 0 0 0 1 0 0 0 0 0 0 0 0 0\n";
try {
new PoissonSeriesParser(17).withPolynomialPart('t', PolynomialParser.Unit.NO_UNITS).withFirstDelaunay(4).withFirstPlanetary(9).withSinCos(0, 2, 1.0, 3, 1.0).parse(new ByteArrayInputStream(data.getBytes()), "dummy");
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, oe.getSpecifier());
Assert.assertEquals(53, oe.getParts()[0]);
Assert.assertTrue(((String) oe.getParts()[2]).startsWith(" 999 0.00"));
}
}
Aggregations