nasa

package module
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 17 Imported by: 0

README

NASA Open APIs

Go package for NASA Open APIs.

APIs Implemented
  • APOD: Astronomy Picture of the Day
  • Asteroids NeoWs: Near Earth Object Web Service
  • DONKI: Space Weather Database of Notifications, Knowledge, Information
  • Earth: Unlock the significant public investment in earth observation data
  • EONET: The Earth Observatory Natural Event Tracker
  • EPIC: Earth Polychromatic Imaging Camera
  • Exoplanet: Programmatic access to NASA's Exoplanet Archive database
  • GeneLab: Programmatic interface for GeneLab's public data repository website
  • Insight: Mars Weather Service API
  • Mars Rover Photos: Image data gathered by NASA's Curiosity, Opportunity, Spirit, and Perseverance rovers on Mars, fetched live from NASA's raw image feeds and the PDS Imaging Atlas
  • NASA Image and Video Library: API to access the NASA Image and Video Library site at images.nasa.gov
  • TechTransfer: Patents, Software, and Tech Transfer Reports
  • Satallite Situation Center: System to cast geocentric spacecraft location information into a framework of (empirical) geophysical regions
  • SSD/CNEOS: Solar System Dynamics and Center for Near-Earth Object Studies
  • Techport: API to make NASA technology project data available in a machine-readable format
  • TLE API: Two line element data for earth-orbiting objects at a given point in time
  • Vesta/Moon/Mars Trek WMTS: A Web Map Tile Service for the Vesta, Moon, and Mars Trek imagery projects

Using From Another Project

Install the module with Go modules.

go get github.com/Oshuma/nasa

Import the package and call the client helpers from your code.

API Examples

All snippets assume a shared set of imports:

import (
	"fmt"
	"log"
	"os"
	"time"

	"github.com/Oshuma/nasa"
)
APOD: Astronomy Picture of the Day
apod, err := nasa.APOD(&nasa.APODParams{
	Date: time.Now(),
})
if err != nil {
	log.Fatal(err)
}

fmt.Printf("%s: %s\n", apod.Date.Format("2006-01-02"), apod.Title)
fmt.Printf("Media: %s\n", apod.URL)

APOD data comes from NASA's APOD WordPress feed, which needs no API key. See APOD_MIGRATION.md for planned changes to the APOD response.

If you need more than one image (for example, a date range) use APODList:

items, err := nasa.APODList(&nasa.APODParams{
	StartDate: time.Now().AddDate(0, 0, -3),
	EndDate:   time.Now(),
	Thumbs:    true,
})
if err != nil {
	log.Fatal(err)
}

for _, item := range items {
	fmt.Printf("%s: %s (%s)\n", item.Date.Format("2006-01-02"), item.Title, item.MediaType)
}
EPIC: Earth Polychromatic Imaging Camera
images, err := nasa.EPIC(&nasa.EPICParams{
	APIKey:     os.Getenv("NASA_API_KEY"),
	Collection: "natural",
})
if err != nil {
	log.Fatal(err)
}

for _, img := range images {
	fmt.Printf("%s - %s\n", img.Date.Format("2006-01-02"), img.Caption)
	fmt.Println("Natural image:", img.URL.Natural)
	fmt.Println("Thumbnail:", img.URL.Thumb.Natural)
}

Passing a Date retrieves imagery for a specific day; otherwise the helper returns the most recent image for the requested collection (natural or enhanced).

Mars Rover Photos

The original Mars Rover Photos API was retired on October 8, 2025. These helpers now fetch full-frame images on the fly, with no API key and no caching:

  • Curiosity and Perseverance come from NASA's raw image feeds, which update as new images arrive.
  • Opportunity and Spirit come from the PDS Imaging Atlas, NASA's archive of mission data. These are ILF products: full-frame images from the Front and Rear Hazcams, Navcam, Pancam and Microscopic Imager (nasa.RoverCameraMI), returned as 1024×1024 JPEGs. Pancam captured each scene through several color filters, so a scene appears as several grayscale images.

Stability: none of these sources is a documented public API. The raw image feeds (mars.nasa.gov/api/v1/raw_image_items for Curiosity and mars.nasa.gov/rss/api for Perseverance) power NASA's own raw image galleries, and the PDS search index (pds-imaging.jpl.nasa.gov/solr/pds_archives/search) powers the Imaging Atlas website. The full-size Opportunity and Spirit image URLs are derived from the archive's folder layout rather than returned by the index. Any of these may change or disappear without notice, which would break these helpers until the library is updated.

photos, err := nasa.MarsRoverPhotos(&nasa.MarsPhotosParams{
	Sol:    1000,
	Camera: nasa.RoverCameraNAVCAM,
	Page:   1,
}, nasa.RoverCuriosity)
if err != nil {
	log.Fatal(err)
}

for _, photo := range photos.Photos {
	fmt.Printf("%s - %s\n", photo.EarthDate.Format("2006-01-02"), photo.Image)
}

