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 create_subdirname(obstime, with_seconds=False, **kwargs): """Generate the pps subdirectory name from the start observation time, ex.: 'npp_20120405_0037_02270'""" sat = kwargs.get('platform_name', 'npp') platform_name = PLATFORM_NAME.get(sat, sat) if "orbit" in kwargs: orbnum = int(kwargs['orbit']) else: from pyorbital.orbital import Orbital from cspp_runner import orbitno try: tle = orbitno.get_tle(TLE_SATNAME.get(platform_name), obstime) orbital_ = Orbital(tle.platform, line1=tle.line1, line2=tle.line2) orbnum = orbital_.get_orbit_number(obstime, tbus_style=TBUS_STYLE) except orbitno.NoTleFile: LOG.error('Not able to determine orbit number!') import traceback traceback.print_exc(file=sys.stderr) orbnum = 1 if with_seconds: return platform_name + obstime.strftime( '_%Y%m%d_%H%M%S_') + '%.5d' % orbnum else: return platform_name + obstime.strftime( '_%Y%m%d_%H%M_') + '%.5d' % orbnum
def get_last_valid_tle_lines(platform_name, epoch): if os.path.exists(os.path.join(REF_DIR, platform_name)): with open(os.path.join(REF_DIR, platform_name)) as fd: ref_lines = fd.readlines() ref_orb = Orbital(platform_name, line1=ref_lines[1], line2=ref_lines[2]) if abs(epoch - ref_orb.tle.epoch) < timedelta(days=7): return ref_lines else: logger.info("cached TLE too old, refreshing") orbit = get_valid_orbit(platform_name, epoch) files = sorted(get_files(), key=os.path.getctime) for tle_file in reversed(files): try: orb = Orbital(platform_name, tle_file=tle_file) except AttributeError: continue except ChecksumError: continue if orb.get_orbit_number(epoch) == orbit: lines = [orb.tle._platform, orb.tle._line1, orb.tle._line2] with open(os.path.join(REF_DIR, platform_name), "w") as fd: fd.write("\n".join(lines)) return lines
def get_valid_orbit(platform_name, epoch): orb_nums = [] for tle_file in sorted(get_files(), reverse=True): try: orb = Orbital(platform_name, tle_file=tle_file) except AttributeError: continue except ChecksumError: continue orb_nums.append(orb.get_orbit_number(epoch)) return int(round(np.median(orb_nums)))
class NPP_Orbit: # Constructor of NPP_Orbit def __init__(self): self.ground_lat = EARTH_STATION_LAT self.ground_long = EARTH_STATION_LONG self.observer = ephem.Observer() self.observer.lat = self.ground_lat self.observer.long = self.ground_long self.observer.date = datetime.utcnow() self.tle = IN_TLE_FILE self.tles = [] self.satellite_name = TRK_SATELLITE self.orb = Orbital(self.satellite_name, tle_file=self.tle) # Functions def read_tle(self): self.tles = open(self.tle, 'r').readlines() self.tles = [item.strip() for item in self.tles] self.tles = [(self.tles[i], self.tles[i+1], self.tles[i+2]) \ for i in xrange(0, len(self.tles)-2, 3)] return def get_pass_num_t(self, yyyy, mm, dd, hh, mn, ss): indate = str(yyyy) + '-' + str(mm) + '-' +str(dd) + ' ' +\ str(hh) + ':' + str(mn) + ':' + str(ss) self.observer.date = indate for tle in self.tles: if tle[0].strip() == self.satellite_name: sat = ephem.readtle(tle[0], tle[1], tle[2]) rt, ra, tt, ta, st, sa = self.observer.next_pass(sat) num = self.orb.get_orbit_number(datetime.strptime( str(tt), "%Y/%m/%d %H:%M:%S"), tbus_style=True) return num def __del__(self): pass
class NPP_Orbit: # Constructor of NPP_Orbit def __init__(self): self.ground_lat = EARTH_STATION_LAT self.ground_long = EARTH_STATION_LONG self.observer = ephem.Observer() self.observer.lat = self.ground_lat self.observer.long = self.ground_long self.observer.date = datetime.utcnow() self.tle = IN_TLE_FILE self.tles = [] self.satellite_name = TRK_SATELLITE self.orb = Orbital(self.satellite_name,tle_file=self.tle) # Functions def read_tle(self): self.tles = open(self.tle, 'r').readlines() self.tles = [item.strip() for item in self.tles] self.tles = [(self.tles[i], self.tles[i+1], self.tles[i+2]) \ for i in xrange(0, len(self.tles)-2, 3)] return def get_pass_num_t(self,yyyy,mm,dd,hh,mn,ss): indate = str(yyyy) + '-' + str(mm) + '-' +str(dd) + ' ' +\ str(hh) + ':' + str(mn) + ':' + str(ss) self.observer.date = indate for tle in self.tles: if tle[0].strip() == self.satellite_name: sat = ephem.readtle(tle[0],tle[1],tle[2]) rt, ra, tt, ta, st, sa = self.observer.next_pass(sat) num = self.orb.get_orbit_number(datetime.strptime(str(tt), "%Y/%m/%d %H:%M:%S"),tbus_style=True) return num def __del__(self): pass
def create_subdirname(obstime, with_seconds=False, **kwargs): """Generate the pps subdirectory name from the start observation time, ex.: 'npp_20120405_0037_02270'""" if "orbit" in kwargs: orbnum = int(kwargs['orbit']) else: from pyorbital.orbital import Orbital from npp_runner import orbitno try: tle = orbitno.get_tle('npp', obstime) orbital_ = Orbital(tle.platform, line1=tle.line1, line2=tle.line2) orbnum = orbital_.get_orbit_number(obstime, tbus_style=TBUS_STYLE) except orbitno.NoTleFile: LOG.error('Not able to determine orbit number!') import traceback traceback.print_exc(file=sys.stderr) orbnum = 1 if with_seconds: return obstime.strftime('npp_%Y%m%d_%H%M%S_') + '%.5d' % orbnum else: return obstime.strftime('npp_%Y%m%d_%H%M_') + '%.5d' % orbnum
def replace_orbitno(filename): stamp = get_npp_stamp(filename) # Correct h5 attributes no_date = datetime(1958, 1, 1) epsilon_time = timedelta(days=2) import h5py def _get_a_good_time(name, obj): del name if isinstance(obj, h5py.Dataset): date_key, time_key = ('Ending_Date', 'Ending_Time') if date_key in obj.attrs.keys(): if not good_time_val_[0]: time_val = datetime.strptime( obj.attrs[date_key][0][0] + obj.attrs[time_key][0][0], '%Y%m%d%H%M%S.%fZ') if abs(time_val - no_date) > epsilon_time: good_time_val_[0] = time_val def _check_orbitno(name, obj): del name if isinstance(obj, h5py.Dataset): for date_key, time_key, orbit_key in ( ('AggregateBeginningDate', 'AggregateBeginningTime', 'AggregateBeginningOrbitNumber'), ('AggregateEndingDate', 'AggregateEndingTime', 'AggregateEndingOrbitNumber'), ('Beginning_Date', 'Beginning_Time', 'N_Beginning_Orbit_Number')): if orbit_key in obj.attrs.keys(): time_val = datetime.strptime( obj.attrs[date_key][0][0] + obj.attrs[time_key][0][0], '%Y%m%d%H%M%S.%fZ') # Check for no date (1958) problem: if abs(time_val - no_date) < epsilon_time: LOG.info("Start time wrong: %s", time_val.strftime('%Y%m%d')) LOG.info("Will use the first good end time encounter " + "in file to determine orbit number") time_val = good_time_val_[0] orbit_val = orbital_.get_orbit_number(time_val, tbus_style=TBUS_STYLE) obj.attrs.modify(orbit_key, [[orbit_val]]) counter_[0] += 1 # Correct h5 attributes orbital_ = Orbital(TLE_SATNAME[stamp.platform]) orbit = orbital_.get_orbit_number(stamp.start_time, tbus_style=TBUS_STYLE) LOG.info("Replacing orbit number %05d with %05d", stamp.orbit_number, orbit) fp = h5py.File(filename, 'r+') try: good_time_val_ = [None] fp.visititems(_get_a_good_time) counter_ = [0] fp.visititems(_check_orbitno) if counter_[0] == 0: raise IOError( "Failed replacing orbit number in hdf5 attributes '%s'" % filename) LOG.info("Replaced orbit number in %d attributes", counter_[0]) finally: fp.close() # Correct filename dname, fname = os.path.split(filename) fname, n = _re_replace_orbitno.subn('_b%05d' % orbit, fname) if n != 1: raise IOError("Failed replacing orbit number in filename '%s'" % fname) return os.path.join(dname, fname), orbit
def get_upcoming_passes(satellite_name, passes_begin_time, passes_period): """Returns potential satellite pass information for input satellite and Two Line Elements over temporal period""" kml = simplekml.Kml() observer = ephem.Observer() observer.lat = ground_station[0] observer.long = ground_station[1] observer.horizon = observer_horizon swathincrement = 1 # make a list to hold dicts of attributes for the upcoming pass information for the selected satellites schedule = [] observer.date = passes_begin_time print("---------------------------------------") for tle in tles: if tle[0] == satellite_name: # Update satellite names for use in filename satname = get_satellite_name(tle) sat = ephem.readtle(tle[0], tle[1], tle[2]) # Report currency of TLE twole = tlefile.read(tle[0], 'tles.txt') now = datetime.utcnow() timesinceepoch = now - twole.epoch.astype(datetime) print("TLE EPOCH:", twole.epoch.astype(datetime)) print("TLE age:", timesinceepoch) print("---------------------------------------") # While lostime of next pass is less than or equal to pass_begin_time + period do something lostime = start # passes_begin_time + passes_period while lostime <= (passes_begin_time + timedelta(minutes=passes_period)): oi = float(str.split(tle[2], ' ')[3]) orb = Orbital(tle[0], "tles.txt", tle[1], tle[2]) rt, ra, tt, ta, st, sa = observer.next_pass(sat) # Confirm that observer details have been computed i.e. are not 'Null' if rt is None: print(rt + "is none") logging.info( "Rise time of satellite not calculated - pass currently under way" ) observer.date = (lostime + timedelta(minutes=90)) return () sat.compute(rt) aos_lat = sat.sublat.real * (180 / math.pi) sat.compute(st) los_lat = sat.sublat.real * (180 / math.pi) # Determine if pass descending or ascending oi, node = get_orbit_node(aos_lat, los_lat, oi) aostime = datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S") loctime = local_time(aostime, 'Australia/Sydney') minutesaway = ((aostime - start).seconds / 60.0) + ( (aostime - start).days * 1440.0) orad = orb.get_lonlatalt(to_datetime(rt))[2] orbitnumber = orb.get_orbit_number( to_datetime(rt)) + orbitoffset # Get code version for provenance - TODO embed this in HTML try: repo = git.Repo(os.getcwd()) tag = repo.tags[ len(repo.tags) - 1].tag.tag # TODO work out if git repo, if not skip TRY except: tag = '0.0.0' print("code tag = ", tag) print("------------------------------------------") print("Satellite = ", satname) print("Orbit = ", orbitnumber) print("Minutes to horizon = ", minutesaway) print("AOStime local = ", loctime) print("AOStime UTC = ", to_datetime(rt)) print("LOStime UTC = ", to_datetime(st)) print("Transit time UTC = ", to_datetime(tt)) SWATH_FILENAME = os.path.join( output_path, satname + "." + str(orbitnumber) + "." + ground_station_name + ".orbit_swath.geojson") ORBIT_FILENAME = os.path.join( output_path, satname + "." + str(orbitnumber) + "." + ground_station_name + ".orbit_track.geojson") # Step from AOS to LOS by configuration timestep interval deltatime = to_datetime(rt) geoeastpoint = [] geowestpoint = [] geotrack = [] # TODO - 1/10 steps out to east and west limbs of pass from track startpoint = True # TODO - confirm nextpass method works when satellite within horizon subsatlat1 = None while deltatime < to_datetime(st): #if subsatlat1 is None: # subsatlat1 = sat.sublat.real * (180 / math.pi) # subsatlon1 = sat.sublong.real * (180 / math.pi) # print("got to here") sat.compute(deltatime) subsatlat = sat.sublat.real * (180 / math.pi) subsatlon = sat.sublong.real * (180 / math.pi) orbaltitude = orb.get_lonlatalt(to_datetime(rt))[2] * 1000 geotrack.append({ 'lat2': subsatlat, 'lon2': subsatlon, 'alt2': orbaltitude, 'time': str(deltatime) }) # Original heading calculation #effectiveheading = get_effective_heading(sat, oi, subsatlat, # subsatlon, orad, sat._n) # TODO Alternate simple heading subsatlat1, subsatlon1 = get_subsat_oneincrement( sat, deltatime, timestep) effectiveheading = Geodesic.WGS84.Inverse( subsatlat1, subsatlon1, subsatlat, subsatlon)['azi1'] eastaz = effectiveheading + 90 westaz = effectiveheading + 270 # 1/10 swath steps out to east and west limbs of pass from track start and end # <-- 1| 2 --> reverse # | ................. | # V . . . V reverse # . . . # ................. # <-- 3| 4 --> # (reverse 3 append to 1) append (append 4 to reversed 2) incrementtoswath = swathincrement if startpoint is True: # Step from sub satellite point to limb of swath with increasing step size while math.pow(incrementtoswath, 5) < swath: geoeastpointdict = Geodesic.WGS84.Direct( subsatlat, subsatlon, eastaz, math.pow(incrementtoswath, 5)) geoeastpointdict['time'] = str(deltatime) geoeastpoint.append(geoeastpointdict) geowestpointdict = Geodesic.WGS84.Direct( subsatlat, subsatlon, westaz, math.pow(incrementtoswath, 5)) geowestpointdict['time'] = str(deltatime) geowestpoint.append(geowestpointdict) incrementtoswath = incrementtoswath + 1 startpoint = False # Trace the eastern limb of the swath geoeastpointdict = Geodesic.WGS84.Direct( subsatlat, subsatlon, eastaz, swath) geoeastpointdict['time'] = str(deltatime) geoeastpoint.append(geoeastpointdict) # Trace the western limb of the swath geowestpointdict = Geodesic.WGS84.Direct( subsatlat, subsatlon, westaz, swath) geowestpointdict['time'] = str(deltatime) geowestpoint.append(geowestpointdict) deltatime = deltatime + timestep time.sleep(0.01) # When the end of the track is reached # Step from sub satellite point to limb of swath with increasing step size geoloseastpoint = [] geoloswestpoint = [] incrementtoswath = swathincrement while math.pow(incrementtoswath, 5) < swath: geodesiceastazdict = Geodesic.WGS84.Direct( subsatlat, subsatlon, eastaz, math.pow(incrementtoswath, 5)) geodesiceastazdict['time'] = str(deltatime) geoloseastpoint.append(geodesiceastazdict) geodesicwestazdict = Geodesic.WGS84.Direct( subsatlat, subsatlon, westaz, math.pow(incrementtoswath, 5)) geodesicwestazdict['time'] = str(deltatime) geoloswestpoint.append(geodesicwestazdict) incrementtoswath = incrementtoswath + 1 # Append reversed geoloswestpoint to geoloseastpoint reversedwest = [] for x in reversed(geoloswestpoint): reversedwest.append(x) for x in geoloseastpoint: reversedwest.append(x) for x in reversedwest: geowestpoint.append(x) polypoints = [] for x in geowestpoint: polypoints.append({ 'lat2': x['lat2'], 'lon2': x['lon2'], 'time': x['time'] }) for x in reversed(geoeastpoint): polypoints.append({ 'lat2': x['lat2'], 'lon2': x['lon2'], 'time': x['time'] }) if len(polypoints) > 0: polypoints.append({ 'lat2': geowestpoint[0]['lat2'], 'lon2': geowestpoint[0]['lon2'], 'time': geowestpoint[0]['time'] }) # TODO add local solar time for AOSTime Lat Lon attributes = { 'Satellite name': satname, 'Sensor code': sensor, 'Orbit height': orad, 'Orbit': orbitnumber, #'Current time': str(now), 'Minutes to horizon': minutesaway, 'Local time': str(loctime), 'AOS time': str(rt), 'LOS time': str(st), 'Transit time': str(tt), 'Node': node, 'SWATH_FILENAME': (satname + "." + str(orbitnumber) + "." + ground_station_name + ".orbit_swath.geojson"), 'Orbit filename': ORBIT_FILENAME, 'Orbit line': geotrack, 'Swath filename': SWATH_FILENAME, 'Swath polygon': polypoints } # Append the attributes to the list of acquisitions for the acquisition period #print('ATTRIBUTES:', attributes) #print('SCHEDULE:', schedule) if not any(d['SWATH_FILENAME'] == attributes['SWATH_FILENAME'] for d in schedule): #if not attributes in schedule: # if not any((x['Satellite name'] == satname and x['Orbit'] == orbitnumber) for x in schedule): if imagingnode == 'both' or imagingnode == attributes[ 'Node']: schedule.append(attributes) # Create swath footprint ogr output get_vector_file(attributes, polypoints, 'polygon', SWATH_FILENAME, 'GeoJSON') get_vector_file(attributes, geotrack, 'line', ORBIT_FILENAME, 'GeoJSON') add_layer_to_map( SWATH_FILENAME, satname + "." + str(orbitnumber) + ".swath", 'blue') add_layer_to_map( ORBIT_FILENAME, satname + "." + str(orbitnumber) + ".orbit", 'red') # Create a temporal KML pol = kml.newpolygon(name=satname + '_' + str(orbitnumber), description=SWATH_FILENAME) kml_polypoints = [] for i in polypoints: kml_polypoints.append((i['lon2'], i['lat2'])) rt_kml = datetime.strptime(str(rt), "%Y/%m/%d %H:%M:%S") st_kml = datetime.strptime(str(st), "%Y/%m/%d %H:%M:%S") pol.outerboundaryis = kml_polypoints pol.style.linestyle.color = simplekml.Color.green pol.style.linestyle.width = 5 pol.style.polystyle.color = simplekml.Color.changealphaint( 100, simplekml.Color.green) pol.timespan.begin = rt_kml.strftime( "%Y-%m-%dT%H:%M:%SZ") pol.timespan.end = st_kml.strftime( "%Y-%m-%dT%H:%M:%SZ") observer.date = (lostime + timedelta(minutes=90)) lostime = (datetime.strptime(str(observer.date), "%Y/%m/%d %H:%M:%S")) kml.save( os.path.join(output_path, satname + "." + ground_station_name + ".kml")) ## plot folium map folium.LayerControl().add_to(satellite_map) foliumhtml = os.path.join( output_path, satname + "." + ground_station_name + ".map.html") satellite_map.save(foliumhtml) folium_timespan_geojson_html(schedule, satname) # render the html schedule and write to file attributeshtml = [] for acquisition in schedule: attributeshtml.append('<td>' + acquisition['Satellite name'] + '</td>'\ '<td><a href="' + str(os.path.relpath(acquisition['Swath filename'],os.path.dirname(foliumhtml)))+ '">' + str(acquisition['Sensor code']) + '</a></td>'\ '<td><a href="' + str(os.path.relpath(acquisition['Orbit filename'],os.path.dirname(foliumhtml))) + '">' + str(acquisition['Orbit']) + '</a></td>'\ '<td>' + str(acquisition['Node']) + '</td>'\ '<td>' + str(acquisition['AOS time']) + '</td>'\ '<td>' + str(acquisition['LOS time']) + '</td>') satelliteslist = [] for x in satellites: schedule_url = get_satellite_name( [x]) + "." + ground_station_name + ".schedule.html" satelliteslist.append([x, schedule_url]) satelliteslist.append(',') renderedoutput = template.render(content=attributeshtml, foliumhtml=os.path.relpath( foliumhtml, output_path), satelliteslist=satelliteslist) with open( os.path.join( output_path, satname + "." + ground_station_name + ".schedule.html"), "w") as fh: fh.write(renderedoutput) return ()
# $ sudo apt_get install python_pyorbital # from pyorbital import tlefile from pyorbital.orbital import Orbital from datetime import datetime # There are two ways we can track orbital elements using PyOrbital # First we will use the TLE files created using tle_web_scraper.py # Dont forget to change the file path to the actual location of the saved TLE files tle = tlefile.read('NOAA 20 [+]', '/path/to/tle/files/noaa_tle_file.txt') print tle # The second method uses current TLEs from the internet, which we do not need to download orb = Orbital( "NOAA 20" ) # For additional satellites, subsitute "NOAA 20" with other NOAA satellites (numbered 1 - 20) now = datetime.utcnow() # Get normalized position and velocity of the satellite current_position = orb.get_position(now) print(current_position) # Get the longitude, latitude and altitude of the satellite current_lonlatalt = orb.get_lonlatalt(now) print(current_lonlatalt) # Get the orbit number of the satellite current_orbit_number = orb.get_orbit_number(now, tbus_style=False) print("Current orbit:", current_orbit_number)
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 ()
utc_time = [datetime.strptime(date_gpm[i]+time_gpm[i][0:4],"%Y%m%d%H%M") for i in range(len(date_gpm))] #Now lets extract the orbit number orbits = [] write_orbit_no = "orbit_no" for i in range(len(utc_time)): orbit_no = rscat.get_orbit_number(utc_time[i]) print(orbit_no) orbits.append(orbit_no) #Write to a text file write_orbit_no += f"{orbit_no}\n" w = open("orbit_no.txt", 'w') w.write(write_orbit_no) w.close()
def replace_orbitno(filename): stamp = get_npp_stamp(filename) # Correct h5 attributes no_date = datetime(1958, 1, 1) epsilon_time = timedelta(days=2) import h5py def _get_a_good_time(name, obj): del name if isinstance(obj, h5py.Dataset): date_key, time_key = ('Ending_Date', 'Ending_Time') if date_key in obj.attrs.keys(): if not good_time_val_[0]: time_val = datetime.strptime( obj.attrs[date_key][0][0] + obj.attrs[time_key][0][0], '%Y%m%d%H%M%S.%fZ') if abs(time_val - no_date) > epsilon_time: good_time_val_[0] = time_val def _check_orbitno(name, obj): del name if isinstance(obj, h5py.Dataset): for date_key, time_key, orbit_key in ( ('AggregateBeginningDate', 'AggregateBeginningTime', 'AggregateBeginningOrbitNumber'), ('AggregateEndingDate', 'AggregateEndingTime', 'AggregateEndingOrbitNumber'), ('Beginning_Date', 'Beginning_Time', 'N_Beginning_Orbit_Number')): if orbit_key in obj.attrs.keys(): time_val = datetime.strptime( obj.attrs[date_key][0][0] + obj.attrs[time_key][0][0], '%Y%m%d%H%M%S.%fZ') # Check for no date (1958) problem: if abs(time_val - no_date) < epsilon_time: LOG.info("Start time wrong: %s", time_val.strftime('%Y%m%d')) LOG.info( "Will use the first good end time encounter " + "in file to determine orbit number") time_val = good_time_val_[0] orbit_val = orbital_.get_orbit_number( time_val, tbus_style=TBUS_STYLE) obj.attrs.modify(orbit_key, [[orbit_val]]) counter_[0] += 1 # Correct h5 attributes orbital_ = Orbital(TLE_SATNAME[stamp.platform]) orbit = orbital_.get_orbit_number(stamp.start_time, tbus_style=TBUS_STYLE) LOG.info("Replacing orbit number %05d with %05d", stamp.orbit_number, orbit) fp = h5py.File(filename, 'r+') try: good_time_val_ = [None] fp.visititems(_get_a_good_time) counter_ = [0] fp.visititems(_check_orbitno) if counter_[0] == 0: raise IOError( "Failed replacing orbit number in hdf5 attributes '%s'" % filename) LOG.info("Replaced orbit number in %d attributes", counter_[0]) finally: fp.close() # Correct filename dname, fname = os.path.split(filename) fname, n = _re_replace_orbitno.subn('_b%05d' % orbit, fname) if n != 1: raise IOError("Failed replacing orbit number in filename '%s'" % fname) return os.path.join(dname, fname), orbit
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 ()