Search in sources :

Example 36 with Propagator

use of org.orekit.propagation.Propagator in project Orekit by CS-SI.

the class RangeTest method genericTestParameterDerivatives.

void genericTestParameterDerivatives(final boolean isModifier, final boolean printResults, final double refErrorsMedian, final double refErrorsMean, final double refErrorsMax) throws OrekitException {
    Context context = EstimationTestUtils.eccentricContext("regular-data:potential:tides");
    final NumericalPropagatorBuilder propagatorBuilder = context.createBuilder(OrbitType.KEPLERIAN, PositionAngle.TRUE, true, 1.0e-6, 60.0, 0.001);
    // Create perfect range measurements
    for (final GroundStation station : context.stations) {
        station.getEastOffsetDriver().setSelected(true);
        station.getNorthOffsetDriver().setSelected(true);
        station.getZenithOffsetDriver().setSelected(true);
    }
    final Propagator propagator = EstimationTestUtils.createPropagator(context.initialOrbit, propagatorBuilder);
    final List<ObservedMeasurement<?>> measurements = EstimationTestUtils.createMeasurements(propagator, new RangeMeasurementCreator(context), 1.0, 3.0, 300.0);
    // List to store the results
    final List<Double> relErrorList = new ArrayList<Double>();
    // Set master mode
    // Use a lambda function to implement "handleStep" function
    propagator.setMasterMode((OrekitStepInterpolator interpolator, boolean isLast) -> {
        for (final ObservedMeasurement<?> measurement : measurements) {
            // Play test if the measurement date is between interpolator previous and current date
            if ((measurement.getDate().durationFrom(interpolator.getPreviousState().getDate()) > 0.) && (measurement.getDate().durationFrom(interpolator.getCurrentState().getDate()) <= 0.)) {
                // Add modifiers if test implies it
                final RangeTroposphericDelayModifier modifier = new RangeTroposphericDelayModifier(SaastamoinenModel.getStandardModel());
                if (isModifier) {
                    ((Range) measurement).addModifier(modifier);
                }
                // Parameter corresponding to station position offset
                final GroundStation stationParameter = ((Range) measurement).getStation();
                // We intentionally propagate to a date which is close to the
                // real spacecraft state but is *not* the accurate date, by
                // compensating only part of the downlink delay. This is done
                // in order to validate the partial derivatives with respect
                // to velocity. If we had chosen the proper state date, the
                // range would have depended only on the current position but
                // not on the current velocity.
                final double meanDelay = measurement.getObservedValue()[0] / Constants.SPEED_OF_LIGHT;
                final AbsoluteDate date = measurement.getDate().shiftedBy(-0.75 * meanDelay);
                final SpacecraftState state = interpolator.getInterpolatedState(date);
                final ParameterDriver[] drivers = new ParameterDriver[] { stationParameter.getEastOffsetDriver(), stationParameter.getNorthOffsetDriver(), stationParameter.getZenithOffsetDriver() };
                if (printResults) {
                    String stationName = ((Range) measurement).getStation().getBaseFrame().getName();
                    System.out.format(Locale.US, "%-15s  %-23s  %-23s  ", stationName, measurement.getDate(), date);
                }
                for (int i = 0; i < 3; ++i) {
                    final double[] gradient = measurement.estimate(0, 0, new SpacecraftState[] { state }).getParameterDerivatives(drivers[i]);
                    Assert.assertEquals(1, measurement.getDimension());
                    Assert.assertEquals(1, gradient.length);
                    // Compute a reference value using finite differences
                    final ParameterFunction dMkdP = Differentiation.differentiate(new ParameterFunction() {

                        /**
                         * {@inheritDoc}
                         */
                        @Override
                        public double value(final ParameterDriver parameterDriver) throws OrekitException {
                            return measurement.estimate(0, 0, new SpacecraftState[] { state }).getEstimatedValue()[0];
                        }
                    }, drivers[i], 3, 20.0);
                    final double ref = dMkdP.value(drivers[i]);
                    if (printResults) {
                        System.out.format(Locale.US, "%10.3e  %10.3e  ", gradient[0] - ref, FastMath.abs((gradient[0] - ref) / ref));
                    }
                    final double relError = FastMath.abs((ref - gradient[0]) / ref);
                    relErrorList.add(relError);
                // Assert.assertEquals(ref, gradient[0], 6.1e-5 * FastMath.abs(ref));
                }
                if (printResults) {
                    System.out.format(Locale.US, "%n");
                }
            }
        // End if measurement date between previous and current interpolator step
        }
    // End for loop on the measurements
    });
    // Rewind the propagator to initial date
    propagator.propagate(context.initialOrbit.getDate());
    // Sort measurements chronologically
    measurements.sort(new ChronologicalComparator());
    // Print results ? Header
    if (printResults) {
        System.out.format(Locale.US, "%-15s  %-23s  %-23s  " + "%10s  %10s  %10s  " + "%10s  %10s  %10s%n", "Station", "Measurement Date", "State Date", "ΔdQx", "rel ΔdQx", "ΔdQy", "rel ΔdQy", "ΔdQz", "rel ΔdQz");
    }
    // Propagate to final measurement's date
    propagator.propagate(measurements.get(measurements.size() - 1).getDate());
    // Convert error list to double[]
    final double[] relErrors = relErrorList.stream().mapToDouble(Double::doubleValue).toArray();
    // Compute statistics
    final double relErrorsMedian = new Median().evaluate(relErrors);
    final double relErrorsMean = new Mean().evaluate(relErrors);
    final double relErrorsMax = new Max().evaluate(relErrors);
    // Print the results on console ?
    if (printResults) {
        System.out.println();
        System.out.format(Locale.US, "Relative errors dR/dQ -> Median: %6.3e / Mean: %6.3e / Max: %6.3e%n", relErrorsMedian, relErrorsMean, relErrorsMax);
    }
    Assert.assertEquals(0.0, relErrorsMedian, refErrorsMedian);
    Assert.assertEquals(0.0, relErrorsMean, refErrorsMean);
    Assert.assertEquals(0.0, relErrorsMax, refErrorsMax);
}
Also used : Mean(org.hipparchus.stat.descriptive.moment.Mean) Max(org.hipparchus.stat.descriptive.rank.Max) ArrayList(java.util.ArrayList) Median(org.hipparchus.stat.descriptive.rank.Median) AbsoluteDate(org.orekit.time.AbsoluteDate) SpacecraftState(org.orekit.propagation.SpacecraftState) Propagator(org.orekit.propagation.Propagator) OrekitException(org.orekit.errors.OrekitException) Context(org.orekit.estimation.Context) ParameterDriver(org.orekit.utils.ParameterDriver) RangeTroposphericDelayModifier(org.orekit.estimation.measurements.modifiers.RangeTroposphericDelayModifier) OrekitStepInterpolator(org.orekit.propagation.sampling.OrekitStepInterpolator) NumericalPropagatorBuilder(org.orekit.propagation.conversion.NumericalPropagatorBuilder) ParameterFunction(org.orekit.utils.ParameterFunction) ChronologicalComparator(org.orekit.time.ChronologicalComparator)

