Search in sources :

Example 51 with OrekitException

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

the class Phasing method findLatitudeCrossing.

/**
 * Find the state at which the reference latitude is crossed.
 * @param latitude latitude to search for
 * @param guessDate guess date for the crossing
 * @param endDate maximal date not to overtake
 * @param shift shift value used to evaluate the latitude function bracketing around the guess date
 * @param maxShift maximum value that the shift value can take
 * @param propagator propagator used
 * @return state at latitude crossing time
 * @throws OrekitException if state cannot be propagated
 * @throws MathRuntimeException if latitude cannot be bracketed in the search interval
 */
private SpacecraftState findLatitudeCrossing(final double latitude, final AbsoluteDate guessDate, final AbsoluteDate endDate, final double shift, final double maxShift, final Propagator propagator) throws OrekitException, MathRuntimeException {
    // function evaluating to 0 at latitude crossings
    final UnivariateFunction latitudeFunction = new UnivariateFunction() {

        /**
         * {@inheritDoc}
         */
        public double value(double x) {
            try {
                final SpacecraftState state = propagator.propagate(guessDate.shiftedBy(x));
                final Vector3D position = state.getPVCoordinates(earth.getBodyFrame()).getPosition();
                final GeodeticPoint point = earth.transform(position, earth.getBodyFrame(), state.getDate());
                return point.getLatitude() - latitude;
            } catch (OrekitException oe) {
                throw new RuntimeException(oe);
            }
        }
    };
    // try to bracket the encounter
    double span;
    if (guessDate.shiftedBy(shift).compareTo(endDate) > 0) {
        // Take a 1e-3 security margin
        span = endDate.durationFrom(guessDate) - 1e-3;
    } else {
        span = shift;
    }
    while (!UnivariateSolverUtils.isBracketing(latitudeFunction, -span, span)) {
        if (2 * span > maxShift) {
            // let the Hipparchus exception be thrown
            UnivariateSolverUtils.verifyBracketing(latitudeFunction, -span, span);
        } else if (guessDate.shiftedBy(2 * span).compareTo(endDate) > 0) {
            // Out of range :
            return null;
        }
        // expand the search interval
        span *= 2;
    }
    // find the encounter in the bracketed interval
    final BaseUnivariateSolver<UnivariateFunction> solver = new BracketingNthOrderBrentSolver(0.1, 5);
    final double dt = solver.solve(1000, latitudeFunction, -span, span);
    return propagator.propagate(guessDate.shiftedBy(dt));
}
Also used : SpacecraftState(org.orekit.propagation.SpacecraftState) MathRuntimeException(org.hipparchus.exception.MathRuntimeException) UnivariateFunction(org.hipparchus.analysis.UnivariateFunction) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) BracketingNthOrderBrentSolver(org.hipparchus.analysis.solvers.BracketingNthOrderBrentSolver)

Example 52 with OrekitException

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

the class OrbitDetermination method readMeasurements.

/**
 * Read a measurements file.
 * @param file measurements file
 * @param stations name to stations data map
 * @param pvData PV measurements data
 * @param satRangeBias range bias due to transponder delay
 * @param weights base weights for measurements
 * @param rangeOutliersManager manager for range measurements outliers (null if none configured)
 * @param rangeRateOutliersManager manager for range-rate measurements outliers (null if none configured)
 * @param azElOutliersManager manager for azimuth-elevation measurements outliers (null if none configured)
 * @param pvOutliersManager manager for PV measurements outliers (null if none configured)
 * @return measurements list
 */
private List<ObservedMeasurement<?>> readMeasurements(final File file, final Map<String, StationData> stations, final PVData pvData, final Bias<Range> satRangeBias, final Weights weights, final OutlierFilter<Range> rangeOutliersManager, final OutlierFilter<RangeRate> rangeRateOutliersManager, final OutlierFilter<AngularAzEl> azElOutliersManager, final OutlierFilter<PV> pvOutliersManager) throws UnsupportedEncodingException, IOException, OrekitException {
    final List<ObservedMeasurement<?>> measurements = new ArrayList<ObservedMeasurement<?>>();
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
        int lineNumber = 0;
        for (String line = br.readLine(); line != null; line = br.readLine()) {
            ++lineNumber;
            line = line.trim();
            if (line.length() > 0 && !line.startsWith("#")) {
                String[] fields = line.split("\\s+");
                if (fields.length < 2) {
                    throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, file.getName(), line);
                }
                switch(fields[1]) {
                    case "RANGE":
                        final Range range = new RangeParser().parseFields(fields, stations, pvData, satRangeBias, weights, line, lineNumber, file.getName());
                        if (rangeOutliersManager != null) {
                            range.addModifier(rangeOutliersManager);
                        }
                        addIfNonZeroWeight(range, measurements);
                        break;
                    case "RANGE_RATE":
                        final RangeRate rangeRate = new RangeRateParser().parseFields(fields, stations, pvData, satRangeBias, weights, line, lineNumber, file.getName());
                        if (rangeRateOutliersManager != null) {
                            rangeRate.addModifier(rangeRateOutliersManager);
                        }
                        addIfNonZeroWeight(rangeRate, measurements);
                        break;
                    case "AZ_EL":
                        final AngularAzEl angular = new AzElParser().parseFields(fields, stations, pvData, satRangeBias, weights, line, lineNumber, file.getName());
                        if (azElOutliersManager != null) {
                            angular.addModifier(azElOutliersManager);
                        }
                        addIfNonZeroWeight(angular, measurements);
                        break;
                    case "PV":
                        final PV pv = new PVParser().parseFields(fields, stations, pvData, satRangeBias, weights, line, lineNumber, file.getName());
                        if (pvOutliersManager != null) {
                            pv.addModifier(pvOutliersManager);
                        }
                        addIfNonZeroWeight(pv, measurements);
                        break;
                    default:
                        throw new OrekitException(LocalizedCoreFormats.SIMPLE_MESSAGE, "unknown measurement type " + fields[1] + " at line " + lineNumber + " in file " + file.getName());
                }
            }
        }
    } finally {
        if (br != null) {
            br.close();
        }
    }
    if (measurements.isEmpty()) {
        throw new OrekitException(LocalizedCoreFormats.SIMPLE_MESSAGE, "not measurements read from file " + file.getAbsolutePath());
    }
    return measurements;
}
Also used : InputStreamReader(java.io.InputStreamReader) PV(org.orekit.estimation.measurements.PV) ArrayList(java.util.ArrayList) Range(org.orekit.estimation.measurements.Range) FileInputStream(java.io.FileInputStream) GeodeticPoint(org.orekit.bodies.GeodeticPoint) BufferedReader(java.io.BufferedReader) RangeRate(org.orekit.estimation.measurements.RangeRate) OrekitException(org.orekit.errors.OrekitException) AngularAzEl(org.orekit.estimation.measurements.AngularAzEl) ObservedMeasurement(org.orekit.estimation.measurements.ObservedMeasurement)

