1   /* Copyright 2002-2025 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;
19  
20  import org.hipparchus.geometry.euclidean.threed.Vector3D;
21  import org.hipparchus.util.FastMath;
22  import org.orekit.bodies.CelestialBody;
23  import org.orekit.bodies.GeodeticPoint;
24  import org.orekit.bodies.OneAxisEllipsoid;
25  import org.orekit.estimation.measurements.GroundStation;
26  import org.orekit.frames.TopocentricFrame;
27  import org.orekit.models.earth.displacement.StationDisplacement;
28  import org.orekit.orbits.CartesianOrbit;
29  import org.orekit.orbits.Orbit;
30  import org.orekit.orbits.PositionAngleType;
31  import org.orekit.propagation.conversion.KeplerianPropagatorBuilder;
32  import org.orekit.time.TimeScale;
33  import org.orekit.time.UT1Scale;
34  import org.orekit.utils.IERSConventions;
35  import org.orekit.utils.PVCoordinates;
36  
37  import java.util.List;
38  
39  public class KeplerianContext implements StationDataProvider {
40  
41      public IERSConventions                        conventions;
42      public OneAxisEllipsoid                       earth;
43      public CelestialBody                          sun;
44      public CelestialBody                          moon;
45      public TimeScale                              utc;
46      public UT1Scale                               ut1;
47      public Orbit                                  initialOrbit;
48      public StationDisplacement[]                  displacements;
49      public List<GroundStation>                    stations;
50  
51      public KeplerianPropagatorBuilder createBuilder(final PositionAngleType angleType, final boolean perfectStart, final double dP) {
52  
53          final Orbit startOrbit;
54          if (perfectStart) {
55              // orbit estimation will start from a perfect orbit
56              startOrbit = initialOrbit;
57          } else {
58              // orbit estimation will start from a wrong point
59              final Vector3D initialPosition = initialOrbit.getPosition();
60              final Vector3D initialVelocity = initialOrbit.getPVCoordinates().getVelocity();
61              final Vector3D wrongPosition   = initialPosition.add(new Vector3D(1000.0, 0, 0));
62              final Vector3D wrongVelocity   = initialVelocity.add(new Vector3D(0, 0, 0.01));
63              startOrbit                     = new CartesianOrbit(new PVCoordinates(wrongPosition, wrongVelocity),
64                                                                  initialOrbit.getFrame(),
65                                                                  initialOrbit.getDate(),
66                                                                  initialOrbit.getMu());
67          }
68  
69          // Initialize builder
70         return new KeplerianPropagatorBuilder(startOrbit, angleType, dP);
71  
72      }
73  
74      GroundStation createStation(double latitudeInDegrees, double longitudeInDegrees,
75                                  double altitude, String name) {
76          final GeodeticPoint gp = new GeodeticPoint(FastMath.toRadians(latitudeInDegrees),
77                                                     FastMath.toRadians(longitudeInDegrees),
78                                                     altitude);
79          return new GroundStation(new TopocentricFrame(earth, gp, name), ut1.getEOPHistory(), displacements);
80      }
81  
82      @Override
83      public List<GroundStation> getStations() {
84          return stations;
85      }
86  
87  }