Search in sources :

Example 36 with OrekitException

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

the class EGMFormatReader 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);
    // file...)
    if (this.useWgs84Coefficients) {
        setAe(Constants.WGS84_EARTH_EQUATORIAL_RADIUS);
        setMu(Constants.WGS84_EARTH_MU);
    } else {
        setAe(Constants.EGM96_EARTH_EQUATORIAL_RADIUS);
        setMu(Constants.EGM96_EARTH_MU);
    }
    final String lowerCaseName = name.toLowerCase(Locale.US);
    if (lowerCaseName.contains("2008") || lowerCaseName.contains("zerotide")) {
        setTideSystem(TideSystem.ZERO_TIDE);
    } else {
        setTideSystem(TideSystem.TIDE_FREE);
    }
    final BufferedReader r = new BufferedReader(new InputStreamReader(input, "UTF-8"));
    final List<List<Double>> c = new ArrayList<List<Double>>();
    final List<List<Double>> s = new ArrayList<List<Double>>();
    boolean okFields = true;
    for (String line = r.readLine(); okFields && line != null; line = r.readLine()) {
        if (line.length() >= 15) {
            // get the fields defining the current the potential terms
            final String[] tab = line.trim().split("\\s+");
            if (tab.length != 6) {
                okFields = false;
            }
            final int i = Integer.parseInt(tab[0]);
            final int j = Integer.parseInt(tab[1]);
            if (i <= getMaxParseDegree() && j <= getMaxParseOrder()) {
                for (int k = 0; k <= i; ++k) {
                    extendListOfLists(c, k, FastMath.min(k, getMaxParseOrder()), missingCoefficientsAllowed() ? 0.0 : Double.NaN);
                    extendListOfLists(s, k, FastMath.min(k, getMaxParseOrder()), missingCoefficientsAllowed() ? 0.0 : Double.NaN);
                }
                parseCoefficient(tab[2], c, i, j, "C", name);
                parseCoefficient(tab[3], s, i, j, "S", name);
            }
        }
    }
    if (missingCoefficientsAllowed() && getMaxParseDegree() > 0 && getMaxParseOrder() > 0) {
        // ensure at least the (0, 0) element is properly set
        extendListOfLists(c, 0, 0, 0.0);
        extendListOfLists(s, 0, 0, 0.0);
        if (Precision.equals(c.get(0).get(0), 0.0, 0)) {
            c.get(0).set(0, 1.0);
        }
    }
    if ((!okFields) || (c.size() < 1)) {
        String loaderName = getClass().getName();
        loaderName = loaderName.substring(loaderName.lastIndexOf('.') + 1);
        throw new OrekitException(OrekitMessages.UNEXPECTED_FILE_FORMAT_ERROR_FOR_LOADER, name, loaderName);
    }
    setRawCoefficients(true, toArray(c), toArray(s), name);
    setReadComplete(true);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) OrekitException(org.orekit.errors.OrekitException)

Example 37 with OrekitException

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

the class FESCnmSnmReader method loadData.

/**
 * {@inheritDoc}
 */