Example 37 with Propagator

use of org.orekit.propagation.Propagator in project Orekit by CS-SI.

the class DSSTPropagatorTest method testEphemerisDates.

@Test
public void testEphemerisDates() throws OrekitException {
    // setup
    TimeScale tai = TimeScalesFactory.getTAI();
    AbsoluteDate initialDate = new AbsoluteDate("2015-07-01", tai);
    AbsoluteDate startDate = new AbsoluteDate("2015-07-03", tai).shiftedBy(-0.1);
    AbsoluteDate endDate = new AbsoluteDate("2015-07-04", tai);
    Frame eci = FramesFactory.getGCRF();
    KeplerianOrbit orbit = new KeplerianOrbit(600e3 + Constants.WGS84_EARTH_EQUATORIAL_RADIUS, 0, 0, 0, 0, 0, PositionAngle.TRUE, eci, initialDate, Constants.EIGEN5C_EARTH_MU);
    double[][] tol = DSSTPropagator.tolerances(1, orbit);
    Propagator prop = new DSSTPropagator(new DormandPrince853Integrator(0.1, 500, tol[0], tol[1]));
    prop.resetInitialState(new SpacecraftState(new CartesianOrbit(orbit)));
    // action
    prop.setEphemerisMode();
    prop.propagate(startDate, endDate);
    BoundedPropagator ephemeris = prop.getGeneratedEphemeris();
    // verify
    TimeStampedPVCoordinates actualPV = ephemeris.getPVCoordinates(startDate, eci);
    TimeStampedPVCoordinates expectedPV = orbit.getPVCoordinates(startDate, eci);
    MatcherAssert.assertThat(actualPV.getPosition(), OrekitMatchers.vectorCloseTo(expectedPV.getPosition(), 1.0));
    MatcherAssert.assertThat(actualPV.getVelocity(), OrekitMatchers.vectorCloseTo(expectedPV.getVelocity(), 1.0));
    MatcherAssert.assertThat(ephemeris.getMinDate().durationFrom(startDate), OrekitMatchers.closeTo(0, 0));
    MatcherAssert.assertThat(ephemeris.getMaxDate().durationFrom(endDate), OrekitMatchers.closeTo(0, 0));
    // test date
    AbsoluteDate date = endDate.shiftedBy(-0.11);
    Assert.assertEquals(ephemeris.propagate(date).getDate().durationFrom(date), 0, 0);
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) Frame(org.orekit.frames.Frame) CartesianOrbit(org.orekit.orbits.CartesianOrbit) Propagator(org.orekit.propagation.Propagator) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) BoundedPropagator(org.orekit.propagation.BoundedPropagator) KeplerianOrbit(org.orekit.orbits.KeplerianOrbit) DormandPrince853Integrator(org.hipparchus.ode.nonstiff.DormandPrince853Integrator) TimeStampedPVCoordinates(org.orekit.utils.TimeStampedPVCoordinates) TimeScale(org.orekit.time.TimeScale) BoundedPropagator(org.orekit.propagation.BoundedPropagator) AbsoluteDate(org.orekit.time.AbsoluteDate) Test(org.junit.Test)

