Covariance.java

  1. /* Copyright 2002-2022 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.files.ccsds.definitions.ElementsType;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.time.TimeStamped;
  24. import org.orekit.utils.units.Unit;

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

  30.     /** Type of the elements. */
  31.     private final ElementsType type;

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

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

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

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

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

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

  81. }