@Override
public void loadData(final InputStream input, final String name) throws OrekitException, IOException {
    // FES ocean tides models have the following form:
    // Coefficients to compute variations in normalized Stokes coefficients (unit = 10^-12)
    // Ocean tide model: FES2004 normalized model (fev. 2004) up to (100,100)
    // (long period from FES2002 up to (50,50) + equilibrium Om1/Om2, atmospheric tide NOT included)
    // Doodson Darw  l   m    DelC+     DelS+       DelC-     DelS-
    // 55.565 Om1   2   0   6.58128  -0.00000    -0.00000  -0.00000
    // 55.575 Om2   2   0  -0.06330   0.00000     0.00000   0.00000
    // 56.554 Sa    1   0  -0.00000  -0.00000    -0.00000  -0.00000
    // 56.554 Sa    2   0   0.56720   0.01099    -0.00000  -0.00000
    // 56.554 Sa    3   0   0.00908  -0.00050    -0.00000  -0.00000
    final String[] fieldsPatterns = new String[] { DOODSON_TYPE_PATTERN, UNKNOWN_TYPE_PATTERN, INTEGER_TYPE_PATTERN, INTEGER_TYPE_PATTERN, REAL_TYPE_PATTERN, REAL_TYPE_PATTERN, REAL_TYPE_PATTERN, REAL_TYPE_PATTERN };
    final StringBuilder builder = new StringBuilder("^\\p{Space}*");
    for (int i = 0; i < fieldsPatterns.length; ++i) {
        builder.append("(");
        builder.append(fieldsPatterns[i]);
        builder.append(")");
        builder.append((i < fieldsPatterns.length - 1) ? "\\p{Space}+" : "\\p{Space}*$");
    }
    final Pattern regularLinePattern = Pattern.compile(builder.toString());
    // parse the file
    startParse(name);
    final BufferedReader r = new BufferedReader(new InputStreamReader(input, "UTF-8"));
    int lineNumber = 0;
    boolean dataStarted = false;
    for (String line = r.readLine(); line != null; line = r.readLine()) {
        ++lineNumber;
        final Matcher regularMatcher = regularLinePattern.matcher(line);
        if (regularMatcher.matches()) {
            // we have found a regular data line
            // parse Doodson, degree and order fields
            final int doodson = Integer.parseInt(regularMatcher.group(1).replaceAll("[.,]", ""));
            final int n = Integer.parseInt(regularMatcher.group(3));
            final int m = Integer.parseInt(regularMatcher.group(4));
            if (canAdd(n, m)) {
                // parse coefficients
                final double cPlus = scale * Double.parseDouble(regularMatcher.group(5));
                final double sPlus = scale * Double.parseDouble(regularMatcher.group(6));
                final double cMinus = scale * Double.parseDouble(regularMatcher.group(7));
                final double sMinus = scale * Double.parseDouble(regularMatcher.group(8));
                // store parsed fields
                addWaveCoefficients(doodson, n, m, cPlus, sPlus, cMinus, sMinus, lineNumber, line);
                dataStarted = true;
            }
        } else if (dataStarted) {
            // all remaining lines should also be data lines
            throw new OrekitException(OrekitMessages.UNABLE_TO_PARSE_LINE_IN_FILE, lineNumber, name, line);
        }
    }
    endParse();
}
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 38 with OrekitException

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

the class JB2008 method getDensity.

/**
 * Get the local density with initial entries.
 * @param dateMJD date and time, in modified julian days and fraction
 * @param sunRA Right Ascension of Sun (radians)
 * @param sunDecli Declination of Sun (radians)
 * @param satLon Right Ascension of position (radians)
 * @param satLat Geocentric latitude of position (radians)
 * @param satAlt Height of position (m)
 * @param f10 10.7-cm Solar flux (1e<sup>-22</sup>*Watt/(m²*Hertz))<br>
 *        (Tabular time 1.0 day earlier)
 * @param f10B 10.7-cm Solar Flux, averaged 81-day centered on the input time<br>
 *        (Tabular time 1.0 day earlier)
 * @param s10 EUV index (26-34 nm) scaled to F10<br>
 *        (Tabular time 1 day earlier)
 * @param s10B UV 81-day averaged centered index
 *        (Tabular time 1 day earlier)
 * @param xm10 MG2 index scaled to F10<br>
 *        (Tabular time 2.0 days earlier)
 * @param xm10B MG2 81-day ave. centered index<br>
 *        (Tabular time 2.0 days earlier)
 * @param y10 Solar X-Ray & Lya index scaled to F10<br>
 *        (Tabular time 5.0 days earlier)
 * @param y10B Solar X-Ray & Lya 81-day ave. centered index<br>
 *        (Tabular time 5.0 days earlier)
 * @param dstdtc Temperature change computed from Dst index
 * @return total mass-Density at input position (kg/m³)
 * @exception OrekitException if altitude is below 90 km
 */
