Station.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.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.List;
  21. import java.util.Map;

  22. import org.hipparchus.geometry.euclidean.threed.Vector3D;
  23. import org.orekit.errors.OrekitException;
  24. import org.orekit.errors.OrekitMessages;
  25. import org.orekit.models.earth.displacement.PsdCorrection;
  26. import org.orekit.time.AbsoluteDate;
  27. import org.orekit.utils.TimeSpanMap;

  28. /**
  29.  * Station model.
  30.  * <p>
  31.  * Since Orekit 11.1, this class handles multiple site antenna
  32.  * eccentricity.
  33.  * The {@link #getEccentricities(AbsoluteDate)} method can be
  34.  * used to access the site antenna eccentricity values for a
  35.  * given epoch.
  36.  * </p>
  37.  * @author Bryan Cazabonne
  38.  * @since 10.3
  39.  */
  40. public class Station {

  41.     /** Site code. */
  42.     private String siteCode;

  43.     /** DOMES number. */
  44.     private String domes;

  45.     /** Start of validity. */
  46.     private AbsoluteDate validFrom;

  47.     /** End of validity. */
  48.     private AbsoluteDate validUntil;

  49.     /** Eccentricity reference system. */
  50.     private ReferenceSystem eccRefSystem;

  51.     /** TimeSpanMap of site antenna eccentricities. */
  52.     private final TimeSpanMap<Vector3D> eccentricitiesTimeSpanMap;

  53.     /** Antenna type.
  54.      * @since 12.0
  55.      */
  56.     private final TimeSpanMap<String> antennaTypesMap;

  57.     /** Post-Seismic Deformation.
  58.      * @since 12.0
  59.      */
  60.     private final TimeSpanMap<List<PsdCorrection>> psdMap;

  61.     /** Station position. */
  62.     private Vector3D position;

  63.     /** Station velocity. */
  64.     private Vector3D velocity;

  65.     /** Coordinates reference epoch. */
  66.     private AbsoluteDate epoch;

  67.     /**
  68.      * Constructor.
  69.      */
  70.     public Station() {
  71.         this.eccentricitiesTimeSpanMap = new TimeSpanMap<>(null);
  72.         this.antennaTypesMap           = new TimeSpanMap<>(null);
  73.         this.psdMap                    = new TimeSpanMap<>(null);
  74.         this.position                  = Vector3D.ZERO;
  75.         this.velocity                  = Vector3D.ZERO;
  76.     }

  77.     /**
  78.      * Get the site code (station identifier).
  79.      * @return the site code
  80.      */
  81.     public String getSiteCode() {
  82.         return siteCode;
  83.     }

  84.     /**
  85.      * Set the site code (station identifier).
  86.      * @param siteCode the site code to set
  87.      */
  88.     public void setSiteCode(final String siteCode) {
  89.         this.siteCode = siteCode;
  90.     }

  91.     /**
  92.      * Get the site DOMES number.
  93.      * @return the DOMES number
  94.      */
  95.     public String getDomes() {
  96.         return domes;
  97.     }

  98.     /**
  99.      * Set the DOMES number.
  100.      * @param domes the DOMES number to set
  101.      */
  102.     public void setDomes(final String domes) {
  103.         this.domes = domes;
  104.     }

  105.     /**
  106.      * Get start of validity.
  107.      * @return start of validity
  108.      */
  109.     public AbsoluteDate getValidFrom() {
  110.         return validFrom;
  111.     }

  112.     /**
  113.      * Set the start of validity.
  114.      * @param validFrom the start of validity to set
  115.      */
  116.     public void setValidFrom(final AbsoluteDate validFrom) {
  117.         this.validFrom = validFrom;
  118.     }

  119.     /**
  120.      * Get end of validity.
  121.      * @return end of validity
  122.      */
  123.     public AbsoluteDate getValidUntil() {
  124.         return validUntil;
  125.     }

  126.     /**
  127.      * Set the end of validity.
  128.      * @param validUntil the end of validity to set
  129.      */
  130.     public void setValidUntil(final AbsoluteDate validUntil) {
  131.         this.validUntil = validUntil;
  132.     }

  133.     /**
  134.      * Get the reference system used to define the eccentricity vector (local or cartesian).
  135.      * @return the reference system used to define the eccentricity vector
  136.      */
  137.     public ReferenceSystem getEccRefSystem() {
  138.         return eccRefSystem;
  139.     }

  140.     /**
  141.      * Set the reference system used to define the eccentricity vector (local or cartesian).
  142.      * @param eccRefSystem the reference system used to define the eccentricity vector
  143.      */
  144.     public void setEccRefSystem(final ReferenceSystem eccRefSystem) {
  145.         this.eccRefSystem = eccRefSystem;
  146.     }

  147.     /**
  148.      * Get the station antenna eccentricities for the given epoch.
  149.      * <p>
  150.      * Vector convention: X-Y-Z or UP-NORTH-EAST.
  151.      * See {@link #getEccRefSystem()} method.
  152.      * <p>
  153.      * If there is no eccentricity values for the given epoch, an
  154.      * exception is thrown.
  155.      * @param date epoch
  156.      * @return station antenna eccentricities (m)
  157.      * @since 11.1
  158.      */
  159.     public Vector3D getEccentricities(final AbsoluteDate date) {
  160.         final Vector3D eccAtEpoch = eccentricitiesTimeSpanMap.get(date);
  161.         // If the entry is null, there is no valid eccentricity values for the input epoch
  162.         if (eccAtEpoch == null) {
  163.             // Throw an exception
  164.             throw new OrekitException(OrekitMessages.MISSING_STATION_DATA_FOR_EPOCH, date);
  165.         }
  166.         return eccAtEpoch;
  167.     }

  168.     /**
  169.      * Get the TimeSpanMap of site antenna eccentricities.
  170.      * @return the TimeSpanMap of site antenna eccentricities
  171.      * @since 11.1
  172.      */
  173.     public TimeSpanMap<Vector3D> getEccentricitiesTimeSpanMap() {
  174.         return eccentricitiesTimeSpanMap;
  175.     }

  176.     /** Add a station eccentricity vector entry valid before a limit date.<br>
  177.      * Using <code>addStationEccentricitiesValidBefore(entry, t)</code> will make <code>entry</code>
  178.      * valid in ]-∞, t[ (note the open bracket).
  179.      * @param entry station eccentricity vector entry
  180.      * @param latestValidityDate date before which the entry is valid
  181.      * (must be different from <b>all</b> dates already used for transitions)
  182.      * @since 11.1
  183.      */
  184.     public void addStationEccentricitiesValidBefore(final Vector3D entry, final AbsoluteDate latestValidityDate) {
  185.         eccentricitiesTimeSpanMap.addValidBefore(entry, latestValidityDate, false);
  186.     }

  187.     /** Add a station eccentricity vector entry valid after a limit date.<br>
  188.      * Using <code>addStationEccentricitiesValidAfter(entry, t)</code> will make <code>entry</code>
  189.      * valid in [t, +∞[ (note the closed bracket).
  190.      * @param entry station eccentricity vector entry
  191.      * @param earliestValidityDate date after which the entry is valid
  192.      * (must be different from <b>all</b> dates already used for transitions)
  193.      * @since 11.1
  194.      */
  195.     public void addStationEccentricitiesValidAfter(final Vector3D entry, final AbsoluteDate earliestValidityDate) {
  196.         eccentricitiesTimeSpanMap.addValidAfter(entry, earliestValidityDate, false);
  197.     }

  198.     /** Get the TimeSpanMap of Post-Seismic Deformation.
  199.      * @return the TimeSpanMap of Post-Seismic Deformation
  200.      * @since 12.1
  201.      */
  202.     public TimeSpanMap<List<PsdCorrection>> getPsdTimeSpanMap() {
  203.         return psdMap;
  204.     }

  205.     /** Add a Post-Seismic Deformation entry valid after a limit date.<br>
  206.      * Using {@code addPsdCorrectionValidAfter(entry, t)} will make {@code entry}
  207.      * valid in [t, +∞[ (note the closed bracket).
  208.      * @param entry Post-Seismic Deformation entry
  209.      * @param earliestValidityDate date after which the entry is valid
  210.      * (must be different from <b>all</b> dates already used for transitions)
  211.      * @since 12.1
  212.      */
  213.     public void addPsdCorrectionValidAfter(final PsdCorrection entry, final AbsoluteDate earliestValidityDate) {

  214.         // get the list of corrections active just after earthquake date
  215.         List<PsdCorrection> corrections = psdMap.get(earliestValidityDate.shiftedBy(1.0e-3));

  216.         if (corrections == null ||
  217.             earliestValidityDate.durationFrom(corrections.get(0).getEarthquakeDate()) > 1.0e-3) {
  218.             // either this is the first earthquake we consider or
  219.             // this earthquake is after another one already considered
  220.             // we need to create a new list of corrections for this new earthquake
  221.             corrections = new ArrayList<>();
  222.             psdMap.addValidAfter(corrections, earliestValidityDate, false);
  223.         }

  224.         // add the entry to the current list
  225.         corrections.add(entry);

  226.     }

  227.     /**
  228.      * Get the antenna type for the given epoch.
  229.      * If there is no antenna types for the given epoch, an
  230.      * exception is thrown.
  231.      * @param date epoch
  232.      * @return antenna type
  233.      * @since 12.0
  234.      */
  235.     public String getAntennaType(final AbsoluteDate date) {
  236.         final String typeAtEpoch = antennaTypesMap.get(date);
  237.         // If the entry is null, there is no valid type for the input epoch
  238.         if (typeAtEpoch == null) {
  239.             // Throw an exception
  240.             throw new OrekitException(OrekitMessages.MISSING_STATION_DATA_FOR_EPOCH, date);
  241.         }
  242.         return typeAtEpoch;
  243.     }

  244.     /**
  245.      * Get the TimeSpanMap of site antenna type.
  246.      * @return the TimeSpanMap of site antenna type
  247.      * @since 12.0
  248.      */
  249.     public TimeSpanMap<String> getAntennaTypeTimeSpanMap() {
  250.         return antennaTypesMap;
  251.     }

  252.     /** Add a antenna type entry valid before a limit date.<br>
  253.      * Using <code>addAntennaTypeValidBefore(entry, t)</code> will make <code>entry</code>
  254.      * valid in ]-∞, t[ (note the open bracket).
  255.      * @param entry antenna type entry
  256.      * @param latestValidityDate date before which the entry is valid
  257.      * (must be different from <b>all</b> dates already used for transitions)
  258.      * @since 12.0
  259.      */
  260.     public void addAntennaTypeValidBefore(final String entry, final AbsoluteDate latestValidityDate) {
  261.         antennaTypesMap.addValidBefore(entry, latestValidityDate, false);
  262.     }

  263.     /** Add a antenna type entry valid after a limit date.<br>
  264.      * Using <code>addAntennaTypeValidAfter(entry, t)</code> will make <code>entry</code>
  265.      * valid in [t, +∞[ (note the closed bracket).
  266.      * @param entry antenna type entry
  267.      * @param earliestValidityDate date after which the entry is valid
  268.      * (must be different from <b>all</b> dates already used for transitions)
  269.      * @since 12.0
  270.      */
  271.     public void addAntennaTypeValidAfter(final String entry, final AbsoluteDate earliestValidityDate) {
  272.         antennaTypesMap.addValidAfter(entry, earliestValidityDate, false);
  273.     }

  274.     /**
  275.      * Get the station position.
  276.      * @return the station position (m)
  277.      */
  278.     public Vector3D getPosition() {
  279.         return position;
  280.     }

  281.     /**
  282.      * Set the station position.
  283.      * @param position the position to set
  284.      */
  285.     public void setPosition(final Vector3D position) {
  286.         this.position = position;
  287.     }

  288.     /**
  289.      * Get the station velocity.
  290.      * @return the station velocity (m/s)
  291.      */
  292.     public Vector3D getVelocity() {
  293.         return velocity;
  294.     }

  295.     /**
  296.      * Set the station velocity.
  297.      * @param velocity the velocity to set
  298.      */
  299.     public void setVelocity(final Vector3D velocity) {
  300.         this.velocity = velocity;
  301.     }

  302.     /**
  303.      * Get the coordinates reference epoch.
  304.      * @return the coordinates reference epoch
  305.      */
  306.     public AbsoluteDate getEpoch() {
  307.         return epoch;
  308.     }

  309.     /**
  310.      * Set the coordinates reference epoch.
  311.      * @param epoch the epoch to set
  312.      */
  313.     public void setEpoch(final AbsoluteDate epoch) {
  314.         this.epoch = epoch;
  315.     }

  316.     /** Eccentricity reference system. */
  317.     public enum ReferenceSystem {

  318.         /** Local reference system Up, North, East. */
  319.         UNE("UNE"),

  320.         /** Cartesian reference system X, Y, Z. */
  321.         XYZ("XYZ");

  322.         /** Codes map. */
  323.         private static final Map<String, ReferenceSystem> CODES_MAP = new HashMap<>();
  324.         static {
  325.             for (final ReferenceSystem type : values()) {
  326.                 CODES_MAP.put(type.getName(), type);
  327.             }
  328.         }

  329.         /** Name used to define the reference system in SINEX file. */
  330.         private final String name;

  331.         /**
  332.          * Constructor.
  333.          * @param name name used to define the reference system in SINEX file
  334.          */
  335.         ReferenceSystem(final String name) {
  336.             this.name = name;
  337.         }

  338.         /**
  339.          * Get the name used to define the reference system in SINEX file.
  340.          * @return the name
  341.          */
  342.         public String getName() {
  343.             return name;
  344.         }

  345.         /**
  346.          * Get the eccentricity reference system corresponding to the given value.
  347.          * @param value given value
  348.          * @return the corresponding eccentricity reference system
  349.          */
  350.         public static ReferenceSystem getEccRefSystem(final String value) {
  351.             return CODES_MAP.get(value);
  352.         }

  353.     }

  354. }