Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting json for leaflet wind map

I'm trying to convert netCDF data to json for use in leaflet-velocity, which used the same format as the output of grib2json used by cambecc in earth. Here's another example of sample json data given by danwild in wind-global.json

Using netCDF4 I've managed to extract arrays of lat/ lot wind data from my netCDF.

I was wondering how the "data" part of the json file (example below) is structured? It seems to be a long array of values (e.g. for 'eastward wind' in the example), but I don't understand how they get mapped to lat/ lon coords later on?

Is there something in the json header which tells Leaflet how to structure the output, or must there be another function in leaflet-velocity.js doing the work?

This question had some clues, but I've been at a loss for some time now trying to adapt it for my own netCDF file.

[
{
    "header": {
    "parameterUnit": "m.s-1",
    "parameterNumber": 2,
    "dx": 1.0,
    "dy": 1.0,
    "parameterNumberName": "eastward_wind",
    "la1": -7.5,
    "la2": -28.5,
    "parameterCategory": 2,
    "lo2": 156.0,
    "nx": 14,
    "ny": 22,
    "refTime": "2017-02-01 23:00:00",
    "lo1": 143.0
  },
    "data":[
        -2.12,
        -2.27,
        -2.41,
        ...
    ]
}
]
like image 526
F. Lumley Avatar asked Sep 20 '25 23:09

F. Lumley


1 Answers

This may help. NCO-JSON produces a different JSON dialect than grib2json, yet works directly and completely for all netCDF files, and, by default, includes brackets indicating array dimensional boundaries. You might find it easier for your purposes...

zender@aerosol:~$ ncks -C -v three_dmn_rec_var --jsn ~/nco/data/in.nc
{
  "dimensions": {
    "lat": 2,
    "lon": 4,
    "time": 10
  },
  "variables": {
    "three_dmn_rec_var": {
      "shape": ["time", "lat", "lon"],
      "type": "float",
      "attributes": {
        "long_name": "three dimensional record variable",
        "units": "watt meter-2",
        "_FillValue": -99.0
      },
      "data": [[[1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0]], [[9.0, 10.0, 11.0, 12.0], [13.0, 14.0, 15.0, 16.0]], [[17.0, 18.0, 19.0, 20.0], [21.0, 22.0, 23.0, 24.0]], [[25.0, 26.0, 27.0, 28.0], [29.0, 30.0, 31.0, 32.0]], [[33.0, 34.0, 35.0, 36.0], [37.0, 38.0, 39.0, 40.0]], [[41.0, 42.0, 43.0, 44.0], [45.0, 46.0, 47.0, 48.0]], [[49.0, 50.0, 51.0, 52.0], [53.0, 54.0, 55.0, 56.0]], [[57.0, 58.0, 59.0, 60.0], [61.0, 62.0, 63.0, 64.0]], [[65.0, 66.0, 67.0, 68.0], [69.0, 70.0, 71.0, 72.0]], [[73.0, 74.0, 75.0, 76.0], [77.0, 78.0, 79.0, 80.0]]]
    }
  }
}
like image 181
Charlie Zender Avatar answered Sep 22 '25 13:09

Charlie Zender