Preparing JSON data for creating a wind map with Leaflet

I am currently working on converting netCDF data to JSON in order to use it with leaflet-velocity. This tool follows the same format as the output of grib2json used by cambecc in earth. An example of sample JSON data can be found at wind-global.json.

By using netCDF4, I have successfully extracted latitude/longitude wind data arrays from my netCDF file.

I am curious about how the "data" part of the JSON file (as shown in the example below) is structured. It appears to be a lengthy array of values (e.g. for 'eastward wind' in the sample), but I am unsure of how these values are mapped to latitude/longitude coordinates later on.

Does the JSON header contain information that guides Leaflet on structuring the output, or does another function in leaflet-velocity.js handle this task?

I came across a related post on Stack Overflow which provided some clues, but I have been struggling for quite some time now to adapt it to my own netCDF file. The link to the question is here.

[
{
    "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,
        ...
    ]
}
]

Answer №1

Here is a potential solution that may be helpful: NCO-JSON generates a unique JSON format compared to grib2json. It can handle all netCDF files seamlessly and includes array dimensional boundaries by default. This tool might simplify the process for your specific needs...

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]]]
    }
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

retrieving the value of an object key based on changing information

console.log(x, obj.fares) //return undefined output adultFare Object {adultFare: "9.00", childFare: null, seniorCitizenFare: null, disabledFare: null,} How do I retrieve the adultFare value from the object? Is looping through the keys necessary? I expec ...

Can we streamline the JSON value reading functions for this instance?

I received a JSON format like this { "items": { "item": { "Beverages": [ { "id": "0001", "name": "Coke", "image": { "url": "json_i ...

Ways to target only the adjacent div

My goal is to target only the next div with the class name indented. Each indented div should have the same id as the <li> element right before it. Currently, I want each div with the class name indented to have the id of the previous <li>. He ...

Troubleshooting issue: Angular not resolving controller dependency in nested route when used with requirejs

When the routes are multiple levels, such as http://www.example.com/profile/view, the RequireJS is failing to resolve dependencies properly. However, if the route is just http://www.example.com/view, the controller dependency is resolved correctly. Below ...

Difficulties arise when working with Json data and performing searches using a for-each

Utilizing an API that returns data in JSON format, which I believe is referred to as "pairs". Apologies if my terminology is incorrect. I am then parsing through the JSON response to locate a specific user ID, which happens to be the second value in each ...

Can you provide instructions on creating a c# class for the following json object?

As a beginner in json, I have the following json object and need assistance in creating a C# class for it: { "JBS" : { "name" : "Jobsite" }, "LNK" : { "name" : "Linked IN" }, "MUK" : { "name" : "Monster UK" } } I requi ...

Establishing a client cookie will help deter any attempts at re-registering

Due to the inability to run server-side code, I am limited in implementing a PHP session for a registration form. Instead, I have opted to utilize a client cookie to ensure that each person can only register once with a unique email address. After reading ...

Steps for extracting values from JSON in MySQL

Could you please help me identify the issue in this query? DECLARE @json LONGTEXT; SET @json = '[ { "name":"John Smith", "address":"780 Mission St, San Francisco, CA 94103"}, { "name":"Sally Bro ...

PHP's `json_encode` is failing to properly convert an array and is outputting `{

My system is running CentOS 7.4 with PHP 5.4 installed. $s='a:91:{s:13:"spotsviewvars";s:7:"1916.74";s:13:"100000T18vars";N;s:17:"100000T18S106vars";s:7:"1746.95";s:17:"100000T18S107vars";s:4:"4.49";s:17:"100000T18S108vars";s:4:"8.29";s:17:"100000T18 ...

Identifying the class name of SVGAnimatedString

While working on creating an SVG map, I encountered an issue where the functions triggered by hovering over 'g' elements were not functioning as expected. In order to troubleshoot this problem, I decided to check for any issues with the class nam ...

Struggling with Getting My Animation to Function Correctly

I am trying to create a JQuery Animation that will move a div covering a text box up into the border when clicked. Despite multiple attempts, I can't seem to get the animation to work properly. Any suggestions? JavaScript function moveup(title,text ...

Enhancing game menus for various mobile screen sizes

I've noticed a consistent pattern in the games I download from the Google Play Store - they all have a background image at the menu with clickable buttons. When testing these games on different devices, I found that the backgrounds didn't stretch ...

Angular Build Showing Error with Visual Studio Code 'experimentalDecorators' Configuration

Currently experiencing an issue in VSC where all my typescript classes are triggering intellisense and showing a warning that says: "[ts] Experimental support for is a feature that is subject to change in a future build. Set the 'experimentalDeco ...

Issue: Inability to scroll on div overflow section

My website consists of one static page with an HTML and CSS file. Oddly enough, when testing the page and inputting content into a multiline textarea until it overflows, the browser fails to display a scrollbar. Despite inspecting the div with the id &apos ...

Variances in errors observed while accessing a website on ports 80 and 5500

I've been developing a chatbot system, and I'm encountering an issue where I receive an error message every time I send a message and expect a response back. What's puzzling is that the error message varies depending on whether I run the si ...

jQuery AJAX calls are unsuccessful, while NodeJS requests are running smoothly

I am experiencing an issue with a RESTful web service that returns JSON. Interestingly, a NodeJS command line test application is able to retrieve the JSON data without any problems: Successful NodeJS Application: var request = require("request"); var bt ...

Tips for creating a responsive background image that adjusts after resizing the window to a certain width

Is there a way to create a responsive background-image that adjusts when the window is resized to a specific width, similar to the main image on ? ...

How can I convert the date format from ngbDatepicker to a string in the onSubmit() function of a form

I'm facing an issue with converting the date format from ngbDatepicker to a string before sending the data to my backend API. The API only accepts dates in string format, so I attempted to convert it using submittedData.MaturityDate.toString(); and su ...

Using Python to validate JSON keys and values

I'm currently working on developing a Python code that takes a JSON file as input. This JSON file can contain various data structures such as dictionaries and lists. The main goal of my program is to print out the keys present in the JSON file. Howeve ...

What is the best way to include specific information in the Header and the Body of a JSON response for a GET request in a Spring Boot application?

In my Spring boot project, I have created an AuthController class. This class contains the code for handling Sign-in POST requests and displaying the generated JWT token upon successful authentication. Below is the snippet of the AuthController class: @P ...