EphemCalc

EphemCalc

A JSON API for ephemeris calculation given a set of coordinates, time and altitude.

  • API is found at http://ephem.perigeo.me
  • Satellite ephemeries use '/satellite'
  • Asteroid ephemeries use '/spacebody'

Parameters for /spacebody

  • xephem_line # Data source
  • lat
  • lon
  • date # in utc unix timestamp
  • elevation # in meters
curl -X GET http://ephem.perigeo.me/spacebody/?xephem_line=xephem_line&lat=lat&lon=lon&date=date&elevation=elevation  

Parameters for /satellite

  • tle0 # Data source
  • tle1
  • tle2
  • lat
  • lon
  • date # in utc unix timestamp
  • elevation
curl -X GET http://ephem.perigeo.me/satellite/?tle0=tle&tle1=tle1&tle2&lat=lat&lon=lon&date=date&elevation=elevation  

Get ephemeries via Ruby

Open your terminal
Install the httparty gem:

$ gem install httparty

Run irb:

$ irb

require 'open-uri'  
require 'httparty'  
require 'pp'  

Get space station ephemeries

Let's get the TLE data for the ISS:

space_stations_raw_data = open('http://www.celestrak.com/NORAD/elements/stations.txt').readlines.each_slice(3).to_a  
iss = space_stations_raw_data[0]  
tle0, tle1, tle2 = iss.collect(&:strip) # use the strip method to remove trailing whitespace  

Let's find out when will be the next pass for the ISS for the Minor Planet Center's offices:

# Setup Observer data
lat = 42.381448  
lon = -71.1281635  
elevation = 21  # meters  
time = Time.now.utc.to_i # unixtimestamp in utc  

Let's create a query for the API:

query = {  
    tle0: tle0,
    tle1: tle1,
    tle2: tle2,
    lat: lat,
    lon: lon,
    date: time,
    elevation: elevation
}

Let's create our request:

url = 'http://ephem.perigeo.me/satellite'  
results = HTTParty.get(url, query: query)  
pp results  
{
    "rise"=>{
        "az"=>2.919262647628784,
        "date_time"=>41741.42858286527
    },
    "set"=>{
        "az"=>0.053070709109306335,
        "date_time"=>41741.36939093282
    },
    "sublat"=>1.2143080234527588,
    "sublong"=>-1.1447027921676636,
    "transit"=>{
        "alt"=>0.2310376763343811,
        "date_time"=>41741.36381180932
    }
}

Cool!

Let's find > $100 trillion in space!

Look up Davida's next transit; estimated by Asterank to be valued at > $100 trillion dollars

mpc_url = 'http://www.minorplanetcenter.net/iau/Ephemerides/Bright/2013/Soft03Bright.txt'  
raw_data = open(mpc_url)  
processed = raw_data.readlines.delete_if {|f| f.start_with?("#")} # remove metadata  
processed.collect!(&:strip) # strip trailing whitespace  
davida = processed.grep(/davida/i) # find Davida  
xephem_line = davida[0] # grep returns an array. Get the first (and only?) object of the array.  

Let's perform our query:

query = {  
    lat: lat,
    lon: lon,
    date: time,
    elevation: elevation,
    xephem_line: xephem_line
}

url = 'http://ephem.perigeo.me/spacebody'  
results = HTTParty.get(url, query: query)  
pp results  
{"next_rising"=>
  {"alt"=>-2.7025691906601423e-07,
   "az"=>1.027448058128357,
   "date_time"=>41742.05250815478},
 "next_setting"=>
  {"alt"=>-2.7076828246208606e-07,
   "az"=>5.254928112030029,
   "date_time"=>41741.67837464503},
 "next_transit"=>
  {"alt"=>1.216389775276184,
   "az"=>3.1415927410125732,
   "date_time"=>41742.36468010251},
 "previous_rising"=>
  {"alt"=>-2.713516096264357e-07,
   "az"=>1.029618501663208,
   "date_time"=>41741.05440737563},
 "previous_setting"=>
  {"alt"=>-2.7076828246208606e-07,
   "az"=>5.254928112030029,
   "date_time"=>41741.67837464503},
 "previous_transit"=>
  {"alt"=>3.1415927410125732,
   "az"=>1.2149168252944946,
   "date_time"=>41741.36630547278}}

 

Comments