1   /* Copyright 2002-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.propagation.conversion;
18  
19  import org.junit.Assert;
20  import org.junit.Before;
21  import org.junit.Test;
22  import org.orekit.Utils;
23  import org.orekit.errors.OrekitException;
24  import org.orekit.errors.OrekitMessages;
25  import org.orekit.orbits.PositionAngle;
26  import org.orekit.propagation.analytical.tle.TLE;
27  import org.orekit.propagation.analytical.tle.TLEPropagator;
28  import org.orekit.utils.ParameterDriver;
29  
30  public class TLEConverterTest {
31  
32      @Test
33      public void testDeselectOrbitals() {
34  
35          final TLE tle = new TLE("1 27508U 02040A   12021.25695307 -.00000113  00000-0  10000-3 0  7326",
36                                  "2 27508   0.0571 356.7800 0005033 344.4621 218.7816  1.00271798 34501");
37          
38          TLEPropagatorBuilder builder = new TLEPropagatorBuilder(tle, PositionAngle.MEAN, 1.0);
39          for (ParameterDriver driver : builder.getOrbitalParametersDrivers().getDrivers()) {
40              Assert.assertTrue(driver.isSelected());
41          }
42          builder.deselectDynamicParameters();
43          for (ParameterDriver driver : builder.getOrbitalParametersDrivers().getDrivers()) {
44              Assert.assertFalse(driver.isSelected());
45          }
46      }
47  
48      @Test
49      public void testIssue859() {
50  
51          // INTELSAT 25 TLE taken from Celestrak the 2021-11-24T07:45:00.000
52          // Because the satellite eccentricity and inclination are closed to zero, this satellite
53          // reach convergence issues when converting the spacecraft's state to TLE.
54          final TLE tle = new TLE("1 33153U 08034A   21327.46310733 -.00000207  00000+0  00000+0 0  9990",
55                                  "2 33153   0.0042  20.7353 0003042 213.9370 323.2156  1.00270917 48929");
56  
57          // Verify convergence issue
58          final TLEPropagatorBuilder propagatorBuilderError = new TLEPropagatorBuilder(tle, PositionAngle.MEAN, 1.);
59          try {
60              propagatorBuilderError.buildPropagator(propagatorBuilderError.getSelectedNormalizedParameters());
61          } catch (OrekitException oe) {
62              Assert.assertEquals(OrekitMessages.UNABLE_TO_COMPUTE_TLE, oe.getSpecifier());
63          }
64  
65          // Now try using different convergence threshold
66          final TLEPropagatorBuilder propagatorBuilder = new TLEPropagatorBuilder(tle, PositionAngle.MEAN, 1., 2.0e-4, 10000);
67          final TLEPropagator propagator = propagatorBuilder.buildPropagator(propagatorBuilderError.getSelectedNormalizedParameters());
68          final TLE newTLE = propagator.getTLE();
69  
70          // Verify
71          Assert.assertEquals(0.0, newTLE.getDate().durationFrom(tle.getDate()), Utils.epsilonTest);
72  
73      }
74  
75      @Before
76      public void setUp() {
77          Utils.setDataRoot("regular-data");
78      }
79  
80  }