AtmosphericComputationParameters.java

  1. /* Copyright 2013-2022 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.rugged.refraction;

  18. import org.orekit.rugged.errors.RuggedException;
  19. import org.orekit.rugged.errors.RuggedMessages;
  20. import org.orekit.rugged.linesensor.LineSensor;
  21. import org.orekit.rugged.utils.GridCreation;

  22. /**
  23.  * Atmospheric refraction computation parameters.
  24.  * Defines for inverse location a set of parameters in order to be able to perform the computation.
  25.  * @author Guylaine Prat
  26.  * @since 2.1
  27.  */

  28. public class AtmosphericComputationParameters {

  29.     /** Margin for definition of the interpolation grid.
  30.      * To be inside the min line and max line range to avoid problem with inverse location grid computation. */
  31.     private static final int MARGIN_LINE = 10;

  32.     /** Default value for pixel step. */
  33.     private static final int DEFAULT_STEP_PIXEL = 100;
  34.     /** Default value for line step. */
  35.     private static final int DEFAULT_STEP_LINE = 100;

  36.     /** Default margin for computation of inverse location with atmospheric refraction correction.
  37.     * @since 3.0
  38.     */
  39.     private static final double DEFAULT_INVLOC_MARGIN = 0.8;

  40.     /** Actual values for pixel step in case default are overwritten. */
  41.     private int pixelStep;
  42.     /** Actual values for line step in case default are overwritten. */
  43.     private int lineStep;

  44.     /** Actual values for inverse location margin with atmospheric refraction  in case default are overwritten.
  45.     * @since 3.0
  46.     */
  47.     private double invlocMargin;

  48.     // Definition of grids for sensor (u = along pixel; v = along line)
  49.     /** Linear grid in pixel. */
  50.     private double[] uGrid;
  51.     /** Linear grid in line. */
  52.     private double[] vGrid;
  53.     /** Size of uGrid = nbPixelGrid. */
  54.     private int nbPixelGrid;
  55.     /** Size of vGrid = nbLineGrid. */
  56.     private int nbLineGrid;

  57.     // Definition of the associated sensor
  58.     /** Current min line. */
  59.     private double minLineSensor = Double.NaN;
  60.     /** Current max line. */
  61.     private double maxLineSensor = Double.NaN;
  62.     /** Current sensor name. */
  63.     private String sensorName = null;

  64.     /**
  65.      * Default constructor.
  66.      */
  67.     public AtmosphericComputationParameters() {
  68.         this.pixelStep = DEFAULT_STEP_PIXEL;
  69.         this.lineStep = DEFAULT_STEP_LINE;
  70.         this.invlocMargin = DEFAULT_INVLOC_MARGIN;
  71.     }

  72.     /** Configuration of the interpolation grid. This grid is associated to the given sensor,
  73.      * with the given min and max lines.
  74.      * @param sensor line sensor
  75.      * @param minLine min line defined for the inverse location
  76.      * @param maxLine max line defined for the inverse location
  77.      */
  78.     public void configureCorrectionGrid(final LineSensor sensor, final int minLine, final int maxLine) {

  79.         // Keep information about the sensor and the required search lines.
  80.         // Needed to test if the grid is initialized with this context.
  81.         this.minLineSensor = minLine;
  82.         this.maxLineSensor = maxLine;
  83.         this.sensorName = sensor.getName();

  84.         // Compute the number of pixels and lines for the grid (round value is sufficient)
  85.         final int sensorNbPxs = sensor.getNbPixels();
  86.         this.nbPixelGrid = sensorNbPxs / this.pixelStep;

  87.         // check the validity of the min and max lines
  88.         if ((maxLine - minLine + 1 - 2 * MARGIN_LINE) < 2 * this.lineStep) {
  89.             final String info = ": (maxLine - minLine + 1 - 2*" + MARGIN_LINE + ") < 2*" + this.lineStep;
  90.             throw new RuggedException(RuggedMessages.INVALID_RANGE_FOR_LINES, minLine, maxLine, info);
  91.         }
  92.         this.nbLineGrid = (maxLine - minLine + 1 - 2 * MARGIN_LINE) / this.lineStep;

  93.         // Compute the linear grids in pixel (u index) and line (v index)
  94.         this.uGrid = GridCreation.createLinearGrid(0, sensorNbPxs - 1, this.nbPixelGrid);
  95.         this.vGrid = GridCreation.createLinearGrid(minLine + MARGIN_LINE, maxLine - MARGIN_LINE, this.nbLineGrid);

  96.     }

  97.     /**
  98.      * Set the grid steps in pixel and line (used to compute inverse location).
  99.      * Overwrite the default values, for time optimization if necessary.
  100.      * @param gridPixelStep grid pixel step for the inverse location computation
  101.      * @param gridLineStep grid line step for the inverse location computation
  102.      */
  103.     public void setGridSteps(final int gridPixelStep, final int gridLineStep) {

  104.         if (gridPixelStep <= 0) {
  105.             final String reason = " pixelStep <= 0";
  106.             throw new RuggedException(RuggedMessages.INVALID_STEP, gridPixelStep, reason);
  107.         }
  108.         if (gridLineStep <= 0) {
  109.             final String reason = " lineStep <= 0";
  110.             throw new RuggedException(RuggedMessages.INVALID_STEP, gridLineStep, reason);
  111.         }
  112.         this.pixelStep = gridPixelStep;
  113.         this.lineStep = gridLineStep;
  114.     }

  115.     /**
  116.      * Set the margin for computation of inverse location with atmospheric refraction correction.
  117.      * Overwrite the default value DEFAULT_INVLOC_MARGIN.
  118.      * No check is done about this margin. A recommended value is around 1.
  119.      * @param inverseLocMargin margin in pixel size to compute inverse location with atmospheric refraction correction.
  120.      * @since 3.0
  121.      */
  122.     public void setInverseLocMargin(final double inverseLocMargin) {
  123.         this.invlocMargin = inverseLocMargin;
  124.     }

  125.     /**
  126.      * @return the inverse location margin for computation of inverse location with atmospheric refraction correction.
  127.     * @since 3.0
  128.     */
  129.     public double getInverseLocMargin () {
  130.         return this.invlocMargin;
  131.     }

  132.     /**
  133.     * @return the default inverse location margin for computation of inverse location with atmospheric refraction correction.
  134.     * @since 3.0
  135.     */
  136.     public double getDefaultInverseLocMargin () {
  137.         return DEFAULT_INVLOC_MARGIN;
  138.     }

  139.     /**
  140.      * @return the size of pixel grid
  141.      */
  142.     public int getNbPixelGrid() {
  143.         return nbPixelGrid;
  144.     }

  145.     /**
  146.      * @return the size of line grid
  147.      */
  148.     public int getNbLineGrid() {
  149.         return nbLineGrid;
  150.     }

  151.     /**
  152.      * @return the pixel grid
  153.      */
  154.     public double[] getUgrid() {
  155.         return uGrid.clone();
  156.     }

  157.     /**
  158.      * @return the line grid
  159.      */
  160.     public double[] getVgrid() {
  161.         return vGrid.clone();
  162.     }

  163.     /**
  164.      * @return the min line used to compute the current grids
  165.      */
  166.     public double getMinLineSensor() {
  167.         return minLineSensor;
  168.     }

  169.     /**
  170.      * @return the max line used to compute the current grids
  171.      */
  172.     public double getMaxLineSensor() {
  173.         return maxLineSensor;
  174.     }

  175.     /**
  176.      * @return the sensor name used to compute the current grids
  177.      */
  178.     public String getSensorName() {
  179.         return sensorName;
  180.     }
  181. }