Skip to content

Commit e3aea2b

Browse files
Mark JessopMark Jessop
authored andcommitted
Add solar elevation calculations for WSPR paylods.
1 parent eb3cdbc commit e3aea2b

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations -
2929
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge colour-map.js >> mobile.js
3030
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge format.js >> mobile.js
3131
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge flight_doc.js >> mobile.js
32+
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge suncalc.js >> mobile.js
3233

3334
#compile plot lib and config
3435
java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge _jquery.flot.js >> init_plot.js

js/format.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,28 @@ function formatData(data) {
145145
}
146146
}
147147

148+
// Payload data post-processing, where we can modify / add data elements if needed.
149+
150+
// Determine if this payload is a WSPR payload
151+
// We determine this through either the modulation field, or comment field.
152+
var wspr_payload = false;
153+
if (data[key][i].hasOwnProperty("modulation")){
154+
if(data[key][i].modulation.includes("WSPR")){
155+
wspr_payload = true;
156+
}
157+
}
158+
if (data[key][i].hasOwnProperty("comment")){
159+
if(data[key][i].comment.includes("WSPR")){
160+
wspr_payload = true;
161+
}
162+
}
163+
164+
// For WSPR payloads, calculate solar elevation.
165+
if(wspr_payload){
166+
dataTempEntry.data['solar_elevation'] = (SunCalc.getPosition(stringToDateUTC(dataTempEntry.gps_time), dataTempEntry.gps_lat, dataTempEntry.gps_lon).altitude/rad).toFixed(1);
167+
}
168+
169+
148170
dataTemp.push(dataTempEntry);
149171
}
150172
}

js/suncalc.js

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Sun Position Calculations from https://github.com/mourner/suncalc
2+
3+
// shortcuts for easier to read formulas
4+
5+
var PI = Math.PI,
6+
sin = Math.sin,
7+
cos = Math.cos,
8+
tan = Math.tan,
9+
asin = Math.asin,
10+
atan = Math.atan2,
11+
acos = Math.acos,
12+
rad = PI / 180;
13+
// date/time constants and conversions
14+
15+
var dayMs = 1000 * 60 * 60 * 24,
16+
J1970 = 2440588,
17+
J2000 = 2451545;
18+
19+
function suncalc_toJulian(date) { return date.valueOf() / dayMs - 0.5 + J1970; }
20+
function suncalc_fromJulian(j) { return new Date((j + 0.5 - J1970) * dayMs); }
21+
function suncalc_toDays(date) { return suncalc_toJulian(date) - J2000; }
22+
23+
24+
// general calculations for position
25+
26+
var suncalc_e = rad * 23.4397; // obliquity of the Earth
27+
28+
function rightAscension(l, b) { return atan(sin(l) * cos(suncalc_e) - tan(b) * sin(suncalc_e), cos(l)); }
29+
function declination(l, b) { return asin(sin(b) * cos(suncalc_e) + cos(b) * sin(suncalc_e) * sin(l)); }
30+
31+
function suncalc_azimuth(H, phi, dec) { return atan(sin(H), cos(H) * sin(phi) - tan(dec) * cos(phi)); }
32+
function suncalc_altitude(H, phi, dec) { return asin(sin(phi) * sin(dec) + cos(phi) * cos(dec) * cos(H)); }
33+
34+
function siderealTime(d, lw) { return rad * (280.16 + 360.9856235 * d) - lw; }
35+
36+
// general sun calculations
37+
38+
function solarMeanAnomaly(d) { return rad * (357.5291 + 0.98560028 * d); }
39+
40+
function eclipticLongitude(M) {
41+
42+
var C = rad * (1.9148 * sin(M) + 0.02 * sin(2 * M) + 0.0003 * sin(3 * M)), // equation of center
43+
P = rad * 102.9372; // perihelion of the Earth
44+
45+
return M + C + P + PI;
46+
}
47+
48+
function sunCoords(d) {
49+
50+
var M = solarMeanAnomaly(d),
51+
L = eclipticLongitude(M);
52+
53+
return {
54+
dec: declination(L, 0),
55+
ra: rightAscension(L, 0)
56+
};
57+
}
58+
59+
var SunCalc = {};
60+
61+
62+
// calculates sun position for a given date and latitude/longitude
63+
64+
SunCalc.getPosition = function (date, lat, lng) {
65+
66+
var lw = rad * -lng,
67+
phi = rad * lat,
68+
d = suncalc_toDays(date),
69+
70+
c = sunCoords(d),
71+
H = siderealTime(d, lw) - c.ra;
72+
73+
return {
74+
azimuth: suncalc_azimuth(H, phi, c.dec),
75+
altitude: suncalc_altitude(H, phi, c.dec)
76+
};
77+
};
78+

0 commit comments

Comments
 (0)