The US Space Weather Prediction Center publishes the output of its Ovation forecast model on their website as JSON files: https://services.swpc.noaa.gov/json/ovation_aurora_latest.json

As far as I can tell, the file is pretty straightforward but it's not a standard GeoJSON file. I'm a beginner both with Leaflet and with JavaScript.

What would be a good way to get this data as an overlay to a Leaflet map?

Should I try to knit a function which reads the JSON, creates a new GeoJSON layer and creates a bunch of polygons or would there be a smart way to pre-convert the data somehow to some format I can just load into Leaflet?

I have touched GDAL here and there but I'm far from "fluent" with it. I imagine, doing the conversion in the browser in JavaScript would be fairly expensive.

  • The file appears to be a full set of one-degree lat-lon gridded values. Do you really want this as 360x181 polygons or as a raster grid? Also, leaflet might struggle to plot things that far N and S... Converting to raster in the browser shouldn't be too bad, what options have you got for processing it "offline"? There are command-line tools for extracting bits of JSON and you could pipe that into GDAL tools...
    – Spacedman
    Mar 7 '21 at 22:39

On a system with standard linux command-line tools and the jq JSON toolkit, you can do this:

jq '.coordinates[]|join(" ")' < ovation_aurora_latest.json \
| sed 's/"//g' \
| sort -n -k 2 -k 1  > ovation.xyz

jq extracts the coordinates, sed gets rid of the quotes (might be doable within jq) and sort arranges in increasing numeric Y then numeric X within Y.

This makes an XYZ file in the right order to be a valid GDAL raster file:

$ gdalinfo ovation.xyz 
Driver: XYZ/ASCII Gridded XYZ
Files: ovation.xyz
Size is 360, 181
Origin = (-0.500000000000000,-90.500000000000000)
Pixel Size = (1.000000000000000,1.000000000000000)

This loads into QGIS which shows it seems okay except the X coord is 0 to 360 where QGIS wants -180 to 180 to go over the basemap:

enter image description here

You should then be able to convert that to a raster format that leaflet can ingest via a raster layer plugin...

  • That is fantastic! I'm really a beginner with this stuff and I have never heard of the XYZ format before! Your answer didn't only solve my the issue at hand but also gave me some new information which will help me solve about a million things I still have on my list! Thank you! Mar 8 '21 at 9:50
  • On the X coordinates matter, I solved this like this: gdalwarp -s_srs "+proj=longlat +ellps=WGS84" -t_srs WGS84 ovation.tif ovation2.tif -wo SOURCE_EXTRA=1000 --config CENTER_LONG 0 That does produce "ERROR 1: Invalid dfSouthLatitudeDeg" 4 times but still outputs a valid file Mar 8 '21 at 9:51
  • And yes, I do have the possibility to run that "offline" :) Mar 8 '21 at 9:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.