Skip to content

Commit

Permalink
feat(raster-api): new colormap for NLCD data (#433)
Browse files Browse the repository at this point in the history
### Issue

#429 

### What?

This PR adds a new colormap for NLCD data (`nlcd`) and documents how the
colormap was created.

### Why?

- The colormap definition for the categorical NLCD data was too long to
bypass firewall url parameter length rules

### Testing?

- See linked issue
  • Loading branch information
anayeaye authored Oct 3, 2024
2 parents 1d21109 + fd7eeb7 commit 96f2830
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions raster_api/runtime/src/cmap_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,55 @@ cmap_vals = my_cmap(x)[:, :]
cmap_uint8 = (cmap_vals * 255).astype('uint8')
np.save("epa-ghgi-ch4.npy", cmap_uint8)
```

##### NLCD colormap

refs:

- https://www.mrlc.gov/data/legends/national-land-cover-database-class-legend-and-description
- https://github.com/NASA-IMPACT/veda-backend/issues/429

```python
import rasterio
from rio_tiler.colormap import parse_color
import numpy as np

# The COGs in the nlcd-annual-conus collection store an internal colormap
nlcd_filename = "/vsis3/veda-data-store/nlcd-annual-conus/nlcd_2001_cog_v2.tif"

# These categories are only used to set transparency and document categories defined in colormap
# https://www.mrlc.gov/data/legends/national-land-cover-database-class-legend-and-description
nlcd_categories = {
"11": "Open Water",
"12": "Perennial Ice/Snow",
"21": "Developed, Open Space",
"22": "Developed, Low Intensity",
"23": "Developed, Medium Intensity",
"24": "Developed, High Intensity",
"31": "Barren Land (Rock/Sand/Clay)",
"41": "Deciduous Forest",
"42": "Evergreen Forest",
"43": "Mixed Forest",
"51": "Dwarf Scrub",
"52": "Shrub/Scrub",
"71": "Grassland/Herbaceous",
"72": "Sedge/Herbaceous",
"73": "Lichens",
"74": "Moss",
"81": "Pasture/Hay",
"82": "Cultivated Crops",
"90": "Woody Wetlands",
"95": "Emergent Herbaceous Wetlands"
}

with rasterio.open(nlcd_filename) as r:
internal_colormap = r.colormap(1)

cmap = np.zeros((256, 4), dtype=np.uint8)
cmap[:] = np.array([0, 0, 0, 255])
for c, v in internal_colormap.items():
if str(c) in nlcd_categories.keys():
cmap[c] = np.array(parse_color(v))

np.save("nlcd.npy", cmap)
```
Binary file added raster_api/runtime/src/cmap_data/nlcd.npy
Binary file not shown.

0 comments on commit 96f2830

Please sign in to comment.