Search in sources :

Example 6 with TimeStampedCacheException

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);
    }
}
Also used : TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) FieldHermiteInterpolator(org.hipparchus.analysis.interpolation.FieldHermiteInterpolator) OrekitInternalError(org.orekit.errors.OrekitInternalError) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate)

Example 7 with TimeStampedCacheException

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();
}
Also used : TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException)

Example 8 with TimeStampedCacheException

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);
    }
}
Also used : TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) OrekitInternalError(org.orekit.errors.OrekitInternalError) HermiteInterpolator(org.hipparchus.analysis.interpolation.HermiteInterpolator) FieldHermiteInterpolator(org.hipparchus.analysis.interpolation.FieldHermiteInterpolator)

Aggregations

TimeStampedCacheException (org.orekit.errors.TimeStampedCacheException)8 OrekitInternalError (org.orekit.errors.OrekitInternalError)4 AbsoluteDate (org.orekit.time.AbsoluteDate)4 ArrayList (java.util.ArrayList)3 RandomGenerator (org.hipparchus.random.RandomGenerator)3 FieldHermiteInterpolator (org.hipparchus.analysis.interpolation.FieldHermiteInterpolator)2 Test (org.junit.Test)2 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)2 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 HermiteInterpolator (org.hipparchus.analysis.interpolation.HermiteInterpolator)1