Skip to content

From lidar to a tree inventory

You are viewing in-progress documentation for v2. Switch to the stable version for the current production release.

The USGS 3D Elevation Program publishes airborne lidar flown over the Blackfoot River valley in Montana in 2021. In this tutorial we will turn its returns into a tree inventory: one row per tree, each with a position, a height, a diameter, a crown base height, and a species.

We will work on about half a square kilometre of river valley, building it in six calls and then inspecting what we made:

StepWhat we do
1Create a domain — the patch of ground everything else hangs off
2Run a coverage check — is there lidar here, and whose?
3Fetch a point cloud — 10.5 million returns, clipped to the domain
4Build a canopy height model — the returns rasterized to a 1 m height surface
5Detect trees — a detected inventory, one tree per treetop
6Fill in the rest — a fully attributed inventory with diameter, crown base height, and species
7Inspect the result

Every step after the first two is asynchronous: one POST starts it, and you GET the resource until its status reaches completed. So the rhythm of the whole tutorial is create → poll → use the id in the next call. In the Python SDK the poll is resource.wait(), and the Python tabs form one continuous script. You import and authenticate once in Step 1, then each step keeps the object it just made and passes it to the next.

  1. An API key. Create one in the FastFuels web app under your account settings. Set it once here and it propagates to every code block on the page: my-api-key. The SDK reads it via ff.set_api_key(...) or the FASTFUELS_API_KEY environment variable.

  2. curl, or Python with the FastFuels SDK — pip install fastfuels-sdk (v0.23.1+ for v2).

That’s all — we create everything else as we go.

A domain is the georeferenced extent every other resource belongs to. We POST a GeoJSON FeatureCollection to /domains.

We give the coordinates in UTM zone 12N (EPSG:32612) rather than longitude and latitude. Every resource we build from the domain keeps that CRS.

POST /domains
curl -X 'POST' \
'https://api.fastfuels.silvxlabs.com/v2/domains' \
-H 'accept: application/json' \
-H 'api-key: my-api-key' \
-H 'Content-Type: application/json' \
-d '{
"type": "FeatureCollection",
"name": "Blackfoot River",
"description": "About half a square kilometre of the Blackfoot River valley, Montana.",
"crs": { "type": "name", "properties": { "name": "EPSG:32612" } },
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[
[294095.0, 5198982.0],
[294785.0, 5198982.0],
[294785.0, 5199750.0],
[294095.0, 5199750.0],
[294095.0, 5198982.0]
]]
}
}
]
}'

This one returns immediately, with no job to wait for. Record the id, since every call below hangs off it: your-domain-id.

Notice the bbox in the response: 294095, 5198982 to 294785, 5199750. That is 690 m east–west by 768 m north–south, and those numbers reappear in every resource we build from here.

Domain
The domain outline over satellite imagery — 0.53 km² of the Blackfoot River valley, about 23 km east of Missoula, Montana.

Before fetching anything, we ask what the USGS 3D Elevation Program holds over this domain. The answer comes back immediately and tells us whether the fetch will succeed and what it will contain.

GET pointclouds/3dep/coverage
curl -X 'GET' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/pointclouds/3dep/coverage' \
-H 'accept: application/json' \
-H 'api-key: my-api-key'

One acquisition, MT_Statewide_P3_4_B21, covers the whole domain on its own: its contribution_fraction is 1.0.

Note the acquisition’s name. We are going to pin it in the next call.

Now we pull the returns. Passing datasets pins the fetch to the acquisition we just found, so this tutorial produces the same cloud today and next year even if USGS publishes new lidar over the valley.

POST pointclouds/3dep
curl -X 'POST' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/pointclouds/3dep' \
-H 'accept: application/json' \
-H 'api-key: my-api-key' \
-H 'Content-Type: application/json' \
-d '{
"name": "Blackfoot ALS (pinned)",
"description": "Pinned to a single 3DEP acquisition so the fetch is reproducible.",
"tags": ["blackfoot", "3dep"],
"datasets": ["MT_Statewide_P3_4_B21"]
}'

Record the id, your-point-cloud-id, and poll until status is completed.

GET the point cloud
curl -X 'GET' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/pointclouds/your-point-cloud-id' \
-H 'accept: application/json' \
-H 'api-key: my-api-key'

10,512,255 returns at 19.8 per square metre. Notice two things in that response.

First, the coverage check in Step 2 estimated 7,847,291 points, and we received 10.5 million, about a third more. The estimate comes from the acquisition’s published average density. See estimate versus delivered for the detail.

