Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
DAR-Mars-F24/Data/roverStatus-f24.R
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 lines (44 sloc)
2.37 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Version: 11 Jul 2024 (added insistent curl) | |
# | |
# Rover status URL: https://mars.nasa.gov/maps/location/api/configure/get?mission=M20 | |
# See also: https://cran.r-project.org/web/packages/curl/vignettes/intro.html | |
require(curl) | |
require(jsonlite) | |
require(purrr) | |
# # Retrieve the status | |
# rover.status <- curl_fetch_memory("https://mars.nasa.gov/maps/location/api/configure/get?mission=M20") | |
# | |
# # Make it readable | |
# rover.status.content.df <- fromJSON(rawToChar(rover.status$content)) | |
# | |
# rover.loc <- rover.status.content.df$tools[[4]][[1]][[2]]$name[[2]] # Should be "Current Location" | |
# rover.current <- rover.status.content.df$tools[[4]][[1]][[2]]$code[[2]] # Should be "NOW" | |
# | |
# # TODO: These might be reversed; check! | |
# rover.lat <- rover.status.content.df$tools[[4]][[1]][[2]]$view[[2]][1] | |
# rover.lon <- rover.status.content.df$tools[[4]][[1]][[2]]$view[[2]][2] | |
# rover.position <<- data.frame(cbind(lon=rover.lon, lat=rover.lat)) | |
# Retrieve all waypoints | |
# NOTE: This call can sometimes time out; we've add error-proofing | |
#rover.waypoints.raw <- curl_fetch_memory("https://mars.nasa.gov/mmgis-maps/M20/Layers/json/M20_waypoints.json") | |
rate <- rate_delay(0.1) # May need to be adjusted... | |
curl_fetch_memory_insistent <- insistently(curl_fetch_memory, rate, quiet = FALSE) | |
rover.waypoints.raw <- curl_fetch_memory_insistent("https://mars.nasa.gov/mmgis-maps/M20/Layers/json/M20_waypoints.json") | |
# Save out to Rds | |
#saveRDS(rover.waypoints.raw, "rover.waypoints.raw.Rds") | |
#rover.waypoints.raw <- readRDS("rover.waypoints.raw.Rds") | |
rover.waypoints.content.def <- fromJSON(rawToChar(rover.waypoints.raw$content)) | |
rover.waypoints.sol <- rover.waypoints.content.def$features$properties$sol | |
rover.waypoints.lon <- rover.waypoints.content.def$features$properties$lon | |
rover.waypoints.lat <- rover.waypoints.content.def$features$properties$lat | |
rover.waypoints <<- data.frame(cbind(sol=rover.waypoints.sol, | |
lat=rover.waypoints.lat, | |
lon=rover.waypoints.lon)) | |
rover.position <<- rover.waypoints[nrow(rover.waypoints),] | |
rover.segments <<- data.frame(cbind( | |
x = rover.waypoints$lon[1:(nrow(rover.waypoints)-1)], | |
xend = rover.waypoints$lon[2:nrow(rover.waypoints)], | |
y = rover.waypoints$lat[1:(nrow(rover.waypoints)-1)], | |
yend = rover.waypoints$lat[2:nrow(rover.waypoints)])) | |
# Update the saved Rds | |
saveRDS(rover.waypoints, "rover.waypoints.Rds") |