use of org.orekit.utils.ParameterFunction in project Orekit by CS-SI.
the class RangeIonosphericDelayModifier method rangeErrorParameterDerivative.
/**
* Compute the derivative of the delay term wrt parameters.
*
* @param station ground station
* @param driver driver for the station offset parameter
* @param state spacecraft state
* @param delay current ionospheric delay
* @return derivative of the delay wrt station offset parameter
* @throws OrekitException if frames transformations cannot be computed
*/
private double rangeErrorParameterDerivative(final GroundStation station, final ParameterDriver driver, final SpacecraftState state, final double delay) throws OrekitException {
final ParameterFunction rangeError = new ParameterFunction() {
/**
* {@inheritDoc}
*/
@Override
public double value(final ParameterDriver parameterDriver) throws OrekitException {
return rangeErrorIonosphericModel(station, state);
}
};
final ParameterFunction rangeErrorDerivative = Differentiation.differentiate(rangeError, driver, 3, 10.0);
return rangeErrorDerivative.value(driver);
}
use of org.orekit.utils.ParameterFunction in project Orekit by CS-SI.
the class RangeRateTroposphericDelayModifier method rangeRateErrorParameterDerivative.
/**
* Compute the derivative of the delay term wrt parameters.
*
* @param station ground station
* @param driver driver for the station offset parameter
* @param state spacecraft state
* @param delay current ionospheric delay
* @return derivative of the delay wrt station offset parameter
* @throws OrekitException if frames transformations cannot be computed
*/
private double rangeRateErrorParameterDerivative(final GroundStation station, final ParameterDriver driver, final SpacecraftState state, final double delay) throws OrekitException {
final ParameterFunction rangeError = new ParameterFunction() {
/**
* {@inheritDoc}
*/
@Override
public double value(final ParameterDriver parameterDriver) throws OrekitException {
return rangeRateErrorTroposphericModel(station, state);
}
};
final ParameterFunction rangeErrorDerivative = Differentiation.differentiate(rangeError, driver, 3, 10.0);
return rangeErrorDerivative.value(driver);
}
use of org.orekit.utils.ParameterFunction in project Orekit by CS-SI.
the class TurnAroundRangeTroposphericDelayModifier method rangeErrorParameterDerivative.
/**
* Compute the derivative of the delay term wrt parameters.
*
* @param station ground station
* @param driver driver for the station offset parameter
* @param state spacecraft state
* @return derivative of the delay wrt station offset parameter
* @throws OrekitException if frames transformations cannot be computed
*/
private double rangeErrorParameterDerivative(final GroundStation station, final ParameterDriver driver, final SpacecraftState state) throws OrekitException {
final ParameterFunction rangeError = new ParameterFunction() {
/**
* {@inheritDoc}
*/
@Override
public double value(final ParameterDriver parameterDriver) throws OrekitException {
return rangeErrorTroposphericModel(station, state);
}
};
final ParameterFunction rangeErrorDerivative = Differentiation.differentiate(rangeError, driver, 3, 10.0);
return rangeErrorDerivative.value(driver);
}
use of org.orekit.utils.ParameterFunction in project Orekit by CS-SI.
the class AngularAzElTest method testParameterDerivatives.
@Test
public void testParameterDerivatives() throws OrekitException {
Context context = EstimationTestUtils.geoStationnaryContext("regular-data:potential:tides");
final NumericalPropagatorBuilder propagatorBuilder = context.createBuilder(OrbitType.EQUINOCTIAL, PositionAngle.TRUE, false, 1.0e-6, 60.0, 0.001);
// create perfect azimuth-elevation 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 AngularAzElMeasurementCreator(context), 0.25, 3.0, 600.0);
propagator.setSlaveMode();
for (final ObservedMeasurement<?> measurement : measurements) {
// parameter corresponding to station position offset
final GroundStation stationParameter = ((AngularAzEl) 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
// angular would have depended only on the current position but
// not on the current velocity.
final AbsoluteDate datemeas = measurement.getDate();
final SpacecraftState stateini = propagator.propagate(datemeas);
final Vector3D stationP = stationParameter.getOffsetToInertial(stateini.getFrame(), datemeas).transformPosition(Vector3D.ZERO);
final double meanDelay = AbstractMeasurement.signalTimeOfFlight(stateini.getPVCoordinates(), stationP, datemeas);
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(2, measurement.getDimension());
Assert.assertEquals(2, gradient.length);
for (final int k : new int[] { 0, 1 }) {
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()[k];
}
}, drivers[i], 3, 50.0);
final double ref = dMkdP.value(drivers[i]);
if (ref > 1.e-12) {
Assert.assertEquals(ref, gradient[k], 3e-10 * FastMath.abs(ref));
}
}
}
}
}
use of org.orekit.utils.ParameterFunction 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);
}
Aggregations