Search in sources :

Example 56 with OrekitException

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

the class Time1 method main.

/**
 * Program entry point.
 * @param args program arguments (unused here)
 */
public static void main(String[] args) {
    try {
        // configure Orekit
        File home = new File(System.getProperty("user.home"));
        File orekitData = new File(home, "orekit-data");
        if (!orekitData.exists()) {
            System.err.format(Locale.US, "Failed to find %s folder%n", orekitData.getAbsolutePath());
            System.err.format(Locale.US, "You need to download %s from the %s page and unzip it in %s for this tutorial to work%n", "orekit-data.zip", "https://www.orekit.org/forge/projects/orekit/files", home.getAbsolutePath());
            System.exit(1);
        }
        DataProvidersManager manager = DataProvidersManager.getInstance();
        manager.addProvider(new DirectoryCrawler(orekitData));
        // get the UTC and TAI time scales
        TimeScale utc = TimeScalesFactory.getUTC();
        TimeScale tai = TimeScalesFactory.getTAI();
        // create a start date from its calendar components in UTC time scale
        AbsoluteDate start = new AbsoluteDate(2005, 12, 31, 23, 59, 50, utc);
        // create an end date 20 seconds after the start date
        double duration = 20.0;
        AbsoluteDate end = start.shiftedBy(duration);
        // output header line
        System.out.println("        UTC date                  TAI date");
        // loop from start to end using a one minute step
        // (a leap second was introduced this day, so the display should show
        // the rare case of an UTC minute with more than 60 seconds)
        double step = 0.5;
        for (AbsoluteDate date = start; date.compareTo(end) < 0; date = date.shiftedBy(step)) {
            System.out.println(date.toString(utc) + "   " + date.toString(tai));
        }
    } catch (OrekitException oe) {
        System.err.println(oe.getMessage());
    }
}
Also used : DirectoryCrawler(org.orekit.data.DirectoryCrawler) DataProvidersManager(org.orekit.data.DataProvidersManager) OrekitException(org.orekit.errors.OrekitException) File(java.io.File) TimeScale(org.orekit.time.TimeScale) AbsoluteDate(org.orekit.time.AbsoluteDate)

Example 57 with OrekitException

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

the class DOPComputation method run.

private void run(final OneAxisEllipsoid shape, final List<GeodeticPoint> zone, final double meshSize, final double minElevation, final AbsoluteDate tStart, final AbsoluteDate tStop, final double tStep) throws IOException, OrekitException, ParseException {
    // Gets the GPS almanacs from the SEM file
    final SEMParser reader = new SEMParser(null);
    reader.loadData();
    final List<GPSAlmanac> almanacs = reader.getAlmanacs();
    // Creates the GPS propagators from the almanacs
    final List<Propagator> propagators = new ArrayList<Propagator>();
    for (GPSAlmanac almanac : almanacs) {
        // Only keeps almanac with health status ok
        if (almanac.getHealth() == 0) {
            propagators.add(new GPSPropagator.Builder(almanac).build());
        } else {
            System.out.println("GPS PRN " + almanac.getPRN() + " is not OK (Health status = " + almanac.getHealth() + ").");
        }
    }
    // Meshes the area of interest into a grid of geodetic points.
    final List<List<GeodeticPoint>> points = sample(shape, zone, meshSize);
    // Creates the DOP computers for all the locations of the sampled geographic zone
    final List<DOPComputer> computers = new ArrayList<DOPComputer>();
    for (List<GeodeticPoint> row : points) {
        for (GeodeticPoint point : row) {
            computers.add(DOPComputer.create(shape, point).withMinElevation(minElevation));
        }
    }
    // Computes the DOP for each point over the period
    final List<List<DOP>> allDop = new ArrayList<List<DOP>>();
    // Loops on the period
    AbsoluteDate tc = tStart;
    while (tc.compareTo(tStop) != 1) {
        // Loops on the grid points
        final List<DOP> dopAtDate = new ArrayList<DOP>();
        for (DOPComputer computer : computers) {
            try {
                final DOP dop = computer.compute(tc, propagators);
                dopAtDate.add(dop);
            } catch (OrekitException oe) {
                System.out.println(oe.getLocalizedMessage());
            }
        }
        allDop.add(dopAtDate);
        tc = tc.shiftedBy(tStep);
    }
    // Post-processing: gets the statistics of PDOP over the zone at each time
    System.out.println("                           PDOP");
    System.out.println("          Date           min  max");
    for (List<DOP> dopAtDate : allDop) {
        final StreamingStatistics pDoP = new StreamingStatistics();
        for (DOP dopAtLoc : dopAtDate) {
            pDoP.addValue(dopAtLoc.getPdop());
        }
        final AbsoluteDate date = dopAtDate.get(0).getDate();
        System.out.format(Locale.ENGLISH, "%s %.2f %.2f%n", date.toString(), pDoP.getMin(), pDoP.getMax());
    }
}
Also used : DOP(org.orekit.gnss.DOP) StreamingStatistics(org.hipparchus.stat.descriptive.StreamingStatistics) ArrayList(java.util.ArrayList) SEMParser(org.orekit.gnss.SEMParser) AbsoluteDate(org.orekit.time.AbsoluteDate) DOPComputer(org.orekit.gnss.DOPComputer) GPSAlmanac(org.orekit.gnss.GPSAlmanac) Propagator(org.orekit.propagation.Propagator) GPSPropagator(org.orekit.propagation.analytical.gnss.GPSPropagator) ArrayList(java.util.ArrayList) List(java.util.List) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint)