public double getDensity(final double dateMJD, final double sunRA, final double sunDecli, final double satLon, final double satLat, final double satAlt, final double f10, final double f10B, final double s10, final double s10B, final double xm10, final double xm10B, final double y10, final double y10B, final double dstdtc) throws OrekitException {
    if (satAlt < ALT_MIN) {
        throw new OrekitException(OrekitMessages.ALTITUDE_BELOW_ALLOWED_THRESHOLD, satAlt, ALT_MIN);
    }
    final double altKm = satAlt / 1000.0;
    // Equation (14)
    final double fn = FastMath.min(1.0, FastMath.pow(f10B / 240., 0.25));
    final double fsb = f10B * fn + s10B * (1. - fn);
    final double tsubc = 392.4 + 3.227 * fsb + 0.298 * (f10 - f10B) + 2.259 * (s10 - s10B) + 0.312 * (xm10 - xm10B) + 0.178 * (y10 - y10B);
    // Equation (15)
    final double eta = 0.5 * FastMath.abs(satLat - sunDecli);
    final double theta = 0.5 * FastMath.abs(satLat + sunDecli);
    // Equation (16)
    final double h = satLon - sunRA;
    final double tau = h - 0.64577182 + 0.10471976 * FastMath.sin(h + 0.75049158);
    double solarTime = FastMath.toDegrees(h + FastMath.PI) / 15.0;
    while (solarTime >= 24) {
        solarTime -= 24.;
    }
    while (solarTime < 0) {
        solarTime += 24.;
    }
    // Equation (17)
    final double cosEta = FastMath.pow(FastMath.cos(eta), 2.5);
    final double sinTeta = FastMath.pow(FastMath.sin(theta), 2.5);
    final double cosTau = FastMath.abs(FastMath.cos(0.5 * tau));
    final double df = sinTeta + (cosEta - sinTeta) * cosTau * cosTau * cosTau;
    final double tsubl = tsubc * (1. + 0.31 * df);
    // Compute correction to dTc for local solar time and lat correction
    final double dtclst = dTc(f10, solarTime, satLat, altKm);
    // Compute the local exospheric temperature.
    // Add geomagnetic storm effect from input dTc value
    final double[] temp = new double[2];
    temp[0] = tsubl + dstdtc;
    final double tinf = temp[0] + dtclst;
    // Equation (9)
    final double tsubx = 444.3807 + 0.02385 * tinf - 392.8292 * FastMath.exp(-0.0021357 * tinf);
    // Equation (11)
    final double gsubx = 0.054285714 * (tsubx - 183.);
    // The TC array will be an argument in the call to localTemp,
    // which evaluates Eq. (10) or (13)
    final double[] tc = new double[4];
    tc[0] = tsubx;
    tc[1] = gsubx;
    // A of Equation (13)
    tc[2] = (tinf - tsubx) * 2. / FastMath.PI;
    tc[3] = gsubx / tc[2];
    // Equation (5)
    final double z1 = 90.;
    final double z2 = FastMath.min(altKm, 105.0);
    double al = FastMath.log(z2 / z1);
    int n = 1 + (int) FastMath.floor(al / R1);
    double zr = FastMath.exp(al / n);
    final double mb1 = mBar(z1);
    final double tloc1 = localTemp(z1, tc);
    double zend = z1;
    double sub2 = 0.;
    double ain = mb1 * gravity(z1) / tloc1;
    double mb2 = 0;
    double tloc2 = 0;
    double z = 0;
    double gravl = 0;
    for (int i = 0; i < n; ++i) {
        z = zend;
        zend = zr * z;
        final double dz = 0.25 * (zend - z);
        double sum1 = WT[0] * ain;
        for (int j = 1; j < 5; ++j) {
            z += dz;
            mb2 = mBar(z);
            tloc2 = localTemp(z, tc);
            gravl = gravity(z);
            ain = mb2 * gravl / tloc2;
            sum1 += WT[j] * ain;
        }
        sub2 += dz * sum1;
    }
    double rho = 3.46e-6 * mb2 * tloc1 / FastMath.exp(sub2 / RSTAR) / (mb1 * tloc2);
    // Equation (2)
    final double anm = AVOGAD * rho;
    final double an = anm / mb2;
    // Equation (3)
    double fact2 = anm / 28.960;
    final double[] aln = new double[6];
    aln[0] = FastMath.log(FRAC[0] * fact2);
    aln[3] = FastMath.log(FRAC[2] * fact2);
    aln[4] = FastMath.log(FRAC[3] * fact2);
    // Equation (4)
    aln[1] = FastMath.log(fact2 * (1. + FRAC[1]) - an);
    aln[2] = FastMath.log(2. * (an - fact2));
    if (altKm <= 105.0) {
        temp[1] = tloc2;
        // Put in negligible hydrogen for use in DO-LOOP 13
        aln[5] = aln[4] - 25.0;
    } else {
        // Equation (6)
        al = FastMath.log(FastMath.min(altKm, 500.0) / z);
        n = 1 + (int) FastMath.floor(al / R2);
        zr = FastMath.exp(al / n);
        sub2 = 0.;
        ain = gravl / tloc2;
        double tloc3 = 0;
        for (int i = 0; i < n; ++i) {
            z = zend;
            zend = zr * z;
            final double dz = 0.25 * (zend - z);
            double sum1 = WT[0] * ain;
            for (int j = 1; j < 5; ++j) {
                z += dz;
                tloc3 = localTemp(z, tc);
                gravl = gravity(z);
                ain = gravl / tloc3;
                sum1 += WT[j] * ain;
            }
            sub2 += dz * sum1;
        }
        al = FastMath.log(FastMath.max(altKm, 500.0) / z);
        final double r = (altKm > 500.0) ? R3 : R2;
        n = 1 + (int) FastMath.floor(al / r);
        zr = FastMath.exp(al / n);
        double sum3 = 0.;
        double tloc4 = 0;
        for (int i = 0; i < n; ++i) {
            z = zend;
            zend = zr * z;
            final double dz = 0.25 * (zend - z);
            double sum1 = WT[0] * ain;
            for (int j = 1; j < 5; ++j) {
                z += dz;
                tloc4 = localTemp(z, tc);
                gravl = gravity(z);
                ain = gravl / tloc4;
                sum1 += WT[j] * ain;
            }
            sum3 += dz * sum1;
        }
        final double altr;
        final double hSign;
        if (altKm <= 500.) {
            temp[1] = tloc3;
            altr = FastMath.log(tloc3 / tloc2);
            fact2 = sub2 / RSTAR;
            hSign = 1.0;
        } else {
            temp[1] = tloc4;
            altr = FastMath.log(tloc4 / tloc2);
            fact2 = (sub2 + sum3) / RSTAR;
            hSign = -1.0;
        }
        for (int i = 0; i < 5; ++i) {
            aln[i] = aln[i] - (1.0 + ALPHA[i]) * altr - fact2 * AMW[i];
        }
        // Equation (7)
        final double al10t5 = FastMath.log10(tinf);
        final double alnh5 = (5.5 * al10t5 - 39.40) * al10t5 + 73.13;
        aln[5] = LOG10 * (alnh5 + 6.) + hSign * (FastMath.log(tloc4 / tloc3) + sum3 * AMW[5] / RSTAR);
    }
    // Equation (24) - J70 Seasonal-Latitudinal Variation
    final double capPhi = ((dateMJD - 36204.0) / 365.2422) % 1;
    final int signum = (satLat >= 0.) ? 1 : -1;
    final double sinLat = FastMath.sin(satLat);
    final double hm90 = altKm - 90.;
    final double dlrsl = 0.02 * hm90 * FastMath.exp(-0.045 * hm90) * signum * FastMath.sin(MathUtils.TWO_PI * capPhi + 1.72) * sinLat * sinLat;
    // Equation (23) - Computes the semiannual variation
    double dlrsa = 0;
    if (z < 2000.0) {
        // Use new semiannual model dLog(rho)
        dlrsa = semian08(dayOfYear(dateMJD), altKm, f10B, s10B, xm10B);
    }
    // Sum the delta-log-rhos and apply to the number densities.
    // In CIRA72 the following equation contains an actual sum,
    // namely DLR = LOG10 * (DLRGM + DLRSA + DLRSL)
    // However, for Jacchia 70, there is no DLRGM or DLRSA.
    final double dlr = LOG10 * (dlrsl + dlrsa);
    for (int i = 0; i < 6; ++i) {
        aln[i] += dlr;
    }
    // Compute mass-density and mean-molecular-weight and
    // convert number density logs from natural to common.
    double sumnm = 0.0;
    for (int i = 0; i < 6; ++i) {
        sumnm += FastMath.exp(aln[i]) * AMW[i];
    }
    rho = sumnm / AVOGAD;
    // Compute the high altitude exospheric density correction factor
    double fex = 1.0;
    if ((altKm >= 1000.0) && (altKm < 1500.0)) {
        final double zeta = (altKm - 1000.) * 0.002;
        final double f15c = CHT[0] + CHT[1] * f10B + (CHT[2] + CHT[3] * f10B) * 1500.0;
        final double f15cZeta = (CHT[2] + CHT[3] * f10B) * 500.0;
        final double fex2 = 3.0 * f15c - f15cZeta - 3.0;
        final double fex3 = f15cZeta - 2.0 * f15c + 2.0;
        fex += zeta * zeta * (fex2 + fex3 * zeta);
    } else if (altKm >= 1500.0) {
        fex = CHT[0] + CHT[1] * f10B + CHT[2] * altKm + CHT[3] * f10B * altKm;
    }
    // Apply the exospheric density correction factor.
    rho *= fex;
    return rho;
}
Also used : OrekitException(org.orekit.errors.OrekitException) GeodeticPoint(org.orekit.bodies.GeodeticPoint) FieldGeodeticPoint(org.orekit.bodies.FieldGeodeticPoint)

