Search in sources :

Example 1 with Pair

use of org.hipparchus.util.Pair in project Orekit by CS-SI.

the class JacobianPropagatorConverter method getModel.

/**
 * {@inheritDoc}
 */
protected MultivariateJacobianFunction getModel() {
    return new MultivariateJacobianFunction() {

        /**
         * {@inheritDoc}
         */
        public Pair<RealVector, RealMatrix> value(final RealVector point) throws IllegalArgumentException, OrekitExceptionWrapper {
            try {
                final RealVector value = new ArrayRealVector(getTargetSize());
                final RealMatrix jacobian = MatrixUtils.createRealMatrix(getTargetSize(), point.getDimension());
                final NumericalPropagator prop = builder.buildPropagator(point.toArray());
                final int stateSize = isOnlyPosition() ? 3 : 6;
                final ParameterDriversList orbitalParameters = builder.getOrbitalParametersDrivers();
                final PartialDerivativesEquations pde = new PartialDerivativesEquations("pde", prop);
                final ParameterDriversList propagationParameters = pde.getSelectedParameters();
                prop.setInitialState(pde.setInitialJacobians(prop.getInitialState()));
                final JacobiansMapper mapper = pde.getMapper();
                final List<SpacecraftState> sample = getSample();
                for (int i = 0; i < sample.size(); ++i) {
                    final int row = i * stateSize;
                    if (prop.getInitialState().getDate().equals(sample.get(i).getDate())) {
                        // use initial state and Jacobians
                        fillRows(value, jacobian, row, prop.getInitialState(), stateSize, orbitalParameters, propagationParameters, mapper);
                    } else {
                        // use a date detector to pick up state and Jacobians
                        prop.addEventDetector(new DateDetector(sample.get(i).getDate()).withHandler(new EventHandler<DateDetector>() {

                            /**
                             * {@inheritDoc}
                             */
                            @Override
                            public Action eventOccurred(final SpacecraftState state, final DateDetector detector, final boolean increasing) throws OrekitException {
                                fillRows(value, jacobian, row, state, stateSize, orbitalParameters, propagationParameters, mapper);
                                return row + stateSize >= getTargetSize() ? Action.STOP : Action.CONTINUE;
                            }
                        }));
                    }
                }
                prop.propagate(sample.get(sample.size() - 1).getDate().shiftedBy(10.0));
                return new Pair<RealVector, RealMatrix>(value, jacobian);
            } catch (OrekitException ex) {
                throw new OrekitExceptionWrapper(ex);
            }
        }
    };
}
Also used : DateDetector(org.orekit.propagation.events.DateDetector) OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) ArrayRealVector(org.hipparchus.linear.ArrayRealVector) EventHandler(org.orekit.propagation.events.handlers.EventHandler) MultivariateJacobianFunction(org.hipparchus.optim.nonlinear.vector.leastsquares.MultivariateJacobianFunction) SpacecraftState(org.orekit.propagation.SpacecraftState) RealMatrix(org.hipparchus.linear.RealMatrix) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) ParameterDriversList(org.orekit.utils.ParameterDriversList) PartialDerivativesEquations(org.orekit.propagation.numerical.PartialDerivativesEquations) ArrayRealVector(org.hipparchus.linear.ArrayRealVector) RealVector(org.hipparchus.linear.RealVector) OrekitException(org.orekit.errors.OrekitException) JacobiansMapper(org.orekit.propagation.numerical.JacobiansMapper) Pair(org.hipparchus.util.Pair)

Example 2 with Pair

use of org.hipparchus.util.Pair in project Orekit by CS-SI.

the class Model method value.

/**
 * {@inheritDoc}
 */
@Override
public Pair<RealVector, RealMatrix> value(final RealVector point) throws OrekitExceptionWrapper {
    try {
        // Set up the propagators parallelizer
        final NumericalPropagator[] propagators = createPropagators(point);
        final Orbit[] orbits = new Orbit[propagators.length];
        for (int i = 0; i < propagators.length; ++i) {
            mappers[i] = configureDerivatives(propagators[i]);
            orbits[i] = propagators[i].getInitialState().getOrbit();
        }
        final PropagatorsParallelizer parallelizer = new PropagatorsParallelizer(Arrays.asList(propagators), configureMeasurements(point));
        // Reset value and Jacobian
        evaluations.clear();
        value.set(0.0);
        for (int i = 0; i < jacobian.getRowDimension(); ++i) {
            for (int j = 0; j < jacobian.getColumnDimension(); ++j) {
                jacobian.setEntry(i, j, 0.0);
            }
        }
        // Run the propagation, gathering residuals on the fly
        if (forwardPropagation) {
            // Propagate forward from firstDate
            parallelizer.propagate(firstDate.shiftedBy(-1.0), lastDate.shiftedBy(+1.0));
        } else {
            // Propagate backward from lastDate
            parallelizer.propagate(lastDate.shiftedBy(+1.0), firstDate.shiftedBy(-1.0));
        }
        observer.modelCalled(orbits, evaluations);
        return new Pair<RealVector, RealMatrix>(value, jacobian);
    } catch (OrekitException oe) {
        throw new OrekitExceptionWrapper(oe);
    }
}
Also used : OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) Orbit(org.orekit.orbits.Orbit) NumericalPropagator(org.orekit.propagation.numerical.NumericalPropagator) PropagatorsParallelizer(org.orekit.propagation.PropagatorsParallelizer) OrekitException(org.orekit.errors.OrekitException) Pair(org.hipparchus.util.Pair)

Example 3 with Pair

