FIRMS quickstart — recent active fires¶
Fetch recent active-fire detections (MODIS / VIIRS) from NASA FIRMS through the earthlens FIRMS backend, and plot the fire pixels coloured by fire radiative power (FRP).
FIRMS is a vector backend: download() returns a pyramids FeatureCollection (a geopandas.GeoDataFrame, CRS EPSG:4326), one row per fire pixel.
Setup¶
Pull in the imports up front: EarthLens is the unified entry point and matplotlib.pyplot is used for the final scatter. We also prepare an output directory — FIRMS is a file-writing-plus-in-memory vector backend, so download() writes the detections to firms_output/ and returns them as a GeoDataFrame.
import datetime as dt
import os
from pathlib import Path
import holoviews as hv
import matplotlib.pyplot as plt
from digitalearth.interactive import InteractiveMap
from earthlens.core import EarthLens
# Registers HoloViews' Bokeh notebook hooks. Without it an InteractiveMap has no
# display path and the cell renders nothing at all.
hv.extension('bokeh')
# Off the system drive; override with EARTHLENS_CACHE.
OUT_DIR = Path(os.environ.get('EARTHLENS_CACHE', 'D:/earthlens-cache')) / 'firms'
OUT_DIR.mkdir(parents=True, exist_ok=True)
Credentials¶
FIRMS needs a free MAP_KEY (https://firms.modaps.eosdis.nasa.gov/api/map_key/). Set FIRMS_MAP_KEY in your environment; the live cells below skip cleanly when it is absent, so the notebook never fails offline.
HAS_KEY = bool(os.environ.get('FIRMS_MAP_KEY'))
print('FIRMS_MAP_KEY set:', HAS_KEY)
Query¶
variables is a list of FIRMS sensor codes (not data variables). We use the 375 m VIIRS S-NPP near-real-time sensor over Southern California for a recent 7-day window. FIRMS caps requests at 10 days / one sensor, but the backend chunks longer windows transparently.
Date window¶
FIRMS near-real-time retains only the most recent ~2 months, so we anchor the window to a recent 7-day span ending today.
TODAY = dt.date.today()
START = (TODAY - dt.timedelta(days=7)).strftime('%Y-%m-%d')
END = TODAY.strftime('%Y-%m-%d')
Build the request and download¶
We build the EarthLens request first — source, sensor (variables), date window, bounding box, and output path — then call download() as a separate step. The whole thing stays inside a guard so the notebook skips cleanly when no MAP_KEY is set or the live query fails. The result is written to firms_output/ and returned in memory.
fires = None
if HAS_KEY:
try:
request = EarthLens(
data_source='firms',
variables=['VIIRS_SNPP_NRT'],
start=START,
end=END,
aoi=[-119.0, 33.0, -117.0, 35.0],
path=OUT_DIR,
)
fires = request.download(progress_bar=False)
print('detections:', len(fires))
except Exception as exc: # keep the notebook safe offline
print('skipped live query:', exc)
Inspect the detections¶
Every row is one fire pixel with a normalised confidence_pct and frp (MW).
if fires is not None and len(fires):
cols = [
'acq_datetime',
'sensor',
'confidence',
'confidence_pct',
'brightness_k',
'frp',
'daynight',
'geometry',
]
display(fires[cols].head())
print('CRS:', fires.crs)
Plot the fire pixels coloured by FRP¶
Plotting the GeoDataFrame directly with column='frp' colours each detection by its fire radiative power, so the most intense pixels stand out.
if fires is not None and len(fires):
ax = fires.plot(column='frp', cmap='inferno', markersize=18, alpha=0.7, legend=True)
ax.set_title(f'FIRMS VIIRS detections, {START} to {END} (colour = FRP, MW)')
ax.set_xlabel('longitude')
ax.set_ylabel('latitude')
plt.show()
Inspecting individual detections — Digital-Earth's interactive tier¶
The scatter above answers "where were the fires"; it cannot answer "what is that one". Every detection carries a brightness, a confidence, an FRP and an acquisition time, and a static PNG shows none of them.
digitalearth.interactive.InteractiveMap renders the same points through HoloViz over an XYZ basemap, so
the map pans and zooms and hover puts each detection's own attributes under the cursor. The rasterize
threshold means this keeps working when a query returns hundreds of thousands of detections instead of a
few hundred — past the threshold the points are aggregated server-side into an image rather than shipped to
the browser individually.
if fires is not None and len(fires):
fire_map = (
InteractiveMap(width=860, height=560)
.tiles('CartoDark')
.points(fires, column='frp', cmap='inferno', size=7)
.hover(
tooltips=[
('acquired', '@acq_datetime{%F %H:%M}'),
('FRP (MW)', '@frp{0.0}'),
('brightness (K)', '@brightness_k{0.0}'),
('confidence', '@confidence'),
('day/night', '@daynight'),
],
formatters={'@acq_datetime': 'datetime'},
)
.colorbar()
)
# Also written as a standalone page, for sending to someone without the notebook.
print('standalone copy:', fire_map.save(str(OUT_DIR / 'firms_detections.html')))
# Pan, zoom, and hover any detection to read its own acquisition time, FRP,
# brightness and confidence. The last expression is the map, so HoloViews renders
# it here rather than it being a picture of a map.
fire_map if fires is not None and len(fires) else 'no detections to map'