Second, point_classes lists 1, 2, 7, 9, 18, 20. Class 2 is ground and class 1 is unclassified, mostly vegetation here. Those two are what the next step needs: without ground returns, there is no surface to measure height above.

The returns themselves, coloured by height above ground:

A low oblique three-dimensional view, from the south, of a 120 metre block of the lidar point cloud, with an inset map showing where that block sits inside the domain. Brown points form a continuous ground surface and understory. Individual conifer crowns rise out of it as distinct spires, shading to green toward their tips. A low oblique three-dimensional view, from the south, of a 120 metre block of the lidar point cloud, with an inset map showing where that block sits inside the domain. Brown points form a continuous ground surface and understory. Individual conifer crowns rise out of it as distinct spires, shading to green toward their tips.

A 120 m block of the domain, holding 359,013 returns. The inset shows where the block sits. Brown points are near the ground, green points are canopy. Every second return is drawn. The full cloud covers the whole domain and holds 10,512,255 returns.

A canopy height model is a raster where each cell holds the height of the tallest return above the ground beneath it. This is the step that turns a cloud of points into a surface we can look for trees in.

POST grids/canopy/point_cloud
curl -X 'POST' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/grids/canopy/point_cloud' \
-H 'accept: application/json' \
-H 'api-key: my-api-key' \
-H 'Content-Type: application/json' \
-d '{
"source_point_cloud_id": "your-point-cloud-id",
"name": "Canopy height from 3DEP lidar",
"description": "CHM rasterized from the pinned Blackfoot point cloud.",
"tags": ["blackfoot", "chm"]
}'

Record the grid id, your-chm-grid-id, and poll it to completed.

GET the grid
curl -X 'GET' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/grids/your-chm-grid-id' \
-H 'accept: application/json' \
-H 'api-key: my-api-key'

We asked for no resolution, so the grid defaulted to 1 m: a shape of [768, 690], one cell per metre of the domain.

Now look at source.ground, which records how the ground under the canopy was found. ground_source is classification: the ground came from the class 2 returns. ground_coverage is 0.9053: 90.5% of cells had ground returns close enough to use directly, and the rest were interpolated. Read source.ground explains each field.

The chm band summary has a count of 495,428 and a nodata_count of 34,492, so 6.5% of the domain has no height at all. Those cells are the river. The CHM leaves out returns classified as water (class 9). The tallest cell is 37.64 m.

The canopy height model of the Blackfoot River domain, shaded green by height with bare ground fading into the background. Individual tree crowns appear as distinct round dots, densest in a band along both banks. A grey ribbon winds across the lower half where the river's water-classified returns are left out. The canopy height model of the Blackfoot River domain, shaded green by height with bare ground fading into the background. Individual tree crowns appear as distinct round dots, densest in a band along both banks. A grey ribbon winds across the lower half where the river's water-classified returns are left out.

The finished CHM, 10.5 million returns rasterized to 1 m. Every dot is a crown. The grey ribbon is the Blackfoot River, the 6.5% of cells with no height.

Now we look for treetops. A treetop is a local maximum in the height surface: a cell taller than everything around it. The lmf algorithm slides a window over the CHM and places one tree at each peak it finds.

Two parameters shape the result. footprint_size: 5 is the diameter of the circular window, in pixels. On our 1 m grid that is a circle 5 m across. min_height: 2 ignores anything under 2 m, so we detect trees rather than shrubs.

POST inventories/tree/chm
curl -X 'POST' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/inventories/tree/chm' \
-H 'accept: application/json' \
-H 'api-key: my-api-key' \
-H 'Content-Type: application/json' \
-d '{
"name": "Detected treetops",
"source_chm_grid_id": "your-chm-grid-id",
"algorithm": {
"name": "lmf",
"min_height": 2,
"footprint_size": 5
}
}'

Record this inventory’s id, inventory-to-complete, and poll it to completed.

GET the inventory
curl -X 'GET' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/inventories/inventory-to-complete' \
-H 'accept: application/json' \
-H 'api-key: my-api-key'

5,704 trees. We have gone from a cloud of points to a list of individual stems. Heights run from the 2 m floor we set to 37.64 m, averaging 13.2 m.

Notice that the tallest tree is exactly as tall as the tallest CHM cell, 37.642742 m in both. A detected treetop is a cell of the height surface, so detection can never return a height the CHM did not already hold.

