Skip to content

Commit

Permalink
Add support for space-separated sexagesimal.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote committed Nov 27, 2018
1 parent a932654 commit ca498a3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
14 changes: 8 additions & 6 deletions findingchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

# pylint: disable=invalid-name

import argparse
import base64
import datetime
import io
Expand All @@ -23,6 +22,7 @@
import numpy
import os
import sys
import traceback
from PIL import Image, ImageOps
from astropy import wcs
from astropy.io import fits
Expand Down Expand Up @@ -115,12 +115,13 @@ def offset_proper_motion(ra_degrees, dec_degrees, pm_ra_degrees, pm_dec_degrees,
return (ra, dec)

def generate_finding_chart(out_year, in_ra, in_dec, in_format, in_year, ra_pm, dec_pm, width, height, survey):
if in_format == 'sexagesimal':
ra_j2000_degrees = parse_sexagesimal(in_ra) * 15
dec_j2000_degrees = parse_sexagesimal(in_dec)
else:
if in_format == 'decimal':
ra_j2000_degrees = float(in_ra)
dec_j2000_degrees = float(in_dec)
else:
ra_j2000_degrees = parse_sexagesimal(in_ra) * 15
dec_j2000_degrees = parse_sexagesimal(in_dec)


ra_pm_degrees = float(ra_pm) / 3600
dec_pm_degrees = float(dec_pm) / 3600
Expand Down Expand Up @@ -181,5 +182,6 @@ def input_display():
def generate_chart_json():
try:
return generate_finding_chart(request.args['outepoch'], request.args['ra'], request.args['dec'], request.args['format'], request.args['epoch'], request.args['rapm'], request.args['decpm'], request.args['size'], request.args['size'], request.args['survey'])
except Exception as e:
except Exception:
traceback.print_exc(file=sys.stdout)
abort(500)
35 changes: 25 additions & 10 deletions static/findingchart.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,19 @@ function setup() {
var name = parts[0];
var ra = parts[1];
var dec = parts[2];
var rapm = parts[3];
var decpm = parts[4];
var epoch = parts[5];
var coord_offset = 0;

if (format == 'sexagesimal') {
if (format == 'decimal') {
if (ra === undefined || parseFloat(ra) != ra) {
$('#error').html('Line ' + line + ': Unable to parse "' + ra + '" as decimal degrees');
return;
}

if (dec === undefined || parseFloat(dec) != dec) {
$('#error').html('Line ' + line + ': Unable to parse "' + dec + '" as decimal degrees');
return;
}
} else if (format == 'sexagesimal-colon') {
if (ra === undefined || !testSexagesimal.test(ra)) {
$('#error').html('Line ' + line + ': Unable to parse "' + ra + '" as HH:MM:SS');
return;
Expand All @@ -276,17 +284,24 @@ function setup() {
return;
}
} else {
if (ra === undefined || parseFloat(ra) != ra) {
$('#error').html('Line ' + line + ': Unable to parse "' + ra + '" as decimal degrees');
ra = parts[1] + ':' + parts[2] + ':' + parts[3];
dec = parts[4] + ':' + parts[5] + ':' + parts[6];
coord_offset = 4;
if (ra === undefined || !testSexagesimal.test(ra)) {
$('#error').html('Line ' + line + ': Unable to parse "' + ra + '" as HH MM SS');
return;
}

if (dec === undefined || parseFloat(dec) != dec) {
$('#error').html('Line ' + line + ': Unable to parse "' + dec + '" as decimal degrees');
if (dec === undefined || !testSexagesimal.test(dec)) {
$('#error').html('Line ' + line + ': Unable to parse "' + dec + '" as DD MM SS');
return;
}
}

var rapm = parseFloat(parts[3 + coord_offset]);
var decpm = parseFloat(parts[4 + coord_offset]);
var epoch = parseFloat(parts[5 + coord_offset]);

if (rapm === undefined || parseFloat(rapm) != rapm) {
$('#error').html('Line ' + line + ': Unable to parse "' + rapm + '" as number');
return;
Expand All @@ -310,9 +325,9 @@ function setup() {
// Enumerate through line to find start of comment (if it exists)
// Want to make sure we take all character from the start of the comment
var comment = undefined;
if (parts.length > 6) {
if (parts.length > 6 + coord_offset) {
var start = 0;
for (var j = 0; j < 7; j++)
for (var j = 0; j < 7 + coord_offset; j++)
start = coords[i].indexOf(parts[j], start);
comment = coords[i].substring(start);
}
Expand Down
3 changes: 2 additions & 1 deletion templates/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ <h1>Finding chart generator</h1>

<label for="type" class="control-label col-sm-2">Coordinates:</label>
<div class="radio col-sm-6">
<label><input type="radio" name="format" id="format-segagesimal" value="sexagesimal" checked>Sexagesimal&nbsp;</label>
<label><input type="radio" name="format" id="format-segagesimal-colon" value="sexagesimal-colon" checked>HH:MM:SS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
<label><input type="radio" name="format" id="format-segagesimal-space" value="sexagesimal-space">HH MM SS&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
<label><input type="radio" name="format" id="format-degrees" value="decimal">Decimal Degrees</label>
</div>
</div>
Expand Down

0 comments on commit ca498a3

Please sign in to comment.