BiasSolutionPredicate.java

  1. /* Copyright 2022-2025 Luc Maisonobe
  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 org.orekit.gnss.MeasurementType;
  19. import org.orekit.gnss.ObservationType;
  20. import org.orekit.gnss.SatInSystem;
  21. import org.orekit.time.AbsoluteDate;
  22. import org.orekit.utils.Constants;

  23. import java.util.function.Predicate;

  24. /** Predicates for bias solution blocks.
  25.  * @author Luc Maisonobe
  26.  * @since 13.0
  27.  */
  28. enum BiasSolutionPredicate implements Predicate<SinexBiasParseInfo> {

  29.     /** Predicate for DSB line. */
  30.     DSB {
  31.         /** {@inheritDoc} */
  32.         @Override
  33.         protected void store(final SinexBiasParseInfo parseInfo,
  34.                              final String svn, final SatInSystem satId, final String siteCode,
  35.                              final ObservationType obs1, final ObservationType obs2,
  36.                              final AbsoluteDate start, final AbsoluteDate end,
  37.                              final double bias) {
  38.             if (siteCode.isEmpty()) {
  39.                 // this is a satellite bias
  40.                 final SatelliteDifferentialSignalBias dsb = parseInfo.getSatelliteDsb(satId);
  41.                 dsb.getDsb().addBias(obs1, obs2, start, end, bias);
  42.             } else {
  43.                 // this is a station bias
  44.                 final StationDifferentialSignalBias dsb = parseInfo.getStationDsb(siteCode);
  45.                 dsb.getDsb(satId.getSystem()).addBias(obs1, obs2, start, end, bias);
  46.             }
  47.         }
  48.     },

  49.     /** Predicate for OSB line. */
  50.     OSB {
  51.         /** {@inheritDoc} */
  52.         @Override
  53.         protected void store(final SinexBiasParseInfo parseInfo,
  54.                              final String svn, final SatInSystem satId, final String siteCode,
  55.                              final ObservationType obs1, final ObservationType obs2,
  56.                              final AbsoluteDate start, final AbsoluteDate end,
  57.                              final double bias) {
  58.             if (siteCode.isEmpty()) {
  59.                 // this is a satellite bias
  60.                 final SatelliteObservableSpecificSignalBias osb = parseInfo.getSatelliteOsb(satId);
  61.                 osb.getOsb().addBias(obs1, start, end, bias);
  62.             } else {
  63.                 // this is a station bias
  64.                 final StationObservableSpecificSignalBias osb = parseInfo.getStationOsb(siteCode);
  65.                 osb.getOsb(satId.getSystem()).addBias(obs1, start, end, bias);
  66.             }
  67.         }
  68.     };

  69.     /** {@inheritDoc} */
  70.     @Override
  71.     public boolean test(final SinexBiasParseInfo parseInfo) {
  72.         if (name().equals(parseInfo.parseString(1, 3))) {
  73.             // this is the data type we are concerned with
  74.             final String          svn      = parseInfo.parseString(6, 4);
  75.             final SatInSystem     satId    = new SatInSystem(parseInfo.parseString(11, 3));
  76.             final String          siteCode = parseInfo.parseString(15, 9);
  77.             final ObservationType obs1     = parseInfo.parseObservationType(satId.getSystem(), 25, 4);
  78.             final ObservationType obs2     = parseInfo.parseObservationType(satId.getSystem(), 30, 4);
  79.             final AbsoluteDate    start    = parseInfo.stringEpochToAbsoluteDate(parseInfo.parseString(35, 14), true);
  80.             final AbsoluteDate    end      = parseInfo.stringEpochToAbsoluteDate(parseInfo.parseString(50, 14), false);

  81.             // code biases are in time units (ns converted to seconds by parseDoubleWithUnit),
  82.             // they must be converted to meters
  83.             // phase biases are in cycles, no conversion is needed for them
  84.             final double          factor   =
  85.                 obs1.getMeasurementType() == MeasurementType.PSEUDO_RANGE ? Constants.SPEED_OF_LIGHT :  1;
  86.             final double          bias     = factor * parseInfo.parseDoubleWithUnit(65, 4, 70, 21);

  87.             store(parseInfo, svn, satId, siteCode, obs1, obs2, start, end, bias);
  88.             return true;
  89.         } else {
  90.             // it is a data type for another predicate
  91.             return false;
  92.         }
  93.     }

  94.     /** Store parsed fields.
  95.      * @param parseInfo container for parse info
  96.      * @param svn satellite SVN
  97.      * @param satId satellite identifier
  98.      * @param siteCode station site code
  99.      * @param obs1 code of first observable
  100.      * @param obs2 code of second observable
  101.      * @param start validity start date
  102.      * @param end validity end date
  103.      * @param bias estimated bias
  104.      */
  105.     protected abstract void store(SinexBiasParseInfo parseInfo,
  106.                                   String svn, SatInSystem satId, String siteCode,
  107.                                   ObservationType obs1, ObservationType obs2,
  108.                                   AbsoluteDate start, AbsoluteDate end,
  109.                                   double bias);

  110. }