CartesianCovariance.java

  1. /* Copyright 2002-2024 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;

  18. import java.util.function.Supplier;

  19. import org.hipparchus.linear.MatrixUtils;
  20. import org.hipparchus.linear.RealMatrix;
  21. import org.orekit.errors.OrekitException;
  22. import org.orekit.errors.OrekitMessages;
  23. import org.orekit.files.ccsds.definitions.FrameFacade;
  24. import org.orekit.files.ccsds.section.CommentsContainer;
  25. import org.orekit.files.ccsds.section.Data;
  26. import org.orekit.time.AbsoluteDate;

  27. /** Container for OPM/OMM/OCM Cartesian covariance matrix.
  28.  * @author sports
  29.  * @since 6.1
  30.  */
  31. public class CartesianCovariance extends CommentsContainer implements Data {

  32.     /** Labels for matrix row/columns. */
  33.     private static final String[] LABELS = {
  34.         "X", "Y", "Z", "X_DOT", "Y_DOT", "Z_DOT"
  35.     };

  36.     /** Supplier for default reference frame. */
  37.     private final Supplier<FrameFacade> defaultFrameSupplier;

  38.     /** Matrix epoch. */
  39.     private AbsoluteDate epoch;

  40.     /** Reference frame in which data are given. */
  41.     private FrameFacade referenceFrame;

  42.     /** Position/Velocity covariance matrix. */
  43.     private RealMatrix covarianceMatrix;

  44.     /** Create an empty data set.
  45.      * @param defaultFrameSupplier supplier for default reference frame
  46.      * if no frame is specified in the CCSDS message
  47.      */
  48.     public CartesianCovariance(final Supplier<FrameFacade> defaultFrameSupplier) {
  49.         this.defaultFrameSupplier = defaultFrameSupplier;
  50.         covarianceMatrix = MatrixUtils.createRealMatrix(6, 6);
  51.         for (int i = 0; i < covarianceMatrix.getRowDimension(); ++i) {
  52.             for (int j = 0; j <= i; ++j) {
  53.                 covarianceMatrix.setEntry(i, j, Double.NaN);
  54.             }
  55.         }
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public void validate(final double version) {
  60.         super.validate(version);
  61.         checkNotNull(epoch, CartesianCovarianceKey.EPOCH.name());
  62.         for (int i = 0; i < covarianceMatrix.getRowDimension(); ++i) {
  63.             for (int j = 0; j <= i; ++j) {
  64.                 if (Double.isNaN(covarianceMatrix.getEntry(i, j))) {
  65.                     throw new OrekitException(OrekitMessages.CCSDS_MISSING_KEYWORD,
  66.                                               "C" + LABELS[i] + "_" + LABELS[j]);
  67.                 }
  68.             }
  69.         }
  70.     }

  71.     /** Get matrix epoch.
  72.      * @return matrix epoch
  73.      */
  74.     public AbsoluteDate getEpoch() {
  75.         return epoch;
  76.     }

  77.     /** Set matrix epoch.
  78.      * @param epoch matrix epoch
  79.      */
  80.     public void setEpoch(final AbsoluteDate epoch) {
  81.         refuseFurtherComments();
  82.         this.epoch = epoch;
  83.     }

  84.     /**
  85.      * Get the reference frame.
  86.      *
  87.      * @return The reference frame specified by the {@code COV_REF_FRAME} keyword
  88.      * or inherited from metadata
  89.      */
  90.     public FrameFacade getReferenceFrame() {
  91.         return referenceFrame == null ? defaultFrameSupplier.get() : referenceFrame;
  92.     }

  93.     /** Set the reference frame in which data are given.
  94.      * @param referenceFrame the reference frame to be set
  95.      */
  96.     public void setReferenceFrame(final FrameFacade referenceFrame) {
  97.         refuseFurtherComments();
  98.         this.referenceFrame = referenceFrame;
  99.     }

  100.     /** Get the Position/Velocity covariance matrix.
  101.      * @return the Position/Velocity covariance matrix
  102.      */
  103.     public RealMatrix getCovarianceMatrix() {
  104.         return covarianceMatrix;
  105.     }

  106.     /** Set an entry in the Position/Velocity covariance matrix.
  107.      * <p>
  108.      * Both m(j, k) and m(k, j) are set.
  109.      * </p>
  110.      * @param j row index (must be between 0 and 5 (inclusive)
  111.      * @param k column index (must be between 0 and 5 (inclusive)
  112.      * @param entry value of the matrix entry
  113.      */
  114.     public void setCovarianceMatrixEntry(final int j, final int k, final double entry) {
  115.         refuseFurtherComments();
  116.         covarianceMatrix.setEntry(j, k, entry);
  117.         covarianceMatrix.setEntry(k, j, entry);
  118.     }

  119. }