Now notice what is missing. The columns are tree_id, x, y, and height, and forestry_metrics is null. A height surface seen from above cannot tell us how thick a trunk is, how far down the crown reaches, or what species we are looking at. Without a diameter there is no basal area, and without basal area there are no stand metrics. Step 6 fills in those columns.

A 200 metre square of the canopy height model at high magnification, with a small pink dot drawn on the peak of each detected crown. The dots sit one per crown across dense forest, thinning out toward the bare river edge along the top. A 200 metre square of the canopy height model at high magnification, with a small pink dot drawn on the peak of each detected crown. The dots sit one per crown across dense forest, thinning out toward the bare river edge along the top.

Detected treetops over a 200 m window of dense forest on the south bank, 523 of the 5,704 trees. Each dot is one row of the inventory, placed at a local maximum of the height surface.

Step 6 — Fill in what the CHM could not see

Section titled “Step 6 — Fill in what the CHM could not see”

GDAM (Generalized Dendro Allometric Model) takes each tree’s position and height and imputes the attributes lidar could not observe. We point it at the inventory we just made.

POST inventories/tree/allometry/gdam
curl -X 'POST' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/inventories/tree/allometry/gdam' \
-H 'accept: application/json' \
-H 'api-key: my-api-key' \
-H 'Content-Type: application/json' \
-d '{
"name": "Fully attributed tree inventory",
"source_tree_inventory_id": "inventory-to-complete"
}'

This creates a new inventory rather than modifying the detected one. Record its id as your-inventory-id and poll it to completed.

GET the inventory
curl -X 'GET' \
'https://api.fastfuels.silvxlabs.com/v2/domains/your-domain-id/inventories/your-inventory-id' \
-H 'accept: application/json' \
-H 'api-key: my-api-key'

Same 5,704 trees, in the same places, at the same heights. The new columns are dbh (diameter at breast height, in cm), fia_species_code, and crown_base_height (the height of the lowest live branches, in m). GDAM also returns crown_ratio, the fraction of each tree’s height that is crown.

And forestry_metrics is no longer null. Its numbers follow FIA convention rather than the metric columns above: basal area in ft²/acre, tree density in trees per acre, and quadratic mean diameter in inches. Our stand comes out at about 44 trees per acre, a basal area of about 31 ft²/acre, and a quadratic mean diameter of about 11.4 in, with pines holding about 74% of the basal area and Douglas-fir about 25%. The imputed values are random draws (see Species), so your run will land close to these numbers rather than on them.

Nothing about the stand changed between Step 5 and Step 6. The diameters now exist, and every metric that depends on them followed.

Three histograms across all 5,704 trees. Height in metres, spread from 2 m with a long tail out to 37 m. Diameter at breast height in centimetres, peaking near 20 cm and tailing out past 100 cm. Crown base height in metres, highest near zero and mostly under 5 m. Three histograms across all 5,704 trees. Height in metres, spread from 2 m with a long tail out to 37 m. Diameter at breast height in centimetres, peaking near 20 cm and tailing out past 100 cm. Crown base height in metres, highest near zero and mostly under 5 m.

Three columns across all 5,704 trees. Height is measured, and its long tail is the spread of the stand. The other two are imputed. Each tree’s value is a draw from GDAM’s model for its position and height, so their spread is the model’s, not a measurement of this stand.

Every column we just added came out of a model. Before building anything on this inventory, we look at it.

The map below draws all 5,704 trees. Click any one to see its stored values, and zoom in where the canopy is dense:

Domain Trees
Every tree in the inventory. Click a marker for its species, height, diameter, and crown base height.

Fetch the same values for the whole inventory with the data endpoints, as Parquet, CSV, or GeoJSON.

  • Detections on things that are not trees. Detection runs on a surface model, which records what is physically there rather than what is vegetation. This domain has an example, in The power line below.
  • The tree count. Our 5,704 detections over 0.53 km² are 44 trees per acre. footprint_size and min_height from Step 5 set that count.
  • Attribute ranges. Across the inventory the imputed columns span 2.2–105.7 cm dbh and 0.01–28.7 m crown_base_height, with a median dbh of 23 cm and a median crown_base_height of 2.5 m.
  • Species composition. See Species below.

A transmission line crosses the north-east of this domain, and detection has placed a chain of trees along it:

A 315 metre square of the canopy height model with detected treetops drawn as circles. Thin parallel lines run diagonally across it, and the detections lying on them are circled in pink, forming a continuous chain, while the grey circles on the surrounding round crowns are real trees. A 315 metre square of the canopy height model with detected treetops drawn as circles. Thin parallel lines run diagonally across it, and the detections lying on them are circled in pink, forming a continuous chain, while the grey circles on the surrounding round crowns are real trees.

