Show active fires in World with FIRMS data
In this notebook we use the last 7d of active fires.
Where get data? You can ask a specific location in history with the links below: Last fires data Ask archives data
Download the last 7 days into a file
const r = await fetch('https://firms.modaps.eosdis.nasa.gov/data/active_fire/modis-c6.1/csv/MODIS_C6_1_Global_7d.csv')
const content = await r.text();
const json = csvJSON(content, ',');
// filter cols and convert CSV to JSON
_fs.writeFileSync(__dirname + '/modis-active-fire.json', JSON.stringify(filter(json, ["latitude", "longitude", "acq_date"])));
print("Done!");
Show last 7 days of active fires
const content = require("./modis-active-fire.json");
async function listDays(start, end) {
for(var arr=[], dt=new Date(start);
dt<=new Date(end);
dt.setDate(dt.getDate()+1)){
arr.push(new Date(dt).toISOString().slice(0,10));
}
return arr;
}
function show(date) {
const last7d = content.filter(e=>e.acq_date.startsWith(date));
var data = [{
type: 'scattergeo',
lon: last7d.map(r=>r.longitude),
lat: last7d.map(r=>r.latitude),
marker: {size: 2, color:'red'},
}];
var layout = {
geo: {
// Africa
//center: { lat: -16.400190, lon: 22.515316},
//projection: {
// scale: 1.5
//},
scope: 'world', // "africa" | "asia" | "europe" | "north america" | "south america" | "usa" | "world"
resolution: 50,
showland: true,
showocean: true,
//bgcolor:"#46484A",
},
title: date,
//paper_bgcolor:"#46484A",
};
Plotly.newPlot(el, data, layout);
}
const today = new Date(); // new Date("2022-08-24")
const lastWeek = new Date();
lastWeek.setDate(today.getDate()-7); // new Date("2022-08-18")
var daylist = await listDays(
lastWeek,
today);
for(const day of daylist) {
show(day);
await sleep(500);
}
// convert csv to JSON
const allfires = __dirname + "/fire_archive_M-C61_419532.csv";
const content = _fs.readFileSync(allfires, 'utf8');
const json = csvJSON(content);
_fs.writeFileSync(__dirname+"/fire_archive_M-C61_419532.json", JSON.stringify(json));
//hide
// All France fires
const content = require("./fire_archive_M-C61_419532.json");
const countByYear =
// get year from date string
content.map(f=>f.acq_date.slice(0,4))
// group by year
.reduce((total, value) => {
total[value] = (total[value] || 0) + 1;
return total;
}, {});
const data = [];
for (const [key, value] of Object.entries(countByYear)) {
data.push({x:key, y:value});
}
lineChart({
horizontal: false,
series: [
{data: data}
],
});