8.9 KiB
nexrad-level-2-data
A javascript implementation for decoding Nexrad Level II radar archive files.
You can find more information on how radar data is encoded at NOAA mainly in the document ICD FOR RDA/RPG - Build RDA 19.0/RPG 19.0 (PDF)
Contents
- Changes in v2.0.0
- Install
- Usage
- API
- Testing
- Error Recovery and handling
- Supported Messages
- Acknowledgements
Changes in v2.0.0
v2.0.0 is a major overhaul of the parsing engine and has several breaking changes. See UPGRADE.md for detailed breaking changes.
- Allow for processing of "chunks" in addition to entire volume scan archives.
- Chunks (real time data) is provided by Unidata in the s3 bucket
s3://unidata-nexrad-level2-chunks/ - Full archives are provided by Unidata in the s3 bucket
s3://noaa-nexrad-level2 - When processing a chunk all data may not be populated in the resulting object. This is deatiled in UPGRADE.md
- Chunks (real time data) is provided by Unidata in the s3 bucket
- Improve error reporting by throwing when data is not present or invalid elevations or scans are accessed.
- Unify the data accessor functions (breaking change)
- Follow NOAA convention of the lowest elevation being 1, and properly sort elevations above 1 into a sparse array (breaking change)
- Provide a mechanism for consolidating data read from several chunks.
Install
$ npm i nexrad-level-2-data
Usage
const { Level2Radar } = require('nexrad-level-2-data')
const fs = require('fs');
const file_to_load = "./data/KTLX20130420_205120_V06" // The radar archive file to load
const rawData = fs.readFileSync(file_to_load);
new Level2Radar(rawData).then(radar => {
console.log(radar.getHighresReflectivity())
})
API
Constructor(rawData, options)
Parses a Nexrad Level 2 Data archive or chunk. Provide rawData as a Buffer. Returns an object formatted per the ICD FOR RDA/RPG - Build RDA 19.0/RPG 19.0 (PDF), or as close as can reasonably be represented in a javascript object. Additional data accessors are provided in the returned object to pull out typical data in a format ready for processing. These are detailed below.
| option | Description |
|---|---|
| options.logger | By default error and information messages will be written to the console. These can be supressed by passing false, or a custom logger can be provided. A custom logger must provide the log() and error() function. |
Level2Data.combineData(data, [data, data], ...)
Combines the data returned by multiple runs of the Level2Data constructor. This is typically used in "chunks" mode to combine all azimuths from one revolution into a single data set. data can be provided as an array of Level2Radar objects, individual Level2Data parameters or any combination thereof.
The combine function blindly combines data and the right-most argument will overwrite any previously provided data. Individual azimuths located in Level2Radar.data[] will be appended. It is up to the calling routine to properly manage the parsing of related chunks and send it in to this routine.
setElevation(Number elevation)
Sets the elevation you want to grab the data from
getHighresReflectivity([scan])
Returns an Object of radar reflectivity data for the current elevation and scan (or all scans if not provided) in the following format
{
gate_count: Number,
first_gate: Number,
gate_size: Number,
rf_threshold: Number,
snr_threshold: Number,
scale: Number,
offset: Number,
data_offset: Number,
moment_data: Array
}
getHighresVelocity([scan])
Returns an Object of radar velocity data for the current elevation and scan (or all scans if not provided) in the following format
{
gate_count: Number,
first_gate: Number,
gate_size: Number,
rf_threshold: Number,
snr_threshold: Number,
scale: Number,
offset: Number,
data_offset: Number,
moment_data: Array
}
getHighresSpectrum([scan])
Returns an Object of radar spectrum data for the current elevation and scan (or all scans if not provided) in the following format
{
gate_count: Number,
first_gate: Number,
gate_size: Number,
rf_threshold: Number,
snr_threshold: Number,
scale: Number,
offset: Number,
data_offset: Number,
moment_data: Array
}
getHighresDiffReflectivity([scan])
Returns an Object of radar diff reflectivity data for the current elevation and scan (or all scans if not provided) in the following format
{
gate_count: Number,
first_gate: Number,
gate_size: Number,
rf_threshold: Number,
snr_threshold: Number,
scale: Number,
offset: Number,
data_offset: Number,
moment_data: Array
}
getHighresDiffPhase([scan])
Returns an Object of radar diff phase data for the current elevation and scan (or all scans if not provided) in the following format
{
gate_count: Number,
first_gate: Number,
gate_size: Number,
rf_threshold: Number,
snr_threshold: Number,
scale: Number,
offset: Number,
data_offset: Number,
moment_data: Array
}
getHighresCorrelationCoefficient([scan])
Returns an Object of radar correlation coefficient data for the current elevation and scan (or all scans if not provided) in the following format
{
gate_count: Number,
first_gate: Number,
gate_size: Number,
rf_threshold: Number,
snr_threshold: Number,
scale: Number,
offset: Number,
data_offset: Number,
moment_data: Array
}
getAzimuth([scan])
Returns an single azimuth value or array of azimuth values forthe current elevation and scan (or all scans if not provided). The order of azimuths in the returned array matches the order of the data in other get* functions above.
Testing
A formal testing suite is not provided. Several test-*.js are provided with matching data in the ./data folder. These can be run individually as shown below.
node test.js
node test-chunks.js
node test-error.js
The output of each test script is sent to the console.
Error recovery and handling
This library will throw on many errors including:
- Buffer not provided for parsing
- Calling a data accessor on non-existant data such as invalid elevations or azimuths
- A successfully parsed file that did not contain any data
- A cursory check on data validity is done by checking the ICAO identifier of each record in the file before further parsing occurs.
- Basic file length checks against offsets and block lengths listed in the file.
The Nexrad archives and chunks do contain errors when read from the Unidata archives in s3 buckets
s3://noaa-nexrad-level2ands3://unidata-nexrad-level2-chunks/. A very basic attempt is made to detect these errors, discard the affected record and find the begining of the next record. This does not always succeeded. The following are the possible outcomes: - Successful error detection and skipping to a known good block.
- Logs to console
Invlaid record idorInvalid block type - Returns as much data that could be parsed with some gaps in data. The actual gaps are not logged. A manual scan of the
Level2Radar.data[] arrayslooking at Azimuths would need to be performed to find the gaps in data. However any program calling this routine should be considering theLevel2Radar.data[].azimuthdata for further processing and thus should be unaffected. Level2Data.hasGapsis set totrue
- Logs to console
- Error detection with no skipping to a known good block
- Logs to console
Invalid record idorInvalid block id - Later logs to console
Unable to recover message - Returns as much data that could be parsed.
Level2Data.isTruncated is set totrueThe scripttest-error.jscan be run to test some of this functionality. It parses data in./data/messagesizeerror`.
- Logs to console
Supported Messages
Nexrad data is stored as message types. This package currently processes the following messages.
| Message | Title | Description |
|---|---|---|
| 1 | Digital Radar Data | Reflectivity and velocity data. Replaced by message 31 in 2008 which supports a higher resolution. |
| 2 | RDA Status | |
| 5 | Volume Coverage Pattern | Overview of the scanning paramaters |
| 7 | Volume Coverage Pattern | Overview of the scanning paramaters |
| 31 | Digital Radar Data Generic Format | Reflectivity and velocity data |
Acknowledgements
This work is based on the project of Unidata and nexrad-radar-data