Helpers such as nasa.RoverCuriosity, nasa.RoverPerseverance, and the predefined RoverCamera* constants ensure only valid camera selections are sent for a rover.

  • Set EarthDate instead of Sol to get the photos captured on that UTC date.
  • Page returns 25 photos per page; leave it at 0 to get every matching photo. photos.Total holds the number of matches across all pages.
  • MarsRoverPhotosLatest returns the photos from the most recent sol that has full-frame images.
  • MarsMissionManifest returns a partial manifest: mission dates and status, MaxSol, MaxDate and TotalPhotos, but no per-sol Photos breakdown.
NASA Image and Video Library
results, err := nasa.MediaSearch(&nasa.MediaParams{
	Query:     "apollo 11",
	MediaType: "image,video",
	Page:      1,
})
if err != nil {
	log.Fatal(err)
}

fmt.Printf("Total hits: %d\n", results.Metadata.TotalHits)

for _, item := range results.Items {
	if len(item.Data) == 0 {
		continue
	}
	data := item.Data[0]
	fmt.Printf("%s - %s\n", data.NasaID, data.Title)
	for _, link := range item.Links {
		if link.Rel == "preview" {
			fmt.Println("Preview:", link.Href)
		}
	}
}

Any combination of documented search parameters can be supplied through MediaParams. Use pagination helpers like Page and PageSize, or refine searches with fields such as Center, Keywords, Photographer, and YearStart / YearEnd.

Documentation

Index

Constants

View Source
const Version = "0.4.1"

Version is the package version.

Variables

View Source
var (
	// ErrorNoAPIKey is returned with no API key is given.
	ErrorNoAPIKey = errors.New("no API key provided; get one at https://api.nasa.gov")

	// ErrorNoMetadata is returned if a media asset has no metadata.
	ErrorNoMetadata = errors.New("media has no metadata")

	// ErrorNoCaptions is returned if a media asset has no captions.
	ErrorNoCaptions = errors.New("media has no captions")

	// ErrorNoQuery is returned if there are no search parameters provided.
	ErrorNoQuery = errors.New("must provide at least one search parameter")

	// ErrorParamsMismatch is returned when the wrong type of ParamEncoder is used.
	ErrorParamsMismatch = errors.New("wrong param type passed")

	// ErrorNoResults is returned when a query that must return items finds none.
	ErrorNoResults = errors.New("no results found")

	// ErrorRoverUnsupported is returned when photos are requested for a rover that has no
	// supported image source.
	ErrorRoverUnsupported = errors.New("rover is not supported")
)
View Source
var (
	RoverCuriosity = Rover{
		Name:        "Curiosity",
		Slug:        "curiosity",
		Cameras:     []RoverCamera{RoverCameraFHAZ, RoverCameraRHAZ, RoverCameraMAST, RoverCameraCHEMCAM, RoverCameraMAHLI, RoverCameraMARDI, RoverCameraNAVCAM},
		LandingDate: time.Date(2012, 8, 6, 0, 0, 0, 0, time.UTC),
		LaunchDate:  time.Date(2011, 11, 26, 0, 0, 0, 0, time.UTC),
		Status:      "active",
	}
	RoverPerseverance = Rover{
		Name: "Perseverance",
		Slug: "perseverance",
		Cameras: []RoverCamera{
			RoverCameraEDLRUCAM,
			RoverCameraEDLRDCAM,
			RoverCameraEDLDDCAM,
			RoverCameraEDLPUCAM1,
			RoverCameraEDLPUCAM2,
			RoverCameraNAVCAMLEFT,
			RoverCameraNAVCAMRIGHT,
			RoverCameraMCZLEFT,
			RoverCameraMCZRIGHT,
			RoverCameraFRONTHAZCAMLEFTA,
			RoverCameraFRONTHAZCAMRIGHTA,
			RoverCameraREARHAZCAMLEFT,
			RoverCameraREARHAZCAMRIGHT,
			RoverCameraSKYCAM,
			RoverCameraSHERLOCWATSON,
			RoverCameraSUPERCAMRMI,
			RoverCameraLCAM,
		},
		LandingDate: time.Date(2021, 2, 18, 0, 0, 0, 0, time.UTC),
		LaunchDate:  time.Date(2020, 7, 30, 0, 0, 0, 0, time.UTC),
		Status:      "active",
	}
	RoverOpportunity = Rover{
		Name:        "Opportunity",
		Slug:        "opportunity",
		Cameras:     []RoverCamera{RoverCameraFHAZ, RoverCameraRHAZ, RoverCameraNAVCAM, RoverCameraPANCAM, RoverCameraMI},
		LandingDate: time.Date(2004, 1, 25, 0, 0, 0, 0, time.UTC),
		LaunchDate:  time.Date(2003, 7, 7, 0, 0, 0, 0, time.UTC),
		Status:      "complete",
	}
	RoverSpirit = Rover{
		Name:        "Spirit",
		Slug:        "spirit",
		Cameras:     []RoverCamera{RoverCameraFHAZ, RoverCameraRHAZ, RoverCameraNAVCAM, RoverCameraPANCAM, RoverCameraMI},
		LandingDate: time.Date(2004, 1, 4, 0, 0, 0, 0, time.UTC),
		LaunchDate:  time.Date(2003, 6, 10, 0, 0, 0, 0, time.UTC),
		Status:      "complete",
	}

	// Rovers is a convenience slice for iterating through every supported rover when
	// building UI pickers or issuing batch calls.
	Rovers = []Rover{
		RoverCuriosity,
		RoverPerseverance,
		RoverOpportunity,
		RoverSpirit,
	}
)

