Merge pull request #99 from danielrichman/master

Catch all the errors
pull/100/head
Adam Greig 2012-12-27 14:16:21 -08:00
commit 0d32e97470
11 zmienionych plików z 132 dodań i 57 usunięć

Wyświetl plik

@ -250,8 +250,8 @@ int main(int argc, const char *argv[]) {
scenario_launch_time = mktime(&timeval);
if(scenario_launch_time <= 0) {
fprintf(stderr, "WARN: Launch time in scenario is invalid, reverting to "
"default timestamp.\n");
fprintf(stderr, "ERROR: Launch time in scenario is invalid\n");
exit(1);
} else {
initial_timestamp = scenario_launch_time;
}

Wyświetl plik

@ -75,13 +75,11 @@ _advance_one_timestep(wind_file_cache_t* cache,
if(!altitude_model_get_altitude(state->alt_model,
timestamp - initial_timestamp, &state->alt))
return 0;
return 0; // alt < 0; finished
if(!get_wind(cache, state->lat, state->lng, state->alt, timestamp,
&wind_v, &wind_u, &wind_var)) {
fprintf(stderr, "ERROR: error getting wind data\n");
return 0;
}
&wind_v, &wind_u, &wind_var))
return -1; // error
_get_frame(state->lat, state->lng, state->alt, &ddlat, &ddlng);
@ -108,7 +106,7 @@ _advance_one_timestep(wind_file_cache_t* cache,
state->loglik += (double)(u_lik + v_lik);
}
return 1;
return 1; // OK, and continue
}
static int _state_compare_rev(const void* a, const void *b)
@ -145,10 +143,18 @@ int run_model(wind_file_cache_t* cache, altitude_model_t* alt_model,
long int timestamp = initial_timestamp;
int log_counter = 0; // only write position to output files every LOG_DECIMATE timesteps
while(_advance_one_timestep(cache, TIMESTEP, timestamp, initial_timestamp,
n_states, states, rmswinderror))
int r, return_code = 1;
while(1)
{
r = _advance_one_timestep(cache, TIMESTEP, timestamp, initial_timestamp,
n_states, states, rmswinderror);
if (r == -1) // error getting wind. Save prediction, but emit error messages
return_code = 0;
if (r != 1) // 1 = continue
break;
// Sort the array of models in order of log likelihood.
qsort(states, n_states, sizeof(model_state_t), _state_compare_rev);
@ -173,12 +179,12 @@ int run_model(wind_file_cache_t* cache, altitude_model_t* alt_model,
free(states);
return 1;
return return_code;
}
int get_wind(wind_file_cache_t* cache, float lat, float lng, float alt, long int timestamp,
float* wind_v, float* wind_u, float *wind_var) {
int i;
int i, s;
float lambda, wu_l, wv_l, wu_h, wv_h;
float wuvar_l, wvvar_l, wuvar_h, wvvar_h;
wind_file_cache_entry_t* found_entries[] = { NULL, NULL };
@ -190,7 +196,7 @@ int get_wind(wind_file_cache_t* cache, float lat, float lng, float alt, long int
&(found_entries[0]), &(found_entries[1]));
if(!found_entries[0] || !found_entries[1]) {
fprintf(stderr, "ERROR: Could not locate appropriate wind data tile for time.\n");
fprintf(stderr, "ERROR: Do not have wind data for this (lat, lon, alt, time).\n");
return 0;
}
@ -211,10 +217,10 @@ int get_wind(wind_file_cache_t* cache, float lat, float lng, float alt, long int
earlier_ts = wind_file_cache_entry_timestamp(found_entries[0]);
later_ts = wind_file_cache_entry_timestamp(found_entries[1]);
if(earlier_ts == later_ts)
if(earlier_ts > timestamp || later_ts < timestamp)
{
fprintf(stderr, "WARN: Do not have two data files around current time. "
"Expect the results to be wrong!\n");
fprintf(stderr, "Error: found_entries have bad times.\n");
return 0;
}
if(earlier_ts != later_ts)
@ -223,8 +229,10 @@ int get_wind(wind_file_cache_t* cache, float lat, float lng, float alt, long int
else
lambda = 0.5f;
wind_file_get_wind(found_files[0], lat, lng, alt, &wu_l, &wv_l, &wuvar_l, &wvvar_l);
wind_file_get_wind(found_files[1], lat, lng, alt, &wu_h, &wv_h, &wuvar_h, &wvvar_h);
s = wind_file_get_wind(found_files[0], lat, lng, alt, &wu_l, &wv_l, &wuvar_l, &wvvar_l);
if (s == 0) return 0; // hard error
s = wind_file_get_wind(found_files[1], lat, lng, alt, &wu_h, &wv_h, &wuvar_h, &wvvar_h);
if (s == 0) return 0;
*wind_u = lambda * wu_h + (1.f-lambda) * wu_l;
*wind_v = lambda * wv_h + (1.f-lambda) * wv_l;

Wyświetl plik

@ -173,11 +173,10 @@ _parse_values_line(const char* line, unsigned int n_values, float* values)
while(1 == sscanf(record, "%f", &value)) {
if(record_idx >= n_values)
{
if(verbosity > 0)
fprintf(stderr, "WARN: Read too many values for axis "
"(%i, expected %i). "
"Ignoring them.\n",
record_idx, n_values);
fprintf(stderr, "ERROR: Read too many values for axis "
"(%i, expected %i).\n",
record_idx, n_values);
return 0;
} else {
values[record_idx] = value;
}
@ -473,7 +472,7 @@ _bilinear_interpolate(float ll, float lr, float rl, float rr, float lambda1, flo
return _lerp(il,ir,lambda2);
}
void
int
wind_file_get_wind(wind_file_t* file, float lat, float lon, float height,
float* windu, float *windv, float *uvar, float *vvar)
{
@ -521,9 +520,8 @@ wind_file_get_wind(wind_file_t* file, float lat, float lon, float height,
if(!_wind_file_axis_find_value(file->axes[1], lat,
_float_is_left_of, &left_lat_idx, &right_lat_idx))
{
if(verbosity > 0)
fprintf(stderr, "WARN: Latitude %f is not covered by file.\n", lat);
return;
fprintf(stderr, "ERROR: Latitude %f is not covered by file.\n", lat);
return 0;
}
left_lat = file->axes[1]->values[left_lat_idx];
right_lat = file->axes[1]->values[right_lat_idx];
@ -532,9 +530,8 @@ wind_file_get_wind(wind_file_t* file, float lat, float lon, float height,
if(!_wind_file_axis_find_value(file->axes[2], lon,
_longitude_is_left_of, &left_lon_idx, &right_lon_idx))
{
if(verbosity > 0)
fprintf(stderr, "WARN: Longitude %f is not covered by file.\n", lon);
return;
fprintf(stderr, "ERROR: Longitude %f is not covered by file.\n", lon);
return 0;
}
left_lon = file->axes[2]->values[left_lon_idx];
right_lon = file->axes[2]->values[right_lon_idx];
@ -665,7 +662,7 @@ wind_file_get_wind(wind_file_t* file, float lat, float lon, float height,
{
fprintf(stderr, "ERROR: Moved to a totally stupid height (%f). "
"Giving up!\n", height);
return;
return 0;
}
if(verbosity > 1)
@ -780,6 +777,8 @@ wind_file_get_wind(wind_file_t* file, float lat, float lon, float height,
*uvar = usqmean - umean * umean;
*vvar = vsqmean - vmean * vmean;
}
return 1;
}
// Data for God's own editor.

Wyświetl plik

@ -29,7 +29,7 @@ wind_file_t *wind_file_new (const char *file);
// Free resources associated with 'file'.
void wind_file_free (wind_file_t *file);
void wind_file_get_wind (wind_file_t *file,
int wind_file_get_wind (wind_file_t *file,
float lat,
float lon,
float height,

Wyświetl plik

@ -310,12 +310,6 @@ wind_file_cache_find_entry(wind_file_cache_t *cache,
}
}
}
if(!*earlier) { *earlier = *later; }
if(!*later) { *later = *earlier; }
// If all else fails, just choose the first entry.
if(!*earlier) { *earlier = *later = cache->entries[0]; }
}
const char*

Wyświetl plik

@ -53,6 +53,8 @@ progress = {
'gfs_timestamp': '',
'pred_running': False,
'pred_complete': False,
'warnings': False,
'pred_output': [],
'error': '',
}
@ -279,12 +281,45 @@ def main():
else:
alarm_flags = []
subprocess.call([pred_binary, '-i' + gfs_dir, '-v', '-o'+uuid_path+'flight_path.csv', uuid_path+'scenario.ini'] + alarm_flags)
command = [pred_binary, '-i' + gfs_dir, '-v', '-o'+uuid_path+'flight_path.csv', uuid_path+'scenario.ini'] + alarm_flags
pred_process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
pred_output = []
while True:
line = pred_process.stdout.readline()
if line == '':
break
# pass through
sys.stdout.write(line)
if "ERROR: Do not have wind data" in line:
pred_output = ["One of the latitude, longitude or time deltas ({0}, {1}, {2}) was too small."
.format(options.latdelta, options.londelta, options.future),
"Please adjust the settings accordingly and re-run your prediction.",
""] + pred_output
if ("WARN" in line or "ERROR" in line) and len(pred_output) < 10:
pred_output.append(line.strip())
exit_code = pred_process.wait()
shutil.rmtree(gfs_dir)
update_progress(pred_running=False, pred_complete=True)
statsd.increment('success')
if exit_code == 1:
# Hard error from the predictor. Tell the javascript it completed, so that it will show the trace,
# but pop up a 'warnings' window with the error messages
update_progress(pred_running=False, pred_complete=True, warnings=True, pred_output=pred_output)
statsd.increment('success_serious_warnings')
elif pred_output:
# Soft error (altitude too low error, typically): pred_output being set forces the debug
# window open with the messages in
update_progress(pred_running=False, pred_complete=True, pred_output=pred_output)
statsd.increment('success_minor_warnings')
else:
assert exit_code == 0
update_progress(pred_running=False, pred_complete=True)
statsd.increment('success')
def purge_cache():
"""

Wyświetl plik

@ -178,7 +178,7 @@ a { text-decoration: underline; color: #333; cursor: pointer; }
width: 400px;
padding: 5px 5px 0px 5px;
bottom: 0; right: 0;
max-height: 400px;
max-height: 500px;
}
#launch-card {

Wyświetl plik

@ -33,6 +33,7 @@ function createModel($post_array) {
$pred_model['delta_lat'] = (int)$post_array['delta_lat'];
$pred_model['delta_lon'] = (int)$post_array['delta_lon'];
$pred_model['delta_time'] = (int)$post_array['delta_time'];
$pred_model['wind_error'] = 0;
@ -89,6 +90,12 @@ function verifyModel( $pred_model, $software_available ) {
$return_array['msg'] = "The latitude or longitude deltas
were outside the allowed range on this server";
}
} else if ( $idx == "delta_time" ) {
if ( $value < 5 || $value > 24) {
$return_array['valid'] = false;
$return_array['msg'] = "The time delta was
outside the allowed range on this server";
}
} else if ( $idx == "asc" || $idx == "des" ) {
if ( $value <= 0 ) {
$return_array['valid'] = false;
@ -138,7 +145,7 @@ function runPred($pred_model) {
$log = PREDS_PATH . $pred_model['uuid'] . "/" . LOG_FILE;
$sh = ROOT . "/predict.py --cd=" . ROOT . " --fork --alarm --redirect=predict/$log -v --latdelta="
.$pred_model['delta_lat']." --londelta=".$pred_model['delta_lon']
." -p1 -f5 -t ".$pred_model['timestamp']
." -p1 -f".$pred_model['delta_time']." -t ".$pred_model['timestamp']
." --lat=".$predictor_lat." --lon=".$predictor_lon." " . $use_hd
. $pred_model['uuid'];
if (defined("PYTHON"))
@ -178,6 +185,7 @@ function makeINI($pred_model) { // makes an ini file
$w_string .= $pred_model['min'] . "\n";
// add our predictor stuff
$w_string .= "[predictor]\nlat-delta = " . $pred_model['delta_lat'] . "\n";
$w_string .= "time-delta = " . $pred_model['delta_time'] . "\n";
$w_string .= "lon-delta = " . $pred_model['delta_lon'] . "\nsoftware = ";
$w_string .= $pred_model['software'] . "\n";

Wyświetl plik

@ -471,14 +471,23 @@ google.load("jqueryui", "1.8.1");
</select>
</td>
</tr>
<tr><td>Display UK NOTAMS &amp; Airspace: </td>
<tr><td>Time Delta:</td>
<td>
<select id="delta_time" name="delta_time">
<option value="5">~5 hour prediction</option>
<option value="10">~10 hour prediction</option>
<option value="24">~24 hour prediction</option>
</select>
</td>
</tr>
<!-- <tr><td>Display UK NOTAMS &amp; Airspace: </td>
<td>
<input id="notam-display" type="checkbox" name="notams" value="notams" />
<a id="notam-settings-show" class="tipsyLink"
title="Advanced NOTAM &amp; Airspace Settings">
Advanced</a>
</td>
</tr>
</tr> -->
<tr>
<td></td>
<td><input type="submit" name="submit" id="run_pred_btn" value="Run Prediction">

Wyświetl plik

@ -43,6 +43,7 @@ function throwError(data) {
// Reset the GUI to a onLoad state ready for a new prediction to be shown
function resetGUI() {
$("#status_message").fadeOut(500);
$("#error_window").fadeOut(500);
// now clear the status window
$("#prediction_status").html("");
$("#prediction_progress").progressbar("options", "value", 0);

Wyświetl plik

@ -57,12 +57,11 @@ function displayOld() {
appendDebug("The prediction was not completed"
+ " correctly, quitting");
} else {
appendDebug("JSON said the prediction completed "
+ "without errors");
appendDebug("JSON said the prediction completed");
processCompletedPrediction(progress);
writePredictionInfo(current_uuid,
progress['run_time'],
progress['gfs_timestamp']);
getCSV(current_uuid);
}
});
}
@ -74,6 +73,8 @@ function displayOld() {
function predSub() {
appendDebug(null, 1); // clear debug window
appendDebug("Sending data to server...");
// Gets in the way of #status_message
$("#error_window").fadeOut(250);
// Initialise progress bar
$("#prediction_progress").progressbar({ value: 0 });
$("#prediction_status").html("Sending data to server...");
@ -109,6 +110,7 @@ function populateFormByUUID(pred_uuid) {
$("#software").val(data.software);
$("#delta_lat").val(data['lat-delta']);
$("#delta_lon").val(data['lon-delta']);
$("#delta_time").val(data['time-delta']);
// now sort the map out
SetSiteOther();
plotClick();
@ -214,6 +216,7 @@ function getCSV(pred_uuid) {
function getJSONProgress(pred_uuid) {
$.ajax({
url:"preds/"+pred_uuid+"/progress.json",
cache: false,
dataType:'json',
timeout: ajaxTimeout,
error: function(xhr, status, error) {
@ -245,6 +248,31 @@ function getJSONProgress(pred_uuid) {
});
}
function processCompletedPrediction(progress) {
// parse the data
getCSV(current_uuid);
appendDebug("Server gave a prediction run timestamp of "
+ progress['run_time']);
appendDebug("Server said it used the "
+ progress['gfs_timestamp'] + " GFS model");
var warnings = "<b>The prediction completed, but with warnings!<br>" +
"The prediction may be unreliable!</b><br><br>";
for (var i = 0; i < progress['pred_output'].length; i++) {
appendDebug("Pred output: " + progress['pred_output'][i]);
warnings += progress['pred_output'][i] + "<br>";
}
if (progress['pred_output'].length != 0)
toggleWindow("scenario_template", "showHideDebug", "Show Debug", "Hide Debug", "show");
if (progress['warnings'])
throwError(warnings);
writePredictionInfo(current_uuid, progress['run_time'],
progress['gfs_timestamp']);
}
// The contents of progress.json are given to this function to process
// If the prediction has completed, reset the GUI and display the new
// prediction; otherwise update the progress window
@ -266,14 +294,7 @@ function processProgress(progress) {
resetGUI();
// stop polling for JSON
clearInterval(ajaxEventHandle);
// parse the data
getCSV(current_uuid);
appendDebug("Server gave a prediction run timestamp of "
+ progress['run_time']);
appendDebug("Server said it used the "
+ progress['gfs_timestamp'] + " GFS model");
writePredictionInfo(current_uuid, progress['run_time'],
progress['gfs_timestamp']);
processCompletedPrediction(progress);
addHashLink("uuid="+current_uuid);
} else if ( progress['pred_running'] != true ) {
$("#prediction_status").html("Waiting for predictor to run...");