def runPrediction(self): """Run a new flight prediction based on current data and plot in Google Earth""" #Note this function is under (semi-permanent) construction... # It really needs to be fixed to handle live-tracking and prediction. print "Running Flight Prediction" #Read the current flight path from the log file logfile = self.tracks["balloon"]["log"] loggedposition = self.readlog(logfile) ##Experimental function to pull wind data out of current track. Needs work. #atmosphere, goingup = LocalPredict.getDataFromFlightPath(loggedposition) #atmosphere = sorted(atmosphere) #direction="down" #if goingup: #direction="up" #direction = "up" #atmosphere = LocalPredict.getData(datetime.datetime.now(),"PUC",timeout=20) #atmosphere = LocalPredict.parse_wind(atmosphere) ##Set the launchsite based on the first position in the track launchsite = eval(loggedposition[0].strip("\n")) #Which is out of order. launchsite = (launchsite[1], launchsite[0], launchsite[2]) #Factory made ascent, descent, and burst values. ascentrate = 1045 descentrate = 1763 burstaltitude = 98000 ##Track if using an adaptive atmosphere, disabled when such atmosphere is disabled. See above. #track = LocalPredict.makeTrack(atmosphere,launchsite,ascentrate,descentrate,burstaltitude,direction=direction) #earthdata = [] lastpoint = 0 direction = "up" #Step through the current data to find the highest point for position in loggedposition: alt = eval(position.strip("\n")) if alt[2] < lastpoint[2] and alt[2] > 10000: #If the current point is lower than altitude than the last point (and not on the ground) direction = "down" #Indicate that the balloon is in decent, and record the highest point lastpoint = eval(loggedposition[-1].strip("\n")) break else: lastpoint = alt #This will either be the highest altitude as the balloon decends, or the current altitude on ascent lastpoint = (lastpoint[1], lastpoint[0], lastpoint[2]) #Numerically determine the closest weather staton. wxstation = LocalPredict.getClosestStation(launchsite=launchsite) #Pull the wind data from NOAA. (Note: I need to enable local weather data storage) data = LocalPredict.getData(datetime.datetime.now(), wxstation, timeout=1) #Parse the data for atmospheric wind levels. atmosphere = LocalPredict.parse_wind(data) #Create a prediction track based on this wind data track = LocalPredict.makeTrack(atmosphere, launchsite, ascentrate, descentrate, burstaltitude, direction) for position in track: #Step through the track and switch the coordinates for use with Google Earth (frustrating) earthdata.append((position[1], position[0], position[2])) #Display the new track in Google Earth self.writetrack("prediction", append=False, coordlist=earthdata)
def runPrediction(self): """Run a new flight prediction based on current data and plot in Google Earth""" #Note this function is under (semi-permanent) construction... # It really needs to be fixed to handle live-tracking and prediction. print "Running Flight Prediction" #Read the current flight path from the log file logfile = self.tracks["balloon"]["log"] loggedposition = self.readlog(logfile) ##Experimental function to pull wind data out of current track. Needs work. #atmosphere, goingup = LocalPredict.getDataFromFlightPath(loggedposition) #atmosphere = sorted(atmosphere) #direction="down" #if goingup: #direction="up" #direction = "up" #atmosphere = LocalPredict.getData(datetime.datetime.now(),"PUC",timeout=20) #atmosphere = LocalPredict.parse_wind(atmosphere) ##Set the launchsite based on the first position in the track launchsite = eval(loggedposition[0].strip("\n")) #Which is out of order. launchsite = (launchsite[1],launchsite[0],launchsite[2]) #Factory made ascent, descent, and burst values. ascentrate = 1045 descentrate = 1763 burstaltitude = 98000 ##Track if using an adaptive atmosphere, disabled when such atmosphere is disabled. See above. #track = LocalPredict.makeTrack(atmosphere,launchsite,ascentrate,descentrate,burstaltitude,direction=direction) #earthdata = [] lastpoint = 0 direction = "up" #Step through the current data to find the highest point for position in loggedposition: alt = eval(position.strip("\n")) if alt[2] < lastpoint[2] and alt[2] > 10000: #If the current point is lower than altitude than the last point (and not on the ground) direction = "down" #Indicate that the balloon is in decent, and record the highest point lastpoint = eval(loggedposition[-1].strip("\n")) break else: lastpoint = alt #This will either be the highest altitude as the balloon decends, or the current altitude on ascent lastpoint = (lastpoint[1],lastpoint[0],lastpoint[2]) #Numerically determine the closest weather staton. wxstation = LocalPredict.getClosestStation(launchsite=launchsite) #Pull the wind data from NOAA. (Note: I need to enable local weather data storage) data = LocalPredict.getData(datetime.datetime.now(),wxstation,timeout=1) #Parse the data for atmospheric wind levels. atmosphere = LocalPredict.parse_wind(data) #Create a prediction track based on this wind data track = LocalPredict.makeTrack(atmosphere,launchsite,ascentrate,descentrate,burstaltitude,direction) for position in track: #Step through the track and switch the coordinates for use with Google Earth (frustrating) earthdata.append((position[1],position[0],position[2])) #Display the new track in Google Earth self.writetrack("prediction",append=False,coordlist=earthdata)
def get(self): keys = self.request.arguments() values = (self.request.get(k, '') for k in keys) query_args = dict(zip(keys, values)) render={} render['inputs'] = jspathforargs(**query_args) if self.request.get('go', '') == '': path = os.path.join(os.path.dirname(__file__), 'home.html') else: path = os.path.join(os.path.dirname(__file__), 'map.html') try: uptrack, downtrack = LocalPredict.webPredict(query_args) formattrack = lambda points: "[%s]" % ",".join("[%s,%s]" % (lat, lon) for lat, lon, alt in points) render['uptrack'] = formattrack(uptrack) render['downtrack'] = formattrack(downtrack) render['error'] = False except LocalPredict.PredictionException as err: path = os.path.join(os.path.dirname(__file__), 'error.html') render['error'] = {'message':err.args[0], 'type':'prediction error'} except Exception as err: path = os.path.join(os.path.dirname(__file__), 'error.html') render['error'] = {'message':err.args, 'type':'other'} self.response.out.write(template.render(path, render))
def get(self): keys = self.request.arguments() values = (self.request.get(k, "") for k in keys) query_args = dict(zip(keys, values)) render = {} render["inputs"] = jspathforargs(**query_args) if self.request.get("go", "") == "": path = os.path.join(os.path.dirname(__file__), "home.html") else: path = os.path.join(os.path.dirname(__file__), "map.html") try: uptrack, downtrack = LocalPredict.webPredict(query_args) formattrack = lambda points: "[%s]" % ",".join("[%s,%s]" % (lat, lon) for lat, lon, alt in points) render["uptrack"] = formattrack(uptrack) render["downtrack"] = formattrack(downtrack) render["error"] = False except LocalPredict.PredictionException as err: path = os.path.join(os.path.dirname(__file__), "error.html") render["error"] = {"message": err.args[0], "type": "prediction error"} except Exception as err: path = os.path.join(os.path.dirname(__file__), "error.html") render["error"] = {"message": err.args, "type": "other"} self.response.out.write(template.render(path, render))