Defines Rovers to be used in Mars rover API requests.

View Source
var (
	// RoverCameraFHAZ is the Front Hazard Avoidance Camera.
	RoverCameraFHAZ = RoverCamera{
		Name:     "FHAZ",
		FullName: "Front Hazard Avoidance Camera",
		Slug:     "fhaz",
	}

	// RoverCameraRHAZ is the Rear Hazard Avoidance Camera.
	RoverCameraRHAZ = RoverCamera{
		Name:     "RHAZ",
		FullName: "Rear Hazard Avoidance Camera",
		Slug:     "rhaz",
	}

	// RoverCameraMAST is the Mast Camera.
	RoverCameraMAST = RoverCamera{
		Name:     "MAST",
		FullName: "Mast Camera",
		Slug:     "mast",
	}

	// RoverCameraCHEMCAM is the Chemistry and Camera Complex.
	RoverCameraCHEMCAM = RoverCamera{
		Name:     "CHEMCAM",
		FullName: "Chemistry and Camera Complex",
		Slug:     "chemcam",
	}

	// RoverCameraMAHLI is the Mars Hand Lens Imager.
	RoverCameraMAHLI = RoverCamera{
		Name:     "MAHLI",
		FullName: "Mars Hand Lens Imager",
		Slug:     "mahli",
	}

	// RoverCameraMARDI is the Mars Descent Imager.
	RoverCameraMARDI = RoverCamera{
		Name:     "MARDI",
		FullName: "Mars Descent Imager",
		Slug:     "mardi",
	}

	// RoverCameraNAVCAM is the Navigation Camera.
	RoverCameraNAVCAM = RoverCamera{
		Name:     "NAVCAM",
		FullName: "Navigation Camera",
		Slug:     "navcam",
	}

	// RoverCameraPANCAM is the Panoramic Camera.
	RoverCameraPANCAM = RoverCamera{
		Name:     "PANCAM",
		FullName: "Panoramic Camera",
		Slug:     "pancam",
	}

	// RoverCameraMI is the Microscopic Imager.
	RoverCameraMI = RoverCamera{
		Name:     "MI",
		FullName: "Microscopic Imager",
		Slug:     "mi",
	}

	// RoverCameraEDLRUCAM is the Entry, Descent, and Landing Rover Up-Look Camera.
	RoverCameraEDLRUCAM = RoverCamera{
		Name:     "EDL_RUCAM",
		FullName: "Entry, Descent, and Landing Rover Up-Look Camera",
		Slug:     "edl_rucam",
	}

	// RoverCameraEDLRDCAM is the Entry, Descent, and Landing Rover Down-Look Camera.
	RoverCameraEDLRDCAM = RoverCamera{
		Name:     "EDL_RDCAM",
		FullName: "Entry, Descent, and Landing Rover Down-Look Camera",
		Slug:     "edl_rdcam",
	}

	// RoverCameraEDLDDCAM is the Entry, Descent, and Landing Descent Stage Down-Look Camera.
	RoverCameraEDLDDCAM = RoverCamera{
		Name:     "EDL_DDCAM",
		FullName: "Entry, Descent, and Landing Descent Stage Down-Look Camera",
		Slug:     "edl_ddcam",
	}

	// RoverCameraEDLPUCAM1 is the Entry, Descent, and Landing Parachute Up-Look Camera A.
	RoverCameraEDLPUCAM1 = RoverCamera{
		Name:     "EDL_PUCAM1",
		FullName: "Entry, Descent, and Landing Parachute Up-Look Camera A",
		Slug:     "edl_pucam1",
	}

	// RoverCameraEDLPUCAM2 is the Entry, Descent, and Landing Parachute Up-Look Camera B.
	RoverCameraEDLPUCAM2 = RoverCamera{
		Name:     "EDL_PUCAM2",
		FullName: "Entry, Descent, and Landing Parachute Up-Look Camera B",
		Slug:     "edl_pucam2",
	}

	// RoverCameraNAVCAMLEFT is the Perseverance Navigation Camera (Left).
	RoverCameraNAVCAMLEFT = RoverCamera{
		Name:     "NAVCAM_LEFT",
		FullName: "Navigation Camera - Left",
		Slug:     "navcam_left",
	}

	// RoverCameraNAVCAMRIGHT is the Perseverance Navigation Camera (Right).
	RoverCameraNAVCAMRIGHT = RoverCamera{
		Name:     "NAVCAM_RIGHT",
		FullName: "Navigation Camera - Right",
		Slug:     "navcam_right",
	}

	// RoverCameraMCZLEFT is the Mastcam-Z Left Camera.
	RoverCameraMCZLEFT = RoverCamera{
		Name:     "MCZ_LEFT",
		FullName: "Mastcam-Z Left Camera",
		Slug:     "mcz_left",
	}

	// RoverCameraMCZRIGHT is the Mastcam-Z Right Camera.
	RoverCameraMCZRIGHT = RoverCamera{
		Name:     "MCZ_RIGHT",
		FullName: "Mastcam-Z Right Camera",
		Slug:     "mcz_right",
	}

	// RoverCameraFRONTHAZCAMLEFTA is the Front Hazard Avoidance Camera (Left A).
	RoverCameraFRONTHAZCAMLEFTA = RoverCamera{
		Name:     "FRONT_HAZCAM_LEFT_A",
		FullName: "Front Hazard Avoidance Camera - Left",
		Slug:     "front_hazcam_left_a",
	}

	// RoverCameraFRONTHAZCAMRIGHTA is the Front Hazard Avoidance Camera (Right A).
	RoverCameraFRONTHAZCAMRIGHTA = RoverCamera{
		Name:     "FRONT_HAZCAM_RIGHT_A",
		FullName: "Front Hazard Avoidance Camera - Right",
		Slug:     "front_hazcam_right_a",
	}

	// RoverCameraREARHAZCAMLEFT is the Rear Hazard Avoidance Camera (Left).
	RoverCameraREARHAZCAMLEFT = RoverCamera{
		Name:     "REAR_HAZCAM_LEFT",
		FullName: "Rear Hazard Avoidance Camera - Left",
		Slug:     "rear_hazcam_left",
	}

	// RoverCameraREARHAZCAMRIGHT is the Rear Hazard Avoidance Camera (Right).
	RoverCameraREARHAZCAMRIGHT = RoverCamera{
		Name:     "REAR_HAZCAM_RIGHT",
		FullName: "Rear Hazard Avoidance Camera - Right",
		Slug:     "rear_hazcam_right",
	}

	// RoverCameraSKYCAM is the SkyCam instrument.
	RoverCameraSKYCAM = RoverCamera{
		Name:     "SKYCAM",
		FullName: "SkyCam",
		Slug:     "skycam",
	}

	// RoverCameraSHERLOCWATSON is the SHERLOC WATSON instrument.
	RoverCameraSHERLOCWATSON = RoverCamera{
		Name:     "SHERLOC_WATSON",
		FullName: "SHERLOC WATSON",
		Slug:     "sherloc_watson",
	}

	// RoverCameraSUPERCAMRMI is the SuperCam Remote Micro-Imager.
	RoverCameraSUPERCAMRMI = RoverCamera{
		Name:     "SUPERCAM_RMI",
		FullName: "SuperCam Remote Micro-Imager",
		Slug:     "supercam_rmi",
	}

	// RoverCameraLCAM is the Lander Vision System Camera.
	RoverCameraLCAM = RoverCamera{
		Name:     "LCAM",
		FullName: "Lander Vision System Camera",
		Slug:     "lcam",
	}

	// RoverCameras is an easily iteratable array of cameras.
	RoverCameras = []RoverCamera{
		RoverCameraFHAZ,
		RoverCameraRHAZ,
		RoverCameraMAST,
		RoverCameraCHEMCAM,
		RoverCameraMAHLI,
		RoverCameraMARDI,
		RoverCameraNAVCAM,
		RoverCameraPANCAM,
		RoverCameraMI,
		RoverCameraEDLRUCAM,
		RoverCameraEDLRDCAM,
		RoverCameraEDLDDCAM,
		RoverCameraEDLPUCAM1,
		RoverCameraEDLPUCAM2,
		RoverCameraNAVCAMLEFT,
		RoverCameraNAVCAMRIGHT,
		RoverCameraMCZLEFT,
		RoverCameraMCZRIGHT,
		RoverCameraFRONTHAZCAMLEFTA,
		RoverCameraFRONTHAZCAMRIGHTA,
		RoverCameraREARHAZCAMLEFT,
		RoverCameraREARHAZCAMRIGHT,
		RoverCameraSKYCAM,
		RoverCameraSHERLOCWATSON,
		RoverCameraSUPERCAMRMI,
		RoverCameraLCAM,
	}
)

