From fd7eeb7308dc9812980328adb33a698b2bde14c2 Mon Sep 17 00:00:00 2001 From: Alexandra Kirk Date: Thu, 3 Oct 2024 13:35:20 -0600 Subject: [PATCH] feat(raster-api): new colormap for NLCD data --- raster_api/runtime/src/cmap_data/README.md | 52 +++++++++++++++++++++ raster_api/runtime/src/cmap_data/nlcd.npy | Bin 0 -> 1152 bytes 2 files changed, 52 insertions(+) create mode 100644 raster_api/runtime/src/cmap_data/nlcd.npy diff --git a/raster_api/runtime/src/cmap_data/README.md b/raster_api/runtime/src/cmap_data/README.md index 821038d0..91c39ecc 100644 --- a/raster_api/runtime/src/cmap_data/README.md +++ b/raster_api/runtime/src/cmap_data/README.md @@ -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) +``` diff --git a/raster_api/runtime/src/cmap_data/nlcd.npy b/raster_api/runtime/src/cmap_data/nlcd.npy new file mode 100644 index 0000000000000000000000000000000000000000..ba5c60b8bff812f03b433313eabbede08307d3a7 GIT binary patch literal 1152 zcmbR27wQ`j$;eQ~P_3SlTAW;@Zl$1JQ);NLqoAIaUsO_*m=~X4l#&V(cT3DEP6dh= zXCxM+0{I$7re-<{CYm}5wF+bcE(QjM|HNXq?D_vM-uppN{k@|{|KFU{^#3)`?A3V8 z-@Il%L9;+^%UB)%UnXAX|JI}Z1l6C}QAtn@vHrb({}54T-MMM`e|3%qUbQ=JzQ&Nx WnZE-=j99mgsv|z#j)oQPumS+nk~ZD| literal 0 HcmV?d00001