1   /* Copyright 2022-2025 Thales Alenia Space
2    * Licensed to CS Communication & Systèmes (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.models.earth.troposphere.iturp834;
18  
19  import org.hipparchus.CalculusFieldElement;
20  import org.hipparchus.analysis.interpolation.GridAxis;
21  import org.orekit.bodies.FieldGeodeticPoint;
22  import org.orekit.bodies.GeodeticPoint;
23  import org.orekit.utils.units.Unit;
24  
25  /** Constant (with respect to time) grid data.
26   * @author Luc Maisonobe
27   * @since 13.0
28   */
29  class ConstantGrid extends AbstractGrid {
30  
31      /** Constant data. */
32      private final double[][] data;
33  
34      /** Build a grid by parsing a resource file.
35       * @param unit unit of values in resource file
36       * @param name name of the resource holding the data
37       */
38      ConstantGrid(final Unit unit, final String name) {
39          data = parse(unit, name);
40      }
41  
42      /** Build a grid by parsing a resource file.
43       * @param data constant data
44       */
45      private ConstantGrid(final double[][] data) {
46          this.data = data;
47      }
48  
49      /** Create a grid by applying a function to all nodes.
50       * @param function function to apply to all nodes
51       * @return new grid
52       */
53      public ConstantGrid apply(final Function function) {
54          final GridAxis latitudeAxis  = getLatitudeAxis();
55          final GridAxis longitudeAxis = getLongitudeAxis();
56          final double[][] values = new double[latitudeAxis.size()][longitudeAxis.size()];
57          for (int i = 0; i < latitudeAxis.size(); ++i) {
58              final double latitude = latitudeAxis.node(i);
59              for (int j = 0; j < longitudeAxis.size(); ++j) {
60                  values[i][j] = function.apply(latitude, longitudeAxis.node(j), data[i][j]);
61              }
62          }
63          return new ConstantGrid(values);
64      }
65  
66      /** {@inheritDoc} */
67      @Override
68      public GridCell getCell(final GeodeticPoint location, final double ignored) {
69          return getRawCell(location, data);
70      }
71  
72      /** {@inheritDoc} */
73      @Override
74      public <T extends CalculusFieldElement<T>> FieldGridCell<T> getCell(final FieldGeodeticPoint<T> location,
75                                                                          final T ignored) {
76          return getRawCell(location, data);
77      }
78  
79      /** Interface for transforming nodes data. */
80      @FunctionalInterface
81      public interface Function {
82          /** Compute a new node data.
83           * @param latitude node latitude
84           * @param longitude node longitude
85           * @param data node value
86           * @return value for new node
87           */
88          double apply(double latitude, double longitude, double data);
89      }
90  
91  }