Functions

func GetMediaCaptions

func GetMediaCaptions(nasaID string) (string, error)

GetMediaCaptions returns the captions for the given nasaID. TODO: Maybe parse the captions in later versions.

Types

type APIParam

type APIParam struct {
	APIKey string
}

APIParam is used when only an API key is needed. Most NASA endpoints require at least this parameter.

func (*APIParam) Encode

func (p *APIParam) Encode() (string, error)

Encode returns a string representation for the given API type.

type APODImage

type APODImage struct {
	Date        Date   `json:"date"`
	Title       string `json:"title"`
	URL         string `json:"url"`
	HDURL       string `json:"hdurl"`
	Explanation string `json:"explanation"`
	MediaType   string `json:"media_type"`
	Copyright   string `json:"copyright"`

	// ThumbnailURL is only set for YouTube videos when APODParams.Thumbs is true.
	ThumbnailURL string `json:"thumbnail_url"`

	// Deprecated: The APOD feed has no service version; it is always empty.
	ServiceVersion string `json:"service_version"`
}

APODImage represents an Astronomy Picture Of the Day. Most callers obtain an APODImage via APOD or APODList rather than instantiating the struct directly.

URL is the image (or video embed for videos) and HDURL the full-size image, matching the retired api.nasa.gov service. Explanation and Copyright may contain HTML.