use of org.hipparchus.util.Pair in project Orekit by CS-SI.

the class YUMAParser method loadData.

@Override
public void loadData(final InputStream input, final String name) throws IOException, ParseException, OrekitException {
    // Clears the lists
    almanacs.clear();
    prnList.clear();
    // Creates the reader
    final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
    try {
        // Gathers data to create one GPSAlmanac from 13 consecutive lines
        final List<Pair<String, String>> entries = new ArrayList<Pair<String, String>>(KEY.length);
        // Reads the data one line at a time
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            // Try to split the line into 2 tokens as key:value
            final String[] token = line.trim().split(":");
            // If the line is made of 2 tokens
            if (token.length == 2) {
                // Adds these tokens as an entry to the entries
                entries.add(new Pair<String, String>(token[0].trim(), token[1].trim()));
            }
            // If the number of entries equals the expected number
            if (entries.size() == KEY.length) {
                // Gets a GPSAlmanac from the entries
                final GPSAlmanac almanac = getAlmanac(entries, name);
                // Adds the GPSAlmanac to the list
                almanacs.add(almanac);
                // Adds the PRN number of the GPSAlmanac to the list
                prnList.add(almanac.getPRN());
                // Clears the entries
                entries.clear();
            }
        }
    } catch (IOException ioe) {
        throw new OrekitException(OrekitMessages.NOT_A_SUPPORTED_YUMA_ALMANAC_FILE, name);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) OrekitException(org.orekit.errors.OrekitException) IOException(java.io.IOException) Pair(org.hipparchus.util.Pair)

Example 4 with Pair

use of org.hipparchus.util.Pair in project Orekit by CS-SI.

the class OEMParserTest method testITRFFrames.

/**
 * Check the parser can parse several ITRF frames. Test case for #361.
 *
 * @throws OrekitException on error.
 */
@Test
public void testITRFFrames() throws OrekitException {
    // setup
    Charset utf8 = StandardCharsets.UTF_8;
    IERSConventions conventions = IERSConventions.IERS_2010;
    boolean simpleEop = true;
    Frame itrf2008 = FramesFactory.getITRF(conventions, simpleEop);
    OEMParser parser = new OEMParser().withSimpleEOP(simpleEop).withConventions(conventions);
    // frames to check
    List<Pair<String, Frame>> frames = new ArrayList<>();
    frames.add(new Pair<>("ITRF-93", Predefined.ITRF_2008_TO_ITRF_93.createTransformedITRF(itrf2008, "ITRF93")));
    frames.add(new Pair<>("ITRF-97", Predefined.ITRF_2008_TO_ITRF_97.createTransformedITRF(itrf2008, "ITRF97")));
    frames.add(new Pair<>("ITRF2000", Predefined.ITRF_2008_TO_ITRF_2000.createTransformedITRF(itrf2008, "ITRF2000")));
    frames.add(new Pair<>("ITRF2005", Predefined.ITRF_2008_TO_ITRF_2005.createTransformedITRF(itrf2008, "ITRF2005")));
    frames.add(new Pair<>("ITRF2008", itrf2008));
    for (Pair<String, Frame> frame : frames) {
        final String frameName = frame.getFirst();
        InputStream pre = OEMParserTest.class.getResourceAsStream("/ccsds/OEMExample7.txt.pre");
        InputStream middle = new ByteArrayInputStream(("REF_FRAME = " + frameName).getBytes(utf8));
        InputStream post = OEMParserTest.class.getResourceAsStream("/ccsds/OEMExample7.txt.post");
        InputStream input = new SequenceInputStream(pre, new SequenceInputStream(middle, post));
        // action
        OEMFile actual = parser.parse(input);
        // verify
        EphemeridesBlock actualBlock = actual.getEphemeridesBlocks().get(0);
        Assert.assertEquals(actualBlock.getFrameString(), frameName);
        // check expected frame
        Frame actualFrame = actualBlock.getFrame();
        Frame expectedFrame = frame.getSecond();
        Assert.assertEquals(actualFrame.getName(), expectedFrame.getName());
        Assert.assertEquals(actualFrame.getTransformProvider(), expectedFrame.getTransformProvider());
    }
}
Also used : Frame(org.orekit.frames.Frame) FactoryManagedFrame(org.orekit.frames.FactoryManagedFrame) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) IERSConventions(org.orekit.utils.IERSConventions) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) EphemeridesBlock(org.orekit.files.ccsds.OEMFile.EphemeridesBlock) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Pair(org.hipparchus.util.Pair) Test(org.junit.Test)

Aggregations

Pair (org.hipparchus.util.Pair)4 OrekitException (org.orekit.errors.OrekitException)3 ArrayList (java.util.ArrayList)2 OrekitExceptionWrapper (org.orekit.errors.OrekitExceptionWrapper)2 NumericalPropagator (org.orekit.propagation.numerical.NumericalPropagator)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 SequenceInputStream (java.io.SequenceInputStream)1 Charset (java.nio.charset.Charset)1 ArrayRealVector (org.hipparchus.linear.ArrayRealVector)1 RealMatrix (org.hipparchus.linear.RealMatrix)1 RealVector (org.hipparchus.linear.RealVector)1 MultivariateJacobianFunction (org.hipparchus.optim.nonlinear.vector.leastsquares.MultivariateJacobianFunction)1 Test (org.junit.Test)1 EphemeridesBlock (org.orekit.files.ccsds.OEMFile.EphemeridesBlock)1 FactoryManagedFrame (org.orekit.frames.FactoryManagedFrame)1 Frame (org.orekit.frames.Frame)1