0

hi i need a little help if any of you know how to calculate the distance of a coordinates and a satellite projection, i mean, when i predict the path of the satellite i need to know what is the distance between the future path and the coordinates that i put. and with that make a message alert notifiyng me when that satellite will be close to the coordinates.

this is the code that i am using any of you could help me that would be great.

from mpl_toolkits.basemap import Basemap
from geopy.distance import great_circle
from matplotlib import colors
from pyorbital import tlefile
import matplotlib.pyplot as plt
import numpy as np
import math
import ephem
from datetime import datetime


tlefile.TLE_URLS = (    'http://celestrak.com/NORAD/elements/resource.txt',)
sat_tle = tlefile.read('NUSAT 1 (FRESCO)')
sat = ephem.readtle("NUSAT 1 (FRESCO)", sat_tle.line1, sat_tle.line2)
obs = ephem.Observer()
# location for tge coordinates
print("Latitud ")
sat_lat = input()
print("Longitud suggested point")
sat_lon = input()
obs.lat = str(sat_lat)
obs.long = str(sat_lon)
# programar proyeccion del mapa
map = Basemap(projection='ortho', lat_0=sat_lat, lon_0=sat_lon, resolution='l')
# draw coastlines, country boundaries, fill continents.
map.drawcoastlines(linewidth=0.25)
map.drawcountries(linewidth=0.25)
map.fillcontinents(color='coral',lake_color='aqua')
# draw the edge of the map projection region (the projection limb)
map.drawmapboundary(fill_color='aqua')
# grid in latitud and longitud every 30 sec.
map.drawmeridians(np.arange(0,360,30))
map.drawparallels(np.arange(-90,90,30))



# plot
passes = 4
for p in range(passes):
    coords = []
    dists = []
    tr, azr, tt, altt, ts, azs = obs.next_pass(sat)
    print """Date/Time (UTC)       Alt/Azim   Lat/Long  Elev"""
    print """====================================================="""
    while tr < ts:
        obs.date = tr
        sat.compute(obs)
    print "%s | %4.1f %5.1f | %4.1f %+6.1f | %5.1f" % \
    (tr, math.degrees(sat.alt), math.degrees(sat.az), math.degrees(sat.sublat),              math.degrees(sat.sublong), sat.elevation/1000.)    
        sat_lat = math.degrees(sat.sublat)
        sat_lon = math.degrees(sat.sublong)
        dist = great_circle((sat_lat, sat_lon), (sat_lat, sat_lon)).miles
        coords.append([sat_lon, sat_lat])
        dists.append(dist)
        tr = ephem.Date(tr + 30.0 * ephem.second)
    md = min(dists)
    imd = 1 - (float(md) / 1400)
    hue = float(240) / float(360)
    clr = colors.hsv_to_rgb([hue, imd, 1])
    map.drawgreatcircle(coords[0][0], coords[0][1], coords[-1][0], coords[-1][1], linewidth=2, color=clr)
    obs.date = tr + ephem.minute
# map with UTC 
date = datetime.utcnow()
cs=map.nightshade(date)



plt.title('next '+ str(passes)+ ' passes of the satellite')
plt.show()
Gring
  • 1
  • 1

1 Answers1

0

You might want to look at http://rhodesmill.org/pyephem/quick.html#other-functions where it describes the function ephem.separation(). You are allowed to call it with two longitude, latitude coordinate pairs, and it will tell you how far apart they are:

ephem.separation((lon1, lat1), (lon2, lat2))

So if you pass the satellites's longitude and latitude as one of the coordinate pairs, and the longitude and latitude of the position you are interested in as the other, then you can watch for when the separation grows very small.

Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147