ObservationsBlock.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.tdm;

  18. import java.util.ArrayList;
  19. import java.util.List;

  20. import org.orekit.files.ccsds.section.CommentsContainer;
  21. import org.orekit.files.ccsds.section.Data;
  22. import org.orekit.time.AbsoluteDate;

  23. /** The Observations Block class contain metadata and the list of observation data lines.
  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 reason for which the observations have been separated into blocks is that the different
  40.  * data blocks in a TDM file usually refers to different types of observations.
  41.  * An observation block is associated with a TDM metadata object and contains a list of observations.
  42.  * At this level, an observation is not an Orekit object, it is a custom object containing:
  43.  * </p>
  44.  * <ul>
  45.  *  <li>a keyword, the type of the observation;</li>
  46.  *  <li>a timetag, the date of the observation;</li>
  47.  *  <li>a measurement, the value of the observation.</li>
  48.  * </ul>
  49.  * @author Maxime Journot
  50.  */
  51. public class ObservationsBlock extends CommentsContainer implements Data {

  52.     /** Current observation epoch. */
  53.     private AbsoluteDate currentObservationEpoch;

  54.     /** List of observations data lines. */
  55.     private List<Observation> observations;

  56.     /** ObservationsBlock constructor. */
  57.     public ObservationsBlock() {
  58.         observations = new ArrayList<>();
  59.     }

  60.     /** Add the epoch of current observation.
  61.      * @param epoch current observation epoch
  62.      * @return alwaus return {@code true}
  63.      */
  64.     boolean addObservationEpoch(final AbsoluteDate epoch) {
  65.         refuseFurtherComments();
  66.         currentObservationEpoch = epoch;
  67.         return true;
  68.     }

  69.     /** Get current observation epoch if set.
  70.      * @return current observation epoch, or null if not set
  71.      */
  72.     AbsoluteDate getCurrentObservationEpoch() {
  73.         return currentObservationEpoch;
  74.     }

  75.     /** Add the value of current observation.
  76.      * @param type type of the observation
  77.      * @param measurement measurement of the observation
  78.      */
  79.     void addObservationValue(final ObservationType type, final double measurement) {
  80.         addObservation(type, currentObservationEpoch, measurement);
  81.         currentObservationEpoch = null;
  82.     }

  83.     /** Get the list of Observations data lines.
  84.      * @return a reference to the internal list of Observations data lines
  85.      */
  86.     public List<Observation> getObservations() {
  87.         return this.observations;
  88.     }

  89.     /** Set the list of Observations Data Lines.
  90.      * @param observations the list of Observations Data Lines to set
  91.      */
  92.     public void setObservations(final List<Observation> observations) {
  93.         refuseFurtherComments();
  94.         this.observations = new ArrayList<>(observations);
  95.     }

  96.     /** Adds an observation data line.
  97.      * @param observation the observation to add to the list
  98.      */
  99.     public void addObservation(final Observation observation) {
  100.         refuseFurtherComments();
  101.         this.observations.add(observation);
  102.     }

  103.     /** Adds an observation data line.
  104.      * @param type type of the observation
  105.      * @param epoch the timetag
  106.      * @param measurement the measurement
  107.      */
  108.     public void addObservation(final ObservationType type,
  109.                                final AbsoluteDate epoch,
  110.                                final double measurement) {
  111.         this.addObservation(new Observation(type, epoch, measurement));
  112.     }

  113. }