Created
March 24, 2011 17:21
-
-
Save bmander/885461 to your computer and use it in GitHub Desktop.
grab radar data from the radarmatic API, convert to cartesian coordinates, and output as CSV, and then a Processing file to render it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Render the data output by radar.py as an image. | |
*/ | |
void setup() { | |
size(700,700); | |
background(255); | |
stroke(0); | |
smooth(); | |
scale(2,2); | |
translate(200,200); | |
String lines[] = loadStrings("radar.csv"); | |
println("there are " + lines.length + " lines"); | |
for (int i=0; i < lines.length; i++) { | |
String[] cols = split(lines[i],','); | |
float x = float(cols[0]); | |
float y = float(cols[1]); | |
float z = float(cols[2]); | |
stroke(z*50); | |
point( x, y ); | |
} | |
save("radar.png"); | |
} | |
void draw() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib import urlopen | |
import json | |
from math import radians, sin, cos | |
fpin = urlopen( "http://radarmatic.com/kokx.json" ) | |
fpout = open( "radar.csv", "w" ) | |
fpout.write( "x,y,z\n" ) | |
radarjson = fpin.read() | |
radar = json.loads( radarjson ) | |
for radial in radar['layers'][0]['radials']: | |
theta = radial['start_angle'] | |
for i, val in enumerate( radial['range_bins'] ): | |
r = i+1 | |
x = cos(radians(theta))*r | |
y = sin(radians(theta))*r | |
z = val | |
fpout.write( "%s,%s,%s\n"%(x,y,z) ) | |
fpout.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment