def initPredictor(): global predictor, predictor_thread, chasemapper_config, pred_settings try: from cusfpredict.predict import Predictor from cusfpredict.utils import gfs_model_age, available_gfs # Check if we have any GFS data _model_age = gfs_model_age(pred_settings['gfs_path']) if _model_age == "Unknown": logging.error("No GFS data in directory.") chasemapper_config['pred_model'] = "No GFS Data." flask_emit_event('predictor_model_update', {'model': "No GFS data."}) chasemapper_config['pred_enabled'] = False else: # Check model contains data to at least 4 hours into the future. (_model_start, _model_end) = available_gfs(pred_settings['gfs_path']) _model_now = datetime.utcnow() + timedelta(0, 60 * 60 * 4) if (_model_now < _model_start) or (_model_now > _model_end): # No suitable GFS data! logging.error("GFS Data in directory does not cover now!") chasemapper_config['pred_model'] = "Old GFS Data." flask_emit_event('predictor_model_update', {'model': "Old GFS data."}) chasemapper_config['pred_enabled'] = False else: chasemapper_config['pred_model'] = _model_age flask_emit_event('predictor_model_update', {'model': _model_age}) predictor = Predictor(bin_path=pred_settings['pred_binary'], gfs_path=pred_settings['gfs_path']) # Start up the predictor thread if it is not running. if predictor_thread == None: predictor_thread = Thread(target=predictorThread) predictor_thread.start() # Set the predictor to enabled, and update the clients. chasemapper_config['pred_enabled'] = True flask_emit_event('server_settings_update', chasemapper_config) except Exception as e: traceback.print_exc() logging.error("Loading predictor failed: " + str(e)) flask_emit_event('predictor_model_update', {'model': "Failed - Check Log."}) chasemapper_config['pred_model'] = "Failed - Check Log." print("Loading Predictor failed.") predictor = None
LAUNCH_TIME = datetime.datetime.utcnow( ) # Note that this time is interpreted as a UTC time LAUNCH_LAT = -34.9499 LAUNCH_LON = 138.5194 LAUNCH_ALT = 0.0 ASCENT_RATE = 5.0 DESCENT_RATE = 5.0 BURST_ALT = 30000.0 # Output file OUTPUT_KML = "prediction.kml" # Create the predictor object. pred = Predictor(bin_path=PRED_BINARY, gfs_path=GFS_PATH) # Run the prediction flight_path = pred.predict(launch_lat=LAUNCH_LAT, launch_lon=LAUNCH_LON, launch_alt=LAUNCH_ALT, ascent_rate=ASCENT_RATE, descent_rate=DESCENT_RATE, burst_alt=BURST_ALT, launch_time=LAUNCH_TIME) # Check the output makes sense if len(flight_path) == 1: print("No Wind Data available for this prediction scenario!") sys.exit(1)
def initPredictor(): global predictor, predictor_thread, chasemapper_config, pred_settings if chasemapper_config["offline_predictions"]: # Attempt to initialize an Offline Predictor instance try: from cusfpredict.predict import Predictor from cusfpredict.utils import gfs_model_age, available_gfs # Check if we have any GFS data _model_age = gfs_model_age(pred_settings["gfs_path"]) if _model_age == "Unknown": logging.error("No GFS data in directory.") chasemapper_config["pred_model"] = "No GFS Data." flask_emit_event("predictor_model_update", {"model": "No GFS data."}) chasemapper_config["offline_predictions"] = False else: # Check model contains data to at least 4 hours into the future. (_model_start, _model_end) = available_gfs(pred_settings["gfs_path"]) _model_now = datetime.utcnow() + timedelta(0, 60 * 60 * 4) if (_model_now < _model_start) or (_model_now > _model_end): # No suitable GFS data! logging.error("GFS Data in directory does not cover now!") chasemapper_config["pred_model"] = "Old GFS Data." flask_emit_event("predictor_model_update", {"model": "Old GFS data."}) chasemapper_config["offline_predictions"] = False else: chasemapper_config[ "pred_model"] = _model_age + " (Offline)" flask_emit_event("predictor_model_update", {"model": _model_age + " (Offline)"}) predictor = Predictor( bin_path=pred_settings["pred_binary"], gfs_path=pred_settings["gfs_path"], ) # Start up the predictor thread if it is not running. if predictor_thread == None: predictor_thread = Thread(target=predictorThread) predictor_thread.start() # Set the predictor to enabled, and update the clients. chasemapper_config["offline_predictions"] = True except Exception as e: traceback.print_exc() logging.error("Loading predictor failed: " + str(e)) flask_emit_event("predictor_model_update", {"model": "Failed - Check Log."}) chasemapper_config["pred_model"] = "Failed - Check Log." print("Loading Predictor failed.") predictor = None else: # No initialization required for the online predictor predictor = "Tawhiri" flask_emit_event("predictor_model_update", {"model": "Tawhiri"}) # Start up the predictor thread if it is not running. if predictor_thread == None: predictor_thread = Thread(target=predictorThread) predictor_thread.start() flask_emit_event("server_settings_update", chasemapper_config)