Skip to content

Instantly share code, notes, and snippets.

@mys721tx
Last active June 13, 2022 11:22
Show Gist options
  • Save mys721tx/ce6ae3d3cd26a264d16dd7b6a25ec447 to your computer and use it in GitHub Desktop.
Save mys721tx/ce6ae3d3cd26a264d16dd7b6a25ec447 to your computer and use it in GitHub Desktop.
ISS ground track plotter
library(tidyverse)
library(asteRisk)
library(ggmap)
library(lubridate)
getLatestSpaceData()
iss_tle <- read_file(
"https://celestrak.com/NORAD/elements/gp.php?CATNR=25544&FORMAT=tle"
) %>%
strsplit(., " *\r\n") %>%
flatten_chr() %>%
parseTLElines()
params <- iss_tle %>% {
list(
n0 = `$`(., meanMotion) * ((2 * pi) / (1440)),
e0 = `$`(., eccentricity),
i0 = `$`(., inclination) * pi / 180,
M0 = `$`(., meanAnomaly) * pi / 180,
omega0 = `$`(., perigeeArgument) * pi / 180,
OMEGA0 = `$`(., ascension) * pi / 180,
Bstar = `$`(., Bstar),
initialDateTime = `$`(., dateTime)
)
}
progress <- now(tzone = "UTC") %>% {
t <- as.numeric(. - as.POSIXct(iss_tle$dateTime, tz = "UTC")) * 60
tibble(
time = c(seq(-50, 50, by = 1) + t, t),
val = map(time, ~rlang::inject(sgdp4(!!!params, targetTime = .)))
)
} %>%
unnest_wider(val)
geodetic <- progress %>%
mutate(
time = as.POSIXct(iss_tle$dateTime, tz = "UTC") + time * 60,
p = map(position, ~ .x * 1000),
a = map2(p, as.character(time), TEMEtoLATLON),
a = map(a, setNames, c("latitude", "longitude", "altitude")),
.keep = "none"
) %>%
unnest_wider(a)
ggmap(get_map(c(left = -180, right = 180, bottom = -80, top = 80))) +
geom_point(
data = geodetic %>% slice(1: n() - 1),
aes(x = longitude, y = latitude, color = time),
size = 0.3,
alpha = 0.8
) +
theme(legend.position = "bottom", legend.key.width = unit(5, "line")) +
geom_point(
data = geodetic %>% slice(n()),
aes(x = longitude, y = latitude),
color = "red",
shape = 3,
size = 4
)
geodetic %>% slice(n())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment