use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class BoxAndSolarArraySpacecraftTest method setUp.
@Before
public void setUp() {
try {
Utils.setDataRoot("regular-data");
mu = 3.9860047e14;
double ae = 6.378137e6;
double c20 = -1.08263e-3;
double c30 = 2.54e-6;
double c40 = 1.62e-6;
double c50 = 2.3e-7;
double c60 = -5.5e-7;
AbsoluteDate date = new AbsoluteDate(new DateComponents(1970, 7, 1), new TimeComponents(13, 59, 27.816), TimeScalesFactory.getUTC());
// Satellite position as circular parameters, raan chosen to have sun elevation with
// respect to orbit plane roughly evolving roughly from 15 to 15.2 degrees in the test range
Orbit circ = new CircularOrbit(7178000.0, 0.5e-4, -0.5e-4, FastMath.toRadians(50.), FastMath.toRadians(280), FastMath.toRadians(10.0), PositionAngle.MEAN, FramesFactory.getEME2000(), date, mu);
propagator = new EcksteinHechlerPropagator(circ, new LofOffset(circ.getFrame(), LOFType.VVLH), ae, mu, c20, c30, c40, c50, c60);
} catch (OrekitException oe) {
Assert.fail(oe.getLocalizedMessage());
}
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class BoxAndSolarArraySpacecraftTest method testWrongParameterLift.
@Test
public void testWrongParameterLift() throws OrekitException {
SpacecraftState state = propagator.getInitialState();
CelestialBody sun = CelestialBodyFactory.getSun();
BoxAndSolarArraySpacecraft s = new BoxAndSolarArraySpacecraft(0, 0, 0, sun, 20.0, Vector3D.PLUS_J, 2.0, 0.4, 1.0, 0.0);
try {
s.dragAcceleration(state.getDate(), state.getFrame(), state.getPVCoordinates().getPosition(), state.getAttitude().getRotation(), state.getMass(), 1.0e-6, Vector3D.PLUS_I, getDragParameters(s), "wrong");
Assert.fail("an exception should have been thrown");
} catch (OrekitException oe) {
Assert.assertEquals(OrekitMessages.UNSUPPORTED_PARAMETER_NAME, oe.getSpecifier());
Assert.assertEquals(3, oe.getParts().length);
Assert.assertEquals("wrong", (String) oe.getParts()[0]);
Assert.assertEquals(DragSensitive.DRAG_COEFFICIENT, (String) oe.getParts()[1]);
Assert.assertEquals(DragSensitive.LIFT_RATIO, (String) oe.getParts()[2]);
}
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class BatchLSEstimatorTest method testMultiSatWithParameters.
/**
* A modified version of the previous test with a selection of propagation drivers to estimate
* One common (µ)
* Some specifics for each satellite (Cr and Ca)
*
* @throws OrekitException
*/
@Test
public void testMultiSatWithParameters() throws OrekitException {
// Test: Set the propagator drivers to estimate for each satellite
final boolean muEstimated = true;
final boolean crEstimated1 = true;
final boolean caEstimated1 = true;
final boolean crEstimated2 = true;
final boolean caEstimated2 = false;
// Builder sat 1
final Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
final NumericalPropagatorBuilder propagatorBuilder1 = context.createBuilder(OrbitType.KEPLERIAN, PositionAngle.TRUE, true, 1.0e-6, 60.0, 1.0, Force.POTENTIAL, Force.SOLAR_RADIATION_PRESSURE);
// Adding selection of parameters
String satName = "sat 1";
for (DelegatingDriver driver : propagatorBuilder1.getPropagationParametersDrivers().getDrivers()) {
if (driver.getName().equals("central attraction coefficient")) {
driver.setSelected(muEstimated);
}
if (driver.getName().equals(RadiationSensitive.REFLECTION_COEFFICIENT)) {
driver.setName(driver.getName() + " " + satName);
driver.setSelected(crEstimated1);
}
if (driver.getName().equals(RadiationSensitive.ABSORPTION_COEFFICIENT)) {
driver.setName(driver.getName() + " " + satName);
driver.setSelected(caEstimated1);
}
}
// Builder for sat 2
final Context context2 = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
final NumericalPropagatorBuilder propagatorBuilder2 = context2.createBuilder(OrbitType.KEPLERIAN, PositionAngle.TRUE, true, 1.0e-6, 60.0, 1.0, Force.POTENTIAL, Force.SOLAR_RADIATION_PRESSURE);
// Adding selection of parameters
satName = "sat 2";
for (ParameterDriver driver : propagatorBuilder2.getPropagationParametersDrivers().getDrivers()) {
if (driver.getName().equals("central attraction coefficient")) {
driver.setSelected(muEstimated);
}
if (driver.getName().equals(RadiationSensitive.REFLECTION_COEFFICIENT)) {
driver.setName(driver.getName() + " " + satName);
driver.setSelected(crEstimated2);
}
if (driver.getName().equals(RadiationSensitive.ABSORPTION_COEFFICIENT)) {
driver.setName(driver.getName() + " " + satName);
driver.setSelected(caEstimated2);
}
}
// Create perfect inter-satellites range measurements
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, propagatorBuilder2);
closePropagator.setEphemerisMode();
closePropagator.propagate(context.initialOrbit.getDate().shiftedBy(3.5 * closeOrbit.getKeplerianPeriod()));
final BoundedPropagator ephemeris = closePropagator.getGeneratedEphemeris();
Propagator propagator1 = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder1);
final List<ObservedMeasurement<?>> r12 = EstimationTestUtils.createMeasurements(propagator1, new InterSatellitesRangeMeasurementCreator(ephemeris), 1.0, 3.0, 300.0);
// create perfect range measurements for first satellite
propagator1 = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder1);
final List<ObservedMeasurement<?>> r1 = EstimationTestUtils.createMeasurements(propagator1, new RangeMeasurementCreator(context), 1.0, 3.0, 300.0);
// create orbit estimator
final BatchLSEstimator estimator = new BatchLSEstimator(new LevenbergMarquardtOptimizer(), propagatorBuilder1, propagatorBuilder2);
for (final ObservedMeasurement<?> interSat : r12) {
estimator.addMeasurement(interSat);
}
for (final ObservedMeasurement<?> range : r1) {
estimator.addMeasurement(range);
}
estimator.setParametersConvergenceThreshold(1.0e-2);
estimator.setMaxIterations(10);
estimator.setMaxEvaluations(20);
estimator.setObserver(new BatchLSObserver() {
int lastIter = 0;
int lastEval = 0;
/**
* {@inheritDoc}
*/
@Override
public void evaluationPerformed(int iterationsCount, int evaluationscount, Orbit[] orbits, ParameterDriversList estimatedOrbitalParameters, ParameterDriversList estimatedPropagatorParameters, ParameterDriversList estimatedMeasurementsParameters, EstimationsProvider evaluationsProvider, Evaluation lspEvaluation) throws OrekitException {
if (iterationsCount == lastIter) {
Assert.assertEquals(lastEval + 1, evaluationscount);
} else {
Assert.assertEquals(lastIter + 1, iterationsCount);
}
lastIter = iterationsCount;
lastEval = evaluationscount;
AbsoluteDate previous = AbsoluteDate.PAST_INFINITY;
for (int i = 0; i < evaluationsProvider.getNumber(); ++i) {
AbsoluteDate current = evaluationsProvider.getEstimatedMeasurement(i).getDate();
Assert.assertTrue(current.compareTo(previous) >= 0);
previous = current;
}
}
});
List<DelegatingDriver> parameters = estimator.getOrbitalParametersDrivers(true).getDrivers();
ParameterDriver a0Driver = parameters.get(0);
Assert.assertEquals("a[0]", a0Driver.getName());
a0Driver.setValue(a0Driver.getValue() + 1.2);
a0Driver.setReferenceDate(AbsoluteDate.GALILEO_EPOCH);
ParameterDriver a1Driver = parameters.get(6);
Assert.assertEquals("a[1]", a1Driver.getName());
a1Driver.setValue(a1Driver.getValue() - 5.4);
a1Driver.setReferenceDate(AbsoluteDate.GALILEO_EPOCH);
final Orbit before = new KeplerianOrbit(parameters.get(6).getValue(), parameters.get(7).getValue(), parameters.get(8).getValue(), parameters.get(9).getValue(), parameters.get(10).getValue(), parameters.get(11).getValue(), PositionAngle.TRUE, closeOrbit.getFrame(), closeOrbit.getDate(), closeOrbit.getMu());
Assert.assertEquals(4.7246, Vector3D.distance(closeOrbit.getPVCoordinates().getPosition(), before.getPVCoordinates().getPosition()), 1.0e-3);
Assert.assertEquals(0.0010514, Vector3D.distance(closeOrbit.getPVCoordinates().getVelocity(), before.getPVCoordinates().getVelocity()), 1.0e-6);
EstimationTestUtils.checkFit(context, estimator, 4, 5, 0.0, 6.0e-06, 0.0, 1.7e-05, 0.0, 4.4e-07, 0.0, 1.7e-10);
final Orbit determined = new KeplerianOrbit(parameters.get(6).getValue(), parameters.get(7).getValue(), parameters.get(8).getValue(), parameters.get(9).getValue(), parameters.get(10).getValue(), parameters.get(11).getValue(), PositionAngle.TRUE, closeOrbit.getFrame(), closeOrbit.getDate(), closeOrbit.getMu());
Assert.assertEquals(0.0, Vector3D.distance(closeOrbit.getPVCoordinates().getPosition(), determined.getPVCoordinates().getPosition()), 5.8e-6);
Assert.assertEquals(0.0, Vector3D.distance(closeOrbit.getPVCoordinates().getVelocity(), determined.getPVCoordinates().getVelocity()), 3.5e-9);
// got a default one
for (final ParameterDriver driver : estimator.getOrbitalParametersDrivers(true).getDrivers()) {
if (driver.getName().startsWith("a[")) {
// user-specified reference date
Assert.assertEquals(0, driver.getReferenceDate().durationFrom(AbsoluteDate.GALILEO_EPOCH), 1.0e-15);
} else {
// default reference date
Assert.assertEquals(0, driver.getReferenceDate().durationFrom(propagatorBuilder1.getInitialOrbitDate()), 1.0e-15);
}
}
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class PVTest method testExceptions.
/**
* Test exceptions raised if the covariance matrix does not have the proper size.
*/
@Test
public void testExceptions() throws OrekitException {
// Context
Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
// Dummy P, V, T
final Vector3D position = context.initialOrbit.getPVCoordinates().getPosition();
final Vector3D velocity = context.initialOrbit.getPVCoordinates().getVelocity();
final AbsoluteDate date = context.initialOrbit.getDate();
final double weight = 1.;
// Build with two 3-sized vectors
try {
new PV(date, position, velocity, new double[] { 0., 0., 0. }, new double[] { 1. }, weight);
Assert.fail("An OrekitException should have been thrown");
} catch (OrekitException e) {
// An exception should indeed be raised here
}
// Build with one 6-sized vector
try {
new PV(date, position, velocity, new double[] { 0., 0., 0. }, weight);
Assert.fail("An OrekitException should have been thrown");
} catch (OrekitException e) {
// An exception should indeed be raised here
}
// Build with two 3x3 matrices
try {
new PV(date, position, velocity, new double[][] { { 0., 0. }, { 0., 0. } }, new double[][] { { 0., 0. }, { 0., 0. } }, weight);
Assert.fail("An OrekitException should have been thrown");
} catch (OrekitException e) {
// An exception should indeed be raised here
}
// Build with one 6x6 matrix
try {
new PV(date, position, velocity, new double[][] { { 0., 0. }, { 0., 0. } }, weight);
Assert.fail("An OrekitException should have been thrown");
} catch (OrekitException e) {
// An exception should indeed be raised here
}
}
use of org.orekit.errors.OrekitException in project Orekit by CS-SI.
the class RangeAnalyticTest method genericTestStateDerivatives.
/**
* Generic test function for derivatives with respect to state
* @param isModifier Use of atmospheric modifiers
* @param isFiniteDifferences Finite differences reference calculation if true, Range class otherwise
* @param printResults Print the results ?
* @throws OrekitException
*/
void genericTestStateDerivatives(final boolean isModifier, final boolean isFiniteDifferences, 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 EstimatedMeasurement<Range> range = new RangeAnalytic((Range) measurement).theoreticalEvaluationAnalytic(0, 0, state);
if (isModifier) {
modifier.modify(range);
}
final double[][] jacobian = range.getStateDerivatives(0);
// Jacobian reference value
final double[][] jacobianRef;
if (isFiniteDifferences) {
// 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);
} else {
// Compute a reference value using Range class function
jacobianRef = ((Range) measurement).theoreticalEvaluation(0, 0, new SpacecraftState[] { state }).getStateDerivatives(0);
}
// //Test: Test point by point with the debugger
// if (!isFiniteDifferences && !isModifier) {
// final EstimatedMeasurement<Range> test =
// new RangeAnalytic((Range)measurement).theoreticalEvaluationValidation(0, 0, state);
// }
// //Test
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);
}
// Reference comparison with Range class
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);
}
Aggregations