Example 39 with OrekitException

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

the class JB2008 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 MJD date
    final T dateMJD = date.durationFrom(AbsoluteDate.MODIFIED_JULIAN_EPOCH).divide(Constants.JULIAN_DAY);
    // compute geodetic position (km and °)
    final FieldGeodeticPoint<T> inBody = earth.transform(position, frame, date);
    // compute sun position
    final Frame ecef = earth.getBodyFrame();
    final FieldVector3D<T> sunPos = new FieldVector3D<>(date.getField(), sun.getPVCoordinates(dateD, ecef).getPosition());
    final FieldGeodeticPoint<T> sunInBody = earth.transform(sunPos, ecef, date);
    return getDensity(dateMJD, sunInBody.getLongitude(), sunInBody.getLatitude(), inBody.getLongitude(), inBody.getLatitude(), inBody.getAltitude(), inputParams.getF10(dateD), inputParams.getF10B(dateD), inputParams.getS10(dateD), inputParams.getS10B(dateD), inputParams.getXM10(dateD), inputParams.getXM10B(dateD), inputParams.getY10(dateD), inputParams.getY10B(dateD), inputParams.getDSTDTC(dateD));
}
Also used : Frame(org.orekit.frames.Frame) OrekitException(org.orekit.errors.OrekitException) FieldVector3D(org.hipparchus.geometry.euclidean.threed.FieldVector3D) FieldAbsoluteDate(org.orekit.time.FieldAbsoluteDate) AbsoluteDate(org.orekit.time.AbsoluteDate)

