aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahiel@protonmail.ch>2015-11-05 23:53:54 +0100
committerRahiel Kasim <rahiel@protonmail.ch>2015-11-05 23:53:54 +0100
commited91837e204d8a5ad366020e50651cc432fdb529 (patch)
tree0c9dc3fbf0e560b52a9a3ad7b4bf9b6a704cc2f6
parentf772f61b8b931574d0b6082f6ea2d908fce2a9db (diff)
add test file for model validation
And add a shiny GPL badge
-rw-r--r--.gitignore1
-rw-r--r--README.md1
-rw-r--r--main.js4
-rw-r--r--systems.js2
-rw-r--r--validation/index.html12
-rw-r--r--validation/solar_system_data.py106
-rw-r--r--validation/test.js53
-rw-r--r--webpack.config.js7
8 files changed, 181 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index bf2ef0c..0fe54ad 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
node_modules
sunsistemo.js
sunsistemo.github.io
+validation/validation.js
diff --git a/README.md b/README.md
index c8628ce..4f5c715 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,7 @@
Sunsistemo
==========
+[![GNU General Public License v3](https://www.gnu.org/graphics/gplv3-127x51.png)](https://www.gnu.org/licenses/gpl.html)
<a href="https://js.org" target="_blank" title="JS.ORG | JavaScript Community">
<img src="https://logo.js.org/dark_tiny.png" width="77" alt="JS.ORG Logo"/></a>
[![Dependency Status](https://david-dm.org/sunsistemo/sunsistemo.svg)](https://david-dm.org/sunsistemo/sunsistemo)
diff --git a/main.js b/main.js
index 7efd9aa..b183e7d 100644
--- a/main.js
+++ b/main.js
@@ -121,7 +121,7 @@ function showSubmenu(submenuList, menuButton) {
let menuSvg = menuDiv.selectAll(".menuSvg");
var buttons = menuSvg.selectAll(".subButton")
.data(choreoSubmenuList);
-
+
buttons.enter()
.append("g")
.attr("class", "button subButton")
@@ -201,7 +201,7 @@ function clearSimulation() {
requestId = undefined;
}
-function simulate(sysFunc, args){
+function simulate(sysFunc, args) {
system = sysFunc(...args);
bodies = system.bodies;
if (system.hasOwnProperty("stepsPerFrame")) {
diff --git a/systems.js b/systems.js
index c081713..86a8768 100644
--- a/systems.js
+++ b/systems.js
@@ -188,7 +188,7 @@ export function gen2Bodies(sunOn) {
return {
bodies: bodies,
- stepsize: 0.004,
+ stepsize: 0.000003,
stepsPerFrame: 100,
camera: {x: 0, y: 0, z: 250},
collisions: false,
diff --git a/validation/index.html b/validation/index.html
new file mode 100644
index 0000000..141bc07
--- /dev/null
+++ b/validation/index.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <script type="text/javascript">if(window.location.protocol=="http:"&&window.location.host=="sunsistemo.js.org")window.location.protocol="https";</script>
+ <title>Sunsistemo - Model Validation</title>
+ </head>
+ <body>
+ <script src="validation.js"></script>
+ </body>
+</html>
diff --git a/validation/solar_system_data.py b/validation/solar_system_data.py
new file mode 100644
index 0000000..422bf6a
--- /dev/null
+++ b/validation/solar_system_data.py
@@ -0,0 +1,106 @@
+import json
+from telnetlib import Telnet
+
+
+def get_solar_system_data():
+ """Gets position and velocity data for bodies in the solar system every year
+ from 1970-01-01 to 2015 from NASA's HORIZONS system and saves it to a json
+ file.
+ """
+ bodies = { # ID's of bodies in the HORIZONS system
+ "mercury": "199",
+ "venus": "299",
+ "moon": "301",
+ "earth": "399",
+ "mars": "499",
+ "jupiter": "599",
+ "saturn": "699",
+ "uranus": "799",
+ "neptune": "899",
+ "pluto": "999"
+ }
+
+ data = {}
+ for body in bodies.keys():
+ print "Getting data for %s" % body
+ data[body] = get_data(bodies[body])
+
+ with open("solar_system.json", 'w') as f:
+ json.dump(data, f)
+
+
+def get_data(body_id):
+ """Get position and velocity of body from NASA's horizon system"""
+ tn = Telnet("horizons.jpl.nasa.gov", 6775)
+
+ def write(message):
+ tn.write(message + '\n')
+
+ tn.read_until("Horizons> ")
+ write(body_id) # choose major body
+
+ tn.read_until("<cr>: ")
+ write('E') # request ephemeris
+
+ tn.read_until(" : ")
+ write('v') # choose vectors
+
+ tn.read_until(" : ")
+ write("500@10") # coordinate center at the sun
+
+ tn.read_until("--> ")
+ write("y") # confirm coordinate center
+
+ tn.read_until(" : ")
+ write("eclip") # ecliptic coordinate system
+
+ tn.read_until(" : ")
+ write("1970-01-01") # starting time: 1970-01-01
+
+ tn.read_until(" : ")
+ write("2015-01-01") # end time in 2015
+
+ tn.read_until(" : ")
+ write("1y") # output interval
+
+ tn.read_until(" : ")
+ write("n") # choose other options
+
+ tn.read_until(" : ")
+ write("J2000") # output reference frame
+
+ tn.read_until(" : ")
+ write("1") # no corrections
+
+ tn.read_until(" : ")
+ write("1") # units in km/s
+
+ tn.read_until(" : ")
+ write("YES") # use CSV format
+
+ tn.read_until(" : ")
+ write("NO") # no output labels
+
+ tn.read_until(" : ")
+ write("2") # request x, y, z, vx, vy, vz values
+
+ tn.read_until("$$SOE")
+ data = tn.read_until("$$EOE")
+ tn.close()
+
+ data = data[:-5].strip().splitlines() # split lines into years
+ data = [y[:-1].split(", ")[2:] for y in data] # extract values
+ data = [[float(e) * 1E3 for e in y] for y in data] # convert to meters
+
+ body = {}
+ year = 1970
+ for d in data:
+ x, y, z, vx, vy, vz = d
+ body[year] = {"position": [x, y, z], "velocity": [vx, vy, vz]}
+ year += 1
+
+ return body
+
+
+if __name__ == '__main__':
+ get_solar_system_data()
diff --git a/validation/test.js b/validation/test.js
new file mode 100644
index 0000000..9c7816f
--- /dev/null
+++ b/validation/test.js
@@ -0,0 +1,53 @@
+import * as systems from "./../systems.js";
+import * as calc from "./../calc.js";
+
+
+function SolarSystem() {
+ // get positions of the bodies in the solar system at the beginning of
+ // each year from 1970 to 2015, used to compare with data from NASA
+ let system = systems.genSolarSystem();
+ let bodies = system.bodies;
+ let timer = new Date(0);
+ let years = 2015 - 1970 + 1;
+
+ // get unix times at midnight January 1st for all years
+ let times = [];
+ let t = new Date(0);
+ for (let i = 0; i < years; i ++) {
+ times.push(t.getTime());
+ t.setFullYear(t.getFullYear() + 1);
+ }
+
+ // override stepsize
+ system.stepsize = 60 * 60 * 12;
+
+ // kickoff leapfrog
+ bodies = calc.leapfrog_initial(bodies, system.stepsize);
+
+ let num_steps = Math.round((60 * 60 * 24) * 365 * years / system.stepsize);
+
+ let results = {};
+ for (let b of bodies) {
+ results[b.texture] = {};
+ }
+
+ let year = 1970;
+ for (let i = 0; i < num_steps; i++) {
+ if (times.indexOf(timer.getTime()) > -1) {
+ for (let b of bodies) {
+ results[b.texture][year] = {
+ "position": [b.r.x, b.r.y, b.r.z]
+ // "velocity": [b.v.x, b.v.y, b.v.z]
+ };
+ }
+ console.log(year);
+ year++;
+ }
+ bodies = calc.leapfrog(bodies, system.stepsize);
+ timer.setTime(timer.getTime() + system.stepsize * 1E3);
+ }
+
+ document.write(JSON.stringify(results));
+}
+
+SolarSystem();
diff --git a/webpack.config.js b/webpack.config.js
index 5c2ea4c..5460e81 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,8 +1,11 @@
module.exports = {
- entry: "./main.js",
+ entry: {
+ sunsistemo: "./main.js",
+ "validation/validation": "./validation/test.js"
+ },
output: {
path: __dirname,
- filename: "sunsistemo.js"
+ filename: "[name].js"
},
module: {
loaders: [