func APOD

func APOD(p ParamEncoder) (APODImage, error)

APOD returns the Astronomy Picture Of the Day for APODParams.Date, or the latest one when Date is not set. Other APODParams filters are ignored; see APODList.

func APODList added in v0.2.0

func APODList(p ParamEncoder) ([]APODImage, error)

APODList returns APOD images for a StartDate/EndDate range (oldest first) or Count random images. Count returns ErrorNoResults if no images are found. With neither set it behaves like APOD.

type APODParams

type APODParams struct {
	// Deprecated: The APOD feed does not require an API key; it is ignored.
	APIKey string

	Date time.Time

	// Deprecated: HDURL is always populated when available; HD is ignored.
	HD bool

	StartDate time.Time
	EndDate   time.Time

	// Count returns this many random images, fetched one date at a time.
	Count int

	// Thumbs sets APODImage.ThumbnailURL for YouTube videos.
	Thumbs bool
}

APODParams wraps the APOD filters used by APOD and APODList, such as Date or StartDate/EndDate.

func (*APODParams) Encode deprecated

func (p *APODParams) Encode() (string, error)

Encode returns the query string for the retired api.nasa.gov APOD service.

Deprecated: APOD and APODList no longer use it.

type Date

type Date struct {
	time.Time
}

Date is a time.Time wrapper.

func (*Date) UnmarshalJSON

func (d *Date) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a date formatted as YYYY-MM-DD.

type EPICDate

type EPICDate struct {
	time.Time
}

EPICDate is a time.Time wrapper used to parse the EPIC date response.

func (*EPICDate) UnmarshalJSON

func (d *EPICDate) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a date formatted as YYYY-MM-DD HH-MM-SS.

type EPICImage

type EPICImage struct {
	Date       EPICDate `json:"date"`
	Identifier string   `json:"identifier"`
	Caption    string   `json:"caption"`
	Image      string   `json:"image"`
	Version    string   `json:"version"`
	Coords     struct {
		Centroid LatLon      `json:"centroid_coordinates"`
		Dscovr   XYZ         `json:"dscovr_j2000_position"`
		Lunar    XYZ         `json:"lunar_j2000_position"`
		Sun      XYZ         `json:"sun_j2000_position"`
		Attitude Quaternions `json:"attitude_quaternions"`
	} `json:"coords"`
	URL struct {
		Natural  string
		Enhanced string
		Thumb    struct {
			Natural  string
			Enhanced string
		} `json:"-"`
	} `json:"-"`
}

EPICImage represents an image from the Earth Polychromatic Imaging Camera. The helper populates archive URLs so clients can link directly to the natural or enhanced imagery returned by the EPIC API.

type EPICImages

type EPICImages []*EPICImage

EPICImages is an array of pointers to EPICImage returned by the EPIC helper.

func EPIC

func EPIC(p ParamEncoder) (EPICImages, error)

EPIC fetches imagery metadata from the Earth Polychromatic Imaging Camera. Populate EPICParams with the desired collection and optional date; when Date is omitted the function returns the most recent image for the requested collection. The helper also annotates each image with convenient archive download URLs.

type EPICParams

type EPICParams struct {
	APIKey     string
	Date       time.Time
	Collection string
}

EPICParams wraps the EPIC API params. Provide the desired collection (natural or enhanced), optional Date, and API key if required.

func (*EPICParams) Encode

func (p *EPICParams) Encode() (string, error)

Encode returns a string representation for the given API type.

type ErrorHTTPStatus added in v0.3.0

type ErrorHTTPStatus struct {
	StatusCode int
	Body       string
}

ErrorHTTPStatus is returned when an API responds with a non-2xx status code. Body holds the raw response body, which often contains the API's own error message.

func (*ErrorHTTPStatus) Error added in v0.3.0

func (e *ErrorHTTPStatus) Error() string

type ErrorRoverCameraMissing

type ErrorRoverCameraMissing struct {
	// contains filtered or unexported fields
}

ErrorRoverCameraMissing is returned if the rover does not have the camera available.

func (*ErrorRoverCameraMissing) Error

func (e *ErrorRoverCameraMissing) Error() string

type LatLon

type LatLon struct {
	Lat float64 `json:"lat"`
	Lon float64 `json:"lon"`
}

LatLon represents latitude/longitude coordinates as returned by several NASA endpoints, including EPIC image metadata.

type ManifestPhoto

