def get_lla(t): orb = Orbital("TJREVERB", tle_file=(Path(__file__).parent.resolve() / "tjreverb_tle.txt")) return ({ 'lat': orb.get_lonlatalt(t)[0], 'lon': orb.get_lonlatalt(t)[1], 'alt': orb.get_lonlatalt(t)[2] })
def get_lonlat(scene, row, col): """Get the longitutes and latitudes for the give *rows* and *cols*. """ try: filename = get_filename(scene, "granules") except IOError: #from mpop.satin.eps1a import get_lonlat_avhrr # return get_lonlat_avhrr(scene, row, col) from pyorbital.orbital import Orbital import pyproj from datetime import timedelta start_time = scene.time_slot end_time = scene.time_slot + timedelta(minutes=3) orbital = Orbital("METOP-A") track_start = orbital.get_lonlatalt(start_time) track_end = orbital.get_lonlatalt(end_time) geod = pyproj.Geod(ellps='WGS84') az_fwd, az_back, dist = geod.inv(track_start[0], track_start[1], track_end[0], track_end[1]) del dist M02_WIDTH = 2821885.8962408099 pos = ((col - 1024) * M02_WIDTH) / 2048.0 if row > 520: lonlatdist = geod.fwd(track_end[0], track_end[1], az_back - 86.253533216206648, -pos) else: lonlatdist = geod.fwd(track_start[0], track_start[1], az_fwd - 86.253533216206648, pos) return lonlatdist[0], lonlatdist[1] try: if scene.lons is None or scene.lats is None: records, form = read_raw(filename) mdrs = [record[1] for record in records if record[0] == "mdr"] sphrs = [record for record in records if record[0] == "sphr"] sphr = sphrs[0][1] scene.lons, scene.lats = _get_lonlats(mdrs, sphr, form) return scene.lons[row, col], scene.lats[row, col] except AttributeError: records, form = read_raw(filename) mdrs = [record[1] for record in records if record[0] == "mdr"] sphrs = [record for record in records if record[0] == "sphr"] sphr = sphrs[0][1] scene.lons, scene.lats = _get_lonlats(mdrs, sphr, form) return scene.lons[row, col], scene.lats[row, col]
def update_graph_scatter(n): satellite = Orbital('TERRA') tiempo = [] Latitude = [] Longitude = [] Altitude = [] valor = [] v = [] X.append(datetime.datetime.now() - datetime.timedelta()) Y.append(random.randrange(-20, 20)) #datetime.datetime.now().time() for i in range(2 * n): v = random.randrange(-20, 20) time = datetime.datetime.now() - datetime.timedelta(seconds=i * 20) lon, lat, alt = satellite.get_lonlatalt(time) Longitude.append(lon) Latitude.append(lat) Altitude.append(alt) tiempo.append(time) valor.append(v) trace1 = go.Scatter(x=list(tiempo), y=list(Altitude), name='Altitud', mode='lines+markers') return { 'data': [trace1], 'layout': go.Layout(transition={ 'duration': 1, 'easing': 'cubic-in-out' }) }
def getGPSPosition(platformName, tleFile, dateTime): orb = Orbital(platformName, tleFile) lon, lat, alt = orb.get_lonlatalt(dateTime) #reading the TLE file file = open(tleFile) data = file.read().replace("\n","::") arr = data.split("::") for i in range(len(arr)): if platformName.rstrip() == arr[i].rstrip(): tleOne= arr[i+1] tleTwo = arr[i+2] file.close() sat = ephem.readtle(platformName, tleOne, tleTwo) #compute satellite position sat.compute(dateTime) satlat = math.degrees(sat.sublat) satlon = math.degrees(sat.sublong) satele = sat.elevation satsize = sat.size satrad = sat.radius satecl = sat.eclipsed satasc = sat.a_ra satdecl = sat.a_dec return [satlon, satlat, satele, satsize, satrad, satecl, satasc, satdecl]
def GetGPSPosition(platformName, tleFile, dateTime): orb = Orbital(platformName, tleFile) lon, lat, alt = orb.get_lonlatalt(dateTime) return [lon, lat, alt, dateTime]
def update_graph_live(n): satellite = Orbital("TERRA") data = {"time": [], "Latitude": [], "Longitude": [], "Altitude": []} # Collect some data for i in range(180): time = datetime.datetime.now() - datetime.timedelta(seconds=i * 20) lon, lat, alt = satellite.get_lonlatalt(time) data["Longitude"].append(lon) data["Latitude"].append(lat) data["Altitude"].append(alt) data["time"].append(time) # Create the graph with subplots fig = plotly.tools.make_subplots(rows=2, cols=1, vertical_spacing=0.2) fig["layout"]["margin"] = {"l": 30, "r": 10, "b": 30, "t": 10} fig["layout"]["legend"] = {"x": 0, "y": 1, "xanchor": "left"} fig.append_trace( {"x": data["time"], "y": data["Altitude"], "name": "Altitude", "mode": "lines+markers", "type": "scatter"}, 1, 1 ) fig.append_trace( { "x": data["Longitude"], "y": data["Latitude"], "text": data["time"], "name": "Longitude vs Latitude", "mode": "lines+markers", "type": "scatter", }, 2, 1, ) return fig
def fix_tle_orbit(lines): if Orbital is None: logger.info("Pyorbital is missing, can't fix orbit number") return lines platform_name = lines[0] orb = Orbital(platform_name, line1=lines[1], line2=lines[2]) epoch = orb.tle.epoch true_epoch = epoch # if too close from equator, fast forward to pole if abs(orb.get_lonlatalt(orb.tle.epoch)[1]) < 5: epoch += timedelta(days=1 / orb.tle.mean_motion / 4) orbnum = orb.get_orbit_number(epoch) ref_lines = get_last_valid_tle_lines(platform_name, epoch) ref_orb = Orbital(platform_name, line1=ref_lines[1], line2=ref_lines[2]) ref_orbnum = ref_orb.get_orbit_number(epoch) if orbnum != ref_orbnum: logger.info("Spurious orbit number for %s: %d (should be %d)", platform_name, orbnum, ref_orbnum) logger.info("replacing...") diff = ref_orbnum - orbnum lines[2] = lines[2][:63] + \ "{0:05d}".format(orb.tle.orbit + diff) + lines[2][68:] lines[2] = append_checksum(lines[2][:-1]) return lines
def get_satellite_lat_lon(norad_id, tle_line1, tle_line2, date_time): username = '******' password = '******' base_url = 'https://www.space-track.org/' login_url = base_url + 'ajaxauth/login' query = base_url + "/basicspacedata/query/class/satcat/NORAD_CAT_ID/" + \ norad_id + \ "/orderby/NORAD_CAT_ID asc/metadata/false" data = {'identity': username, 'password': password, 'query': query} # Makes a POST REST call to space-track.org and return the result as a list of JSON try: resp = requests.post(login_url, data=data) except requests.exceptions.RequestException as err: print("POST RESTful call unsuccessful - unable to obtain LAT/LON : " + err) tip_data_list = json.loads(resp.text) satellite_name = str(tip_data_list[0].get('SATNAME')) orb = Orbital(satellite=satellite_name, line1=tle_line1, line2=tle_line2) # Gets longitude, latitude and altitude of the satellite: lon, lan, alt = orb.get_lonlatalt(date_time) print("------------------------- DATE & TIME IN UTC : " + str(date_time) + " -------------------------") print("LONGITUDE = " + str(lon)) print("LATITUDE = " + str(lan)) return lon, lan
def update_graph_live(n): data = {'time': [], 'Latitude': [], 'Longitude': [], 'Altitude': []} sat = Orbital('TERRA') # Collect some data for seconds in range(0, 3600, 20): time = datetime.datetime.now() - datetime.timedelta(seconds=seconds) data['time'].append(time) lon, lat, alt = sat.get_lonlatalt(time) data['Longitude'].append(lon) data['Latitude'].append(lat) data['Altitude'].append(alt) # Create the graph with subplots result = make_subplots(cols=1, rows=2, vertical_spacing=0.2, ) result['layout']['margin'] = {'b': 30, 'l': 30, 'r': 10, 't': 10, } result['layout']['legend'] = {'x': 0, 'xanchor': 'left', 'y': 1, } result.append_trace({'mode': 'lines+markers', 'name': 'Altitude', 'type': 'scatter', 'x': data['time'], 'y': data['Altitude'], }, 1, 1) result.append_trace( {'mode': 'lines+markers', 'name': 'Longitude vs Latitude', 'text': data['time'], 'type': 'scatter', 'x': data['Longitude'], 'y': data['Latitude'], }, 2, 1) return result
def create_orbital_track_shapefile_for_day (track_day, step, dur): # получаем TLE для NOAA-19 tle_1 = '1 33591U 09005A 21067.53688389 .00000027 00000-0 40065-4 0 9999' tle_2 = '2 33591 99.1917 85.7021 0014730 58.0337 302.2263 14.12454575622414' # Создаём экземляр класса Orbital orb = Orbital("N", line1=tle_1, line2=tle_2) i = 0 minutes = 0 coord = np.arange(3*dur).reshape(dur, 3) while minutes < dur: # Расчитаем час, минуту, секунду (для текущего шага) utc_hour = int(minutes // 60) utc_minutes = int((minutes - (utc_hour*60)) // 1) utc_seconds = int(round((minutes - (utc_hour*60) - utc_minutes)*60)) utc_string = str(utc_hour) + '-' + str(utc_minutes) + '-' + str(utc_seconds) utc_time = datetime(track_day.year,track_day.month,track_day.day,utc_hour,utc_minutes,utc_seconds) # Считаем положение спутника lon, lat, alt = orb.get_lonlatalt(utc_time) coord[i] [0] = lon coord[i] [1] = lat coord[i] [2] = alt + 6400 i += 1 minutes += step return coord
def runProp(): #orb = Orbital(tle) orb = Orbital("TJREVERB", tle_file="FILE PATH TO TLE") now = datetime.utcnow() #print(tle.inclination) #print(orb.get_position(now)) print(orb.get_lonlatalt(now)) print() print(orb.get_next_passes(now, 12, -77.10428, 8.88101, 276, tol=0.001, horizon=0))
def update_graph_live(n): satellite = Orbital('TERRA') data = { 'time': [], 'Latitude': [], 'Longitude': [], 'Altitude': [] } # Collect some data for i in range(180): time = datetime.datetime.now() - datetime.timedelta(seconds=i*20) lon, lat, alt = satellite.get_lonlatalt( time ) data['Longitude'].append(lon) data['Latitude'].append(lat) data['Altitude'].append(alt) data['time'].append(time) # Create the graph with subplots fig = plotly.tools.make_subplots(rows=2, cols=2, vertical_spacing=0.2) fig['layout']['margin'] = { 'l': 30, 'r': 10, 'b': 30, 't': 10 } fig['layout']['legend'] = {'x': 0, 'y': 1, 'xanchor': 'left'} fig.append_trace ({ 'x': data['time'], 'y': data['Altitude'], 'name': 'Altitude', 'mode': 'lines+markers', 'type': 'scatter' }, 1, 1) j = go.Scatter( x =data['Longitude'], y= data['Latitude'], text= data['time'], name= 'Longitude vs Latitude', mode= 'lines+markers', type= 'scatter' ) #trace = go.Figure(data = airports) #trace = [i,j] fig.append_trace(j , 2, 1) #fig.append_trace(j , 2, 1) return fig
def create_orbital_track_shapefile_for_day(year, month, day, step_minutes, tle_line1, tle_line2, output_shapefile): try: orb = Orbital("N", tle_file=None, line1=tle_line1, line2=tle_line2) except (ChecksumError): print 'Invalid TLE' return 2 try: year = int(year) month = int(month) day = int(day) step_minutes = float(step_minutes) except: print 'Invalid date' return 3 w = shapefile.Writer(shapefile.POINT) w.field('ID', 'C', 40) w.field('TIME', 'C', 40) w.field('LAT', 'C', 40) w.field('LON', 'C', 40) i = 0 minutes = 0 while minutes < 1440: utc_hour = int(minutes // 60) utc_minutes = int((minutes - (utc_hour * 60)) // 1) utc_seconds = int(round( (minutes - (utc_hour * 60) - utc_minutes) * 60)) utc_string = str(utc_hour) + '-' + str(utc_minutes) + '-' + str( utc_seconds) utc_time = datetime.datetime(year, month, day, utc_hour, utc_minutes, utc_seconds) lon, lat, alt = orb.get_lonlatalt(utc_time) w.point(lon, lat) w.record(str(i), utc_string, str(lat), str(lon)) i += 1 minutes += step_minutes try: prj = open("%s.prj" % output_shapefile.replace('.shp', ''), "w") epsg = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]' prj.write(epsg) prj.close() w.save(output_shapefile) except: print 'Unable to save shapefile' return 4
def create_orbital_track_shapefile_for_day (year, month, day, step_minutes, tle_line1, tle_line2, sat_name): try: orb = Orbital("N",tle_file=None,line1=tle_line1, line2=tle_line2) except: raise NameError try: year = int(year) month = int(month) day = int(day) step_minutes = float(step_minutes) except: raise TypeError trackLayerName = 'Track Layer (' + str(sat_name) + ': ' + str(year) + ':' + str(month) + ':' + str(day) + ')' trackLayer = QgsVectorLayer("Point", trackLayerName, "memory") trackLayer.setCrs(QgsCoordinateReferenceSystem(4326)) trackLayerDataProvider = trackLayer.dataProvider() trackLayer.startEditing() trackLayerDataProvider.addAttributes( [ QgsField("ID", QVariant.Int), QgsField("TIME", QVariant.String), QgsField("LAT", QVariant.Double), QgsField("LON", QVariant.Double)] ) i = 0 minutes = 0 while minutes < 1440: QApplication.processEvents() utc_hour = int(minutes // 60) utc_minutes = int((minutes - (utc_hour*60)) // 1) utc_seconds = int(round((minutes - (utc_hour*60) - utc_minutes)*60)) utc_string = str(utc_hour) + ':' + str(utc_minutes) + ':' + str(utc_seconds) utc_time = datetime.datetime(year,month,day,utc_hour,utc_minutes,utc_seconds) lon, lat, alt = orb.get_lonlatalt(utc_time) trackPoint = QgsFeature() trackPoint.setGeometry(QgsGeometry.fromPoint(QgsPoint(lon,lat))) trackPoint.setAttributes([i,utc_string,float(lat),float(lon)]) trackLayerDataProvider.addFeatures ([trackPoint]) i += 1 minutes += step_minutes trackLayer.commitChanges() trackLayer.updateExtents() return trackLayer
def update_graph_live(n): satellite = Orbital('TERRA') data = {'time': [], 'Latitude': [], 'Longitude': [], 'Altitude': []} # Collect some data for i in range(180): time = datetime.datetime.now() - datetime.timedelta(seconds=i * 20) lon, lat, alt = satellite.get_lonlatalt(time) data['Longitude'].append(lon) data['Latitude'].append(lat) data['Altitude'].append(alt) data['time'].append(time) # Create the graph with subplots fig = plotly.tools.make_subplots(rows=3, cols=1, vertical_spacing=0.2) fig['layout']['margin'] = {'l': 30, 'r': 10, 'b': 30, 't': 10} fig['layout']['legend'] = {'x': 0, 'y': 1, 'xanchor': 'left'} fig.append_trace( { 'x': data['time'], 'y': data['Altitude'], 'name': 'Altitude', 'mode': 'lines+markers', 'type': 'scatter' }, 1, 1) fig.append_trace( { 'x': data['Longitude'], 'y': data['Latitude'], 'text': data['time'], 'name': 'Longitude vs Latitude', 'mode': 'lines+markers', 'type': 'scatter' }, 2, 1) df = px.data.iris() fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width', color='petal_length', size='petal_length', size_max=18, symbol='species', opacity=0.7) # tight layout fig.update_layout(margin=dict(l=0, r=0, b=0, t=0)) return fig
def orbitpos(file_name, names, date): orbit = [] cont = 0 for nam in names: try: orb = Orbital(nam, file_name) orbit.append( [nam, orb.get_lonlatalt(date), orb.get_position(date)]) #altitudine in km da terra #pos normalizata r_sat/r_terra except: cont += 1 print(nam, cont) return orbit
def generate_points_per_satellite(satellite, start, end): orb = Orbital(satellite) point_list = [] increment_in_minutes = 0.25 increment = datetime.timedelta(minutes=float(increment_in_minutes)) while start < end: lon, lat, alt = orb.get_lonlatalt(start) point_list.append([lat, lon, alt, str(start)]) start += increment light_list = [] for j in range((len(point_list)) - 1): if point_list[j][0] >= point_list[j + 1][0]: light_list.append(point_list[j]) return light_list
def actuate_sats(): """ Use external library to get positions of requested satellites. Create new Satellite (look at models) object if there is no satellite with found name, or update existing satellite if it's already in the DB :return: None - only create/update/do nothing on DB objects """ for name in SAT_NAME: try: orb = Orbital(name) now = datetime.utcnow() # Get longitude, latitude and altitude of the satellite geo_position = orb.get_lonlatalt(now) print("Found {} - {}".format(name, geo_position)) try: if Satellite.objects.get(name=name): # if there is satellite with such name -> update info sat = Satellite.objects.get(name=name) # save past position sat_hist = SatHistory.objects.create(name=sat.name, longi=sat.longi, lati=sat.lati, alti=sat.alti) sat_hist.save() # update to actual position sat.longi = geo_position[0] sat.lati = geo_position[1] sat.alti = geo_position[2] sat.date = datetime.utcnow() sat.save() sat.hist = SatHistory.objects.filter(name=name) sat.save() except ObjectDoesNotExist: # if there is no satellite with such name # creating is possible sat = Satellite.objects.create(name=name, longi=geo_position[0], lati=geo_position[1], alti=geo_position[2] ) sat.save() # if there is no satellite with such name in sources except (KeyError, NotImplementedError): print('No satellite name found in the sources: {}'.format(name))
def create_orbital_track_shapefile_for_day(track_day, step, dur, tle): # получаем TLE для NOAA-19 tle_1 = str(tle[0]) tle_2 = str(tle[1]) # Создаём экземляр класса Orbital orb = Orbital("N", line1=tle_1, line2=tle_2) i = 0 minutes = 0 coord = np.arange(8 * dur).reshape(dur, 8) while minutes < dur: # Расчитаем час, минуту, секунду (для текущего шага) utc_hour = int(minutes // 60) utc_minutes = int((minutes - (utc_hour * 60)) // 1) utc_seconds = int(round( (minutes - (utc_hour * 60) - utc_minutes) * 60)) utc_string = str(utc_hour) + '-' + str(utc_minutes) + '-' + str( utc_seconds) utc_time = datetime(track_day.year, track_day.month, track_day.day, utc_hour, utc_minutes, utc_seconds) # Считаем положение спутника lon, lat, alt = orb.get_lonlatalt(utc_time) dec_coord = CoordToDec(lon, lat, alt + 6370) coord[i][0] = int(dec_coord[0]) coord[i][1] = int(dec_coord[1]) coord[i][2] = int(dec_coord[2]) coord[i][3] = int(utc_hour + 3) coord[i][4] = int(utc_minutes) coord[i][5] = int(track_day.day) coord[i][6] = int(track_day.month) coord[i][7] = int(track_day.year) i += 1 minutes += step return coord # возвращает координаты и время в формате: x, y, z, час, минута, д, м, гггг (время местное = Московское)
def generate_points_per_satellite(satellite, start, end): orb = Orbital(satellite) satellite_lat_lons = [] increment_in_minutes = 0.083 #Every 5 seconds increment = datetime.timedelta(minutes=float(increment_in_minutes)) list_of_dates = [] while start < end: cd = str(start.date()) if cd not in list_of_dates: list_of_dates.append(cd) lon, lat, alt = orb.get_lonlatalt(start) satellite_lat_lons.append([lat, lon, alt, str(start)]) start += increment light_list = [] for j in range((len(satellite_lat_lons)) - 1): if satellite_lat_lons[j][0] >= satellite_lat_lons[j + 1][0]: light_list.append(satellite_lat_lons[j]) return light_list, list_of_dates
s_name = os.environ['SATELLITE'] satellite = Orbital(s_name) producer = Producer({'bootstrap.servers': bootstrap_servers}) def acked(err, msg): if err is not None: print("Failed to deliver message: {}".format(err)) else: print("Produced record to topic {} partition [{}] @ offset {}".format( msg.topic(), msg.partition(), msg.offset())) # send data every one second while True: time = datetime.datetime.now() lon, lat, alt = satellite.get_lonlatalt(time) record_value = json.dumps({ 'lon': lon, 'lat': lat, 'alt': alt, 'time': str(time) }) producer.produce(topic, key=None, value=record_value, on_delivery=acked) producer.poll() sleep(1)
# times for each pixel times = sgeom.times(start_of_scan) # get position and velocity for each time of each pixel pos, vel = orb.get_position(times, normalize=False) # now, get the vectors pointing to each pixel vectors = sgeom.vectors(pos, vel) ## compute intersection of lines (directed by vectors and passing through ## (0, 0, 0)) and sphere ## http://en.wikipedia.org/wiki/Line%E2%80%93sphere_intersection # get the radius of the earth at the given times (lon, lat, alt) = orb.get_lonlatalt(times) radius = vnorm(pos) - alt # do the computation of distance between line and sphere # centre = -pos # ldotc = np.einsum("ij,ij->j", centre, vectors) # centre_square = np.einsum("ij,ij->j", centre, centre) # d1_ = ldotc - np.sqrt((ldotc ** 2 - centre_square + radius ** 2)) # do the computation between line and ellipsoid centre = -pos a__ = 6378.137 # km b__ = 6356.752314245 # km radius = np.array([[1/a__, 1/a__, 1/b__]]).T xr_ = vectors * radius cr_ = centre * radius
def run(self): # run forever until terminated while (self.running): self.counter += 1 # download the latest TLE files cmd = "wget -O " + self.path + "/satellites0a.txt 'https://www.celestrak.com/NORAD/elements/active.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites1a.txt 'https://www.celestrak.com/NORAD/elements/engineering.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites2a.txt 'https://www.celestrak.com/NORAD/elements/globalstar.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites3a.txt 'https://www.celestrak.com/NORAD/elements/iridium.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites4a.txt 'https://www.celestrak.com/NORAD/elements/nnss.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites5a.txt 'https://www.celestrak.com/NORAD/elements/orbcomm.txt'" subprocess.check_output(cmd, shell=True) #print('\n') # for each file in the search list for fileNum in range(0, len(self.searchFiles)): searchfile = self.searchFiles[fileNum] tlefile = self.tleFiles[fileNum] writefile = self.writeFiles[fileNum] file_object = open(searchfile, 'r') ifile = iter(file_object) # load all the static information as dictionaries for easy referencing # a new dictionary is created for each set of static information file name_to_func = {} name_to_unid = {} name_to_year = {} name_to_info = {} for item in ifile: n = item.find(':') s1 = item.find(',') s2 = item.find(',', s1 + 1) s3 = item.find(',', s2 + 1) unid = item[:n] name = item[n + 1:s1] func = item[s1 + 1:s2] year = item[s2 + 1:s3] info = item[s3 + 1:].rstrip() name_to_func[name] = func name_to_unid[name] = unid name_to_year[name] = year name_to_info[name] = info file_object.close() # for every satellite in the static information file, # search the corresponding tle file, and get their longitude, latitude, altitude local_list = [ ] # list to append satellites in the search window for sat in name_to_unid: now = datetime.utcnow() try: # calls to the PyOrbital files to get the dynamic information orb = Orbital(sat, tlefile) (lon, lat, alt) = orb.get_lonlatalt(now) # error handling except OrbitalError: continue except NotImplementedError: continue except KeyError: continue # check if the satellite is in the search window if (abs(lon - clon) <= self.gps_threshold and abs(lat - clat) <= self.gps_threshold): # if it is, append the satellite and static information to the list # name, unique_id, function, year launched, launch number and piece, longitude, latitude, altitude tmp = [ sat, name_to_unid[sat], name_to_func[sat], name_to_year[sat], name_to_info[sat], lon, lat, alt ] local_list.append(tmp) # write the list to the respective output files f = open(writefile, 'w') for item in local_list: entry = item[1] + ':' + item[0] + ',' + item[ 2] + ',' + item[3] + ',' + item[4] f.write(entry + '\n') #print(item) f.close()
def run(self): # run forever until terminated while (self.running): self.counter += 1 # download the latest TLE files cmd = "wget -O " + self.path + "/satellites0b.txt 'https://www.celestrak.com/NORAD/elements/active.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites1b.txt 'https://www.celestrak.com/NORAD/elements/engineering.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites2b.txt 'https://www.celestrak.com/NORAD/elements/globalstar.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites3b.txt 'https://www.celestrak.com/NORAD/elements/iridium.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites4b.txt 'https://www.celestrak.com/NORAD/elements/nnss.txt'" subprocess.check_output(cmd, shell=True) cmd = "wget -O " + self.path + "/satellites5b.txt 'https://www.celestrak.com/NORAD/elements/orbcomm.txt'" subprocess.check_output(cmd, shell=True) self.currentList = [] # list of satellites in the field of view # for each file in the search list for fileNum in range(0, len(self.searchFiles)): searchfile = self.searchFiles[fileNum] tlefile = self.tleFiles[fileNum] file_object = open(searchfile, 'r') ifile = iter(file_object) # load all the static information as dictionaries for easy referencing # a new dictionary is created for each set of static information file name_to_func = {} name_to_unid = {} name_to_year = {} name_to_info = {} for item in ifile: n = item.find(':') s1 = item.find(',') s2 = item.find(',', s1 + 1) s3 = item.find(',', s2 + 1) unid = item[:n] name = item[n + 1:s1] func = item[s1 + 1:s2] year = item[s2 + 1:s3] info = item[s3 + 1:].rstrip() name_to_func[name] = func name_to_unid[name] = unid name_to_year[name] = year name_to_info[name] = info file_object.close() # for every satellite in the static information file, # search the corresponding tle file, and get their longitude, latitude, altitude for sat in name_to_unid: now = datetime.utcnow() try: # calls to the PyOrbital files to get the dynamic information orb = Orbital(sat, tlefile) (lon, lat, alt) = orb.get_lonlatalt(now) # error handling except OrbitalError: continue except NotImplementedError: continue except KeyError: continue # if it is, append the satellite and static information to the list if (abs(lon - clon) <= self.gps_threshold and abs(lat - clat) <= self.gps_threshold): # name, unique_id, function, year launched, launch number and piece, longitude, latitude, altitude # do some post-processing for displaying the name in a cleaner form # in the PiTFT np1 = sat.find('(') if np1 < 0: np1 = len(sat) np2 = sat.find('[') if np2 < 0: np2 = len(sat) np = min(np1, np2) name = sat[:np].rstrip() # check if the satellite is new or was already found if name in self.previousList: # if satellite was found before use the same colour satColor = self.previousList[name] else: # else generate a new rgb colour # the lower limit for the rgb is 30 because any number below that # is too dim on the LED matrix satColor = [ randint(30, 255), randint(30, 255), randint(30, 255) ] self.previousList[name] = satColor # name, unique_id, function, year launched, launch number and piece, longitude, latitude, altitude tmp = [ name, name_to_unid[sat], name_to_func[sat], name_to_year[sat], name_to_info[sat], lon, lat, alt, satColor ] self.currentList.append(tmp) # append to list # write all the found sats to the output files f = open(self.writeFile, 'w') for item in self.currentList: f.write(str(item) + '\n') #print(item) f.close() f = open(self.writeFile2, 'w') for item in self.currentList: f.write(str(item) + '\n') f.close() if (self.counter > 1000): self.counter = 0
def getUpcomingPasses(satellite_name,satellite_swath,tle_information, passes_begin_time, passes_period): observer = ephem.Observer() observer.lat = GROUND_STATION[0] observer.long = GROUND_STATION[1] #updatetime = 0 period = passes_period #Get most recent TLE for determining upcoming passes from now tles = tle_information # make a list of dicts to hold the upcoming pass information for the selected satellites SCHEDULE = [] observer.date = passes_begin_time while 1: for tle in tles: if tle[0].strip()== satellite_name: #TODO clean up the use of pyephem versus orbital. Orbital can give a orbit number and does many of the pyephem functions #TODO add the individual acquisitions as layers in the same ogr output #TODO use an appropriate google earth icon for satellites at a visible display resolution with a name tag and minutesaway #TODO print output to logging satname = str(tle[0]).replace(" ","_") sat = ephem.readtle(tle[0],tle[1],tle[2]) twole = tlefile.read(tle[0],DATA_IN_DIR+'tles.txt') now = datetime.utcnow() #TODO check age of TLE - if older than x days get_tle() # print "TLE EPOCH:",twole.epoch oi = float(str.split(tle[2],' ')[3]) orb = Orbital(tle[0]) attributes = [] rt, ra, tt, ta, st, sa = observer.next_pass(sat) # Determine is pass descending or ascending sat.compute(rt) aos_lat = sat.sublat.real*(180/math.pi) sat.compute(st) los_lat = sat.sublat.real*(180/math.pi) if (aos_lat > los_lat): # print "PASS = descending" node = "descending" else: # print "PASS = ascending" node = "ascending" oi = 360 - oi AOStime = datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S") minutesaway = (AOStime-now).seconds/60.0 # print "Satellie = ", satname # print "Minutes to horizon = ", minutesaway # print "AOStime = ", rt # print "LOStime = ", st # print "Transit time = ", tt # ----------------------------------------------------------------------------- # This is a test routine for calculating Az, El angles # ----------------------------------------------------------------------------- orad = orb.get_lonlatalt(datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S"))[2] # print '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&' test_az_el_cal(orb,observer, rt, ra, tt, ta, st, sa,orad) # print '&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&' # attributes = {'Satellite name': satname, 'Orbit height': orad, 'Orbit': orb.get_orbit_number(datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S")), \ # attributes = {'Satellite name': satname, 'Orbit height': orad, 'Orbit': orb.get_orbit_number(datetime.strptime(str(tt), "%Y/%m/%d %H:%M:%S")), \ 'Current time': str(now),'Minutes to horizon': minutesaway, 'AOS time': str(rt), \ 'LOS time': str(st), 'Transit time': str(tt), 'Node': node} # Append the attributes to the list of acquisitions for the acquisition period if not any ((x['Satellite name'] == satname and x['Orbit'] == orb.get_orbit_number(datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S")))for x in SCHEDULE): # if not any ((x['Satellite name'] == satname and x['Orbit'] == orb.get_orbit_number(datetime.strptime(str(tt), "%Y/%m/%d %H:%M:%S")))for x in SCHEDULE): SCHEDULE.append(attributes) # Step from AOS to LOS in 100 second intervals # delta = timedelta(seconds=100) delta = timedelta(seconds=DELTA_TIME_STEP) deltatime = datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S") geoeastpoint = [] geowestpoint = [] geotrack = [] # print "DELTATIME", deltatime # print "SETTING TIME", datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S") # Tesing for next satellite # -------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------- # The following set of lines have been for testing while making comparision in seconds # instead of string comparisiom # -------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------- # print '================ Testing Loop starts ===========================================' # print 'deltatime = ',deltatime # print 'Secs Time = ', get_time_secs(str(deltatime).replace("-","/")) # print 'st = ',str(datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S")) # print 'st in Secs Time = ',get_time_secs(str(datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S")).replace('-','/')) # print '================ Testing Loop Ends ===========================================' # The following if statement has ben included on the basis of dpoch seconds # if get_time_secs(str(deltatime).replace("-","/")) >= \ get_time_secs(str(datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S")).replace('-','/')): return() print 'Delta Time = ',deltatime print 'date time = ',datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S") print '---------------------------' # if deltatime >= datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S"): # return() while deltatime < datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S"): sat.compute(deltatime) geotrack.append({'lat2': sat.sublat.real*(180/math.pi), \ 'lon2': sat.sublong.real*(180/math.pi), \ 'alt2': orb.get_lonlatalt(datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S"))[2]*1000}) eastaz = getEffectiveHeading(sat,oi,sat.sublat.real*(180/math.pi), sat.sublong.real*(180/math.pi), orad, sat._n)+90 westaz = getEffectiveHeading(sat,oi,sat.sublat.real*(180/math.pi), sat.sublong.real*(180/math.pi), orad, sat._n)+270 #Set ground swath per satellite sensor #TODO use view angle check to refine step from satellite track see IFOV swath = float(satellite_swath)/2. geoeastpoint.append(Geodesic.WGS84.Direct(sat.sublat.real*180/math.pi, sat.sublong.real*180/math.pi, eastaz, swath)) geowestpoint.append(Geodesic.WGS84.Direct(sat.sublat.real*180/math.pi, sat.sublong.real*180/math.pi, westaz, swath)) deltatime = deltatime+delta # Create current location ogr output nowpoint = [{'lat2':orb.get_lonlatalt(datetime.utcnow())[1],'lon2':orb.get_lonlatalt(datetime.utcnow())[0],'alt2':orb.get_lonlatalt(datetime.utcnow())[2]*1000}] #TODO ensure the now attributes are actually attributes for the current position of the satellite and include relevant next pass information...tricky? #if ((attributes['Orbit']==orb.get_orbit_number(datetime.utcnow()))and(AOStime<now)): now_attributes = {'Satellite name': satname, 'Orbit height': orb.get_lonlatalt(datetime.utcnow())[2], 'Orbit': orb.get_orbit_number(datetime.utcnow()), \ 'Current time': str(now),'Minutes to horizon': "N/A", 'AOS time': "N/A", \ 'LOS time': "N/A", 'Transit time': "N/A", 'Node': "N/A"} #now_attributes=attributes #CURRENT_POSITION_FILENAME = satname+"_current_position.kml" CURRENT_POSITION_FILENAME = OUTPUT_DIR+satname+"_current_position.kml" #TODO draw the current orbit forward for the passes period time from the satellite position as a long stepped ogr line getVectorFile(now_attributes,nowpoint,'point', CURRENT_POSITION_FILENAME, 'KML') polypoints = [] for x in geowestpoint: polypoints.append({'lat2':x['lat2'],'lon2':x['lon2']}) for x in reversed(geoeastpoint): polypoints.append({'lat2':x['lat2'],'lon2':x['lon2']}) if len(polypoints)>0: polypoints.append({'lat2':geowestpoint[0]['lat2'],'lon2':geowestpoint[0]['lon2']}) # Create swath footprint ogr output SWATH_FILENAME = os.path.join(output_path,satname+"."+str(orb.get_orbit_number(datetime.strptime(str(rt),"%Y/%m/%d %H:%M:%S")))+".ALICE.orbit_swath.kml") ORBIT_FILENAME = os.path.join(output_path,satname+"."+str(orb.get_orbit_number(datetime.strptime(str(rt),"%Y/%m/%d %H:%M:%S")))+".ALICE.orbit_track.kml") TRACKING_SWATH_FILENAME = os.path.join(output_path,satname+"_tracking_now.kml") # Create currently acquiring polygon #TODO def this # Step from AOS to current time second intervals observer.date=datetime.utcnow() sat.compute(observer) # tkdelta = timedelta(seconds=100) tkdelta = timedelta(seconds=DELTA_TIME_STEP) tkrt, tkra, tktt, tkta, tkst, tksa = observer.next_pass(sat) tkdeltatime = datetime.utcnow() tkgeoeastpoint = [] tkgeowestpoint = [] tkgeotrack = [] while tkdeltatime < (datetime.utcnow() or datetime.strptime(str(tkst),"%Y/%m/%d %H:%M:%S")): sat.compute(tkdeltatime) tkgeotrack.append({'lat2':sat.sublat.real*(180/math.pi),'lon2':sat.sublong.real*(180/math.pi),'alt2':orb.get_lonlatalt(datetime.strptime(str(rt),"%Y/%m/%d %H:%M:%S"))[2]}) tkeastaz = getEffectiveHeading(sat,oi,sat.sublat.real*(180/math.pi), sat.sublong.real*(180/math.pi),orad,sat._n)+90 tkwestaz = getEffectiveHeading(sat,oi,sat.sublat.real*(180/math.pi), sat.sublong.real*(180/math.pi),orad,sat._n)+270 #TODO use view angle check to refine step from satellite track see IFOV tkswath = float(satellite_swath)/2. tkgeoeastpoint.append(Geodesic.WGS84.Direct(sat.sublat.real*180/math.pi, sat.sublong.real*180/math.pi, tkeastaz, tkswath)) tkgeowestpoint.append(Geodesic.WGS84.Direct(sat.sublat.real*180/math.pi, sat.sublong.real*180/math.pi, tkwestaz, tkswath)) tkdeltatime = tkdeltatime+tkdelta tkpolypoints = [] for x in tkgeowestpoint: tkpolypoints.append({'lat2':x['lat2'],'lon2':x['lon2']}) for x in reversed(tkgeoeastpoint): tkpolypoints.append({'lat2':x['lat2'],'lon2':x['lon2']}) if len(tkpolypoints)>0: tkpolypoints.append({'lat2':tkgeowestpoint[0]['lat2'],'lon2':tkgeowestpoint[0]['lon2']}) if not ((attributes['Node']=="ascending")and(satname not in ("AQUA"))): # Create swath ogr output getVectorFile(attributes,polypoints,'polygon', SWATH_FILENAME, 'KML') # Create orbit track ogr output getVectorFile(attributes,geotrack,'line', ORBIT_FILENAME, 'KML') # Create currently acquiring ogr output if ((now >= datetime.strptime(str(tkrt),"%Y/%m/%d %H:%M:%S")) and (now <= datetime.strptime(str(tkst),"%Y/%m/%d %H:%M:%S"))): getVectorFile(now_attributes,tkpolypoints,'polygon', TRACKING_SWATH_FILENAME, 'KML') if minutesaway <= period: # print tle[0], 'WILL BE MAKING A PASS IN ', minutesaway, " MINUTES" # print ' Rise Azimuth: ', ra # print ' Transit Time: ', tt # print ' Transit Altitude: ', ta # print ' Set Time: ', st # print ' Set Azimuth: ', sa # print '=================================================' # print 'Satellite Name = ',satellite_name for x in sorted(SCHEDULE, key=lambda k: k['AOS time']): # print x output_orbit_parameters(x) # For dictionary entries with 'LOS time' older than now time - remove if ((datetime.strptime(str(x['LOS time']),"%Y/%m/%d %H:%M:%S"))<(datetime.utcnow())): # Delete output ogr if os.path.exists(os.path.join(output_path,satname+"."+str(x['Orbit'])+".ALICE.orbit_swath.kml")): os.remove(os.path.join(output_path,satname+"."+str(x['Orbit'])+".ALICE.orbit_swath.kml")) if os.path.exists(os.path.join(output_path,satname+"."+str(x['Orbit'])+".ALICE.orbit_track.kml")): os.remove(os.path.join(output_path,satname+"."+str(x['Orbit'])+".ALICE.orbit_track.kml")) # Delete dictionary entry for pass SCHEDULE.remove(x) # Unlikely - if no entries in the SCHEDULE don't try to print it if len(SCHEDULE)>0: print (datetime.strptime(str(SCHEDULE[0]['AOS time']),"%Y/%m/%d %H:%M:%S")) # If the AOS time is less than now + the time delta, shift the time to the latest recorded pass LOS time if ((datetime.strptime(str(SCHEDULE[len(SCHEDULE)-1]['AOS time']),"%Y/%m/%d %H:%M:%S")<(datetime.utcnow()+timedelta(minutes=period)))): observer.date = (datetime.strptime(str(SCHEDULE[len(SCHEDULE)-1]['LOS time']),"%Y/%m/%d %H:%M:%S")+timedelta(minutes=5)) # Recompute the satellite position for the update time sat.compute(observer) # print "MODIFIED OBSERVER DATE",observer.date else: # print "--------NOTHING TO MODIFY MOVING TO NEXT SATELLITE IN LIST------" #TODO - write to html # Exit the def if the SCHEDULE isn't able to update because there are no passes in the acquisition window return () # print 'Before Time Sleep ......' # print 'Loop for While .........' print '=============================================================================' time.sleep(1*SLEEP_STATUS) return ()
def create_orbital_track_shapefile_for_day(sat_id, track_day, step_minutes, output_shapefile): # Для начала получаем TLE # Если запрошенная дата наступит в будущем, то запрашиваем самые последний набор TLE if track_day > date.today(): tle_1, tle_2 = get_spacetrack_tle(sat_id, None, None, USERNAME, PASSWORD, True) # Иначе на конкретный период, формируя запрос для указанной даты и дня после неё + timedelta(days = 1) else: tle_1, tle_2 = get_spacetrack_tle(sat_id, track_day, track_day + timedelta(days=1), USERNAME, PASSWORD, False) # Если не получилось добыть if not tle_1 or not tle_2: print('Impossible to retrieve TLE') return # Создаём экземляр класса Orbital orb = Orbital("N", line1=tle_1, line2=tle_2) # Создаём экземпляр класса Writer для создания шейп-файла, указываем тип геометрии track_shape = shapefile.Writer(shapefile.POINT) # Добавляем поля - идентификатор, время, широту и долготу # N - целочисленный тип, C - строка, F - вещественное число # Для времени придётся использовать строку, т.к. нет поддержки формата "дата и время" track_shape.field('ID', 'N', 40) track_shape.field('TIME', 'C', 40) track_shape.field('LAT', 'F', 40) track_shape.field('LON', 'F', 40) # Объявляем счётчики, i для идентификаторов, minutes для времени i = 0 minutes = 0 # Простой способ пройти сутки - с заданным в минутах шагом дойти до 1440 минут. # Именно столько их в сутках! while minutes < 1440: # Расчитаем час, минуту, секунду (для текущего шага) utc_hour = int(minutes // 60) utc_minutes = int((minutes - (utc_hour * 60)) // 1) utc_seconds = int(round( (minutes - (utc_hour * 60) - utc_minutes) * 60)) # Сформируем строку для атрибута utc_string = str(utc_hour) + '-' + str(utc_minutes) + '-' + str( utc_seconds) # И переменную с временем текущего шага в формате datetime utc_time = datetime(track_day.year, track_day.month, track_day.day, utc_hour, utc_minutes, utc_seconds) # Считаем положение спутника lon, lat, alt = orb.get_lonlatalt(utc_time) # Создаём в шейп-файле новый объект # Определеяем геометрию track_shape.point(lon, lat) # и атрибуты track_shape.record(i, utc_string, lat, lon) # Не забываем про счётчики i += 1 minutes += step_minutes # Вне цикла нам осталось записать созданный шейп-файл на диск. # Т.к. мы знаем, что координаты положений ИСЗ были получены в WGS84 # можно заодно создать файл .prj с нужным описанием try: # Создаем файл .prj с тем же именем, что и выходной .shp prj = open("%s.prj" % output_shapefile.replace('.shp', ''), "w") # Создаем переменную с описанием EPSG:4326 (WGS84) wgs84_wkt = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]' # Записываем её в файл .prj prj.write(wgs84_wkt) # И закрываем его prj.close() # Функцией save также сохраняем и сам шейп. track_shape.save(output_shapefile) except: # Вдруг нет прав на запись или вроде того... print('Unable to save shapefile') return
JY1SAT (JO-97) 1 43803U 18099AX 19134.16991763 .00000149 00000-0 18753-4 0 9997 2 43803 97.7441 206.5509 0016839 88.1084 272.2065 14.95242491 24118""" tle = StringIO() tle.write(amateur_file) orb = Orbital( "AO-7", line1= "1 07530U 74089B 19134.19581420 -.00000034 00000-0 67853-4 0 9992", line2= "2 07530 101.7410 102.2252 0012571 56.5062 14.6811 12.53638015 36076") now = datetime.utcnow() # arrayat=Orbital.get_observer_look(lon=120.77,lat=15.15,alt=0.020) pprint(orb) # >>> # Get longitude, latitude and altitude of the satellite: >>> pprint(orb.get_lonlatalt(now)) passes = orb.get_next_passes(now, length=4, lon=120.77, lat=15.15, alt=0.02) # # Each Pass a tuple of 3, rise, set, max ele # start_pass = passes[0][0] end_pass = passes[0][1] min_elevation = 10 while (start_pass < end_pass): sky_location = orb.get_observer_look(start_pass, lon=120.77, lat=15.15, alt=0.02) if sky_location[1] >= min_elevation: print("Az {:6.2f} Ele {:6.2f} ".format(sky_location[0], sky_location[1]))
def initMap(input,hourval,minuteval): #orb = Orbital(input,tle_file='stations.txt') print hourval print minuteval latlist = [] longlist = [] textlist = [] now = datetime.datetime.utcnow() newdate = now.replace(hour=hourval, minute=minuteval) if type(input) is list: textlist = input for a in input: orb = Orbital(a,tle_file=my_file) locationset = orb.get_lonlatalt(newdate) latlist.append(locationset[0]) longlist.append(locationset[1]) else: textlist = [input] print textlist orb = Orbital(input, tle_file=my_file) locationset = orb.get_lonlatalt(newdate) latlist = [locationset[0]] longlist = [locationset[1]] print latlist print longlist data = [ dict( text = textlist, lat = latlist, mode = "markers+text", lon = longlist, type = "scattergeo", showlegend = True, textposition = "bottom center" ) ] layout = dict( width = 1000, height = 700, geo = dict( scope = 'world', showland = True, showframe = False, #landcolor = "rgb(212, 212, 212)", #subunitcolor = "rgb(255, 255, 255)", countrycolor = "rgb(255, 255, 255)", #showlakes = True, #showsubunits = True, showcountries = True, projection = dict(type = "orthographic"), # lonaxis = dict( # showgrid = False, # gridwidth = 0.5, # range= [ -1080, 1080.0 ], # dtick = 5 # ), # lataxis = dict ( # showgrid = False, # gridwidth = 0.5, # range= [ -1080, 1080 ], # dtick = 5 # ) ) ) fig = {'data': data, 'layout': layout} return fig
day = 4 month = 3 hour = 19 minute = 30 second = 49 """## Cálculo de trayectoria""" orb = Orbital(satelite) #now = datetime.utcnow() local_tz = pytz.timezone("America/Montevideo") UTC_dif = 3 dtobj = datetime(year, month, day, hour + UTC_dif, minute, second) dtobj2 = dtobj + timedelta(seconds=duracion_s) lon, lat, alt = orb.get_lonlatalt(dtobj) lon2, lat2, alt2 = orb.get_lonlatalt(dtobj2) coords_1 = (lat, lon) coords_2 = (lat2, lon2) distancia = geopy.distance.vincenty(coords_1, coords_2).km print("Posición inicio:", orb.get_position(dtobj)) print("Longitud:", lon) print("Latitud:", lat) print("Altura (km):", alt) print("\nPosición final:", orb.get_position(dtobj2)) print("Longitud:", lon2) print("Latitud:", lat2)
satellite = sys.argv[1] userLat = float(sys.argv[2]) userLng = float(sys.argv[3]) userAlt = float(sys.argv[4]) line1 = sys.argv[5] line2 = sys.argv[6] tle = tlefile.read(satellite, None, line1, line2) orb = Orbital(satellite, None, line1, line2) now = datetime.utcnow() # Get normalized position and velocity of the satellite: pos, vel = orb.get_position(now) # Get longitude, latitude and altitude of the satellite: position = orb.get_lonlatalt(now) data = {} timestamp = calendar.timegm(now.utctimetuple()) az, el = orb.get_observer_look(now, userLng, userLat, userAlt); data['user_view'] = {} data['user_view']['azimuth'] = az data['user_view']['elevation'] = el data['timestamp'] = timestamp data['satellite'] = satellite
brng = (brng + 360) % 360 brng = 360 - brng return brng orb = Orbital("NOAA 19", tle_file='../tle/noaa18_June_14_2018.txt') tc = datetime(2018, 6, 15, 14, 7, 52) im = plt.imread('m3.png') im = im[:, 85:995] oim = im[:] print(im.shape) tdelta = int(im.shape[0] / 16) top = orb.get_lonlatalt(tc + timedelta(seconds=int(im.shape[0] / 4) - tdelta))[:2][::-1] bot = orb.get_lonlatalt(tc + timedelta(seconds=int(im.shape[0] / 4) + tdelta))[:2][::-1] center = orb.get_lonlatalt(tc + timedelta(seconds=int(im.shape[0] / 4)))[:2][::-1] rot = angleFromCoordinate(*bot, *top) print(rot) rotated_img = ndimage.rotate(im, rot) rimg = rotated_img[:] w = rotated_img.shape[1] h = rotated_img.shape[0] m = Basemap(projection='cass', lon_0=center[1],
def get_lat_lon_sgp(tle_1, tle_2, utc_time): # Инициализируем экземпляр класса Orbital двумя строками TLE orb = Orbital("N", line1=tle_1, line2=tle_2) # Вычисляем географические координаты функцией get_lonlatalt, её аргумент - время в UTC. lon, lat, alt = orb.get_lonlatalt(utc_time) return lon, lat
class Satellite(object): def __init__(self, name, speed=60, orbit_count=1, swath_color=(255, 0, 0, 127), track_color=(255, 255, 255, 200), swath_width=10000): self.name = name self.orbit = Orbital(name) self.NUM_STEPS = 255 self.speed = speed self.orbit_count = orbit_count self.swath_width = swath_width # Styling self.swath_color = swath_color self.track_color = track_color @property def period(self): return self.orbit.orbit_elements.period * self.orbit_count @property def time(self): return datetime.datetime.utcnow() @property def timestep(self): return (self.period / self.NUM_STEPS) * 60 def time_steps(self): steps = [] start_time = self.time for step in range(self.NUM_STEPS): step_info = {'startTime': start_time} start_time += datetime.timedelta(seconds=self.timestep) step_info.update({'endTime': start_time}) steps.append(step_info) return steps def ground_track(self, time=True, altitude=True): duration = 0 track = [] for item in [ self.orbit.get_lonlatalt(x['startTime']) for x in self.time_steps() ]: if time: track.append(duration) track.append(item[0]) track.append(item[1]) if altitude: track.append(1000 * item[2]) else: track.append(0) duration += self.timestep return track def to_czml(self): output = [] time_steps = self.time_steps() ground_track = self.ground_track() start_time = time_steps[0]['startTime'].strftime("%Y-%m-%dT%H:%M:%S") end_time = time_steps[-1]['endTime'].strftime("%Y-%m-%dT%H:%M:%S") # Global packet global_element = { 'id': 'document', 'name': self.name, 'version': '1.0', 'clock': { 'interval': start_time + '/' + end_time, 'currentTime': start_time, 'multiplier': self.speed, } } output.append(global_element) # Path object path_object = { 'id': self.name + '/Propagated Orbit', 'name': self.name + ' Propagated Orbit', 'availability': start_time + '/' + end_time, 'position': { 'epoch': start_time, 'cartographicDegrees': ground_track }, 'path': { "material": { "polylineOutline": { "color": { "rgba": self.track_color }, "outlineColor": { "rgba": [255, 255, 255, 200] }, "outlineWidth": 5 } }, 'width': 1, 'resolution': 120, } } output.append(path_object) # Point variable point_object = { "id": self.name + '/Satellite', "name": self.name + " Satellite", "availability": start_time + '/' + end_time, "position": { "epoch": start_time, "cartographicDegrees": ground_track }, "billboard": { "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAADJSURBVDhPnZHRDcMgEEMZjVEYpaNklIzSEfLfD4qNnXAJSFWfhO7w2Zc0Tf9QG2rXrEzSUeZLOGm47WoH95x3Hl3jEgilvDgsOQUTqsNl68ezEwn1vae6lceSEEYvvWNT/Rxc4CXQNGadho1NXoJ+9iaqc2xi2xbt23PJCDIB6TQjOC6Bho/sDy3fBQT8PrVhibU7yBFcEPaRxOoeTwbwByCOYf9VGp1BYI1BA+EeHhmfzKbBoJEQwn1yzUZtyspIQUha85MpkNIXB7GizqDEECsAAAAASUVORK5CYII=", "scale": 2 }, "label": { "fillColor": { "rgba": [0, 255, 0, 255] }, "font": "15pt Lucida Console", "horizontalOrigin": "LEFT", "outlineColor": { "rgba": [0, 0, 0, 255] }, "outlineWidth": 4, "pixelOffset": { "cartesian2": [12, 0] }, "style": "FILL_AND_OUTLINE", "text": self.name, "verticalOrigin": "CENTER", } } output.append(point_object) # Corridor (swath width) corridor_object = { 'id': self.name + '/Corridor', 'name': self.name + ' Ground Swath', 'corridor': { 'positions': { 'cartographicDegrees': self.ground_track(time=False, altitude=False) }, 'width': self.swath_width, "material": { "solidColor": { "color": { "rgba": self.swath_color } } } } } output.append(corridor_object) return output def to_czml_multi(self, placeholder, conn): conn.send(self.to_czml()) conn.close()
def getUpcomingPasses(satellite_name, tle_information, passes_begin_time, passes_period): observer = ephem.Observer() observer.lat = ground_station[0] observer.long = ground_station[1] #updatetime = 0 period = passes_period #Get most recent TLE for determining upcoming passes from now tles = tle_information # make a list of dicts to hold the upcoming pass information for the selected satellites schedule = [] observer.date = passes_begin_time while 1: print "---------------------------------------" for tle in tles: if tle[0] == satellite_name: #TODO clean up the use of pyephem versus orbital. Orbital can give a orbit number and does many of the pyephem functions #TODO add the individual acquisitions as layers in the same ogr output #TODO use an appropriate google earth icon for satellites at a visible display resolution with a name tag and minutesaway #TODO print output to logging satname = str(tle[0]).replace(" ","_") sat = ephem.readtle(tle[0],tle[1],tle[2]) twole = tlefile.read(tle[0],'tles.txt') now = datetime.utcnow() #TODO check age of TLE - if older than x days get_tle() print "TLE EPOCH:",twole.epoch #if twole.epoch < now - timedelta(days=5): # get_tles() # satname = str(tle[0]).replace(" ","_") # sat = ephem.readtle(tle[0],tle[1],tle[2]) # twole = tlefile.read(tle[0],'tles.txt') print "---------------------------------------" print tle[0] oi = float(str.split(tle[2],' ')[3]) orb = Orbital(tle[0]) attributes = [] rt, ra, tt, ta, st, sa = observer.next_pass(sat) # Determine is pass descending or ascending sat.compute(rt) aos_lat = sat.sublat.real*(180/math.pi) sat.compute(st) los_lat = sat.sublat.real*(180/math.pi) if (aos_lat > los_lat): print "PASS = descending" node = "descending" else: print "PASS = ascending" node = "ascending" oi = 360 - oi AOStime = datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S") minutesaway = (AOStime-now).seconds/60.0 print "Minutes to horizon = ", minutesaway print "AOStime = ", rt print "LOStime = ", st print "Transit time = ", tt orad = orb.get_lonlatalt(datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S"))[2] attributes = {'Satellite name': satname, 'Orbit height': orad, 'Orbit': orb.get_orbit_number(datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S")), \ 'Current time': str(now),'Minutes to horizon': minutesaway, 'AOS time': str(rt), \ 'LOS time': str(st), 'Transit time': str(tt), 'Node': node} # Append the attributes to the list of acquisitions for the acquisition period if not any ((x['Satellite name'] == satname and x['Orbit'] == orb.get_orbit_number(datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S")))for x in schedule): schedule.append(attributes) # Step from AOS to LOS in 100 second intervals delta = timedelta(seconds=100) deltatime = datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S") geoeastpoint = [] geowestpoint = [] geotrack = [] print "DELTATIME", deltatime print "SETTING TIME", datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S") while deltatime < datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S"): sat.compute(deltatime) geotrack.append({'lat2': sat.sublat.real*(180/math.pi), \ 'lon2': sat.sublong.real*(180/math.pi), \ 'alt2': orb.get_lonlatalt(datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S"))[2]*1000}) eastaz = getEffectiveHeading(sat,oi,sat.sublat.real*(180/math.pi), sat.sublong.real*(180/math.pi), orad, sat._n)+90 westaz = getEffectiveHeading(sat,oi,sat.sublat.real*(180/math.pi), sat.sublong.real*(180/math.pi), orad, sat._n)+270 #Set ground swath per satellite sensor #TODO use view angle check to refine step from satellite track see IFOV if tle[0] in ("LANDSAT 8","LANDSAT 7"): swath = 185000/2 if tle[0] in ("TERRA","AQUA"): swath = 2330000/2 if tle[0] in ("NOAA 15", "NOAA 18", "NOAA 19"): swath = 1100000/2 if tle[0] == "SUOMI NPP": swath = 2200000/2 geoeastpoint.append(Geodesic.WGS84.Direct(sat.sublat.real*180/math.pi, sat.sublong.real*180/math.pi, eastaz, swath)) geowestpoint.append(Geodesic.WGS84.Direct(sat.sublat.real*180/math.pi, sat.sublong.real*180/math.pi, westaz, swath)) deltatime = deltatime+delta # Create current location ogr output nowpoint = [{'lat2':orb.get_lonlatalt(datetime.utcnow())[1],'lon2':orb.get_lonlatalt(datetime.utcnow())[0],'alt2':orb.get_lonlatalt(datetime.utcnow())[2]*1000}] #TODO ensure the now attributes are actually attributes for the current position of the satellite and include relevant next pass information...tricky? #if ((attributes['Orbit']==orb.get_orbit_number(datetime.utcnow()))and(AOStime<now)): now_attributes = {'Satellite name': satname, 'Orbit height': orb.get_lonlatalt(datetime.utcnow())[2], 'Orbit': orb.get_orbit_number(datetime.utcnow()), \ 'Current time': str(now),'Minutes to horizon': "N/A", 'AOS time': "N/A", \ 'LOS time': "N/A", 'Transit time': "N/A", 'Node': "N/A"} #now_attributes=attributes CURRENT_POSITION_FILENAME = satname+"_current_position.kml" #TODO draw the current orbit forward for the passes period time from the satellite position as a long stepped ogr line getVectorFile(now_attributes,nowpoint,'point', CURRENT_POSITION_FILENAME, 'KML') polypoints = [] for x in geowestpoint: polypoints.append({'lat2':x['lat2'],'lon2':x['lon2']}) for x in reversed(geoeastpoint): polypoints.append({'lat2':x['lat2'],'lon2':x['lon2']}) if len(polypoints)>0: polypoints.append({'lat2':geowestpoint[0]['lat2'],'lon2':geowestpoint[0]['lon2']}) # Create swath footprint ogr output SWATH_FILENAME = os.path.join(output_path,satname+"."+str(orb.get_orbit_number(datetime.strptime(str(rt),"%Y/%m/%d %H:%M:%S")))+".ALICE.orbit_swath.kml") ORBIT_FILENAME = os.path.join(output_path,satname+"."+str(orb.get_orbit_number(datetime.strptime(str(rt),"%Y/%m/%d %H:%M:%S")))+".ALICE.orbit_track.kml") TRACKING_SWATH_FILENAME = os.path.join(output_path,satname+"_tracking_now.kml") # Create currently acquiring polygon #TODO def this # Step from AOS to current time second intervals observer.date=datetime.utcnow() sat.compute(observer) tkdelta = timedelta(seconds=100) tkrt, tkra, tktt, tkta, tkst, tksa = observer.next_pass(sat) tkdeltatime = datetime.utcnow() tkgeoeastpoint = [] tkgeowestpoint = [] tkgeotrack = [] while tkdeltatime < (datetime.utcnow() or datetime.strptime(str(tkst),"%Y/%m/%d %H:%M:%S")): sat.compute(tkdeltatime) tkgeotrack.append({'lat2':sat.sublat.real*(180/math.pi),'lon2':sat.sublong.real*(180/math.pi),'alt2':orb.get_lonlatalt(datetime.strptime(str(rt),"%Y/%m/%d %H:%M:%S"))[2]}) tkeastaz = getEffectiveHeading(sat,oi,sat.sublat.real*(180/math.pi), sat.sublong.real*(180/math.pi),orad,sat._n)+90 tkwestaz = getEffectiveHeading(sat,oi,sat.sublat.real*(180/math.pi), sat.sublong.real*(180/math.pi),orad,sat._n)+270 #TODO use view angle check to refine step from satellite track see IFOV if tle[0] in ("LANDSAT 8","LANDSAT 7"): tkswath = 185000/2 if tle[0] in ("TERRA","AQUA"): tkswath = 2330000/2 if tle[0] in ("NOAA 15", "NOAA 18", "NOAA 19"): tkswath = 1100000/2 if tle[0] == "SUOMI NPP": tkswath = 2200000/2 tkgeoeastpoint.append(Geodesic.WGS84.Direct(sat.sublat.real*180/math.pi, sat.sublong.real*180/math.pi, tkeastaz, tkswath)) tkgeowestpoint.append(Geodesic.WGS84.Direct(sat.sublat.real*180/math.pi, sat.sublong.real*180/math.pi, tkwestaz, tkswath)) tkdeltatime = tkdeltatime+tkdelta tkpolypoints = [] for x in tkgeowestpoint: tkpolypoints.append({'lat2':x['lat2'],'lon2':x['lon2']}) for x in reversed(tkgeoeastpoint): tkpolypoints.append({'lat2':x['lat2'],'lon2':x['lon2']}) if len(tkpolypoints)>0: tkpolypoints.append({'lat2':tkgeowestpoint[0]['lat2'],'lon2':tkgeowestpoint[0]['lon2']}) if not ((attributes['Node']=="ascending")and(satname not in ("AQUA"))): # Create swath ogr output getVectorFile(attributes,polypoints,'polygon', SWATH_FILENAME, 'KML') # Create orbit track ogr output getVectorFile(attributes,geotrack,'line', ORBIT_FILENAME, 'KML') # Create currently acquiring ogr output if ((now >= datetime.strptime(str(tkrt),"%Y/%m/%d %H:%M:%S")) and (now <= datetime.strptime(str(tkst),"%Y/%m/%d %H:%M:%S"))): getVectorFile(now_attributes,tkpolypoints,'polygon', TRACKING_SWATH_FILENAME, 'KML') if minutesaway <= period: print "---------------------------------------" print tle[0], 'WILL BE MAKING A PASS IN ', minutesaway, " MINUTES" print ' Rise Azimuth: ', ra print ' Transit Time: ', tt print ' Transit Altitude: ', ta print ' Set Time: ', st print ' Set Azimuth: ', sa for x in sorted(schedule, key=lambda k: k['AOS time']): print x # For dictionary entries with 'LOS time' older than now time - remove if ((datetime.strptime(str(x['LOS time']),"%Y/%m/%d %H:%M:%S"))<(datetime.utcnow())): # Delete output ogr if os.path.exists(os.path.join(output_path,satname+"."+str(x['Orbit'])+".ALICE.orbit_swath.kml")): os.remove(os.path.join(output_path,satname+"."+str(x['Orbit'])+".ALICE.orbit_swath.kml")) if os.path.exists(os.path.join(output_path,satname+"."+str(x['Orbit'])+".ALICE.orbit_track.kml")): os.remove(os.path.join(output_path,satname+"."+str(x['Orbit'])+".ALICE.orbit_track.kml")) # Delete dictionary entry for pass schedule.remove(x) # Unlikely - if no entries in the schedule don't try to print it if len(schedule)>0: print (datetime.strptime(str(schedule[0]['AOS time']),"%Y/%m/%d %H:%M:%S")) # If the AOS time is less than now + the time delta, shift the time to the latest recorded pass LOS time if ((datetime.strptime(str(schedule[len(schedule)-1]['AOS time']),"%Y/%m/%d %H:%M:%S")<(datetime.utcnow()+timedelta(minutes=period)))): observer.date = (datetime.strptime(str(schedule[len(schedule)-1]['LOS time']),"%Y/%m/%d %H:%M:%S")+timedelta(minutes=5)) # Recompute the satellite position for the update time sat.compute(observer) print "MODIFIED OBSERVER DATE",observer.date else: print "--------NOTHING TO MODIFY MOVING TO NEXT SATELLITE IN LIST------" #TODO - write to html # Exit the def if the schedule isn't able to update because there are no passes in the acquisition window return () time.sleep(1*sleep_status) return ()
# PyOrbital get_position and get_lonlatalt cases # Use current TLEs from Celestrak: http://celestrak.com/NORAD/elements/ # SATELLITE sat = "SENTINEL-3A" #orb = Orbital('SENTINEL-3A', tle_file='./EO_Sat.txt') orb = Orbital(sat) now = datetime.utcnow() # Get position and velocity of the satellite: print(orb.get_position(now, normalize=False)) # Get longitude, latitude and altitude of the satellite: print(orb.get_lonlatalt(now)) # Create a new Map centered on position [0,0] m = folium.Map(location=[10, 0],zoom_start = 1) # Function to get position with a deltatime from now(). (Default deltatime is 0) def getsatpos(DeltaTiming=0): now = datetime.utcnow() + timedelta(seconds = DeltaTiming) # Get longitude, latitude and altitude of the satellite: lon,lat,alt = orb.get_lonlatalt(now) return(lat,lon) # Function to get an orbit over an specified period of time. (Default period is 101 min) def getoneorbit(period=6060): prd = period/2