| Title: | Access National Aeronautics and Space Administration (NASA) APIs |
|---|---|
| Description: | Provides functions to access and download data from various NASA APIs, including: Astronomy Picture of the Day (APOD), Mars Rover Photos, Earth Polychromatic Imaging Camera (EPIC), Near Earth Object Web Service (NeoWs), Earth Observatory Natural Event Tracker (EONET), and NASA Earthdata CMR Search. Most endpoints require a NASA API key for access. Data is retrieved, cleaned for analysis, and returned in a dataframe-friendly format. |
| Authors: | Steph Buongiorno [aut, cre] |
| Maintainer: | Steph Buongiorno <[email protected]> |
| License: | GPL-3 |
| Version: | 1.0.0 |
| Built: | 2026-05-06 05:12:12 UTC |
| Source: | https://github.com/rOpenGov/nasa |
Queries NASA's Astronomy Picture of the Day (APOD) API to retrieve images and metadata between a specified start and end date. Only image media types are included.
get_apod_metadata( start_date, end_date, api_key = "DEMO_KEY", folder_name = NULL )get_apod_metadata( start_date, end_date, api_key = "DEMO_KEY", folder_name = NULL )
start_date |
Character. Start date for the query in "YYYY-MM-DD" format. |
end_date |
Character. End date for the query in "YYYY-MM-DD" format. |
api_key |
Character. NASA API key. Defaults to "DEMO_KEY", but a personal API key is recommended. |
folder_name |
Character or NULL. Folder name to save images on Desktop if provided. If NULL, images are only printed and not saved. |
The function filters out any media types that are not images—for example, videos. It prints the image along with a truncated explanation for each entry, then returns the full metadata as a data frame.
A data frame containing metadata about the APOD images (date, title, explanation, URL, and media type).
## Not run: # Retrieve APOD images for a date range apod_metadata <- get_apod_metadata( start_date = "2024-04-01", end_date = "2024-04-02", api_key = "DEMO_KEY" ) ## End(Not run)## Not run: # Retrieve APOD images for a date range apod_metadata <- get_apod_metadata( start_date = "2024-04-01", end_date = "2024-04-02", api_key = "DEMO_KEY" ) ## End(Not run)
Queries NASA's Common Metadata Repository (CMR) to search Earth science datasets related to a specified keyword. Optionally filters results by a temporal range.
get_earthdata(keyword, n_results, start_date = NULL, end_date = NULL)get_earthdata(keyword, n_results, start_date = NULL, end_date = NULL)
keyword |
Character. A search term or phrase used to find relevant datasets in titles, descriptions, keywords, and provider names. |
n_results |
Integer. The number of dataset entries to retrieve. If more than 2000, multiple pages will be requested automatically. |
start_date |
Character or NULL. Optional start date filter in "YYYY-MM-DD" format.
If provided, must be used with |
end_date |
Character or NULL. Optional end date filter in "YYYY-MM-DD" format.
If provided, must be used with |
CMR is the Earthdata search engine, the backend database that stores metadata about:
- Satellite datasets - Earth science data (climate, ocean, atmosphere, land) - Observational granules (single files like images, temperature readings, etc.) - Services (subsetting, reformatting, and other data services)
The search finds matches based on the keyword provided. The keyword can appear in:
- Dataset titles - Dataset descriptions - Dataset keywords (tags) - Some provider names
The function accesses the CMR API endpoint:
https://cmr.earthdata.nasa.gov/
search/collections.json
(Note: This is an API endpoint and may return an error when opened in a browser.)
It harmonizes columns across API pages and returns up to the number of requested results.
If no results are found, an empty data frame is returned.
A data frame containing metadata about the matching datasets, with only cleaned column names (columns with '.' or '$' removed).
## Not run: # Search for 1 dataset related to sea surface temperature results <- get_earthdata(keyword = "sea surface temperature", n_results = 1) # Search with a temporal constraint results_time <- get_earthdata( keyword = "sea surface temperature", n_results = 1, start_date = "2020-01-01", end_date = "2020-01-02" ) ## End(Not run)## Not run: # Search for 1 dataset related to sea surface temperature results <- get_earthdata(keyword = "sea surface temperature", n_results = 1) # Search with a temporal constraint results_time <- get_earthdata( keyword = "sea surface temperature", n_results = 1, start_date = "2020-01-01", end_date = "2020-01-02" ) ## End(Not run)
Queries NASA's EPIC (Earth Polychromatic Imaging Camera) API to retrieve metadata and images of Earth taken on a specified date. Images can optionally be saved to a folder on the user's Desktop.
get_epic_earth_images(date = NULL, api_key = "DEMO_KEY", folder_name = NULL)get_epic_earth_images(date = NULL, api_key = "DEMO_KEY", folder_name = NULL)
date |
Character or NULL. The Earth date in "YYYY-MM-DD" format to retrieve images from. If NULL, today's date is used. Note that today's images may not yet be available. |
api_key |
Character. NASA API key. Defaults to |
folder_name |
Character or NULL. If provided, images will be saved in a folder with this name on the user's Desktop. If NULL, images are only displayed and not saved. |
The function builds the download URLs based on NASA's EPIC archive structure, which organizes images into
year/month/day subfolders. Only natural color images are retrieved.
Images are displayed using the magick package and can be optionally saved as PNG files.
A data frame containing metadata for the retrieved EPIC images, including image names, dates, and captions.
## Not run: # Retrieve and view EPIC images from April 1, 2024 epic_data <- get_epic_earth_images(date = "2024-04-01", api_key = "your_actual_api_key") # Retrieve and save EPIC images to Desktop/EPIC_Images epic_data_saved <- get_epic_earth_images( date = "2024-04-01", api_key = "DEMO_KEY", folder_name = "EPIC_Images" ) ## End(Not run)## Not run: # Retrieve and view EPIC images from April 1, 2024 epic_data <- get_epic_earth_images(date = "2024-04-01", api_key = "your_actual_api_key") # Retrieve and save EPIC images to Desktop/EPIC_Images epic_data_saved <- get_epic_earth_images( date = "2024-04-01", api_key = "DEMO_KEY", folder_name = "EPIC_Images" ) ## End(Not run)
Queries NASA's Mars Rover Photos API to retrieve photos taken by a specified rover on a given Earth date. Optionally saves the images to a folder on the user's Desktop.
get_mars_rover_photos_and_metadata( rover, earth_date, api_key = "DEMO_KEY", folder_name = NULL )get_mars_rover_photos_and_metadata( rover, earth_date, api_key = "DEMO_KEY", folder_name = NULL )
rover |
Character. The name of the Mars rover. Must be one of the following:
|
earth_date |
Character. The Earth date to query in |
api_key |
Character. NASA API key. Defaults to |
folder_name |
Character or NULL. If provided, images will be saved in a folder with this name on the user's Desktop. If NULL, images are only displayed and not saved. |
The function prints each retrieved image and associated metadata to the console. If a folder name is specified, images are saved to the Desktop inside the given folder. Only images taken on the specified date are returned; if no images exist, the function stops with an error.
A data frame containing metadata about the retrieved photos, including photo ID, sol (Martian day), camera name, image source URL, Earth date, and rover name.
## Not run: # Retrieve and save photos taken by Curiosity on June 3, 2015 mars_photos_metadata <- get_mars_rover_photos_and_metadata( rover = "curiosity", earth_date = "2015-06-03", api_key = "DEMO_KEY", folder_name = "MarsPhotos" ) ## End(Not run)## Not run: # Retrieve and save photos taken by Curiosity on June 3, 2015 mars_photos_metadata <- get_mars_rover_photos_and_metadata( rover = "curiosity", earth_date = "2015-06-03", api_key = "DEMO_KEY", folder_name = "MarsPhotos" ) ## End(Not run)
Queries NASA's Near Earth Object Web Service (NeoWs) to retrieve data about asteroids and comets approaching Earth within a specified date range.
get_neo_feed(start_date, end_date = NULL, api_key = "DEMO_KEY")get_neo_feed(start_date, end_date = NULL, api_key = "DEMO_KEY")
start_date |
Character. The start date for asteroid data in "YYYY-MM-DD" format. |
end_date |
Character or NULL. The end date in "YYYY-MM-DD" format. If NULL, defaults to 7 days after |
api_key |
Character. NASA API key. Defaults to |
The function calls the NeoWs feed endpoint at https://api.nasa.gov/neo/rest/v1/feed. Each asteroid's metadata is extracted into a tidy format for analysis. The maximum allowed range between start and end dates is 7 days.
A data frame containing information about near-Earth objects, including name, close approach date, relative velocity (km/h), miss distance (kilometers), and estimated diameter (meters).
## Not run: # Retrieve asteroid data for a 5-day period neo_data <- get_neo_feed( start_date = "2024-04-01", end_date = "2024-04-05", api_key = "DEMO_KEY" ) ## End(Not run)## Not run: # Retrieve asteroid data for a 5-day period neo_data <- get_neo_feed( start_date = "2024-04-01", end_date = "2024-04-05", api_key = "DEMO_KEY" ) ## End(Not run)