The conductors appear in the CHM as thin parallel lines, and 95 of the 5,704 detections, 1.7% of the inventory, sit on them.

The vendor left the wires in ASPRS class 1 with the vegetation, so they appear in the CHM as canopy. Nothing in the pipeline flags these 95 detections. They stay in the inventory until you remove them, as Next steps describes.

GDAM assigned 8 species. Ponderosa pine and Douglas-fir make up 97.6% of the trees:

SpeciesFIA codeTrees
ponderosa pine1223,976
Douglas-fir2021,592
Rocky Mountain juniper6697
western larch7328
grand fir174
lodgepole pine1083
quaking aspen7462
limber pine1132

GDAM does not pick the likeliest species for a tree. It draws one at random from its model’s distribution for that position and height. The draws are seeded from the inventory’s id, so a new run of this tutorial, which creates a new inventory, gives slightly different counts. Species are model draws, not observations.

Every call above, in order, with the polling folded in:

build_inventory.py — 3DEP lidar to an attributed tree inventory
"""Blackfoot River: 3DEP lidar to a fully attributed tree inventory.
Runs the whole tutorial end to end with the FastFuels v2 SDK.
`resource.wait()` replaces the manual poll loop. It blocks until the resource
reaches `completed`, or raises if it `failed`.
"""
import fastfuels_sdk.v2 as ff
from fastfuels_sdk.v2.client_library.models import StemIsolationLmf
ff.set_api_key("my-api-key")
# 1 — the domain (Blackfoot River valley, EPSG:32612)
domain = ff.Domain.from_geojson(
{
"type": "FeatureCollection",
"crs": {"type": "name", "properties": {"name": "EPSG:32612"}},
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[294095.0, 5198982.0],
[294785.0, 5198982.0],
[294785.0, 5199750.0],
[294095.0, 5199750.0],
[294095.0, 5198982.0],
]
],
},
}
],
},
name="Blackfoot River",
description="About half a square kilometre of the Blackfoot River valley, Montana.",
)
print(f"domain {domain.id}")
# 2 — is there lidar here, and whose?
coverage = ff.point_clouds.check_3dep_coverage(domain).to_dict()
print(f"coverage {coverage['coverage_fraction']:.0%}, "
f"~{coverage['estimated_point_count']:,} points estimated")
# 3 — fetch it, pinned to one acquisition so the run is reproducible
point_cloud = ff.point_clouds.create_point_cloud_from_3dep(
domain,
datasets=["MT_Statewide_P3_4_B21"],
name="Blackfoot ALS (pinned)",
description="Pinned to a single 3DEP acquisition so the fetch is reproducible.",
tags=["blackfoot", "3dep"],
)
point_cloud.wait()
summary = point_cloud.to_dict()["summary"]
print(f"point cloud {point_cloud.id}: "
f"{summary['point_count']:,} points, {summary['density']:.1f} pts/m2")
# 4 — rasterize the canopy surface
grid = ff.grids.create_canopy_height_grid_from_point_cloud(
point_cloud,
name="Canopy height from 3DEP lidar",
description="CHM rasterized from the pinned Blackfoot point cloud.",
tags=["blackfoot", "chm"],
)
grid.wait()
ground = grid.to_dict()["source"]["ground"]
print(f"chm {grid.id}: ground from {ground['ground_source']}, "
f"{ground['ground_coverage']:.1%} covered")
# 5 — one tree per treetop
detected = ff.inventories.create_tree_inventory_from_chm_grid(
domain,
grid,
algorithm=StemIsolationLmf(min_height=2, footprint_size=5),
name="Detected treetops",
)
detected.wait()
print(f"detected {detected.id}: "
f"{[c['key'] for c in detected.to_dict()['columns']]}")
# 6 — fill in what the CHM could not see
inventory = ff.inventories.create_tree_inventory_with_gdam_allometry(
domain,
detected,
name="Fully attributed tree inventory",
)
inventory.wait()
doc = inventory.to_dict()
metrics = doc["forestry_metrics"]
print(f"inventory {inventory.id}: {[c['key'] for c in doc['columns']]}")
print(f" {metrics['tree_count']:,} trees, "
f"{metrics['tree_density']:.0f} per acre, "
f"QMD {metrics['quadratic_mean_diameter']:.1f} in")
for group in metrics["dominant_species_groups"]:
print(f" {group['basal_area_share']:.1%} {group['name']}")