use of org.orekit.errors.TimeStampedCacheException 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.orekit.errors.TimeStampedCacheException in project Orekit by CS-SI.
the class ImmutableTimeStampedCache method getNeighbors.
/**
* {@inheritDoc}
*/
public Stream<T> getNeighbors(final AbsoluteDate central) throws TimeStampedCacheException {
// find central index
final int i = findIndex(central);
// check index in in the range of the data
if (i < 0) {
throw new TimeStampedCacheException(OrekitMessages.UNABLE_TO_GENERATE_NEW_DATA_BEFORE, this.getEarliest().getDate());
} else if (i >= this.data.size()) {
throw new TimeStampedCacheException(OrekitMessages.UNABLE_TO_GENERATE_NEW_DATA_AFTER, this.getLatest().getDate());
}
// force unbalanced range if necessary
int start = FastMath.max(0, i - (this.neighborsSize - 1) / 2);
final int end = FastMath.min(this.data.size(), start + this.neighborsSize);
start = end - this.neighborsSize;
// return list without copying
return this.data.subList(start, end).stream();
}
use of org.orekit.errors.TimeStampedCacheException 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 selector selector for EOP entry component
* @return interpolated value
*/
private double interpolate(final AbsoluteDate date, final Function<EOPEntry, Double> selector) {
try {
final HermiteInterpolator interpolator = new HermiteInterpolator();
getNeighbors(date).forEach(entry -> interpolator.addSamplePoint(entry.getDate().durationFrom(date), new double[] { selector.apply(entry) }));
return interpolator.value(0)[0];
} catch (TimeStampedCacheException tce) {
// this should not happen because of date check performed by caller
throw new OrekitInternalError(tce);
}
}
Aggregations