1   /* Copyright 2002-2020 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  
18  package org.orekit.estimation.common;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.orekit.estimation.measurements.modifiers.RangeIonosphericDelayModifier;
24  import org.orekit.estimation.measurements.modifiers.RangeRateIonosphericDelayModifier;
25  import org.orekit.gnss.Frequency;
26  import org.orekit.models.earth.ionosphere.IonosphericModel;
27  import org.orekit.models.earth.ionosphere.KlobucharIonoCoefficientsLoader;
28  import org.orekit.models.earth.ionosphere.KlobucharIonoModel;
29  import org.orekit.time.AbsoluteDate;
30  import org.orekit.time.DateComponents;
31  import org.orekit.time.TimeScalesFactory;
32  
33  /** Ionospheric modifiers.
34   * @author Bryan Cazabonne
35   */
36  class Iono {
37  
38      /** Flag for two-way range-rate. */
39      private final boolean twoWay;
40  
41      /** Map for range modifiers. */
42      private final Map<Frequency, Map<DateComponents, RangeIonosphericDelayModifier>> rangeModifiers;
43  
44      /** Map for range-rate modifiers. */
45      private final Map<Frequency, Map<DateComponents, RangeRateIonosphericDelayModifier>> rangeRateModifiers;
46  
47      /** Simple constructor.
48       * @param twoWay flag for two-way range-rate
49       */
50      Iono(final boolean twoWay) {
51          this.twoWay             = twoWay;
52          this.rangeModifiers     = new HashMap<>();
53          this.rangeRateModifiers = new HashMap<>();
54      }
55  
56      /** Get range modifier for a measurement.
57       * @param frequency frequency of the signal
58       * @param date measurement date
59       * @return range modifier
60       */
61      public RangeIonosphericDelayModifier getRangeModifier(final Frequency frequency,
62                                                            final AbsoluteDate date) {
63          final DateComponents dc = date.getComponents(TimeScalesFactory.getUTC()).getDate();
64          ensureFrequencyAndDateSupported(frequency, dc);
65          return rangeModifiers.get(frequency).get(dc);
66      }
67  
68      /** Get range-rate modifier for a measurement.
69       * @param frequency frequency of the signal
70       * @param date measurement date
71       * @return range-rate modifier
72       */
73      public RangeRateIonosphericDelayModifier getRangeRateModifier(final Frequency frequency,
74                                                                    final AbsoluteDate date) {
75          final DateComponents dc = date.getComponents(TimeScalesFactory.getUTC()).getDate();
76          ensureFrequencyAndDateSupported(frequency, dc);
77          return rangeRateModifiers.get(frequency).get(dc);
78      }
79  
80      /** Create modifiers for a frequency and date if needed.
81       * @param frequency frequency of the signal
82       * @param dc date for which modifiers are required
83       */
84      private void ensureFrequencyAndDateSupported(final Frequency frequency, final DateComponents dc) {
85  
86          if (!rangeModifiers.containsKey(frequency)) {
87              rangeModifiers.put(frequency, new HashMap<>());
88              rangeRateModifiers.put(frequency, new HashMap<>());
89          }
90  
91          if (!rangeModifiers.get(frequency).containsKey(dc)) {
92  
93              // load Klobuchar model for the L1 frequency
94              final KlobucharIonoCoefficientsLoader loader = new KlobucharIonoCoefficientsLoader();
95              loader.loadKlobucharIonosphericCoefficients(dc);
96              final IonosphericModel model = new KlobucharIonoModel(loader.getAlpha(), loader.getBeta());
97  
98              // scale for current frequency
99              final double f = frequency.getMHzFrequency() * 1.0e6;
100 
101             // create modifiers
102             rangeModifiers.get(frequency).put(dc, new RangeIonosphericDelayModifier(model, f));
103             rangeRateModifiers.get(frequency).put(dc, new RangeRateIonosphericDelayModifier(model, f, twoWay));
104 
105         }
106 
107     }
108 
109 }