Skip to content

Instantly share code, notes, and snippets.

@dceejay
Last active April 2, 2018 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dceejay/59b1a953dbf96dba3db9 to your computer and use it in GitHub Desktop.
Save dceejay/59b1a953dbf96dba3db9 to your computer and use it in GitHub Desktop.
Aurora visibility

An idea shamelessly borrowed from http://blog.riyas.org/2014/01/raspberry-pi-as-northern-light-forcast.html to go and get the Geomagnetic Activity (KP Index) from NOAA and parse it and produce two outputs.

First is the actual current KP value and the second is a crudely calculated true false output that would indicate if you have any chance of seeing the aurora at the latitude hard coded in the function. (and yes it only handles northern hemisphere :-)

For more info on the Kp index - see http://www.spaceweatherlive.com/en/auroral-activity/kp

(Sadly it has nothing to do with Kevin Pietersen's batting performance - though given the random nature of the index... maybe it does...)

[{"id":"457c4f87.2929b8","type":"inject","name":"","topic":"","payload":"","repeat":"","crontab":"*/30 * * * *","once":false,"x":134.16666889190674,"y":103.16669178009033,"z":"9e3ede37.ad0aa","wires":[["c61a00d1.df899"]]},{"id":"c61a00d1.df899","type":"http request","name":"","method":"GET","url":"http://www.swpc.noaa.gov/wingkp/wingkp_list.txt","x":259.1666603088379,"y":159.16669178009033,"z":"9e3ede37.ad0aa","wires":[["95cf58eb.ad865"]]},{"id":"2741b193.92e1ce","type":"debug","name":"","active":true,"complete":"false","x":645.1667060852051,"y":104.1666841506958,"z":"9e3ede37.ad0aa","wires":[]},{"id":"95cf58eb.ad865","type":"function","name":"parse NOAA kp log","func":"var lat = 51.05;\n\n// first output is the current kp value\n// second is whether it is likely to be visible from your latitude\n// ( on a clear night etc etc )\n\nvar lines = msg.payload.split(\"\\n\");\nvar last = lines[lines.length - 2];\nlast = last.replace(/\\s{2,}/g, ' ');\nvar bits = last.split(\" \");\nvar status = Number(bits[4]);\nvar kp = Number(bits[bits.length - 1]);\n\nvar visible = false;\nvar edge = 3;\nif (lat >= 60) edge = 3;\nelse edge = (60-lat)/2 + 3;\n\nif (kp > edge) visible = true;\nif (lat < 45) visible = false;\n\nmsg = { payload:kp };\nmsg2 = { payload:visible };\n\nif (status <= 1) return [msg,msg2];\nreturn null;","outputs":"2","x":419.1666793823242,"y":103.1666841506958,"z":"9e3ede37.ad0aa","wires":[["2741b193.92e1ce"],["8b774bee.d4c848"]]},{"id":"1e6719b0.ce9ba6","type":"comment","name":"Idea shamelessly copied from http://blog.riyas.org/2014/01/raspberry-pi-as-northern-light-forcast.html?m=1","info":"","x":406.1666564941406,"y":61.166669845581055,"z":"9e3ede37.ad0aa","wires":[]},{"id":"8b774bee.d4c848","type":"debug","name":"","active":true,"complete":"false","x":647.1667060852051,"y":148.1666774749756,"z":"9e3ede37.ad0aa","wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment