SigmaEigenvectorsCovariance.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.cdm;

  18. import org.orekit.errors.OrekitException;
  19. import org.orekit.errors.OrekitMessages;
  20. import org.orekit.files.ccsds.section.CommentsContainer;

  21. import java.util.Arrays;

  22. /**
  23.  * Container for Sigma/Eigenvectors Covariance data.
  24.  * <p>
  25.  * Beware that the Orekit getters and setters all rely on SI units. The parsers
  26.  * and writers take care of converting these SI units into CCSDS mandatory units.
  27.  * The {@link org.orekit.utils.units.Unit Unit} class provides useful
  28.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  29.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} methods in case the callers
  30.  * already use CCSDS units instead of the API SI units. The general-purpose
  31.  * {@link org.orekit.utils.units.Unit Unit} class (without an 's') and the
  32.  * CCSDS-specific {@link org.orekit.files.ccsds.definitions.Units Units} class
  33.  * (with an 's') also provide some predefined units. These predefined units and the
  34.  * {@link org.orekit.utils.units.Unit#fromSI(double) fromSi} and
  35.  * {@link org.orekit.utils.units.Unit#toSI(double) toSI} conversion methods are indeed
  36.  * what the parsers and writers use for the conversions.
  37.  * </p>
  38.  * <p>
  39.  * The positional covariance one-sigma dispersions corresponding to the major,
  40.  * intermediate and minor eigenvalues, followed by the associated eigenvectors.
  41.  * The data is presented on a single line (12 values separated by spaces).
  42.  * (Condition: Mandatory if {@code ALT_COV_TYPE = CSIG3EIGVEC3})
  43.  * </p>
  44.  */
  45. public class SigmaEigenvectorsCovariance extends CommentsContainer {

  46.     /** Sigma/Eigenvectors Covariance covariance matrix. */
  47.     private double[] csig3eigvec3;

  48.     /** Flag indicating whether the alternate covariance type set in the CDM Object metadata section is Sigma/Eigenvectors Covariance. */
  49.     private final boolean altCovFlag;

  50.     /** Simple constructor.
  51.      * <p> The Sigma/Eigenvectors Covariance data is only provided if {@link CdmMetadataKey#ALT_COV_TYPE} is {@link AltCovarianceType#CSIG3EIGVEC3}, otherwise
  52.      * its terms will return NaN. </p>
  53.      * @param altCovFlag Flag indicating whether the alternate covariance type set in the CDM Object metadata section is Sigma/Eigenvectors Covariance.
  54.      */
  55.     public SigmaEigenvectorsCovariance(final boolean altCovFlag) {
  56.         this.altCovFlag = altCovFlag;
  57.         csig3eigvec3 = new double[12];

  58.         Arrays.fill(csig3eigvec3, Double.NaN);
  59.     }

  60.     /** {@inheritDoc} */
  61.     @Override
  62.     public void validate(final double version) {
  63.         super.validate(version);

  64.         // Conditional on ALT_COV_TYPE = Sigma/Eigenvectors Covariance
  65.         if (!isAltCovFlagSet()) {
  66.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD, CdmMetadataKey.ALT_COV_TYPE);
  67.         }

  68.         // We only check values that are mandatory in a cdm file
  69.         for (int i = 0; i < getCsig3eigvec3().length; i++) {
  70.             checkNotNaN(getCsig3eigvec3()[i], SigmaEigenvectorsCovarianceKey.CSIG3EIGVEC3.name());
  71.         }
  72.     }


  73.     /**
  74.      * Get the Sigma/Eigenvectors Covariance data.
  75.      * <p> The Sigma/Eigenvectors Covariance data is only provided if {@link CdmMetadataKey#ALT_COV_TYPE} is {@link AltCovarianceType#CSIG3EIGVEC3}, otherwise
  76.      * its terms will return NaN. </p>
  77.      * @return covarianceData the covariance data in the Sigma/Eigenvectors format.
  78.      */
  79.     public double[] getCsig3eigvec3() {
  80.         return csig3eigvec3 == null ? null : csig3eigvec3.clone();
  81.     }

  82.     /**
  83.      * Set the Sigma/Eigenvectors Covariance data.
  84.      * @param csig3eigvec3 the covariance data in the Sigma/Eigenvectors format.
  85.      */
  86.     public void setCsig3eigvec3(final double[] csig3eigvec3) {
  87.         refuseFurtherComments();

  88.         // Conditional on ALT_COV_TYPE = Sigma/Eigenvectors Covariance
  89.         if (!isAltCovFlagSet()) {
  90.             throw new OrekitException(OrekitMessages.CCSDS_DATE_INVALID_PREAMBLE_FIELD, CdmMetadataKey.ALT_COV_TYPE);
  91.         }

  92.         this.csig3eigvec3 = csig3eigvec3 == null ? null : csig3eigvec3.clone();
  93.     }

  94.     /** Get the flag indicating whether the alternate covariance type set in the CDM Object metadata section is Sigma/Eigenvectors Covariance.
  95.      * @return the altCovFlag
  96.      */
  97.     public boolean isAltCovFlagSet() {
  98.         return altCovFlag;
  99.     }

  100. }