1
0
Fork 0

Add polar plot in observation view

environments/stage/deployments/85^2
Fabian P. Schmidt 2018-01-28 23:51:14 +01:00 committed by Nikos Roussos
parent 16369919c5
commit 5ddb1b4050
No known key found for this signature in database
GPG Key ID: BADFF1767BA7C8E1
2 changed files with 115 additions and 1 deletions

View File

@ -1,4 +1,4 @@
/* global WaveSurfer URI */
/* global WaveSurfer URI satellite moment */
$(document).ready(function() {
'use strict';
@ -108,6 +108,69 @@ $(document).ready(function() {
var metadata = $('#json-renderer').data('json');
$('#json-renderer').jsonViewer(metadata, {collapsed: true});
// Draw orbit in polar plot
var tleLine1 = $('svg#polar').data('tle1');
var tleLine2 = $('svg#polar').data('tle2');
var timeframe = {
start: new Date($('svg#polar').data('timeframe-start')),
end: new Date($('svg#polar').data('timeframe-end'))
};
const pi = Math.PI;
const deg2rad = pi / 180.0;
const rad2deg = 180 / pi;
// Get the observer at lat/lon in RADIANS, altitude in km above ground (NOTE: BUG, should be elevation?)
var observerGd = {
longitude: $('svg#polar').data('groundstation-lon') * deg2rad,
latitude: $('svg#polar').data('groundstation-lat') * deg2rad,
height: $('svg#polar').data('groundstation-alt') / 1000
};
var polarGetXY = function(az, el) {
var ret = new Object();
ret.x = (90 - el) * Math.sin(az * deg2rad);
ret.y = (el - 90) * Math.cos(az * deg2rad);
return ret;
};
var polarOrbit = document.createElementNS('http://www.w3.org/2000/svg', 'path');
polarOrbit.setAttributeNS(null, 'fill', 'none');
polarOrbit.setAttributeNS(null, 'stroke', 'blue');
polarOrbit.setAttributeNS(null, 'stroke-opacity', '1.0');
polarOrbit.setAttributeNS(null, 'stroke-width', '2');
// Initialize the satellite record
var satrec = satellite.twoline2satrec(tleLine1, tleLine2);
// Draw the orbit pass on the polar az/el plot
var g = '';
for (var t = moment(timeframe.start); t < moment(timeframe.end); t.add(20, 's')) {
var positionAndVelocity = satellite.propagate(satrec, t.toDate());
var gmst = satellite.gstime(t.toDate());
var positionEci = positionAndVelocity.position;
var positionEcf = satellite.eciToEcf(positionEci, gmst);
var lookAngles = satellite.ecfToLookAngles(observerGd, positionEcf);
var azimuth = lookAngles.azimuth * rad2deg,
elevation = lookAngles.elevation * rad2deg;
var coord = polarGetXY(azimuth, elevation);
if (g == '') {
// Start of line
g += 'M';
} else {
// Continue line
g += ' L';
}
g += coord.x + ' ' + coord.y;
}
polarOrbit.setAttribute('d', g);
$('svg#polar').append(polarOrbit);
// Hotkeys bindings
$(document).bind('keyup', function(event){
if (event.which == 88) {

View File

@ -179,6 +179,56 @@
</span>
</div>
{% endif %}
<div class="front-line">
<span class="label label-default">Polar Plot</span>
<span class="front-data">
<div id="polar_plot">
<svg
xmlns="http://www.w3.org/2000/svg" version="1.1"
id="polar"
data-tle1="{{ observation.tle.tle1 }}"
data-tle2="{{ observation.tle.tle2 }}"
data-timeframe-start="{{ observation.start|date:"c" }}"
data-timeframe-end="{{ observation.end|date:"c" }}"
data-groundstation-lat="{{ observation.ground_station.lat }}"
data-groundstation-lon="{{ observation.ground_station.lng }}"
data-groundstation-alt="{{ observation.ground_station.alt }}"
width="120px" height="120px"
viewBox="-110 -110 220 220"
overflow="hidden">
<path
fill="none" stroke="black" stroke-width="1"
d="M 0 -95 v 190 M -95 0 h 190"
/>
<circle
fill="none" stroke="black"
cx="0" cy="0" r="30"
/>
<circle
fill="none" stroke="black"
cx="0" cy="0" r="60"
/>
<circle
fill="none" stroke="black"
cx="0" cy="0" r="90"
/>
<text x="-4" y="-96">
N
</text>
<text x="-4" y="105">
S
</text>
<text x="96" y="4">
E
</text>
<text x="-106" y="4">
W
</text>
</svg>
</div>
</span>
</div>
<div class="front-line">
{% if observation.has_audio or observation.waterfall %}
<span class="label label-default">Downloads</span>
@ -336,6 +386,7 @@
<script src="{% static 'lib/moment/min/moment.min.js' %}"></script>
<script src="{% static 'lib/urijs/src/URI.min.js' %}"></script>
<script src="{% static 'lib/jquery.json-viewer/json-viewer/jquery.json-viewer.js' %}"></script>
<script src="{% static 'lib/satellite.js/dist/satellite.min.js' %}"></script>
<script src="{% static 'js/utc.js' %}"></script>
<script src="{% static 'js/observation_view.js' %}"></script>
<script src="{% static 'js/satellite.js' %}"></script>