Example 58 with OrekitException

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

the class TrackCorridor method main.

/**
 * Program entry point.
 * @param args program arguments
 */
public static void main(String[] args) {
    try {
        // configure Orekit
        File home = new File(System.getProperty("user.home"));
        File orekitData = new File(home, "orekit-data");
        if (!orekitData.exists()) {
            System.err.format(Locale.US, "Failed to find %s folder%n", orekitData.getAbsolutePath());
            System.err.format(Locale.US, "You need to download %s from the %s page and unzip it in %s for this tutorial to work%n", "orekit-data.zip", "https://www.orekit.org/forge/projects/orekit/files", home.getAbsolutePath());
            System.exit(1);
        }
        DataProvidersManager manager = DataProvidersManager.getInstance();
        manager.addProvider(new DirectoryCrawler(orekitData));
        // input/out
        File input = new File(TrackCorridor.class.getResource("/track-corridor.in").toURI().getPath());
        File output = new File(input.getParentFile(), "track-corridor.csv");
        new TrackCorridor().run(input, output, ",");
        System.out.println("corridor saved as file " + output);
    } catch (URISyntaxException use) {
        System.err.println(use.getLocalizedMessage());
        System.exit(1);
    } catch (IOException ioe) {
        System.err.println(ioe.getLocalizedMessage());
        System.exit(1);
    } catch (IllegalArgumentException iae) {
        System.err.println(iae.getLocalizedMessage());
        System.exit(1);
    } catch (OrekitException oe) {
        System.err.println(oe.getLocalizedMessage());
        System.exit(1);
    }
}
Also used : DirectoryCrawler(org.orekit.data.DirectoryCrawler) DataProvidersManager(org.orekit.data.DataProvidersManager) OrekitException(org.orekit.errors.OrekitException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) File(java.io.File)

Example 59 with OrekitException

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

the class AlongTrackAiming method alongTileDirection.

/**
 * {@inheritDoc}
 */
@Override
public Vector3D alongTileDirection(final Vector3D point, final GeodeticPoint gp) throws OrekitException {
    final double lStart = halfTrack.get(0).getFirst().getLatitude();
    final double lEnd = halfTrack.get(halfTrack.size() - 1).getFirst().getLatitude();
    // check the point can be reached
    if (gp.getLatitude() < FastMath.min(lStart, lEnd) || gp.getLatitude() > FastMath.max(lStart, lEnd)) {
        throw new OrekitException(OrekitMessages.OUT_OF_RANGE_LATITUDE, FastMath.toDegrees(gp.getLatitude()), FastMath.toDegrees(FastMath.min(lStart, lEnd)), FastMath.toDegrees(FastMath.max(lStart, lEnd)));
    }
    // bracket the point in the half track sample
    int iInf = 0;
    int iSup = halfTrack.size() - 1;
    while (iSup - iInf > 1) {
        final int iMiddle = (iSup + iInf) / 2;
        if ((lStart < lEnd) ^ (halfTrack.get(iMiddle).getFirst().getLatitude() > gp.getLatitude())) {
            // the specified latitude is in the second half
            iInf = iMiddle;
        } else {
            // the specified latitude is in the first half
            iSup = iMiddle;
        }
    }
    // ensure we can get points at iStart, iStart + 1, iStart + 2 and iStart + 3
    final int iStart = FastMath.max(0, FastMath.min(iInf - 1, halfTrack.size() - 4));
    // interpolate ground sliding point at specified latitude
    final HermiteInterpolator interpolator = new HermiteInterpolator();
    for (int i = iStart; i < iStart + 4; ++i) {
        final Vector3D position = halfTrack.get(i).getSecond().getPosition();
        final Vector3D velocity = halfTrack.get(i).getSecond().getVelocity();
        interpolator.addSamplePoint(halfTrack.get(i).getFirst().getLatitude(), new double[] { position.getX(), position.getY(), position.getZ(), velocity.getX(), velocity.getY(), velocity.getZ() });
    }
    final DerivativeStructure[] p = interpolator.value(factory.variable(0, gp.getLatitude()));
    // extract interpolated ground position/velocity
    final Vector3D position = new Vector3D(p[0].getValue(), p[1].getValue(), p[2].getValue());
    final Vector3D velocity = new Vector3D(p[3].getValue(), p[4].getValue(), p[5].getValue());
    // adjust longitude to match the specified one
    final Rotation rotation = new Rotation(Vector3D.PLUS_K, position, Vector3D.PLUS_K, point);
    final Vector3D fixedVelocity = rotation.applyTo(velocity);
    // the tile direction is aligned with sliding point velocity
    return fixedVelocity.normalize();
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) DerivativeStructure(org.hipparchus.analysis.differentiation.DerivativeStructure) OrekitException(org.orekit.errors.OrekitException) Rotation(org.hipparchus.geometry.euclidean.threed.Rotation) GeodeticPoint(org.orekit.bodies.GeodeticPoint) HermiteInterpolator(org.hipparchus.analysis.interpolation.HermiteInterpolator)

