Connecting to Skynet

Connecting to Skynet using Hypertext Transfer Protocol (HTTP)

Setting Up a Skynet Account

In order to use Skynet’s telescopes to take a picture you must first set up an account which will contain your Time Account ID number and then acquire a token to use for submitting observation requests. You can click on the links for more information regarding Skynet and Skynet Junior Scholars.

Taking a Picture

After you have setup an account through Skynet and obtained your "token" and "Time Account ID" you are all set to start taking pictures using Skynet’s telescopes. There are two ways you can request an observation (picture) including:

  • Astronomical Target Name : such as ("Pinwheel Galaxy", "Saturn")
  • Astronomical Target Coordinates : such as (RA: 14h 3m 13s | Dec: 54°20'57")

To start in the process of taking a picture and obtaining data from Skynet’s Response Message we will need to add the following libraries:

use Libraries.Network.NetworkResponseEvent
use Libraries.Data.Formats.JavaScriptObjectNotation
use Libraries.Science.Astronomy.Skynet
use Libraries.Science.Astronomy.SkynetListener
use Libraries.System.File
use Libraries.Containers.HashTable
use Libraries.Containers.Iterator

Next, we will create a text type variable called "token" which will contain our token key obtained from Skynet for ease of use. Then we will create a Skynet object called "skynet" which we will add all of our specifications to in the next step.

class DriverCode is SkynetListener
   text token = "your token will go here"
   Skynet skynet

In this next step we will add all of the necessary specifications in obtaining a picture to our Skynet object "skynet" as shown below:

For further information on the meaning of these specifications look to SkynetJuniorScholars.org Explorations IDATA section which includes a module dedicated to Using Telescopes to take Images of Asteroids.

   action Main
       skynet:AddListener(me)
        //sets your previously defined "token" as the Skynet Account key to be used in
        //requesting the observation.
       skynet:SetAccountKey(token)
        //sets the maximum sun elevation integer (we used the default of -12 in this case) 
       skynet:SetMaxSun(-12)
        //sets the minimum object elevation integer (we used the default of 30.0
        //in this case)
       skynet:SetMinElevation(30.0)
        //sets your 5 digit time account ID integer for a specific telescope which must 
        //have an adequate time allowance to be used in requesting an observation.
        //(We used a sample account ID in this example to show that the time account 
        //ID should be entered as an integer)
       skynet:SetTimeAccount(12345)
        //sets the name of the telescope you will be using to make your observations,
        //(for more information on available telescopes and their associated Time 
        //Account ID’s look at your Account on Skynet.)
       skynet:AddTelescope("Prompt6")
        //sets the filter for your observation
       skynet:AddFilter("Clear")
        //sets the number of exposures for your observation
       skynet:SetNumberOfExposures(2)
        //sets the exposure length for your observation
       skynet:SetExposureLength(30.0)

Submitting an Observation Request by Name

If you wish to submit an observation request by coordinates, then you can skip this step and move to the section labeled "Submitting an Observation Request by Coordinates" below.

To submit a request for an observation by name you will have to provide the following information:

  • Name : used to identify the Astronomical target. (We will use "M104" in this example)
  • Type : used to specify the type of Astronomical target you are observing. (We will use "sidereal" in this example)

The information will be added to the existing code in the following format:

        //sets the Astronomical Type to "sidereal"
       skynet:SetAstronomicalType("sidereal")
        //sets the name of the Astronomical Target to "M104"
       skynet:SetName("M104")
        //lets Skynet know that we are submitting the observation request by name
       skynet:SubmitObservationByName()

Submitting an Observation Request by Coordinates

If you are already submitting an observation request by name then you can skip this step and move to the section labeled "Handling Skynet’s Response Message" below.

To submit a request for an observation by coordinates you will have to provide the following information:

  • Name : used to identify the Astronomical target. (We will use "M104" in this example)
  • Right Ascension & Declination : specify the direction of the Astronomical target in the sky. If you are unsure of the coordinates you can find them by searching the Astronomical target on the internet.

In a search for our example Astronomical Target The Right Ascension and Declination for our Astronomical target "M104" you will find the following results (12h 39m 59.4s) and (-11° 37’ 23") which need to be formatted as follows to "12:39:59.4" and "-11:37:23" so that the coordinates will be interpreted correctly by Skynet.)

The information will be added to the existing code in the following format:

       //sets the name of the Astronomical Target to "M104"
       skynet:SetName("M104")
       //sets the Right Ascension for the specified Astronomical Target "M104"
       skynet:SetRightAscension("12:39:59.4")
       //sets the Declination for the specified Astronomical Target "M104"
       skynet:SetDeclination("-11:37:23")
       //lets Skynet know that we are submitting the Observation Request by Coordinates
       skynet:SubmitObservationByCoordinates()

Handling Skynet’s Response Message

We have all of the code necessary to complete an observation request through Skynet, however, we will want to view the components of the Response Message that they send back to us. There are several ways in which we can view and format this data. In this tutorial we will go over how to output specific Response Data such as the Web Address accessed, the Status Code and Status Text, the Content Type and the Response Headers. We will also go over how to output the Response Text in formatted JavaScript Object Notation.

We will begin by creating a NetworkResponseEvent "response" and outputting "response’s" web address, status code, status text, and content type with labels for readability.

   //creates a NetworkResponseEvent object "response" which will hold the contents of
   //the Response Message from Skynet
   action ResponseReceived(NetworkResponseEvent response)
       //outputs the Response Message’s web address, Status Code, Status Text, and
       //Content Type with their labels
       output " URL : " + response:GetWebAddress()
       output " Status Code : " + response:GetStatusCode()
       output " Status Text : " + response:GetStatusText()
       output " Content Type : " + response:GetContentType()
       //creates a HashTable object "headers" which holds all of the
       //NetworkResponseEvent object "response’s" Response Headers.

Next, we will output the Response Headers with a label, by iterating (or going through) the HashTable object "headers" that contains the response headers as shown below.

       output "Response Headers : "
       HashTable<text, text> headers = response:GetHeaders()
       //iterates (goes through) the entire HashTable object "headers" and outputs the
       //key name and its associated value(s) separated by a colon ":" for readability.
       Iterator<text> keys = headers:GetKeyIterator()
       repeat while keys:HasNext()
           key = keys:Next()
           output key + ":" + headers:GetValue(key)
       end

Finally, we will output the specific "obsId" and "telescope" key names and their associated value(s) that are included in the returned Response Text using JavaScript Object Notation formatting.

       //creates a JavaScriptObjectNotation object "json" which is used to read in the
       //Response Text from the NetworkResponseEvent object "response" and output 
       //the requested key name’s associated values in JavaScript Object Notation
       //format
       JavaScriptObjectNotation json
       json:Read(response:GetResponseText())
       output " ObservationID : " + json:GetValue("obsId")
       output "Telescope Info : " + json:GetVaue("telescope")

If you would like to view ALL of the key names and values included in the Response Text in JavaScript Object Notation format then you can use the following code instead:

       //creates a JavaScriptObjectNotation object "json" which is used to read in the
       //Response Text from the NetworkResponseEvent object "response" and output 
       //in JavaScript Object Notation format
       JavaScriptObjectNotation json
       json:Read(response:GetResponseText())
       output Response Text in JavaScript Object Notation Format : " + json:ToText()

Alternately, if you would like to condense the JavaScript Object Notation Response Text you can use the following code instead without the need to create the JavaScriptObjectNotation object "json":

output "Response Text : " + response:GetResponseText()

In which case the condensed Response Text will look something like this:

Response Text : 
        {"endBefore": null, "commandedDec": null, "telescope": {"site": {"lngDegs": -70.8053888736413, 
        "id": 2, "name": "CTIO", "latDegs": -30.167638879504135}, "name": "Prompt6", "id": 31}, 
        "startAfter": null, "timeArchived": null, "linkedExps": [], "wcsState": "not_attempted", 
        "filterRequested": {"id": 19, "name": "Clear"}, "statsState": "not_attempted", 
        "timeIn": "2018-06-21T18:49:33", "id": 21762074, "compression": null, 
        "parentCollabTimeAccountId": null, "creditsCharged": 30, "teleId": 31, 
        "timeAccountId": 12345, "expLength": 30.0, "delay": null, "state": "ready", 
        "timeSubmitted": "2018-06-21T18:49:33.619087", "obsId": 2933191, "expNum": 2, 
        "wcsSolution": null, "type": "light", "filterIdUsed": null, "expLengthUsed": null, 
        "teleOwner": null, "commandedRa": null, "timeTaken": null, "timeTakenIsFromHdr": false, 
        "filterIdRequested": 19, "filterUsed": null, "wcsId": null, "targetExpId": null, 
        "teleOwnerIdUsed": null, "binningRequested": 2, "isCompressed": false, 
        "binningUsed": 1, "numFileErrors": 0, "parentGroupTimeAccountId": null, "obs": 
        {"id": 2933191, "name": "M104"}}

The complete code section for submitting an observation request by coordinates and handling the response message from Skynet is shown below:

use Libraries.Network.NetworkResponseEvent
use Libraries.Data.Formats.JavaScriptObjectNotation
use Libraries.Science.Astronomy.Skynet
use Libraries.Science.Astronomy.SkynetListener
use Libraries.System.File
use Libraries.Containers.HashTable
use Libraries.Containers.Iterator
use Libraries.Containers.Array

class DriverCode is SkynetListener
  text token = "Your token goes here"
  Skynet skynet

  action Main
      skynet:AddListener(me)
       //If you would like to submit an observation request by name simply omit the next two
       //lines and replace them with  "skynet:SetAstronomicalType("sidereal")"
      skynet:SetRightAscension("12:39:59.4")
      skynet:SetDeclination("-11:37:23")
      skynet:SetName("M104")

      skynet:SetAccountKey(token)
      skynet:SetMaxSun(-12)
      skynet:SetMinElevation(30.0)
       //you will need to use your 5 digit Time Account integer here
      skynet:SetTimeAccount(12345)
      skynet:AddTelescope("Prompt6")
      skynet:AddFilter("Clear")
      skynet:SetNumberOfExposures(2)
      skynet:SetExposureLength(30.0)
       //if you would like to submit an observation request by name simply omit the following
       //line and replace it with "skynet:SubmitObservationByName()"
      skynet:SubmitObservationByCoordinates()
  end

  action ResponseReceived(NetworkResponseEvent response)
      output "URL : " + response:GetWebAddress()
      output "Status Code : " + response:GetStatusCode()
      output "Status Text : " + response:GetStatusText()
      output "Content Type : " + response:GetContentType()
      output "Response Headers : "
      HashTable<text, text> headers = response:GetHeaders()
      Iterator<text> keys = headers:GetKeyIterator()
      repeat while keys:HasNext()
          key = keys:Next()
          output key + " : " + headers:GetValue(key)
      end
      JavaScriptObjectNotation json
      json:Read(response:GetResponseText())
      output "ObservationID : " + json:GetValue("obsId")
      output "Telescope Info : " + json:GetValue("telescope")
  end
end

The output should look something like this:

URL  : https://api.skynet.unc.edu/2.0/exps
Status Code  : 200
Status Text  : OK
Content Type  : text/html; charset=utf-8
Response Headers : 
content-type : text/html; charset=utf-8
expires : Thu, 21 Jun 2018 18:45:09 GMT
cache-control : no-store, no-cache, must-revalidate, post-check=0, pre-check=0
pragma : no-cache
ObservationID : 2933108
Telescope Info : {
   "site":     {
{
      "lngDegs": -70.8053888736413,
      "id": 2,
      "name": "CTIO",
      "latDegs": -30.167638879504135
}
  },
  "name": "Prompt6",
  "id": 31
}

End of Lesson

You have reached the end of the lesson for Network. To view more tutorials, press the button below or you can go back to the previous lesson pages.