Skip to content

Commit

Permalink
Add error handling and other fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Sep 1, 2016
1 parent c11f805 commit 50d4258
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 12 deletions.
16 changes: 10 additions & 6 deletions pmfinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from astropy import wcs
from astropy.io import fits

from flask import abort
from flask import Flask
from flask import render_template
from flask import request
Expand Down Expand Up @@ -135,9 +136,12 @@ def input_display():
@app.route('/generate')
def generate_chart():
print(request.args)
chart = generate_finding_chart(request.args['outepoch'], request.args['ra'], request.args['dec'], request.args['epoch'], request.args['rapm'], request.args['decpm'], request.args['size'], request.args['size'], request.args['survey'])
output = io.BytesIO()
chart.save(output, format='PNG')
output.seek(0)

return send_file(output, attachment_filename='chart.png', mimetype='image/png')
try:
chart = generate_finding_chart(request.args['outepoch'], request.args['ra'], request.args['dec'], request.args['epoch'], request.args['rapm'], request.args['decpm'], request.args['size'], request.args['size'], request.args['survey'])
output = io.BytesIO()
chart.save(output, format='PNG')
output.seek(0)

return send_file(output, attachment_filename='chart.png', mimetype='image/png')
except:
abort(404)
2 changes: 2 additions & 0 deletions static/FileSaver.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added static/failed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions static/jszip.min.js

Large diffs are not rendered by default.

Binary file added static/loading.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 33 additions & 6 deletions templates/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Generates finding charts from the digitized sky survey, accounting for proper motion of the target.">
<meta name="author" content="Paul Chote">
<meta charset="utf-8">
<title>Finding Chart Generator</title>
<link href="http://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic" rel="stylesheet">
Expand All @@ -17,8 +19,6 @@
.thumb-label { font-size: 10px; margin: 3px 0; color: #fff; }
.popover { max-width: none; }
#download { margin-right: 10px; }
#generate { color: #51586a; }
#generate:hover { color: #cfd2da;}
</style>
</head>
<body>
Expand Down Expand Up @@ -127,7 +127,7 @@ <h1>Finding chart generator</h1>
$('#thumbrow').append(thumbContainer);

var img = new Image();
img.addEventListener("load", function() {
img.addEventListener('load', function() {
chartContext.drawImage(img, chartImageX, chartImageY);

thumbImage.removeClass('thumb-loading');
Expand All @@ -136,7 +136,16 @@ <h1>Finding chart generator</h1>
thumbImage.height(128);
}, false);

// TODO: Handle generation failure
img.addEventListener('error', function() {
chartContext.fillStyle = '#fff';
chartContext.fillRect(chartImageX+2, chartImageY+2, 508, 508);
chartContext.font = '28px serif';
chartContext.textAlign = 'center'
chartContext.fillStyle = '#000';
chartContext.fillText('Source Image Unavailable', chartWidth / 2, chartImageY + 256);
thumbImage.prop('src', '{{ url_for('static', filename='failed.png') }}');
}, false);
img.src = url;
}
Expand Down Expand Up @@ -169,7 +178,25 @@ <h1>Finding chart generator</h1>
var type = $("input[name='type']:checked").val();
var coords = $("textarea[name='coords']").val().split('\n');

// TODO: Validate size and epoch
if (parseFloat(size) != size) {
$('#error').html('Unable to parse "' + size + '" as a number');
return;
}

if (size <= 1 || size > 100) {
$('#error').html('Field size must be between 1 and 100 arcmin');
return;
}

if (parseFloat(outepoch) != outepoch) {
$('#error').html('Unable to parse "' + outepoch + '" as a number');
return;
}

if (outepoch <= 1900 || outepoch > 2100) {
$('#error').html('Observing epoch must be between 1900 and 2100');
return;
}

$('#error').html('');
$('#thumbrow').empty();
Expand Down Expand Up @@ -246,7 +273,7 @@ <h1>Finding chart generator</h1>
if (targets.length == 0)
return;

$('#generate').removeClass('btn-primary').text('Regenerate');
$('#generate').removeClass('btn-primary').addClass('btn-default').text('Regenerate');
$('#download').show();
for (i in targets)
generateChart(targets[i]);
Expand Down

0 comments on commit 50d4258

Please sign in to comment.