-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathSatellite_Updates.java
142 lines (122 loc) · 5.92 KB
/
Satellite_Updates.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONObject;
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
import matplotlib.pyplot as plt;
import mpl_toolkits.mplot3d.Axes3D;
import requests;
public class SatelliteVisualization {
public static void main(String[] args) {
try {
// Step 1: Retrieve satellite data from the API
String satelliteDataApiUrl = "API_URL_HERE";
String satelliteDataJson = sendGetRequest(satelliteDataApiUrl);
JSONArray satelliteData = new JSONArray(satelliteDataJson);
// Step 2: Parse TLE data using skyfield
List<String[]> tleData = new ArrayList<>();
for (int i = 0; i < satelliteData.length(); i++) {
JSONObject satellite = satelliteData.getJSONObject(i);
String line1 = satellite.getString("tle_line1");
String line2 = satellite.getString("tle_line2");
tleData.add(new String[] { line1, line2 });
}
// Step 3: Visualize satellite orbits in 3D
fig = plt.figure();
ax = fig.add_subplot(111, projection='3d');
for (String[] tle : tleData) {
// Calculate the satellite's position over time
TimeScale ts = TimeScalesFactory.getUTC();
AbsoluteDate start = AbsoluteDate.J2000_EPOCH;
AbsoluteDate end = AbsoluteDate.J2000_EPOCH.shiftedBy(3600);
List<AbsoluteDate> dates = new ArrayList<>();
for (AbsoluteDate date = start; date.compareTo(end) <= 0; date = date.shiftedBy(60)) {
dates.add(date);
}
Satellite satellite = new Satellite(new TLE(tle[0], tle[1]), CelestialBodyFactory.getEarth());
List<PVCoordinates> pvCoordinatesList = satellite.getPVCoordinatesList(dates);
List<GeodeticPoint> subpoints = new ArrayList<>();
for (PVCoordinates pvCoordinates : pvCoordinatesList) {
subpoints.add(Ellipsoid.WGS84.transform(pvCoordinates.getPosition(), FramesFactory.getICRF(),
AbsoluteDate.J2000_EPOCH));
}
// Extract latitude, longitude, and altitude
List<Double> latitudeList = new ArrayList<>();
List<Double> longitudeList = new ArrayList<>();
List<Double> altitudeList = new ArrayList<>();
for (GeodeticPoint subpoint : subpoints) {
latitudeList.add(subpoint.getLatitude());
longitudeList.add(subpoint.getLongitude());
altitudeList.add(subpoint.getAltitude());
}
// Plot the satellite's trajectory in 3D
ax.plot(longitudeList, latitudeList, altitudeList);
}
ax.set_xlabel("Longitude");
ax.set_ylabel("Latitude");
ax.set_zlabel("Altitude (km)");
// Step 4: Map satellites to countries using the satellite database API
String satelliteDbApiUrl = "SATELLITE_DB_API_URL_HERE";
String satelliteDbJson = sendGetRequest(satelliteDbApiUrl);
JSONArray satelliteDb = new JSONArray(satelliteDbJson);
// Mapping satellite names to countries
Map<String, String> satelliteCountryMap = new HashMap<>();
for (int i = 0; i < satelliteData.length(); i++) {
JSONObject satellite = satelliteData.getJSONObject(i);
String name = satellite.getString("name");
for (int j = 0; j < satelliteDb.length(); j++) {
JSONObject entry = satelliteDb.getJSONObject(j);
if (entry.getString("name").equals(name)) {
String country = entry.getString("country");
satelliteCountryMap.put(name, country);
break;
}
}
}
// Printing satellite information
for (int i = 0; i < satelliteData.length(); i++) {
JSONObject satellite = satelliteData.getJSONObject(i);
String name = satellite.getString("name");
double angle = satellite.getDouble("angle");
String country = satelliteCountryMap.getOrDefault(name, "Unknown");
System.out.println("Satellite Name: " + name);
System.out.println("Orbital Angle: " + angle + " degrees");
System.out.println("Country: " + country);
System.out.println();
}
// Show the 3D plot
plt.show();
} catch (Exception e) {
e.printStackTrace();
}
}
private static String sendGetRequest(String url) throws IOException {
HttpURLConnection connection = null;
BufferedReader reader = null;
StringBuilder response = new StringBuilder();
try {
URL requestUrl = new URL(url);
connection = (HttpURLConnection) requestUrl.openConnection();
connection.setRequestMethod("GET");
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
} finally {
if (reader != null) {
reader.close();
}
if (connection != null) {
connection.disconnect();
}
}
return response.toString();
}
}