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);
}
}
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);
}
}
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();
}
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");
}
}
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");
}
}
Aggregations