Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Using Node.js, it is possible to access HDF5 data in JavaScript language. Node.js package ecosystem, npm, provides HDF5 package as well as other packages that can run web service and visualize data on global maps.
You can download the latest Node.js from here.
Install Node.js first and use npm
command line tool to install hdf5 package as shown below.
Optionally, you can download HDF5 module source code from here in case your npm fails to install hdf5 package automatically.
Usage is similar to any other scripting laguange (e.g., Python and MATLAB) usage. First, you declare required modules that call hdf5 package.
Second, you open an HDF5 file, open a group, and read data from a specific dataset under the group.
Finally, you close all the resources at the end.
Node.js provides many npm packages that allow you to plot data. We demonstrate two use cases with Canvas and PlanetaryJS packages. In our examples, Canvas is used for generating a PNG plot and PlanetaryJS is used for generating HTML5 served by Node.js web server.
Although JavaScript is mainly for web browser, it is possible to generate a static PNG image as shown below using Node.js.
The complete JavaScript code is test.js. The sample HDF5 file is oco2_L2StdND_03945a_150330_B6000_150331024816.h5. To run the script, please download world-110m.json as well and run as follows.
With Node.js, running a custom web service is easy and you can visualize HDF5 data from your web sever as shown below.
The above service reads the first lat/lon data point from OCO-2 HDF5 data, modifies the template HTML file that has PlanetaryJS, and sends the updated HTML file via HTTP on port 3000. The server code is index.js and the template HTML file is index.html (use right mouse click to download and save the HTML file). The sample HDF5 file is oco2_L2StdND_03945a_150330_B6000_150331024816.h5. To run the server script, please download world-110m.json as well, put all 4 files (index.js, index.html, sample oco2 HDF5, and world-110m.json) on the same directory, and run sever script as follows.
http://localhost:3000
. You will get the same screen as shown above.