Example 38 with Propagator

use of org.orekit.propagation.Propagator 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 39 with Propagator

use of org.orekit.propagation.Propagator in project Orekit by CS-SI.

the class TrackCorridor method createPropagator.

/**
 * Create an orbit propagator for a TLE orbit
 * @param line1 firs line of the TLE
 * @param line2 second line of the TLE
 * @return an orbit propagator
 * @exception OrekitException if the TLE lines are corrupted (wrong checksums ...)
 */
private Propagator createPropagator(final String line1, final String line2) throws OrekitException {
    // create pseudo-orbit
    TLE tle = new TLE(line1, line2);
    // create propagator
    Propagator propagator = TLEPropagator.selectExtrapolator(tle);
    return propagator;
}
Also used : TLEPropagator(org.orekit.propagation.analytical.tle.TLEPropagator) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) Propagator(org.orekit.propagation.Propagator) TLE(org.orekit.propagation.analytical.tle.TLE)

Example 40 with Propagator

use of org.orekit.propagation.Propagator in project Orekit by CS-SI.

the class TrackCorridor method run.

private void run(final File input, final File output, final String separator) throws IOException, IllegalArgumentException, OrekitException {
    // read input parameters
    KeyValueFileParser<ParameterKey> parser = new KeyValueFileParser<ParameterKey>(ParameterKey.class);
    try (final FileInputStream fis = new FileInputStream(input)) {
        parser.parseInput(input.getAbsolutePath(), fis);
    }
    TimeScale utc = TimeScalesFactory.getUTC();
    Propagator propagator;
    if (parser.containsKey(ParameterKey.TLE_LINE1)) {
        propagator = createPropagator(parser.getString(ParameterKey.TLE_LINE1), parser.getString(ParameterKey.TLE_LINE2));
    } else {
        propagator = createPropagator(parser.getDate(ParameterKey.ORBIT_CIRCULAR_DATE, utc), parser.getDouble(ParameterKey.ORBIT_CIRCULAR_A), parser.getDouble(ParameterKey.ORBIT_CIRCULAR_EX), parser.getDouble(ParameterKey.ORBIT_CIRCULAR_EY), parser.getAngle(ParameterKey.ORBIT_CIRCULAR_I), parser.getAngle(ParameterKey.ORBIT_CIRCULAR_RAAN), parser.getAngle(ParameterKey.ORBIT_CIRCULAR_ALPHA));
    }
    // simulation properties
    AbsoluteDate start = parser.getDate(ParameterKey.START_DATE, utc);
    double duration = parser.getDouble(ParameterKey.DURATION);
    double step = parser.getDouble(ParameterKey.STEP);
    double angle = parser.getAngle(ParameterKey.ANGULAR_OFFSET);
    // set up a handler to gather all corridor points
    CorridorHandler handler = new CorridorHandler(angle);
    propagator.setMasterMode(step, handler);
    // perform propagation, letting the step handler populate the corridor
    propagator.propagate(start, start.shiftedBy(duration));
    // retrieve the built corridor
    List<CorridorPoint> corridor = handler.getCorridor();
    // create a 7 columns csv file representing the corridor in the user home directory, with
    // date in column 1 (in ISO-8601 format)
    // left limit latitude in column 2 and left limit longitude in column 3
    // center track latitude in column 4 and center track longitude in column 5
    // right limit latitude in column 6 and right limit longitude in column 7
    DecimalFormat format = new DecimalFormat("#00.00000", new DecimalFormatSymbols(Locale.US));
    try (final PrintStream stream = new PrintStream(output, "UTF-8")) {
        for (CorridorPoint p : corridor) {
            stream.println(p.getDate() + separator + format.format(FastMath.toDegrees(p.getLeft().getLatitude())) + separator + format.format(FastMath.toDegrees(p.getLeft().getLongitude())) + separator + format.format(FastMath.toDegrees(p.getCenter().getLatitude())) + separator + format.format(FastMath.toDegrees(p.getCenter().getLongitude())) + separator + format.format(FastMath.toDegrees(p.getRight().getLatitude())) + separator + format.format(FastMath.toDegrees(p.getRight().getLongitude())));
        }
    }
}
Also used : PrintStream(java.io.PrintStream) KeyValueFileParser(fr.cs.examples.KeyValueFileParser) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat) TimeScale(org.orekit.time.TimeScale) FileInputStream(java.io.FileInputStream) AbsoluteDate(org.orekit.time.AbsoluteDate) TLEPropagator(org.orekit.propagation.analytical.tle.TLEPropagator) EcksteinHechlerPropagator(org.orekit.propagation.analytical.EcksteinHechlerPropagator) Propagator(org.orekit.propagation.Propagator)

