OrbitCovariance.java

  1. /* Copyright 2002-2025 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.orekit.files.ccsds.ndm.odm.ocm;

  18. import java.util.List;

  19. import org.hipparchus.linear.MatrixUtils;
  20. import org.hipparchus.linear.RealMatrix;
  21. import org.orekit.time.AbsoluteDate;
  22. import org.orekit.time.TimeStamped;
  23. import org.orekit.utils.units.Unit;

  24. /** Covariance entry.
  25.  * @author Luc Maisonobe
  26.  * @since 11.0
  27.  */
  28. public class OrbitCovariance implements TimeStamped {

  29.     /** Type of the elements. */
  30.     private final OrbitElementsType type;

  31.     /** Entry date. */
  32.     private final AbsoluteDate date;

  33.     /** Covariance matrix. */
  34.     private final RealMatrix matrix;

  35.     /** Simple constructor.
  36.      * @param type type of the elements
  37.      * @param ordering ordering to use
  38.      * @param date entry date
  39.      * @param fields matrix elements
  40.      * @param first index of first field to consider
  41.      */
  42.     public OrbitCovariance(final OrbitElementsType type, final Ordering ordering, final AbsoluteDate date,
  43.                            final String[] fields, final int first) {
  44.         final List<Unit> units = type.getUnits();
  45.         this.type   = type;
  46.         this.date   = date;
  47.         this.matrix = MatrixUtils.createRealMatrix(units.size(), units.size());
  48.         final CovarianceIndexer indexer = new CovarianceIndexer(units.size());
  49.         for (int k = 0; first + k < fields.length; ++k) {
  50.             if (!indexer.isCrossCorrelation()) {
  51.                 final int    i         = indexer.getRow();
  52.                 final int    j         = indexer.getColumn();
  53.                 final double raw       = Double.parseDouble(fields[first + k]);
  54.                 final double converted = units.get(i).toSI(units.get(j).toSI(raw));
  55.                 matrix.setEntry(i, j, converted);
  56.                 if (i != j) {
  57.                     matrix.setEntry(j, i, converted);
  58.                 }
  59.             }
  60.             ordering.update(indexer);
  61.         }
  62.     }

  63.     /** {@inheritDoc} */
  64.     @Override
  65.     public AbsoluteDate getDate() {
  66.         return date;
  67.     }

  68.     /** Get the covariance matrix.
  69.      * @return covariance matrix
  70.      */
  71.     public RealMatrix getMatrix() {
  72.         return matrix;
  73.     }

  74.     /** Get the type of the elements.
  75.      * @return type of the elements
  76.      */
  77.     public OrbitElementsType getType() {
  78.         return type;
  79.     }

  80. }