Example 40 with OrekitException

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

the class TDMParser method parseXml.

/**
 * Parse a CCSDS Tracking Data Message with XML format.
 * @param stream stream containing message
 * @param fileName name of the file containing the message (for error messages)
 * @return parsed file content in a TDMFile object
 * @exception OrekitException if Tracking Date Message cannot be parsed
 */
public TDMFile parseXml(final InputStream stream, final String fileName) throws OrekitException {
    try {
        // Create the handler
        final XMLHandler handler = new XMLHandler(new ParseInfo(this.getMissionReferenceDate(), this.getConventions(), this.isSimpleEOP(), fileName));
        // Create the XML SAX parser factory
        final SAXParserFactory factory = SAXParserFactory.newInstance();
        // Build the parser and read the xml file
        final SAXParser parser = factory.newSAXParser();
        parser.parse(stream, handler);
        // Get the content of the file
        final TDMFile tdmFile = handler.parseInfo.tdmFile;
        // Check time systems consistency
        tdmFile.checkTimeSystems();
        return tdmFile;
    } catch (ParserConfigurationException | SAXException | IOException e) {
        // throw caught exception as an OrekitException
        throw new OrekitException(e, new DummyLocalizable(e.getMessage()));
    }
}
Also used : DummyLocalizable(org.hipparchus.exception.DummyLocalizable) SAXParser(javax.xml.parsers.SAXParser) OrekitException(org.orekit.errors.OrekitException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) SAXParserFactory(javax.xml.parsers.SAXParserFactory) SAXException(org.xml.sax.SAXException)

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