Skip to content

Commit 47090f8

Browse files
committed
add 61.ntv
1 parent 811e164 commit 47090f8

File tree

7 files changed

+119
-1
lines changed

7 files changed

+119
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ I've developed parsing algorithms for that the products that I needed most for m
9494
|56|N0S, N1S, N2S, N3S|Storm relative velocity|
9595
|58|NTP|Storm Tracking Information|
9696
|59|NHI|Hail Index|
97+
|61|NTV|Tornadic Vortex Signature|
9798
|62|NSS|Storm Structure|
9899
|78|N1P|One-hour precipitation|
99100
|80|NTP|Storm Total Rainfall Accumulation|

data/sn.0011

2.89 KB
Binary file not shown.

data/sn.0012

2.89 KB
Binary file not shown.

src/packets/c.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const code = 12;
2+
const description = 'Tornado Vortex Signautre';
3+
4+
const parser = (raf) => {
5+
// packet header
6+
const packetCode = raf.readUShort();
7+
const lengthOfBlock = raf.readShort();
8+
9+
// test packet code
10+
if (packetCode !== code) throw new Error(`Packet codes do not match ${code} !== ${packetCode}`);
11+
12+
// parse the data
13+
const result = {
14+
points: [],
15+
};
16+
// also providethe packet code in hex
17+
result.packetCodeHex = packetCode.toString(16);
18+
19+
// read all special symbols
20+
let i = 0;
21+
for (i = 0; (i < lengthOfBlock) && (i + 4 <= lengthOfBlock); i += 4) {
22+
const iStartingPoint = raf.readShort();
23+
const jStartingPoint = raf.readShort();
24+
result.points.push({
25+
iStartingPoint,
26+
jStartingPoint,
27+
});
28+
}
29+
30+
// skip past extra data
31+
raf.skip(result.lengthOfBlock - i);
32+
33+
return result;
34+
};
35+
36+
module.exports = {
37+
code,
38+
description,
39+
parser,
40+
};

src/products/61/formatter.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// format the text data provided
2+
// extract data from lines that follow this format
3+
// " TVS F0 74/ 52 35 52 52/ 4.9 >11.1 < 4.9/ 16.0 16/ 4.9 "
4+
// using this header information
5+
// " Feat Storm AZ/RAN AVGDV LLDV MXDV/Hgt Depth Base/Top MXSHR/Hgt "
6+
// " Type ID (deg,nm) (kt) (kt) (kt,kft) (kft) (kft) (E-3/s,kft) "
7+
// returns an array of objects {
8+
// type: feature type
9+
// id: id of storm assigned by algorithm
10+
// az: azimuth
11+
// range: range to storm
12+
// avgdv
13+
// lldv
14+
// mxdv
15+
// mxdvhgt
16+
// depth
17+
// base
18+
// top
19+
// maxshear
20+
// maxshearheight
21+
// }
22+
23+
module.exports = (data) => {
24+
// extract relevant data
25+
const pages = data?.tabular?.pages;
26+
if (!pages) return {};
27+
const result = {};
28+
29+
// format line by line
30+
pages.forEach((page) => {
31+
page.forEach((line) => {
32+
// extrat values
33+
const rawMatch = line.match(/ {2}([A-Z0-9]{3}) {4}([A-Z][0-9]) {3,5}([0-9.]{1,3})\/ {0,2}([0-9.]{1,3}) {3,5}([0-9.]{1,3}) {3,5}([0-9.]{1,3}) {3,5}([0-9.]{1,3})\/ {0,2}([0-9.]{1,3})[ <>]{4}([0-9.]{4})[ <>]{3,4}([0-9.]{3,4})\/ {0,2}([0-9.]{1,4}) {3,5}([0-9.]{2,4})\/ {0,2}([0-9.]{1,4})/);
34+
if (!rawMatch) return;
35+
36+
// format the result
37+
const [, type, id, az, range, avfdv, lldv, mxdv, mvdvhgt, depth, base, top, maxshear, maxshearheight] = [...rawMatch];
38+
// store to array
39+
result[id] = {
40+
type,
41+
az: +az,
42+
range: +range,
43+
avfdv: +avfdv,
44+
lldv: +lldv,
45+
mxdv: +mxdv,
46+
mvdvhgt: +mvdvhgt,
47+
depth: +depth,
48+
base: +base,
49+
top: +top,
50+
maxshear: +maxshear,
51+
maxshearheight: +maxshearheight,
52+
};
53+
});
54+
});
55+
56+
return {
57+
tvs: result,
58+
};
59+
};

src/products/61/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const code = 61;
2+
const abbreviation = ['NTV'];
3+
const description = 'Tornadic Vortex Signature';
4+
const formatter = require('./formatter');
5+
6+
module.exports = {
7+
code,
8+
abbreviation,
9+
description,
10+
formatter,
11+
12+
productDescription: {
13+
},
14+
};

test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const parser = require('./src');
1414
// const file = fs.readFileSync('./data/DTW_NHI_2021_04_08_19_47');
1515
// const file = fs.readFileSync('./data/TBW_NHI_2021_04_19_19_02');
1616

17+
// 61 NTV
18+
// const file = fs.readFileSync('./data/sn.0011');
19+
const file = fs.readFileSync('./data/sn.0012');
20+
1721
// 62 NSS
1822
// const file = fs.readFileSync('./data/TBW_NSS_2021_04_19_19_02');
1923

@@ -27,7 +31,7 @@ const parser = require('./src');
2731
// const file = fs.readFileSync('./data/LOT_N0H_2021_01_31_11_06_30');
2832

2933
// 172 DTA Storm Total Precipitation
30-
const file = fs.readFileSync('./data/LOT_DTA_2021_02_28_15_05_33');
34+
// const file = fs.readFileSync('./data/LOT_DTA_2021_02_28_15_05_33');
3135
// const file = fs.readFileSync('./data-error/LOT_DTA_2021_05_08_03_47_25'); // has error
3236
// const file = fs.readFileSync('./data-error/LOT_DAA_2021_05_08_03_40_29'); // different radial packet from standard = 1, no radial data
3337

0 commit comments

Comments
 (0)