Aggregations

Propagator (org.orekit.propagation.Propagator)177 Test (org.junit.Test)141 SpacecraftState (org.orekit.propagation.SpacecraftState)92 AbsoluteDate (org.orekit.time.AbsoluteDate)90 Context (org.orekit.estimation.Context)67 NumericalPropagatorBuilder (org.orekit.propagation.conversion.NumericalPropagatorBuilder)67 ArrayList (java.util.ArrayList)62 Vector3D (org.hipparchus.geometry.euclidean.threed.Vector3D)58 KeplerianOrbit (org.orekit.orbits.KeplerianOrbit)51 Orbit (org.orekit.orbits.Orbit)46 KeplerianPropagator (org.orekit.propagation.analytical.KeplerianPropagator)41 ObservedMeasurement (org.orekit.estimation.measurements.ObservedMeasurement)40 Event (org.orekit.propagation.events.handlers.RecordAndContinue.Event)38 StopOnEvent (org.orekit.propagation.events.handlers.StopOnEvent)38 OrekitException (org.orekit.errors.OrekitException)30 EcksteinHechlerPropagator (org.orekit.propagation.analytical.EcksteinHechlerPropagator)29 GeodeticPoint (org.orekit.bodies.GeodeticPoint)28 OneAxisEllipsoid (org.orekit.bodies.OneAxisEllipsoid)28 PVCoordinates (org.orekit.utils.PVCoordinates)26 ParameterDriver (org.orekit.utils.ParameterDriver)23