type ManifestPhoto struct {
	Sol         int      `json:"sol"`
	EarthDate   Date     `json:"earth_date"`
	TotalPhotos int      `json:"total_photos"`
	Cameras     []string `json:"cameras"`
}

ManifestPhoto stores info about mission manifest photos.

type MarsPhotosParams

type MarsPhotosParams struct {
	// APIKey is not used: NASA's raw image feeds do not require one.
	//
	// Deprecated: The Mars photo sources ignore it.
	APIKey    string
	Sol       int
	EarthDate time.Time
	Camera    RoverCamera
	Page      int
}

MarsPhotosParams wraps the Mars photo filters. Use it with MarsRoverPhotos or MarsRoverPhotosLatest to supply a sol or earth date, camera, and page.

func (*MarsPhotosParams) Encode

func (p *MarsPhotosParams) Encode() (string, error)

Encode returns a string representation for the given API type.

type Media

type Media struct {
	Metadata struct {
		TotalHits int `json:"total_hits"`
	} `json:"metadata"`

	Items []struct {
		Data []struct {
			Center           string    `json:"center"`
			Album            []string  `json:"album"`
			SecondaryCreator string    `json:"secondary_creator"`
			Keywords         []string  `json:"keywords"`
			Description      string    `json:"description"`
			Description508   string    `json:"description_508"`
			MediaType        string    `json:"media_type"`
			NasaID           string    `json:"nasa_id"`
			DateCreated      time.Time `json:"date_created"`
			Location         string    `json:"location"`
			Photographer     string    `json:"photographer"`
			Title            string    `json:"title"`
		} `json:"data"`

		Links []struct {
			Render string `json:"render"`
			Href   string `json:"href"`
			Rel    string `json:"rel"`
			Prompt string `json:"prompt"`
			Width  int    `json:"width"`
			Height int    `json:"height"`
			Size   int64  `json:"size"`
		} `json:"links"`

		Href string `json:"href"`
	} `json:"items"`

	Links []struct {
		Prompt string `json:"prompt"`
		Href   string `json:"href"`
		Rel    string `json:"rel"`
	} `json:"links"`

	Version string `json:"version"`
	Href    string `json:"href"`
}

Media represents a NASA Image and Video Library search response. The structure maps directly to the Collection+JSON payload returned by the /search endpoint.

func MediaSearch

func MediaSearch(p ParamEncoder) (Media, error)

MediaSearch queries the NASA Image and Video Library /search endpoint using the provided MediaParams. At least one search parameter must be supplied; the helper unmarshals the Collection+JSON response into a Media value for easier consumption.

type MediaAssets

type MediaAssets struct {
	Items []struct {
		Href string `json:"href"`
	} `json:"items"`
	Version string `json:"version"`
	Href    string `json:"href"`
}

MediaAssets represents the results from the media asset manifest endpoint, describing downloadable resources for a media item identified by NASA ID.

func GetMediaAssets

func GetMediaAssets(nasaID string) (MediaAssets, error)

GetMediaAssets retrieves the media asset manifest for the given NASA ID, returning download links for each available rendition (image, video, metadata, etc.).

type MediaMetadata

