-
Notifications
You must be signed in to change notification settings - Fork 0
/
GP.Cor.04Aug23.rmd
315 lines (246 loc) · 9.15 KB
/
GP.Cor.04Aug23.rmd
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
---
title: "GP.Corr.11Aug23"
author: "bvt"
date: "2023-08-30"
output:
html_document: default
pdf_document: default
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## GP RSO Time series
**Objective:**
Match, as close as possible, GP sets from different catalogs
**Discussion:**
This is how to download the entire space-track catalog
https://www.space-track.org/basicspacedata/query/class/gp/NORAD_CAT_ID/>1/orderby/CCSDS_OMM_VERS asc/format/csv/emptyresult/show
From Celestrak
https://celestrak.org/satcat/search.php - download the raw csv, rename the 'satcat' to 'celestrak.satcat.day/Month/year
There are many ways to understand a system's behavior using statistical
analysis of the generated output data.
```{r cars, eval=FALSE, include=FALSE}
summary(cars)
```
```{r initial, message=TRUE, warning=FALSE, include=FALSE}
#library(lubridate)
#library(rgl)
library(ggplot2)
# library(knitr)
# library(fBasics)
library(tidyverse)
# library(RecordLinkage)
# library(cluster)
# library(proxy)
library(asteRisk)
# set your working directory
#setwd("/home/bvt/Dropbox/eng_science/R/wd/GP_Corr")
knitr::opts_knit$set(root.dir = "/home/bvt/Dropbox/eng_science/R/wd/GP_Corr")
```
## Correlation Applications
Applications
```{r prepare.data, message=TRUE, warning=TRUE, include=FALSE, results='asis'}
# load in the data sets
df.source.1 <- read.csv("data/st_25544.history.csv", sep = ",", header = TRUE)
# added mean_motion = 1 / (period/1440) value to celestrak
df.source.1$MEAN_MOTION <- ((1) / (df.source.1$PERIOD/1440))
# massage the data by sub-setting the rows and columns into some more mangable and for specific searches,
# Altitude = (Mean Motion)^2 * 6,371,000 * (1 - Eccentricity^2)^-1/2
# The approximate mean motion for a satellite in the 800-850 range is 14.4-15.1 revolutions per day.
# Mean Motion = sqrt(6,371,000 / Altitude)
df.source.1.sel <-
df.source.1 %>%
#select(OBJECT_ID, OBJECT_NAME, INCLINATION, MEAN_MOTION) %>%
#select(NORAD_CAT_ID, INCLINATION, MEAN_MOTION) %>%
#filter(between(MEAN_MOTION, 14.40, 14.402))
filter(between(CREATION_DATE, "2004-08-17T15:22:27", "2004-08-17T15:22:45"))
#print()
#cat("==========================================================================================================")
#cat("==========================================================================================================")
```
```{r coor.1, eval=FALSE, message=TRUE, warning=TRUE, include=FALSE}
#df.rowname.1 <- rownames(df.source.1.sel[1])
library(asteRisk)
# Set the Keplerian orbital elements
a <- df.source.1$SEMIMAJOR_AXIS
e <- df.source.1$ECCENTRICITY
i <- df.source.1$INCLINATION #iclination
M <- df.source.1$MEAN_ANOMALY # mean anomoly
omega <- df.source.1$ARG_OF_PERICENTER # omega
OMEGA <- df.source.1$RA_OF_ASC_NODE # OMEGA
# Calculate the ECI coordinates
position_ECI <- KOEtoECI(a, e, i, M, omega, OMEGA)
position_ECI <- KOEtoECI(a, e, i, M, omega, OMEGA)
position_ECI <- KOEtoECI(select(df.source.1, a, e, i, M, omega, OMEGA))
position_ECI <- apply(d)
# Print the ECI coordinates
print(position_ECI)
```
```{r coor.2, eval=FALSE, message=TRUE, warning=FALSE, include=FALSE}
# from Bard
library(asteRisk)
# Create a function to calculate the ECI coordinates
KOEtoECI <- function(a, e, i, M, omega, OMEGA) {
# Calculate the ECI coordinates
x <- a * (cos(M) * cos(i) - e * cos(omega) * sin(i))
y <- a * (sin(M) * cos(i) + e * cos(omega) * cos(i) * sin(M))
z <- a * (sin(i) * sqrt(1 - e^2)) * sin(M)
# Return the ECI coordinates
return(c(x, y, z))
}
# Create a data frame
df <- data.frame(
a = c(6378137, 6378137),
e = c(0.009, 0.009),
i = c(90, 90),
M = c(0, 0),
omega = c(0, 0),
OMEGA = c(0, 0)
)
# Calculate the ECI coordinates for each row
xyz <- apply(df.source.1.sel, 1, KOEtoECI)
# Print the ECI coordinates
print(xyz)
```
```{r coor.3, eval=FALSE, include=FALSE}
# from Bard
library(asteRisk)
#library(satellite)
#library(raster)
library(asteRisk)
results_list <- list()
data <- data.frame(a = c(1, 1.1, 1.05), e = c(0.1, 0.12, 0.2), i = c(0.3, 0.3, 0.301), M = c(0.5, 0.6, 0.5), omega = c(0.7, 0.67, 0.8), OMEGA = c(0.9, 0.93, 0.91))
#for (i in 1:nrow(df.source.1.sel)) {
#result <- with(df.source.1.sel[i, ], KOEtoECI(a = SEMIMAJOR_AXIS, e = ECCENTRICITY, i = INCLINATION, M = MEAN_ANOMALY, omega = PERIAPSIS, OMEGA = RA_OF_ASC_NODE))
print(result)
#}
for (i in 1:nrow(data)) {
result <- with(data[i, ], KOEtoECI(a, e, i, M, omega, OMEGA))
results_list[[i]] <- result
}
# Right Ascension of the Ascending Node (Ω)
# Argument of Periapsis (ω)
print(as.data.frame(results_list))
```
placeholder
```{r coor.4, eval=FALSE, include=FALSE}
# # Create an empty list to store the results
results_list <- list()
# Loop through each row in the data frame
for (i in 1:nrow(data)) {
# Extract Keplerian elements for the current row
a <- data[i, "a"]
e <- data[i, "e"]
i <- data[i, "i"]
M <- data[i, "M"]
omega <- data[i, "omega"]
OMEGA <- data[i, "OMEGA"]
}
# Use the KOEtoECI function to compute ECI coordinates
result <- KOEtoECI(a, e, i, M, omega, OMEGA)
# Store the result in the list
results_list[[i]] <- result
}
# Convert the list of coordinates to a data frame
eci_df <- as.data.frame(do.call(rbind, results_list))
colnames(eci_df) <- c("x", "y", "z")
# Print the resulting ECI coordinates
print(eci_df)
```
```{r match, eval=FALSE, include=FALSE}
# Sample data in two data frames with row names
df_company1 <- data.frame(
RSO_ID = c("ST1", "ST2", "ST3"),
X = c(1.0, 1.1, 3.0), #
Y = c(0.5, 1.5, 2.5), #
Z = c(0.94, 1.6, 2.3) #
)
df_company2 <- data.frame(
RSO_ID = c("CT1", "CT2", "CT3"),
X = c(1.02, 2.3, 3.0), #
Y = c(0.5, 1.5, 2.44), #
Z = c(0.35, 1.2, 2.3) #
)
# Extract the Keplerian elements from each data.frame
df1_keplerian <- df_company1[, c("X", "Y", "Z")]
df2_keplerian <- df_company2[, c("X", "Y", "Z")]
# Calculate the Euclidean distance matrix using the dist function
euclidean_matrix <- as.matrix(dist(rbind(df1_keplerian, df2_keplerian)))
# Label the rows and columns of the matrix with the RSO_IDs
rownames(euclidean_matrix) <- c(df_company1$RSO_ID, df_company2$RSO_ID)
colnames(euclidean_matrix) <- rownames(euclidean_matrix)
# Print out the labeled results
print(euclidean_matrix)
#print(euclidean_matrix[lower.tri(euclidean_matrix, diag = TRUE)])
# Your existing code to calculate the Euclidean distance matrix...
# (Same as the code you provided)
# Get the lower triangular elements and set upper triangular elements to NA
lower_tri_matrix <- euclidean_matrix
lower_tri_matrix[upper.tri(lower_tri_matrix)] <- NA
# Print out the labeled lower triangular part of the matrix without showing 'NA' values
print(lower_tri_matrix)
```
```{r GPT.4, eval=FALSE, include=FALSE}
library(asteRisk)
# Create a function to calculate the ECI coordinates
KOEtoECI <- function(a, e, i, M, omega, OMEGA) {
# Calculate the ECI coordinates
x <- a * (cos(M) * cos(i) - e * cos(omega) * sin(i))
y <- a * (sin(M) * cos(i) + e * cos(omega) * cos(i) * sin(M))
z <- a * (sin(i) * sqrt(1 - e^2)) * sin(M)
# Return the ECI coordinates
return(c(x, y, z))
}
# Create a data frame
df <- data.frame(
a = c(6378137, 6378137),
e = c(0.009, 0.009),
i = c(90, 90),
M = c(0, 0),
omega = c(0, 0),
OMEGA = c(0, 0)
)
# Calculate the ECI coordinates for each row
#xyz <- apply(df, 1, KOEtoECI)
# Print the ECI coordinates
#print(xyz)
```
```{r PDF.1, echo=FALSE}
library(ggplot2)
# Create a vector of data
data <- as.data.frame(df.source.1$MEAN_MOTION)
# Plot the PDF
ggplot(data = df.source.1, aes(x = df.source.1$MEAN_MOTION)) +
geom_density(color = "blue") +
labs(title = "PDF of the Mean") +
geom_vline(aes(xintercept=mean(df.source.1$MEAN_MOTION)),
color="blue", linetype="dashed", size=1) +
geom_histogram(aes(y=..density..), colour="black", fill="white")+
geom_density(alpha=.2, fill="#FF6666")
print(ggplot)
# Plot the CDF
ggplot(data = df.source.1, aes(x = df.source.1$MEAN_ANOMALY)) +
stat_ecdf(color = "blue") +
labs(title = "CDF of the Mean Motion")
# Add mean line
ggplot(data=df.source.1, aes(y=MEAN_MOTION, x=df.source.1$EPOCH, group=1)) +
geom_smooth()
#geom_point()
print(ggplot)
```
```{r Notes, eval=FALSE, include=FALSE}
# Work Notes
# Entity Resoultion - https://github.com/cleanzr/record-linkage-tutorial
# https://cran.r-project.org/web/packages/diyar/vignettes/links.html
# https://stats.stackexchange.com/questions/15289/when-to-use-weighted-euclidean-distance-and-how-to-determine-the-weights-to-use#15325
# https://en.wikipedia.org/wiki/Mahalanobis_distance
# https://www.youtube.com/watch?v=hyNPsstKhfQ&t=677s
# EM - https://www.codingninjas.com/blog/2020/09/15/what-is-em-algorithm-in-machine-learning/
# https://medium.com/@gshriya195/top-5-distance-similarity-measures-implementation-in-machine-learning-1f68b9ecb0a3
# euclidean <- function(a,b) sqrt(sum((a-b^2)))
# nice list of distance types - https://www.statology.org/dist-function-in-r/
# https://rdrr.io/cran/asteRisk/f/vignettes/asteRisk.Rmd
#https://www.space-track.org/basicspacedata/query/class/gp_history/OBJECT_ID/25544/orderby/CCSDS_OMM_VERS asc/emptyresult/show
```