Search in sources :

Example 41 with OrekitException

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

the class SP3Parser method parse.

@Override
public SP3File parse(final BufferedReader reader, final String fileName) throws OrekitException, IOException {
    // initialize internal data structures
    final ParseInfo pi = new ParseInfo();
    int lineNumber = 0;
    Stream<LineParser> candidateParsers = Stream.of(LineParser.HEADER_VERSION);
    for (String line = reader.readLine(); line != null; line = reader.readLine()) {
        ++lineNumber;
        final String l = line;
        final Optional<LineParser> selected = candidateParsers.filter(p -> p.canHandle(l)).findFirst();
        if (selected.isPresent()) {
            try {
                selected.get().parse(line, pi);
            } catch (StringIndexOutOfBoundsException | NumberFormatException e) {
                throw new OrekitException(e, OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, fileName, line);
            }
            candidateParsers = selected.get().allowedNext();
        } else {
            throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, fileName, line);
        }
        if (pi.done) {
            if (pi.nbEpochs != pi.file.getNumberOfEpochs()) {
                throw new OrekitException(OrekitMessages.SP3_NUMBER_OF_EPOCH_MISMATCH, pi.nbEpochs, fileName, pi.file.getNumberOfEpochs());
            }
            return pi.file;
        }
    }
    // we never reached the EOF marker
    throw new OrekitException(OrekitMessages.SP3_UNEXPECTED_END_OF_FILE, lineNumber);
}
Also used : CartesianDerivativesFilter(org.orekit.utils.CartesianDerivativesFilter) SP3Coordinate(org.orekit.files.sp3.SP3File.SP3Coordinate) Frame(org.orekit.frames.Frame) TimeScale(org.orekit.time.TimeScale) Scanner(java.util.Scanner) IERSConventions(org.orekit.utils.IERSConventions) Function(java.util.function.Function) OrekitExceptionWrapper(org.orekit.errors.OrekitExceptionWrapper) Locale(java.util.Locale) EphemerisFileParser(org.orekit.files.general.EphemerisFileParser) TimeSystem(org.orekit.files.sp3.SP3File.TimeSystem) Constants(org.orekit.utils.Constants) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) Files(java.nio.file.Files) FramesFactory(org.orekit.frames.FramesFactory) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) StandardCharsets(java.nio.charset.StandardCharsets) OrekitMessages(org.orekit.errors.OrekitMessages) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) OrekitException(org.orekit.errors.OrekitException) TimeScalesFactory(org.orekit.time.TimeScalesFactory) Optional(java.util.Optional) BufferedReader(java.io.BufferedReader) Pattern(java.util.regex.Pattern) SP3FileType(org.orekit.files.sp3.SP3File.SP3FileType) SP3OrbitType(org.orekit.files.sp3.SP3File.SP3OrbitType) InputStream(java.io.InputStream) AbsoluteDate(org.orekit.time.AbsoluteDate) OrekitException(org.orekit.errors.OrekitException)

Example 42 with OrekitException

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

the class DTM2000 method readcoefficients.

/**
 * Store the DTM model elements coefficients in internal arrays.
 * @exception OrekitException if some resource file reading error occurs
 */