Example 53 with OrekitException

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

the class PVCoordinatesTest method differentiate.

private Vector3D differentiate(CartesianOrbit orbit, OrbitFunction picker) {
    try {
        HermiteInterpolator interpolator = new HermiteInterpolator();
        final double step = 0.01;
        for (int i = -4; i < 4; ++i) {
            double dt = i * step;
            interpolator.addSamplePoint(dt, picker.apply(orbit.shiftedBy(dt)).toArray());
        }
        return new Vector3D(interpolator.derivatives(0.0, 1)[1]);
    } catch (OrekitException oe) {
        return null;
    }
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) OrekitException(org.orekit.errors.OrekitException) HermiteInterpolator(org.hipparchus.analysis.interpolation.HermiteInterpolator)

Example 54 with OrekitException

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

the class KeyValueFileParser method parseInput.

/**
 * Parse an input file.
 * <p>
 * The input file syntax is a set of {@code key=value} lines or
 * {@code key[i]=value} lines. Blank lines and lines starting with '#'
 * (after whitespace trimming) are silently ignored. The equal sign may
 * be surrounded by space characters. Keys must correspond to the
 * {@link Key} enumerate constants, given that matching is not case
 * sensitive and that '_' characters may appear as '.' characters in
 * the file. This means that the lines:
 * <pre>
 *   # this is the semi-major axis
 *   orbit.circular.a   = 7231582
 * </pre>
 * are perfectly right and correspond to key {@code Key#ORBIT_CIRCULAR_A} if
 * such a constant exists in the enumerate.
 * </p>
 * <p>
 * When the key[i] notation is used, all the values extracted from lines
 * with the same key will be put in a general array that will be retrieved
 * using one of the {@code getXxxArray(key)} methods. They will <em>not</em>
 * be available with the {@code getXxx(key)} methods without the {@code Array}.
 * </p>
 * @param input input stream
 * @exception IOException if input file cannot be read
 * @exception OrekitException if a line cannot be read properly
 */
public void parseInput(final String name, final InputStream input) throws IOException, OrekitException {
    final Pattern arrayPattern = Pattern.compile("([\\w\\.]+)\\s*\\[([0-9]+)\\]");
    try (final BufferedReader reader = new BufferedReader(new InputStreamReader(input, "UTF-8"))) {
        int lineNumber = 0;
        for (String line = reader.readLine(); line != null; line = reader.readLine()) {
            ++lineNumber;
            line = line.trim();
            // we ignore blank lines and line starting with '#'
            if ((line.length() > 0) && !line.startsWith("#")) {
                String[] fields = line.split("\\s*=\\s*");
                if (fields.length != 2) {
                    throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, line);
                }
                final Matcher matcher = arrayPattern.matcher(fields[0]);
                if (matcher.matches()) {
                    // this is a key[i]=value line
                    String canonicalized = matcher.group(1).toUpperCase().replaceAll("\\.", "_");
                    Key key = Key.valueOf(enumType, canonicalized);
                    Integer index = Integer.valueOf(matcher.group(2));
                    List<String> list = arrayMap.get(key);
                    if (list == null) {
                        list = new ArrayList<String>();
                        arrayMap.put(key, list);
                    }
                    while (index >= list.size()) {
                        // insert empty strings for missing elements
                        list.add("");
                    }
                    list.set(index, fields[1]);
                } else {
                    // this is a key=value line
                    String canonicalized = fields[0].toUpperCase().replaceAll("\\.", "_");
                    Key key = Key.valueOf(enumType, canonicalized);
                    scalarMap.put(key, fields[1]);
                }
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) OrekitException(org.orekit.errors.OrekitException)

Example 55 with OrekitException

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

the class DSSTPropagation 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/output (in user's home directory)
        File input = new File(new File(System.getProperty("user.home")), "dsst-propagation.in");
        File output = new File(input.getParentFile(), "dsst-propagation.out");
        new DSSTPropagation().run(input, output);
    } 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);
    } catch (ParseException pe) {
        System.err.println(pe.getLocalizedMessage());
        System.exit(1);
    }
}
Also used : DirectoryCrawler(org.orekit.data.DirectoryCrawler) DataProvidersManager(org.orekit.data.DataProvidersManager) OrekitException(org.orekit.errors.OrekitException) IOException(java.io.IOException) ParseException(java.text.ParseException) File(java.io.File)

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