type MediaMetadata struct {
	// TODO: Split these off into structs based on their namespace.
	// TODO: Parse the weird timestamps: "2006:01:02 15:04:05" and "2006:01:02 15:04:05-0700"
	AVAILAlbum                   StringList `json:"AVAIL:Album"`
	AVAILCenter                  string     `json:"AVAIL:Center"`
	AVAILDateCreated             string     `json:"AVAIL:DateCreated"`
	AVAILDescription             string     `json:"AVAIL:Description"`
	AVAILDescription508          string     `json:"AVAIL:Description508"`
	AVAILKeywords                []string   `json:"AVAIL:Keywords"`
	AVAILLocation                string     `json:"AVAIL:Location"`
	AVAILMediaType               string     `json:"AVAIL:MediaType"`
	AVAILNASAID                  string     `json:"AVAIL:NASAID"`
	AVAILOwner                   string     `json:"AVAIL:Owner"`
	AVAILPhotographer            string     `json:"AVAIL:Photographer"`
	AVAILSecondaryCreator        string     `json:"AVAIL:SecondaryCreator"`
	AVAILTitle                   string     `json:"AVAIL:Title"`
	CompositeImageSize           string     `json:"Composite:ImageSize"`
	CompositeMegapixels          float64    `json:"Composite:Megapixels"`
	EXIFColorSpace               string     `json:"EXIF:ColorSpace"`
	EXIFComponentsConfiguration  string     `json:"EXIF:ComponentsConfiguration"`
	EXIFCreateDate               string     `json:"EXIF:CreateDate"`
	EXIFExifVersion              string     `json:"EXIF:ExifVersion"`
	EXIFFlashpixVersion          string     `json:"EXIF:FlashpixVersion"`
	EXIFImageDescription         string     `json:"EXIF:ImageDescription"`
	EXIFResolutionUnit           string     `json:"EXIF:ResolutionUnit"`
	EXIFXResolution              int        `json:"EXIF:XResolution"`
	EXIFYCbCrPositioning         string     `json:"EXIF:YCbCrPositioning"`
	EXIFYResolution              int        `json:"EXIF:YResolution"`
	ExifToolExifToolVersion      float64    `json:"ExifTool:ExifToolVersion"`
	FileBitsPerSample            int        `json:"File:BitsPerSample"`
	FileColorComponents          int        `json:"File:ColorComponents"`
	FileCurrentIPTCDigest        string     `json:"File:CurrentIPTCDigest"`
	FileDirectory                string     `json:"File:Directory"`
	FileEncodingProcess          string     `json:"File:EncodingProcess"`
	FileExifByteOrder            string     `json:"File:ExifByteOrder"`
	FileFileAccessDate           string     `json:"File:FileAccessDate"`
	FileFileInodeChangeDate      string     `json:"File:FileInodeChangeDate"`
	FileFileModifyDate           string     `json:"File:FileModifyDate"`
	FileFileName                 string     `json:"File:FileName"`
	FileFilePermissions          string     `json:"File:FilePermissions"`
	FileFileSize                 string     `json:"File:FileSize"`
	FileFileType                 string     `json:"File:FileType"`
	FileFileTypeExtension        string     `json:"File:FileTypeExtension"`
	FileImageHeight              int        `json:"File:ImageHeight"`
	FileImageWidth               int        `json:"File:ImageWidth"`
	FileMIMEType                 string     `json:"File:MIMEType"`
	FileYCbCrSubSampling         string     `json:"File:YCbCrSubSampling"`
	IPTCApplicationRecordVersion int        `json:"IPTC:ApplicationRecordVersion"`
	IPTCKeywords                 StringList `json:"IPTC:Keywords"`
	JFIFJFIFVersion              float64    `json:"JFIF:JFIFVersion"`
	JFIFResolutionUnit           string     `json:"JFIF:ResolutionUnit"`
	JFIFXResolution              int        `json:"JFIF:XResolution"`
	JFIFYResolution              int        `json:"JFIF:YResolution"`
	SourceFile                   string     `json:"SourceFile"`
	XMPCreateDate                string     `json:"XMP:CreateDate"`
	XMPCreatedate                string     `json:"XMP:Createdate"`
	XMPCredit                    string     `json:"XMP:Credit"`
	XMPDateCreated               string     `json:"XMP:DateCreated"`
	XMPDescription               string     `json:"XMP:Description"`
	XMPImageDescription          string     `json:"XMP:ImageDescription"`
	XMPNasaID                    string     `json:"XMP:Nasa_id"`
	XMPSource                    string     `json:"XMP:Source"`
	XMPTitle                     string     `json:"XMP:Title"`
	XMPXMPToolkit                string     `json:"XMP:XMPToolkit"`
}

MediaMetadata holds metadata info for a media resource. Use GetMediaMetadata to fetch the metadata JSON and unmarshal it into this structure.

func GetMediaMetadata

func GetMediaMetadata(nasaID string) (MediaMetadata, error)

GetMediaMetadata gets the metadata for media with the provided NASA ID. The helper first resolves the metadata location and then retrieves the JSON payload.

type MediaParams

type MediaParams struct {
	Query            string
	Center           string
	Description      string
	Description508   string
	Keywords         string
	Location         string
	MediaType        string
	NasaID           string
	Page             int
	PageSize         int
	Photographer     string
	SecondaryCreator string
	Title            string
	YearStart        string
	YearEnd          string
}

MediaParams wraps the Image and Video Library (media) search parameters. At least one non-pagination filter, such as Query, NasaID, or Keywords, must be specified before a search can be performed.

func (*MediaParams) Encode

func (p *MediaParams) Encode() (string, error)

Encode returns a string representation for the given API type.

type MissionManifest

type MissionManifest struct {
	Name        string `json:"name"`
	LandingDate Date   `json:"landing_date"`
	LaunchDate  Date   `json:"launch_date"`
	Status      string `json:"status"`

	// MaxSol and MaxDate are the sol and UTC capture date of the most recent full-frame
	// photos.
	MaxSol  int  `json:"max_sol"`
	MaxDate Date `json:"max_date"`

	// TotalPhotos is the image count reported by the rover's source. For Perseverance,
	// Opportunity and Spirit it counts full frames only; for Curiosity it also counts
	// thumbnails and subframes.
	TotalPhotos int `json:"total_photos"`

	// Photos is not populated, since building it requires one request per sol.
	Photos []ManifestPhoto `json:"photos"`
}

MissionManifest represents rover mission details. MarsMissionManifest fills in a partial manifest: Photos is always empty.

func MarsMissionManifest

func MarsMissionManifest(p ParamEncoder, rover Rover) (MissionManifest, error)

MarsMissionManifest returns a partial mission manifest for the rover, fetched live (see RoverPhoto for the sources). See MissionManifest for which fields are populated.

Curiosity, Perseverance, Opportunity and Spirit are supported. A custom Rover returns ErrorRoverUnsupported.

type ParamEncoder

type ParamEncoder interface {
	Encode() (string, error)
}