private static void readcoefficients() throws OrekitException {
    final int size = NLATM + 1;
    tt = new double[size];
    h = new double[size];
    he = new double[size];
    o = new double[size];
    az2 = new double[size];
    o2 = new double[size];
    az = new double[size];
    t0 = new double[size];
    tp = new double[size];
    final InputStream in = DTM2000.class.getResourceAsStream(DTM2000);
    if (in == null) {
        throw new OrekitException(OrekitMessages.UNABLE_TO_FIND_RESOURCE, DTM2000);
    }
    BufferedReader r = null;
    try {
        r = new BufferedReader(new InputStreamReader(in, "UTF-8"));
        r.readLine();
        r.readLine();
        for (String line = r.readLine(); line != null; line = r.readLine()) {
            final int num = Integer.parseInt(line.substring(0, 4).replace(' ', '0'));
            line = line.substring(4);
            tt[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
            line = line.substring(13 + 9);
            h[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
            line = line.substring(13 + 9);
            he[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
            line = line.substring(13 + 9);
            o[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
            line = line.substring(13 + 9);
            az2[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
            line = line.substring(13 + 9);
            o2[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
            line = line.substring(13 + 9);
            az[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
            line = line.substring(13 + 9);
            t0[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
            line = line.substring(13 + 9);
            tp[num] = Double.parseDouble(line.substring(0, 13).replace(' ', '0'));
        }
    } catch (IOException ioe) {
        throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
    } finally {
        if (r != null) {
            try {
                r.close();
            } catch (IOException ioe) {
                throw new OrekitException(ioe, new DummyLocalizable(ioe.getMessage()));
            }
        }
    }
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) OrekitException(org.orekit.errors.OrekitException) IOException(java.io.IOException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) FieldGeodeticPoint(org.orekit.bodies.FieldGeodeticPoint)

Example 43 with OrekitException

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

the class DTM2000 method getDensity.

/**
 * {@inheritDoc}
 */
@Override
public <T extends RealFieldElement<T>> T getDensity(final FieldAbsoluteDate<T> date, final FieldVector3D<T> position, final Frame frame) throws OrekitException {
    // check if data are available :
    final AbsoluteDate dateD = date.toAbsoluteDate();
    if ((dateD.compareTo(inputParams.getMaxDate()) > 0) || (dateD.compareTo(inputParams.getMinDate()) < 0)) {
        throw new OrekitException(OrekitMessages.NO_SOLAR_ACTIVITY_AT_DATE, dateD, inputParams.getMinDate(), inputParams.getMaxDate());
    }
    // compute day number in current year
    final Calendar cal = new GregorianCalendar();
    cal.setTime(date.toDate(TimeScalesFactory.getUTC()));
    final int day = cal.get(Calendar.DAY_OF_YEAR);
    // position in ECEF so we only have to do the transform once
    final Frame ecef = earth.getBodyFrame();
    final FieldVector3D<T> pEcef = frame.getTransformTo(ecef, date).transformPosition(position);
    // compute geodetic position
    final FieldGeodeticPoint<T> inBody = earth.transform(pEcef, ecef, date);
    final T alti = inBody.getAltitude();
    final T lon = inBody.getLongitude();
    final T lat = inBody.getLatitude();
    // compute local solar time
    final Vector3D sunPos = sun.getPVCoordinates(dateD, ecef).getPosition();
    final T y = pEcef.getY().multiply(sunPos.getX()).subtract(pEcef.getX().multiply(sunPos.getY()));
    final T x = pEcef.getX().multiply(sunPos.getX()).add(pEcef.getY().multiply(sunPos.getY()));
    final T hl = y.atan2(x).add(FastMath.PI);
    // get current solar activity data and compute
    return getDensity(day, alti, lon, lat, hl, inputParams.getInstantFlux(dateD), inputParams.getMeanFlux(dateD), inputParams.getThreeHourlyKP(dateD), inputParams.get24HoursKp(dateD));
}
Also used : Frame(org.orekit.frames.Frame) Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) OrekitException(org.orekit.errors.OrekitException) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate) GeodeticPoint(org.orekit.bodies.GeodeticPoint) FieldGeodeticPoint(org.orekit.bodies.FieldGeodeticPoint)

Example 44 with OrekitException

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

the class ICGEMFormatReader method loadData.

/**
 * {@inheritDoc}
 */
public void loadData(final InputStream input, final String name) throws IOException, ParseException, OrekitException {
    // reset the indicator before loading any data
    setReadComplete(false);
    referenceDate = null;
    cTrend.clear();
    sTrend.clear();
    cCos.clear();
    cSin.clear();
    sCos.clear();
    sSin.clear();
    // by default, the field is normalized with unknown tide system
    // (will be overridden later if non-default)
    normalized = true;
    tideSystem = TideSystem.UNKNOWN;
    final BufferedReader r = new BufferedReader(new InputStreamReader(input, "UTF-8"));
    boolean inHeader = true;
    double[][] c = null;
    double[][] s = null;
    boolean okCoeffs = false;
    int lineNumber = 0;
    for (String line = r.readLine(); line != null; line = r.readLine()) {
        try {
            ++lineNumber;
            if (line.trim().length() == 0) {
                continue;
            }
            final String[] tab = line.split("\\s+");
            if (inHeader) {
                if ((tab.length == 2) && PRODUCT_TYPE.equals(tab[0])) {
                    if (!GRAVITY_FIELD.equals(tab[1])) {
                        throw new OrekitParseException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, line);
                    }
                } else if ((tab.length == 2) && tab[0].endsWith(GRAVITY_CONSTANT)) {
                    setMu(parseDouble(tab[1]));
                } else if ((tab.length == 2) && REFERENCE_RADIUS.equals(tab[0])) {
                    setAe(parseDouble(tab[1]));
                } else if ((tab.length == 2) && MAX_DEGREE.equals(tab[0])) {
                    final int degree = FastMath.min(getMaxParseDegree(), Integer.parseInt(tab[1]));
                    final int order = FastMath.min(getMaxParseOrder(), degree);
                    c = buildTriangularArray(degree, order, missingCoefficientsAllowed() ? 0.0 : Double.NaN);
                    s = buildTriangularArray(degree, order, missingCoefficientsAllowed() ? 0.0 : Double.NaN);
                } else if ((tab.length == 2) && TIDE_SYSTEM_INDICATOR.equals(tab[0])) {
                    if (ZERO_TIDE.equals(tab[1])) {
                        tideSystem = TideSystem.ZERO_TIDE;
                    } else if (TIDE_FREE.equals(tab[1])) {
                        tideSystem = TideSystem.TIDE_FREE;
                    } else if (TIDE_UNKNOWN.equals(tab[1])) {
                        tideSystem = TideSystem.UNKNOWN;
                    } else {
                        throw new OrekitParseException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, line);
                    }
                } else if ((tab.length == 2) && NORMALIZATION_INDICATOR.equals(tab[0])) {
                    if (NORMALIZED.equals(tab[1])) {
                        normalized = true;
                    } else if (UNNORMALIZED.equals(tab[1])) {
                        normalized = false;
                    } else {
                        throw new OrekitParseException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, line);
                    }
                } else if ((tab.length == 2) && END_OF_HEADER.equals(tab[0])) {
                    inHeader = false;
                }
            } else {
                if ((tab.length == 7 && GFC.equals(tab[0])) || (tab.length == 8 && GFCT.equals(tab[0]))) {
                    final int i = Integer.parseInt(tab[1]);
                    final int j = Integer.parseInt(tab[2]);
                    if (i < c.length && j < c[i].length) {
                        parseCoefficient(tab[3], c, i, j, "C", name);
                        parseCoefficient(tab[4], s, i, j, "S", name);
                        okCoeffs = true;
                        if (tab.length == 8) {
                            // check the reference date (format yyyymmdd)
                            final DateComponents localRef = new DateComponents(Integer.parseInt(tab[7].substring(0, 4)), Integer.parseInt(tab[7].substring(4, 6)), Integer.parseInt(tab[7].substring(6, 8)));
                            if (referenceDate == null) {
                                // first reference found, store it
                                referenceDate = localRef;
                            } else if (!referenceDate.equals(localRef)) {
                                throw new OrekitException(OrekitMessages.SEVERAL_REFERENCE_DATES_IN_GRAVITY_FIELD, referenceDate, localRef, name);
                            }
                        }
                    }
                } else if (tab.length == 7 && (DOT.equals(tab[0]) || TRND.equals(tab[0]))) {
                    final int i = Integer.parseInt(tab[1]);
                    final int j = Integer.parseInt(tab[2]);
                    if (i < c.length && j < c[i].length) {
                        // store the secular trend coefficients
                        extendListOfLists(cTrend, i, j, 0.0);
                        extendListOfLists(sTrend, i, j, 0.0);
                        parseCoefficient(tab[3], cTrend, i, j, "Ctrend", name);
                        parseCoefficient(tab[4], sTrend, i, j, "Strend", name);
                    }
                } else if (tab.length == 8 && (ASIN.equals(tab[0]) || ACOS.equals(tab[0]))) {
                    final int i = Integer.parseInt(tab[1]);
                    final int j = Integer.parseInt(tab[2]);
                    if (i < c.length && j < c[i].length) {
                        // extract arrays corresponding to period
                        final Double period = Double.valueOf(tab[7]);
                        if (!cCos.containsKey(period)) {
                            cCos.put(period, new ArrayList<List<Double>>());
                            cSin.put(period, new ArrayList<List<Double>>());
                            sCos.put(period, new ArrayList<List<Double>>());
                            sSin.put(period, new ArrayList<List<Double>>());
                        }
                        final List<List<Double>> cCosPeriod = cCos.get(period);
                        final List<List<Double>> cSinPeriod = cSin.get(period);
                        final List<List<Double>> sCosPeriod = sCos.get(period);
                        final List<List<Double>> sSinPeriod = sSin.get(period);
                        // store the pulsation coefficients
                        extendListOfLists(cCosPeriod, i, j, 0.0);
                        extendListOfLists(cSinPeriod, i, j, 0.0);
                        extendListOfLists(sCosPeriod, i, j, 0.0);
                        extendListOfLists(sSinPeriod, i, j, 0.0);
                        if (ACOS.equals(tab[0])) {
                            parseCoefficient(tab[3], cCosPeriod, i, j, "Ccos", name);
                            parseCoefficient(tab[4], sCosPeriod, i, j, "SCos", name);
                        } else {
                            parseCoefficient(tab[3], cSinPeriod, i, j, "Csin", name);
                            parseCoefficient(tab[4], sSinPeriod, i, j, "Ssin", name);
                        }
                    }
                } else {
                    throw new OrekitParseException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, line);
                }
            }
        } catch (NumberFormatException nfe) {
            final OrekitParseException pe = new OrekitParseException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, line);
            pe.initCause(nfe);
            throw pe;
        }
    }
    if (missingCoefficientsAllowed() && c.length > 0 && c[0].length > 0) {
        // ensure at least the (0, 0) element is properly set
        if (Precision.equals(c[0][0], 0.0, 0)) {
            c[0][0] = 1.0;
        }
    }
    if (Double.isNaN(getAe()) || Double.isNaN(getMu()) || !okCoeffs) {
        String loaderName = getClass().getName();
        loaderName = loaderName.substring(loaderName.lastIndexOf('.') + 1);
        throw new OrekitException(OrekitMessages.UNEXPECTED_FILE_FORMAT_ERROR_FOR_LOADER, name, loaderName);
    }
    setRawCoefficients(normalized, c, s, name);
    setTideSystem(tideSystem);
    setReadComplete(true);
}
Also used : InputStreamReader(java.io.InputStreamReader) DateComponents(org.orekit.time.DateComponents) OrekitParseException(org.orekit.errors.OrekitParseException) BufferedReader(java.io.BufferedReader) OrekitException(org.orekit.errors.OrekitException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 45 with OrekitException

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

the class HarrisPriester method getDensity.

/**
 * Get the local density.
 * @param sunInEarth position of the Sun in Earth frame (m)
 * @param posInEarth target position in Earth frame (m)
 * @return the local density (kg/m³)
 * @exception OrekitException if altitude is below the model minimal altitude
 */
public double getDensity(final Vector3D sunInEarth, final Vector3D posInEarth) throws OrekitException {
    final double posAlt = getHeight(posInEarth);
    // Check for height boundaries
    if (posAlt < getMinAlt()) {
        throw new OrekitException(OrekitMessages.ALTITUDE_BELOW_ALLOWED_THRESHOLD, posAlt, getMinAlt());
    }
    if (posAlt > getMaxAlt()) {
        return 0.;
    }
    // Diurnal bulge apex direction
    final Vector3D sunDir = sunInEarth.normalize();
    final Vector3D bulDir = new Vector3D(sunDir.getX() * COSLAG - sunDir.getY() * SINLAG, sunDir.getX() * SINLAG + sunDir.getY() * COSLAG, sunDir.getZ());
    // Cosine of angle Psi between the diurnal bulge apex and the satellite
    final double cosPsi = bulDir.normalize().dotProduct(posInEarth.normalize());
    // (1 + cos(Psi))/2 = cos²(Psi/2)
    final double c2Psi2 = (1. + cosPsi) / 2.;
    final double cPsi2 = FastMath.sqrt(c2Psi2);
    final double cosPow = (cPsi2 > MIN_COS) ? c2Psi2 * FastMath.pow(cPsi2, n - 2) : 0.;
    // Search altitude index in density table
    int ia = 0;
    while (ia < tabAltRho.length - 2 && posAlt > tabAltRho[ia + 1][0]) {
        ia++;
    }
    // Fractional satellite height
    final double dH = (tabAltRho[ia][0] - posAlt) / (tabAltRho[ia][0] - tabAltRho[ia + 1][0]);
    // Min exponential density interpolation
    final double rhoMin = tabAltRho[ia][1] * FastMath.pow(tabAltRho[ia + 1][1] / tabAltRho[ia][1], dH);
    if (Precision.equals(cosPow, 0.)) {
        return rhoMin;
    } else {
        // Max exponential density interpolation
        final double rhoMax = tabAltRho[ia][2] * FastMath.pow(tabAltRho[ia + 1][2] / tabAltRho[ia][2], dH);
        return rhoMin + (rhoMax - rhoMin) * cosPow;
    }
}
Also used : Vector3D(org.hipparchus.geometry.euclidean.threed.Vector3D) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) OrekitException(org.orekit.errors.OrekitException)

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