use of org.hipparchus.analysis.interpolation.FieldHermiteInterpolator in project Orekit by CS-SI.
the class EOPHistory method interpolate.
/**
* Interpolate a single EOP component.
* <p>
* This method should be called <em>only</em> when {@link #hasDataFor(AbsoluteDate)} returns true.
* </p>
* @param date interpolation date
* @param aDate interpolation date, as an {@link AbsoluteDate}
* @param selector selector for EOP entry component
* @param <T> type of the field elements
* @return interpolated value
*/
private <T extends RealFieldElement<T>> T interpolate(final FieldAbsoluteDate<T> date, final AbsoluteDate aDate, final Function<EOPEntry, Double> selector) {
try {
final FieldHermiteInterpolator<T> interpolator = new FieldHermiteInterpolator<>();
final T[] y = MathArrays.buildArray(date.getField(), 1);
final T zero = date.getField().getZero();
// here, we attempt to get a constant date,
final FieldAbsoluteDate<T> central = new FieldAbsoluteDate<>(aDate, zero);
// for example removing derivatives
// if T was DerivativeStructure
getNeighbors(aDate).forEach(entry -> {
y[0] = zero.add(selector.apply(entry));
interpolator.addSamplePoint(central.durationFrom(entry.getDate()).negate(), y);
});
// here, we introduce derivatives again (in DerivativeStructure case)
return interpolator.value(date.durationFrom(central))[0];
} catch (TimeStampedCacheException tce) {
// this should not happen because of date check performed by caller
throw new OrekitInternalError(tce);
}
}
use of org.hipparchus.analysis.interpolation.FieldHermiteInterpolator in project Orekit by CS-SI.
the class FieldSpacecraftState method interpolate.
/**
* Get an interpolated instance.
* <p>
* The additional states that are interpolated are the ones already present
* in the instance. The sample instances must therefore have at least the same
* additional states has the instance. They may have more additional states,
* but the extra ones will be ignored.
* </p>
* <p>
* As this implementation of interpolation is polynomial, it should be used only
* with small samples (about 10-20 points) in order to avoid <a
* href="http://en.wikipedia.org/wiki/Runge%27s_phenomenon">Runge's phenomenon</a>
* and numerical problems (including NaN appearing).
* </p>
* @param date interpolation date
* @param sample sample points on which interpolation should be done
* @return a new instance, interpolated at specified date
* @exception OrekitException if the number of point is too small for interpolating
*/
public FieldSpacecraftState<T> interpolate(final FieldAbsoluteDate<T> date, final Stream<FieldSpacecraftState<T>> sample) throws OrekitException {
// prepare interpolators
final List<FieldOrbit<T>> orbits = new ArrayList<>();
final List<FieldAttitude<T>> attitudes = new ArrayList<>();
final FieldHermiteInterpolator<T> massInterpolator = new FieldHermiteInterpolator<>();
final Map<String, FieldHermiteInterpolator<T>> additionalInterpolators = new HashMap<String, FieldHermiteInterpolator<T>>(additional.size());
for (final String name : additional.keySet()) {
additionalInterpolators.put(name, new FieldHermiteInterpolator<>());
}
// extract sample data
try {
sample.forEach(state -> {
try {
final T deltaT = state.getDate().durationFrom(date);
orbits.add(state.getOrbit());
attitudes.add(state.getAttitude());
final T[] mm = MathArrays.buildArray(orbit.getA().getField(), 1);
mm[0] = state.getMass();
massInterpolator.addSamplePoint(deltaT, mm);
for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
entry.getValue().addSamplePoint(deltaT, state.getAdditionalState(entry.getKey()));
}
} catch (OrekitException oe) {
throw new OrekitExceptionWrapper(oe);
}
});
} catch (OrekitExceptionWrapper oew) {
throw oew.getException();
}
// perform interpolations
final FieldOrbit<T> interpolatedOrbit = orbit.interpolate(date, orbits);
final FieldAttitude<T> interpolatedAttitude = attitude.interpolate(date, attitudes);
final T interpolatedMass = massInterpolator.value(orbit.getA().getField().getZero())[0];
final Map<String, T[]> interpolatedAdditional;
if (additional.isEmpty()) {
interpolatedAdditional = null;
} else {
interpolatedAdditional = new HashMap<String, T[]>(additional.size());
for (final Map.Entry<String, FieldHermiteInterpolator<T>> entry : additionalInterpolators.entrySet()) {
interpolatedAdditional.put(entry.getKey(), entry.getValue().value(orbit.getA().getField().getZero()));
}
}
// create the complete interpolated state
return new FieldSpacecraftState<>(interpolatedOrbit, interpolatedAttitude, interpolatedMass, interpolatedAdditional);
}
Aggregations