33
$\begingroup$

I ♥ NASA. You ♥ NASA. We all ♥ NASA.

So how can I use the images and things they expose in their APIs in Mathematica?

$\endgroup$
37
$\begingroup$

I built a ServiceConnect paclet for this (details on how I did this can be found at the end of this post).

You can access it like so:

PacletInstall[
 "ServiceConnection_NASA",
 "Site"->
  "http://www.wolframcloud.com/objects/b3m2a1.paclets/PacletServer"
 ]

paclet

(note that unless you have BTools installed and have loaded the PacletTools package (e.g. by just calling PacletUpload raw to get the autoloader to run) you won't get this formatted form)

Then just connect and have at it!

$so = ServiceConnect["NASA"]

nasdasdasd

Pic of the Day

$so["PictureOfTheDay"]["Image"]

nasa img

Earth

$so["EarthImages",
  "Date" -> Today - Quantity[1, "Weeks"], 
  "ImportImages" -> True,
  "ImportSelection" -> ;; 3
  ][All, {"Image", "caption"}]

images

Mars

$so["MarsImages", 
  "earth_date" -> Today, "ImportImages" -> True, 
  "ImportSelection" -> {1}
  ][2]

asdasd

And more!

You can get the currently supported requests like so:

$so["Requests"]

{"APIKey", "Authentication", "EarthImages", "ID", \
"ImportEarthImages", "Information", "LandsatAssets", "LandsatImages", \
"MarsImage", "MarsRoverData", "Name", "NeoFeed", "NeoLookup", \
"Patents", "PictureOfTheDay", "RawRequests", "RequestData", \
"RequestParameters", "RoverCameras"}

And you can figure out what to pass to each using the "RequestParameters" like so:

$so["RequestParameters", "Request" -> "Patents"]

<|"Parameters" -> {"api_key", "query", "concept_tags", "limit"}, 
 "Required" -> {}|>

$so["Patents"]["results", 1, "title"]

"Selective functionalization of carbon nanotubes based upon distance  \
   traveled"

If you want me to implement more requests I can easily do so


Construction Process

I built this according to the process laid out in my answer to the question Creating a custom web API ServiceConnection.

The actual construction notebook can be obtained here so you can see what went into building it.

Essentially, I just have a template notebook that you fill out and which formats a call to the CustomServiceConnection function in my BTools package.

$\endgroup$
  • $\begingroup$ I love NASA⊙ Also. $\endgroup$ – quintumnia Jan 14 '18 at 17:03
  • 1
    $\begingroup$ +1 of course but please include at least the very initial implementation. We try to avoid link based answers as they can become useless once links are invalid. Would be also nice to link BTools if you mention them. $\endgroup$ – Kuba Jan 15 '18 at 6:19
  • $\begingroup$ @Kuba that's handled. I didn't go into the actual gory details but mostly just linked to a construction notebook and my previous answer on building ServiceConnections $\endgroup$ – b3m2a1 Jan 15 '18 at 8:14
  • $\begingroup$ @b3m2a1 'How to' overview is handled but the answer is still only on wofram cloud. $\endgroup$ – Kuba Jan 15 '18 at 8:21
  • 2
    $\begingroup$ @b3m2a1 You are right, it is not a must so let's stay with more example focused answers linked together with github and wpc. $\endgroup$ – Kuba Jan 15 '18 at 8:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.