ParamEncoder is the interface passed to most API methods.

type Quaternions

type Quaternions struct {
	Q0 float64 `json:"q0"`
	Q1 float64 `json:"q1"`
	Q2 float64 `json:"q2"`
	Q3 float64 `json:"q3"`
}

Quaternions represents spacecraft attitude quaternions. EPIC responses embed this orientation information for the DSCOVR spacecraft.

type Rover

type Rover struct {
	Name        string
	Slug        string
	Cameras     []RoverCamera
	LandingDate time.Time
	LaunchDate  time.Time
	Status      string
}

Rover represents a Mars rover. Use the predefined Rover* values when calling MarsRoverPhotos or MarsMissionManifest to avoid constructing your own instance.

type RoverCamera

type RoverCamera struct {
	Name     string
	FullName string
	Slug     string
}

RoverCamera represents a rover camera type. Refer to the exported RoverCamera* variables for valid camera selections per rover.

type RoverPhoto

type RoverPhoto struct {
	// ID is the feed's numeric image ID. Only Curiosity provides one; it is 0 for the
	// other rovers.
	ID int `json:"id"`

	// ImageID is the source's image identifier, available for every rover. For Opportunity
	// and Spirit it is the PDS product ID.
	ImageID string `json:"image_id"`

	Sol   int    `json:"sol"`
	Image string `json:"img_src"`

	// EarthDate is the UTC calendar date of TakenAt.
	EarthDate Date `json:"earth_date"`

	// TakenAt is when the image was captured, in UTC.
	TakenAt time.Time `json:"taken_at"`

	Camera struct {
		// ID and RoverID were database IDs in the retired API and are always 0.
		ID       int    `json:"id"`
		Name     string `json:"name"`
		FullName string `json:"full_name"`
		RoverID  int    `json:"rover_id"`

		// Instrument is the source's own instrument name, such as "NAV_LEFT_B". Opportunity
		// and Spirit report FRONT_HAZCAM, REAR_HAZCAM, NAVCAM, PANCAM or MI. Photos from
		// instruments that do not belong to one of the rover's RoverCameras use it as
		// their Name and FullName.
		Instrument string `json:"instrument"`
	} `json:"camera"`

	// Rover describes the rover that took the photo. ID, MaxSol, MaxDate and TotalPhotos
	// are not populated; use MarsMissionManifest for mission statistics.
	Rover struct {
		ID          int    `json:"id"`
		Name        string `json:"name"`
		LandingDate Date   `json:"landing_date"`
		LaunchDate  Date   `json:"launch_date"`
		Status      string `json:"status"`
		MaxSol      int    `json:"max_sol"`
		MaxDate     Date   `json:"max_date"`
		TotalPhotos int    `json:"total_photos"`
		Cameras     []struct {
			Name     string `json:"name"`
			FullName string `json:"full_name"`
		} `json:"cameras"`
	} `json:"rover"`
}

RoverPhoto represents a single full-frame Mars rover image, fetched live from NASA's raw image feeds (Curiosity and Perseverance) or the PDS Imaging Atlas (Opportunity and Spirit).

func MarsRoverPhotosLatest

func MarsRoverPhotosLatest(p ParamEncoder, rover Rover) ([]*RoverPhoto, error)

MarsRoverPhotosLatest returns the full-frame photos from the most recent sol that has any, fetched live (see RoverPhoto for the sources). The Camera and Page fields of MarsPhotosParams are applied to that sol; Sol and EarthDate are ignored.

Curiosity, Perseverance, Opportunity and Spirit are supported. A custom Rover returns ErrorRoverUnsupported.

type RoverPhotos

type RoverPhotos struct {
	Photos []*RoverPhoto `json:"photos"`
	Page   int
	Total  int
}

RoverPhotos wraps an array of RoverPhoto pointers along with the requested page number and the total number of matching photos across all pages. Use MarsRoverPhotos to populate this type.

func MarsRoverPhotos

func MarsRoverPhotos(p ParamEncoder, rover Rover) (RoverPhotos, error)

MarsRoverPhotos returns full-frame photos for the given MarsPhotosParams and Rover, fetched live (see RoverPhoto for the sources). Photos are selected by EarthDate (the UTC date each image was captured) when it is set, otherwise by Sol, and can be narrowed to one Camera. A Page of 1 or more returns that page of 25 photos; otherwise every matching photo is returned.

Curiosity, Perseverance, Opportunity and Spirit are supported. A custom Rover returns ErrorRoverUnsupported.

type StringList added in v0.3.1

type StringList []string

StringList is a []string that also accepts a single JSON string, which some metadata fields use when they hold only one value.

func (*StringList) UnmarshalJSON added in v0.3.1

func (l *StringList) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals either a JSON string or an array of strings.

type XYZ

type XYZ struct {
	X float64 `json:"x"`
	Y float64 `json:"y"`
	Z float64 `json:"z"`
}

XYZ represents coordinates in 3D space. NASA services commonly use this shape for positional data such as DSCOVR-to-sun vectors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL