Skip to content

Commit

Permalink
Added experimental STORMS database support
Browse files Browse the repository at this point in the history
  • Loading branch information
StrawberryMaster committed Nov 16, 2024
1 parent 3d2a23b commit b876a4d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ <h3>Stage</h3>
<option>ATCF</option>
<option>IBTrACS</option>
<option>RSMC</option>
<option>STORMS</option>
</select>
</div>
<div id="page2-content">
Expand Down Expand Up @@ -261,6 +262,7 @@ <h3>Stage</h3>
<script src="static/js/rsmc.js"></script>
<script src="static/js/hurdat.js"></script>
<script src="static/js/ibtracs.js"></script>
<script src="static/js/storms.js"></script>
<script src="static/js/file_upload.js"></script>

<script src="static/js/manual_input.js"></script>
Expand Down
2 changes: 2 additions & 0 deletions static/js/file_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function mapFromFile(data, type, accessible) {
parsed = parseIbtracs(data);
} else if (type === "rsmc") {
parsed = parseRsmc(data);
} else if (type === "storms") {
parsed = parseStorms(data)
} else {
return;
}
Expand Down
60 changes: 60 additions & 0 deletions static/js/storms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const WIND_SPEED_THRESHOLDS = {
TD: 34,
TS: 64,
C1: 83,
C2: 96,
C3: 113,
C4: 137
};
const MS_TO_KNOTS = 1.943844;

function windSpeedToCategory(speed) {
const knots = speed * MS_TO_KNOTS;

for (const [category, threshold] of Object.entries(WIND_SPEED_THRESHOLDS)) {
if (knots < threshold) return category;
}
return 'C5';
}

function getStormsShape(category) {
if (['TD', 'TS'].includes(category) || category.startsWith('C')) {
return 'circle';
}
console.error("Unknown STORMS category shape: " + category);
return 'triangle';
}

function formatLatitude(lat) {
return `${Math.abs(lat).toFixed(1)}${lat < 0 ? 'S' : 'N'}`;
}

function formatLongitude(lon) {
const adjustedLon = lon > 180 ? lon - 360 : lon;
return `${Math.abs(adjustedLon).toFixed(1)}${adjustedLon < 0 ? 'W' : 'E'}`;
}

function parseStorms(data) {
const lines = data.trim().split('\n');
const parsed = [];

lines.forEach(line => {
const cols = line.trim().split(/[\s,]+/).filter(col => col.length > 0);

if (cols.length >= 13) {
const tcNumber = cols[2].padStart(2, '0');
const windSpeedKnots = parseFloat(cols[8]) * MS_TO_KNOTS;
const category = windSpeedToCategory(parseFloat(cols[9]));

parsed.push({
name: tcNumber,
shape: getStormsShape(category),
category: speedToCat(windSpeedKnots),
latitude: formatLatitude(parseFloat(cols[5])),
longitude: formatLongitude(parseFloat(cols[6])),
});
}
});

return parsed;
}

0 comments on commit b876a4d

Please sign in to comment.