Show JTWC cyclones: western Pacific, Indian Ocean and Southern Hemisphere (#1891)

* Show JTWC warnings in Cyclone advisories

Cyclone advisories now also read the Joint Typhoon Warning Center (keyless,
public domain) for the western North Pacific, North Indian Ocean and Southern
Hemisphere, beside NHC and CPHC.

- server/providers/jtwc.js reads JTWC's warnings feed, each storm's JMV 3.0
  warning (.tcw) and its overlay (.kmz). /api/cyclones merges them with NHC's:
  one storm per id, NHC's advisory where NHC lists the storm. A failed JTWC
  read keeps its last storms, marked stale, and never hides NHC's.
- Storms carry an agency. A JTWC warning has no cone; its 34-knot wind danger
  area is drawn as its own dashed area and named for the selected storm.
- A JTWC storm's card notes that the regional centre's warning is official
  and that JTWC winds are 1-minute averages. Source and coverage wording names
  both agencies.
- Each storm is served while its own advisory is usable (12 hours for NHC,
  13 for JTWC).

* Keep one JTWC failure from affecting other storms or NHC

- A storm whose JTWC warning cannot be read or parsed is left out and the
  others are shown; the read fails only when every listed storm's does.
- JTWC is read under its own 8-second deadline. A failed or slow JTWC read
  keeps JTWC's last good storms and never delays, fails or stales the NHC
  answer.
- Danger-swath longitudes past ±180 (a ring crossing the antimeridian) are
  wrapped into -180..180 instead of dropping the ring.

* Add the changelog entry for JTWC cyclones
This commit is contained in:
Sameh Khamis authored and GitHub committed 2026-11-20 21:48:15 -08:00
1 parent ae212e5b63
commit 5608b12a25
33 files changed
+1699 -201

No files matched your search

+161 -2
View File
@@ -74,7 +74,12 @@ function collections(adv = '10') {
}
function install(options = {}, preview = false) {
let handler;
const plugin = cycloneProxy({ now: () => NOW, ...options });
// JTWC has its own tests below; these cover NHC alone.
const plugin = cycloneProxy({
now: () => NOW,
readJtwc: async () => [],
...options,
});
plugin[preview ? 'configurePreviewServer' : 'configureServer']({
middlewares: {
use(path, callback) {
@@ -297,7 +302,7 @@ test('dev and preview serve only fixed bounded NOAA queries, caching a complete
const snapshot = body(await request());
assert.equal(snapshot.unavailable, false);
assert.equal(snapshot.stale, false);
assert.match(snapshot.coverage, /not worldwide/);
assert.match(snapshot.coverage, /JTWC: western North Pacific/);
assert.equal(snapshot.storms[0].geometryStatus, 'current');
assert.equal(snapshot.fetchedAt, NOW);
assert.equal(calls.length, 4);
@@ -491,3 +496,157 @@ test('shared refresh caps waiting consumers and rejects redirects without exposi
});
assert.equal(body(await redirected.request()).unavailable, true);
});
function jtwcStorm(overrides = {}) {
return {
id: 'sh042027',
agency: 'jtwc',
name: 'Xavier',
classification: 'TC',
basin: 'SH',
position: { longitude: -164.5, latitude: -11.6 },
positionAt: TIME,
advisoryNumber: '15',
issuedAt: TIME,
windKt: 45,
pressureHpa: 995,
movement: { directionDegrees: 245, speedKt: 4 },
advisoryUrl: 'https://www.metoc.navy.mil/jtwc/products/sh0427web.txt',
outlookUrl: 'https://www.metoc.navy.mil/jtwc/products/abpwweb.txt',
geometryStatus: 'pending',
geometryAdvisoryNumber: null,
forecastPoints: [],
track: null,
cone: null,
dangerArea: null,
...overrides,
};
}
test('JTWC storms join NHC’s, and NHC’s advisory wins for a storm both list', async () => {
const crossing = jtwcStorm({
id: 'ep152026',
basin: 'EP',
name: 'JTWC copy',
});
const { request } = install({
fetchImpl: fetcher(),
readJtwc: async () => [jtwcStorm(), crossing],
});
const snapshot = body(await request());
assert.deepEqual(
snapshot.storms.map((storm) => [storm.id, storm.agency, storm.name]),
[
['ep152026', 'nhc', 'Fifteen-E'],
['sh042027', 'jtwc', 'Xavier'],
],
);
assert.equal(snapshot.stale, false);
assert.match(snapshot.source, /JTWC/);
assert.match(snapshot.attribution, /Joint Typhoon Warning Center/);
});
test('JTWC reads go through the bounded fetch with no redirects', async () => {
const calls = [];
const { request } = install({
fetchImpl: async (url, options) => {
calls.push({ url, options });
if (url.includes('jtwc.rss'))
return new Response(
'<rss><item><guid>NWPAC-NIO-WARNINGS</guid>No Current Tropical Cyclone Warnings</item><item><guid>EPAC-CPAC-WARNINGS</guid>No Current Tropical Cyclone Warnings</item><item><guid>SH-WARNINGS</guid>No Current Tropical Cyclone Warnings</item></rss>',
);
return fetcher()(url, options);
},
readJtwc: undefined,
});
const snapshot = body(await request());
assert.equal(snapshot.stale, false);
const jtwc = calls.filter(({ url }) => url.includes('metoc.navy.mil'));
assert.deepEqual(
jtwc.map(({ url }) => url),
['https://www.metoc.navy.mil/jtwc/rss/jtwc.rss'],
);
assert.equal(jtwc[0].options.redirect, 'error');
});
test('a failed JTWC read keeps its last storms and leaves NHC’s answer fresh', async () => {
let fail = false;
let clock = NOW;
const { request } = install({
fetchImpl: fetcher(),
now: () => clock,
readJtwc: async () => {
if (fail) throw new Error('jtwc down');
return [jtwcStorm()];
},
});
assert.equal(body(await request()).storms.length, 2);
fail = true;
clock += 6 * 60_000;
const kept = body(await request());
assert.equal(kept.stale, false);
assert.equal(kept.reason, null);
assert.deepEqual(
kept.storms.map((storm) => storm.id),
['ep152026', 'sh042027'],
);
// Past their use, both advisories leave the cached answer.
clock = Date.parse(TIME) + 13 * 3600_000 + 60_000;
const later = body(await request());
assert.deepEqual(
later.storms.map((storm) => storm.id),
[],
);
});
test('a cached answer drops each storm whose own advisory is past use, not all of them', async () => {
let up = true;
let clock = NOW;
const { request } = install({
fetchImpl: async (url, options) => {
if (!up) throw new Error('down');
return fetcher()(url, options);
},
now: () => clock,
readJtwc: async () => [
jtwcStorm({ issuedAt: new Date(NOW - 30 * 60_000).toISOString() }),
],
});
assert.equal(body(await request()).storms.length, 2);
up = false;
// 12 h 10 min after the NHC advisory: NHC's is past use, JTWC's is not.
clock = Date.parse(TIME) + 12 * 3600_000 + 10 * 60_000;
const cached = body(await request());
assert.equal(cached.stale, true);
assert.deepEqual(
cached.storms.map((storm) => storm.id),
['sh042027'],
);
});
test('a JTWC that hangs or answers 500 leaves NHC’s answer unchanged', async (t) => {
const nhcOnly = body(await install({ fetchImpl: fetcher() }).request());
assert.equal(nhcOnly.stale, false);
const jtwcCalls = [];
for (const mode of ['500', 'hang']) {
const { request } = install({
readJtwc: undefined,
jtwcTimeoutMs: 20,
fetchImpl: async (url, options) => {
if (!String(url).includes('metoc.navy.mil'))
return fetcher()(url, options);
jtwcCalls.push(mode);
if (mode === '500') return new Response('down', { status: 500 });
// Hangs until its own deadline aborts it.
return new Promise((_, reject) =>
options.signal.addEventListener('abort', () =>
reject(Object.assign(new Error('aborted'), { name: 'AbortError' })),
),
);
},
});
const answer = body(await request());
assert.deepEqual(answer, nhcOnly, `JTWC ${mode}`);
}
assert.deepEqual(jtwcCalls, ['500', 'hang']);
});
+1 -1
View File
@@ -563,7 +563,7 @@ export const DATA_CREDITS = [
},
{
key: 'weather-cyclones',
html: 'Cyclone advisories: <a href="https://www.nhc.noaa.gov/" target="_blank" rel="noopener">NOAA/NWS NHC / CPHC</a> · Atlantic and eastern/central North Pacific. Forecast center uncertainty, not storm size.',
html: 'Cyclone advisories: <a href="https://www.nhc.noaa.gov/" target="_blank" rel="noopener">NOAA/NWS NHC / CPHC</a> · Atlantic and eastern/central North Pacific; <a href="https://www.metoc.navy.mil/jtwc/jtwc.html" target="_blank" rel="noopener">Joint Typhoon Warning Center</a> · western North Pacific, North Indian Ocean, Southern Hemisphere. The NHC cone is forecast center uncertainty, not storm size.',
},
{
key: 'weather-lightning',