Search in sources :

Example 1 with TimeStampedCacheException

use of org.orekit.errors.TimeStampedCacheException in project Orekit by CS-SI.

the class EOPHistory method getUT1MinusUTC.

/**
 * Get the UT1-UTC value.
 * <p>The data provided comes from the IERS files. It is smoothed data.</p>
 * @param date date at which the value is desired
 * @param <T> type of the field elements
 * @return UT1-UTC in seconds (0 if date is outside covered range)
 * @since 9.0
 */
public <T extends RealFieldElement<T>> T getUT1MinusUTC(final FieldAbsoluteDate<T> date) {
    // check if there is data for date
    final AbsoluteDate absDate = date.toAbsoluteDate();
    if (!this.hasDataFor(absDate)) {
        // no EOP data available for this date, we use a default 0.0 offset
        return (tidalCorrection == null) ? date.getField().getZero() : tidalCorrection.value(date)[2];
    }
    // we have EOP data -> interpolate offset
    try {
        final FieldDUT1Interpolator<T> interpolator = new FieldDUT1Interpolator<>(date, absDate);
        getNeighbors(absDate).forEach(interpolator);
        T interpolated = interpolator.getInterpolated();
        if (tidalCorrection != null) {
            interpolated = interpolated.add(tidalCorrection.value(date)[2]);
        }
        return interpolated;
    } catch (TimeStampedCacheException tce) {
        // this should not happen because of date check above
        throw new OrekitInternalError(tce);
    }
}
Also used : TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) OrekitInternalError(org.orekit.errors.OrekitInternalError) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate)

Example 2 with TimeStampedCacheException

use of org.orekit.errors.TimeStampedCacheException in project Orekit by CS-SI.

the class EOPHistory method getUT1MinusUTC.

/**
 * Get the UT1-UTC value.
 * <p>The data provided comes from the IERS files. It is smoothed data.</p>
 * @param date date at which the value is desired
 * @return UT1-UTC in seconds (0 if date is outside covered range)
 */
public double getUT1MinusUTC(final AbsoluteDate date) {
    // check if there is data for date
    if (!this.hasDataFor(date)) {
        // no EOP data available for this date, we use a default 0.0 offset
        return (tidalCorrection == null) ? 0.0 : tidalCorrection.value(date)[2];
    }
    // we have EOP data -> interpolate offset
    try {
        final DUT1Interpolator interpolator = new DUT1Interpolator(date);
        getNeighbors(date).forEach(interpolator);
        double interpolated = interpolator.getInterpolated();
        if (tidalCorrection != null) {
            interpolated += tidalCorrection.value(date)[2];
        }
        return interpolated;
    } catch (TimeStampedCacheException tce) {
        // this should not happen because of date check above
        throw new OrekitInternalError(tce);
    }
}
Also used : TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) OrekitInternalError(org.orekit.errors.OrekitInternalError)

Example 3 with TimeStampedCacheException

use of org.orekit.errors.TimeStampedCacheException in project Orekit by CS-SI.

the class GenericTimeStampedCacheTest method checkDatesMultiThread.

private int checkDatesMultiThread(final List<AbsoluteDate> centralDates, final GenericTimeStampedCache<AbsoluteDate> cache, final int threadPoolSize) throws TimeStampedCacheException {
    final int n = cache.getNeighborsSize();
    final double step = ((Generator) cache.getGenerator()).getStep();
    final AtomicReference<AbsoluteDate[]> failedDates = new AtomicReference<AbsoluteDate[]>();
    final AtomicReference<TimeStampedCacheException> caught = new AtomicReference<TimeStampedCacheException>();
    ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);
    for (final AbsoluteDate central : centralDates) {
        executorService.execute(new Runnable() {

            public void run() {
                try {
                    final List<AbsoluteDate> neighbors = cache.getNeighbors(central).collect(Collectors.toList());
                    Assert.assertEquals(n, neighbors.size());
                    for (final AbsoluteDate date : neighbors) {
                        if (date.durationFrom(central) < -(n + 1) * step || date.durationFrom(central) > n * step) {
                            AbsoluteDate[] dates = new AbsoluteDate[n + 1];
                            dates[0] = central;
                            System.arraycopy(neighbors, 0, dates, 1, n);
                            failedDates.set(dates);
                        }
                    }
                } catch (TimeStampedCacheException tce) {
                    caught.set(tce);
                }
            }
        });
    }
    try {
        executorService.shutdown();
        Assert.assertTrue("Not enough time for all threads to complete, try increasing the timeout", executorService.awaitTermination(10, TimeUnit.MINUTES));
    } catch (InterruptedException ie) {
        Assert.fail(ie.getLocalizedMessage());
    }
    if (caught.get() != null) {
        throw caught.get();
    }
    if (failedDates.get() != null) {
        AbsoluteDate[] dates = failedDates.get();
        StringBuilder builder = new StringBuilder();
        String eol = System.getProperty("line.separator");
        builder.append("central = ").append(dates[0]).append(eol);
        builder.append("step = ").append(step).append(eol);
        builder.append("neighbors =").append(eol);
        for (int i = 1; i < dates.length; ++i) {
            builder.append("    ").append(dates[i]).append(eol);
        }
        Assert.fail(builder.toString());
    }
    return centralDates.size();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) AbsoluteDate(org.orekit.time.AbsoluteDate) TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) List(java.util.List) RandomGenerator(org.hipparchus.random.RandomGenerator)

Example 4 with TimeStampedCacheException

use of org.orekit.errors.TimeStampedCacheException in project Orekit by CS-SI.

the class GenericTimeStampedCacheTest method testFutureInfinityRange.

@Test
public void testFutureInfinityRange() throws TimeStampedCacheException {
    GenericTimeStampedCache<AbsoluteDate> cache = new GenericTimeStampedCache<AbsoluteDate>(2, 10, Constants.JULIAN_YEAR, Constants.JULIAN_DAY, new Generator(AbsoluteDate.MODIFIED_JULIAN_EPOCH, AbsoluteDate.FUTURE_INFINITY, 10.0));
    List<AbsoluteDate> list = new ArrayList<AbsoluteDate>();
    list.add(AbsoluteDate.J2000_EPOCH);
    list.add(AbsoluteDate.GALILEO_EPOCH);
    Assert.assertEquals(2, checkDatesSingleThread(list, cache));
    Assert.assertEquals(2, cache.getGetNeighborsCalls());
    try {
        cache.getNeighbors(AbsoluteDate.JULIAN_EPOCH);
        Assert.fail("expected TimeStampedCacheException");
    } catch (TimeStampedCacheException tce) {
    // expected behavior
    } catch (Exception e) {
        Assert.fail("wrong exception caught");
    }
}
Also used : TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) ArrayList(java.util.ArrayList) AbsoluteDate(org.orekit.time.AbsoluteDate) TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) RandomGenerator(org.hipparchus.random.RandomGenerator) Test(org.junit.Test)

Example 5 with TimeStampedCacheException

use of org.orekit.errors.TimeStampedCacheException in project Orekit by CS-SI.

the class GenericTimeStampedCacheTest method testPastInfinityRange.

@Test
public void testPastInfinityRange() throws TimeStampedCacheException {
    GenericTimeStampedCache<AbsoluteDate> cache = new GenericTimeStampedCache<AbsoluteDate>(2, 10, Constants.JULIAN_YEAR, Constants.JULIAN_DAY, new Generator(AbsoluteDate.PAST_INFINITY, AbsoluteDate.J2000_EPOCH, 10.0));
    List<AbsoluteDate> list = new ArrayList<AbsoluteDate>();
    list.add(AbsoluteDate.GALILEO_EPOCH);
    list.add(AbsoluteDate.MODIFIED_JULIAN_EPOCH);
    list.add(AbsoluteDate.JULIAN_EPOCH);
    Assert.assertEquals(3, checkDatesSingleThread(list, cache));
    Assert.assertEquals(3, cache.getGetNeighborsCalls());
    try {
        cache.getNeighbors(AbsoluteDate.J2000_EPOCH.shiftedBy(100.0));
        Assert.fail("expected TimeStampedCacheException");
    } catch (TimeStampedCacheException tce) {
    // expected behavior
    } catch (Exception e) {
        Assert.fail("wrong exception caught");
    }
}
Also used : TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) ArrayList(java.util.ArrayList) AbsoluteDate(org.orekit.time.AbsoluteDate) TimeStampedCacheException(org.orekit.errors.TimeStampedCacheException) RandomGenerator(org.hipparchus.random.RandomGenerator) Test(org.junit.Test)

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