Example 60 with OrekitException

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

the class SpacecraftState method interpolate.

/**
 * {@inheritDoc}
 * <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>
 */
public SpacecraftState interpolate(final AbsoluteDate date, final Stream<SpacecraftState> sample) throws OrekitException {
    // prepare interpolators
    final List<Orbit> orbits = new ArrayList<>();
    final List<Attitude> attitudes = new ArrayList<>();
    final HermiteInterpolator massInterpolator = new HermiteInterpolator();
    final Map<String, HermiteInterpolator> additionalInterpolators = new HashMap<String, HermiteInterpolator>(additional.size());
    for (final String name : additional.keySet()) {
        additionalInterpolators.put(name, new HermiteInterpolator());
    }
    // extract sample data
    try {
        sample.forEach(state -> {
            try {
                final double deltaT = state.getDate().durationFrom(date);
                orbits.add(state.getOrbit());
                attitudes.add(state.getAttitude());
                massInterpolator.addSamplePoint(deltaT, new double[] { state.getMass() });
                for (final Map.Entry<String, HermiteInterpolator> 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 Orbit interpolatedOrbit = orbit.interpolate(date, orbits);
    final Attitude interpolatedAttitude = attitude.interpolate(date, attitudes);
    final double interpolatedMass = massInterpolator.value(0)[0];
    final Map<String, double[]> interpolatedAdditional;
    if (additional.isEmpty()) {
        interpolatedAdditional = null;
    } else {
        interpolatedAdditional = new HashMap<String, double[]>(additional.size());
        for (final Map.Entry<String, HermiteInterpolator> entry : additionalInterpolators.entrySet()) {
            interpolatedAdditional.put(entry.getKey(), entry.getValue().value(0));
        }
    }
    // create the complete interpolated state
    return new SpacecraftState(interpolatedOrbit, interpolatedAttitude, interpolatedMass, interpolatedAdditional);
}
Also used : OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) Orbit(org.orekit.orbits.Orbit) Attitude(org.orekit.attitudes.Attitude) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HermiteInterpolator(org.hipparchus.analysis.interpolation.HermiteInterpolator) OrekitException(org.orekit.errors.OrekitException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

OrekitException (org.orekit.errors.OrekitException)332 AbsoluteDate (org.orekit.time.AbsoluteDate)150 Test (org.junit.Test)135 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)91 SpacecraftState (org.orekit.propagation.SpacecraftState)75 Frame (org.orekit.frames.Frame)62 FieldAbsoluteDate (org.orekit.time.FieldAbsoluteDate)59 ArrayList (java.util.ArrayList)48 Before (org.junit.Before)48 FieldVector3D (org.hipparchus.geometry.euclidean.threed.FieldVector3D)42 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)42 DateComponents (org.orekit.time.DateComponents)42 GeodeticPoint (org.orekit.bodies.GeodeticPoint)41 Orbit (org.orekit.orbits.Orbit)40 PVCoordinates (org.orekit.utils.PVCoordinates)37 OneAxisEllipsoid (org.orekit.bodies.OneAxisEllipsoid)36 IOException (java.io.IOException)32 InputStream (java.io.InputStream)31 Propagator (org.orekit.propagation.Propagator)30 UnivariateFunction (org.hipparchus.analysis.UnivariateFunction)28