Dcb.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.sinex;

  18. import java.util.HashMap;
  19. import java.util.HashSet;

  20. import org.hipparchus.util.Pair;
  21. import org.orekit.gnss.ObservationType;
  22. import org.orekit.time.AbsoluteDate;
  23. import org.orekit.utils.TimeSpanMap;

  24. /**
  25.  * Class to store DCB Solution data parsed in the SinexLoader.
  26.  * <p>
  27.  * This class is made to handle both station and satellite DCB data.
  28.  * Bias values are stored in TimeSpanMaps associated with a given pair
  29.  * of observation codes. Those TimeSpanMaps are stored in a Map, which
  30.  * associate a pair of observation code (as a HashSet of ObservationType)
  31.  * to a TimeSpanMap,  encapsulated in a DCBCode object.
  32.  * </p>
  33.  * @author Louis Aucouturier
  34.  * @since 12.0
  35.  */
  36. public class Dcb {

  37.     /** Ensemble of observation code pairs available for the satellite. */
  38.     private HashSet<Pair<ObservationType, ObservationType>> observationSets;

  39.     /**
  40.      * Ensemble of DCBCode object, identifiable by observation code pairs,
  41.      * each containing the corresponding TimeSpanMap of biases (DCB).
  42.      */
  43.     private HashMap<Pair<ObservationType, ObservationType>, DcbCode> dcbCodeMap;

  44.     /** Simple constructor. */
  45.     public Dcb() {
  46.         this.observationSets = new HashSet<>();
  47.         this.dcbCodeMap      = new HashMap<>();
  48.     }

  49.     // Class to store the TimeSpanMap per DCB Observation Code set
  50.     private static class DcbCode {

  51.         /** TimeSpanMap containing the DCB bias values. */
  52.         private TimeSpanMap<Double> dcbMap;

  53.         /**
  54.          * Simple constructor.
  55.          */
  56.         DcbCode() {
  57.             this.dcbMap = new TimeSpanMap<>(null);
  58.         }

  59.         /**
  60.          * Getter for the TimeSpanMap of DCB values.
  61.          *
  62.          * @return a time span map containing DCB values, for the observation code pair
  63.          * corresponding to this DCBCode object
  64.          */
  65.         public TimeSpanMap<Double> getDcbTimeMap() {
  66.             return dcbMap;
  67.         }

  68.     }

  69.     /**
  70.      * Add the content of a DCB line to the DCBSatellite object.
  71.      * <p>
  72.      * The method check the presence of a Code pair in a map, and add
  73.      * values to the corresponding TimeSpanMap.
  74.      * </p>
  75.      * @param obs1 String corresponding to the first code used for the DCB computation
  76.      * @param obs2 String corresponding to the second code used for the DCB computation
  77.      * @param spanBegin Absolute Date corresponding to the beginning of the validity span for this bias value
  78.      * @param spanEnd Absolute Date corresponding to the end of the validity span for this bias value
  79.      * @param biasValue DCB bias value expressed in S.I. units
  80.      */
  81.     public void addDcbLine(final String obs1, final String obs2,
  82.                            final AbsoluteDate spanBegin, final AbsoluteDate spanEnd,
  83.                            final double biasValue) {

  84.         // Setting a pair of observation type.
  85.         final Pair<ObservationType, ObservationType> observationPair = new Pair<>(ObservationType.valueOf(obs1), ObservationType.valueOf(obs2));

  86.         // If not present add a new DCBCode to the map, identified by the Observation Pair.
  87.         // Then add the bias value and validity period.
  88.         if (observationSets.add(observationPair)) {
  89.             dcbCodeMap.put(observationPair, new DcbCode());
  90.         }

  91.         dcbCodeMap.get(observationPair).getDcbTimeMap().addValidBetween(biasValue, spanBegin, spanEnd);
  92.     }

  93.     /**
  94.      * Get the value of the Differential Code Bias for a given observation pair
  95.      * and a at a given date.
  96.      *
  97.      * @param obs1 string corresponding to the first code used for the DCB computation
  98.      * @param obs2 string corresponding to the second code used for the DCB computation
  99.      * @param date date at which to obtain the DCB
  100.      * @return the value of the DCB in S.I. units
  101.      */
  102.     public double getDcb(final String obs1, final String obs2, final AbsoluteDate date) {
  103.         return getDcb(ObservationType.valueOf(obs1), ObservationType.valueOf(obs2), date);
  104.     }

  105.     /**
  106.      * Get the value of the Differential Code Bias for a given observation pair
  107.      * and a at a given date.
  108.      *
  109.      * @param obs1 first observation type
  110.      * @param obs2 second observation type
  111.      * @param date date at which to obtain the DCB
  112.      * @return the value of the DCB in S.I. units
  113.      */
  114.     public double getDcb(final ObservationType obs1, final ObservationType obs2, final AbsoluteDate date) {
  115.         return getTimeSpanMap(obs1, obs2).get(date);
  116.     }

  117.     /**
  118.      * Get all available observation code pairs for the satellite.
  119.      *
  120.      * @return HashSet(HashSet(ObservationType)) Observation code pairs obtained.
  121.      */
  122.     public HashSet<Pair<ObservationType, ObservationType>> getAvailableObservationPairs() {
  123.         return observationSets;
  124.     }

  125.     /**
  126.      * Get the minimum valid date for a given observation pair.
  127.      *
  128.      * @param obs1 sString corresponding to the first code used for the DCB computation
  129.      * @param obs2 string corresponding to the second code used for the DCB computation
  130.      * @return minimum valid date for the observation pair
  131.      */
  132.     public AbsoluteDate getMinimumValidDateForObservationPair(final String obs1, final String obs2) {
  133.         return getMinimumValidDateForObservationPair(ObservationType.valueOf(obs1), ObservationType.valueOf(obs2));
  134.     }

  135.     /**
  136.      * Get the minimum valid date for a given observation pair.
  137.      *
  138.      * @param obs1 first observation type
  139.      * @param obs2 second observation type
  140.      * @return minimum valid date for the observation pair
  141.      */
  142.     public AbsoluteDate getMinimumValidDateForObservationPair(final ObservationType obs1, final ObservationType obs2) {
  143.         return getTimeSpanMap(obs1, obs2).getFirstTransition().getDate();
  144.     }

  145.     /**
  146.      * Get the maximum valid date for a given observation pair.
  147.      *
  148.      * @param obs1 string corresponding to the first code used for the DCB computation
  149.      * @param obs2 string corresponding to the second code used for the DCB computation
  150.      * @return maximum valid date for the observation pair
  151.      */
  152.     public AbsoluteDate getMaximumValidDateForObservationPair(final String obs1, final String obs2) {
  153.         return getMaximumValidDateForObservationPair(ObservationType.valueOf(obs1), ObservationType.valueOf(obs2));
  154.     }

  155.     /**
  156.      * Get the maximum valid date for a given observation pair.
  157.      *
  158.      * @param obs1 first observation type
  159.      * @param obs2 second observation type
  160.      * @return maximum valid date for the observation pair
  161.      */
  162.     public AbsoluteDate getMaximumValidDateForObservationPair(final ObservationType obs1, final ObservationType obs2) {
  163.         return getTimeSpanMap(obs1, obs2).getLastTransition().getDate();
  164.     }

  165.     /**
  166.      * Return the TimeSpanMap object for a given observation code pair,
  167.      * for further operation on the object directly.
  168.      *
  169.      * @param obs1 first observation type
  170.      * @param obs2 second observation type
  171.      * @return the time span map for a given observation code pair
  172.      */
  173.     private TimeSpanMap<Double> getTimeSpanMap(final ObservationType obs1, final ObservationType obs2) {
  174.         return dcbCodeMap.get(new Pair<>(obs1, obs2)).getDcbTimeMap();
  175.     }

  176. }