Visualizing NCEO Aboveground Woody Biomass 2017 prioritization areas

Explores NCEO Aboveground Woody Biomass priority areas in Guinea using zonal statistics.
Author

Kathryn Berger

Published

March 20, 2023

Run this notebook

You can launch this notebook in VEDA JupyterHub by clicking the link below.

Launch in VEDA JupyterHub (requires access)

Learn more

Inside the Hub

This notebook was written on the VEDA JupyterHub and as such is designed to be run on a jupyterhub which is associated with an AWS IAM role which has been granted permissions to the VEDA data store via its bucket policy. The instance used provided 16GB of RAM.

See (VEDA Analytics JupyterHub Access)[https://nasa-impact.github.io/veda-docs/veda-jh-access.html] for information about how to gain access.

Outside the Hub

The data is in a protected bucket. Please request access by emailng aimee@developmentseed.org or alexandra@developmentseed.org and providing your affiliation, interest in or expected use of the dataset and an AWS IAM role or user Amazon Resource Name (ARN). The team will help you configure the cognito client.

You should then run:

%run -i 'cognito_login.py'

Approach

  1. Query STAC API and explore item contents for a given collection
  2. Read and access the data
  3. Visualize the collection with hvplot
  4. Run zonal statistics on collection using rasterstats
  5. Visualize resultant zonal statistics on a choropleth map

About the Data

The NCEO Aboveground Woody Biomass 2017 dataset is a map for Africa at 100 m spatial resolution which was developed using a combination of LiDAR, Synthetic Aperture Radar (SAR) and optical based data. Aboveground woody biomass (AGB) plays an key role in the study of the Earth’s carbon cycle and response to climate change. Estimation based on Earth Observation measurements is an effective method for regional scale studies and the results are expressed as dry matter in Mg ha-1.

Important Note: Users of this dataset should keep in mind that the map is a continental-scale dataset, generated using a combination of different remote sensing data types, with a single method for the whole study area produced in 2017. Users, therefore, should understand that accuracy may vary for different regions and vegetation types.

The Case Study - Guinea

Mapping and understanding the spatial distribution of AGB is key to understanding carbon dioxide emissions from tropical deforestation through the loss of woody carbon stocks. The resulting carbon fluxes from these land-use changes and vegetation degradation can have negative impacts on the global carbon cycle. Change analysis between AGB maps overtime can display losses in high biomass forests, due to suspected deforestation and forest degredation.

The forests of southern Guinea are reported to have some of the highest density AGB of any forest in the world and are one of the most threatened ecoregions in Africa. Importantly, this area was also the epicenter of the 2014 Ebola outbreak, which had a lasting impact on the region. There is more and more evidence that human deforestation activities in this area may have accelerated the spread of the deadly virus as a result of increasing human-bat interactions in the region.

In this example we explore the NCEO AGB dataset for 2017, running zonal statistics at the district (administrative 2) level to understand those areas in Guinea that need greatest prioritization for protection and conservation.

Setting up the Environment

To run zonal statistics we’ll need to import a python package called rasterstats into our environment. You can uncomment the following line for installation. This cell needs only needs to be run once.

!pip install rasterstats --quiet

Querying the STAC API

from pystac_client import Client
# Provide STAC API endpoint
STAC_API_URL = "https://openveda.cloud/api/stac/"

# Declare collection of interest - NCEO Biomass
collection = "nceo_africa_2017"

Now let’s check how many total items are available.

search = Client.open(STAC_API_URL).search(collections=[collection])
items = list(search.items())
print(f"Found {len(items)} items")
Found 1 items

This makes sense as there is only one item available: a map for 2017.

# Explore the "cog_default" asset of one item to see what it contains
items[0].assets["cog_default"].to_dict()
{'href': 's3://nasa-maap-data-store/file-staging/nasa-map/nceo-africa-2017/AGB_map_2017v0m_COG.tif',
 'type': 'image/tiff; application=geotiff; profile=cloud-optimized',
 'title': 'Default COG Layer',
 'description': 'Cloud optimized default layer to display on map',
 'raster:bands': [{'scale': 1,
   'nodata': 'inf',
   'offset': 0,
   'sampling': 'area',
   'data_type': 'uint16',
   'histogram': {'max': 429,
    'min': 0,
    'count': 11,
    'buckets': [405348,
     44948,
     18365,
     6377,
     3675,
     3388,
     3785,
     9453,
     13108,
     1186]},
   'statistics': {'mean': 37.58407913145342,
    'stddev': 81.36678677343947,
    'maximum': 429,
    'minimum': 0,
    'valid_percent': 50.42436439336373}}],
 'roles': ['data', 'layer']}

Explore through the item’s assets. We can see from the data’s statistics values that the min and max values for the observed values range from 0 to 429 Mg ha-1.

Reading and accessing the data

Now that we’ve explored the dataset through the STAC API, let’s read and access the dataset itself.

import stackstac
import rioxarray


da = stackstac.stack(items[0])
da
/srv/conda/envs/notebook/lib/python3.11/site-packages/stackstac/prepare.py:408: UserWarning: The argument 'infer_datetime_format' is deprecated and will be removed in a future version. A strict version of it is now the default, see https://pandas.pydata.org/pdeps/0004-consistent-to-datetime-parsing.html. You can safely remove this argument.
  times = pd.to_datetime(
<xarray.DataArray 'stackstac-52df0ce77b6e6dbb5f28f680fe94f581' (time: 1,
                                                                band: 1,
                                                                y: 81025,
                                                                x: 78078)> Size: 51GB
dask.array<fetch_raster_window, shape=(1, 1, 81025, 78078), dtype=float64, chunksize=(1, 1, 1024, 1024), chunktype=numpy.ndarray>
Coordinates: (12/16)
  * time            (time) datetime64[ns] 8B NaT
    id              (time) <U19 76B 'AGB_map_2017v0m_COG'
  * band            (band) <U11 44B 'cog_default'
  * x               (x) float64 625kB -18.27 -18.27 -18.27 ... 51.86 51.86 51.86
  * y               (y) float64 648kB 37.73 37.73 37.73 ... -35.05 -35.05 -35.05
    proj:bbox       object 8B {-35.054059016911935, 51.86423292864056, 37.731...
    ...              ...
    proj:shape      object 8B {81024, 78077}
    start_datetime  <U25 100B '2017-01-01T00:00:00+00:00'
    raster:bands    object 8B {'scale': 1, 'nodata': 'inf', 'offset': 0, 'sam...
    title           <U17 68B 'Default COG Layer'
    description     <U47 188B 'Cloud optimized default layer to display on map'
    epsg            int64 8B 4326
Attributes:
    spec:        RasterSpec(epsg=4326, bounds=(-18.274427824843425, -35.05405...
    crs:         epsg:4326
    transform:   | 0.00, 0.00,-18.27|\n| 0.00,-0.00, 37.73|\n| 0.00, 0.00, 1.00|
    resolution:  0.0008983152841195214

In this example, we’ll explore the data contained in the NCEO AGB collection and analyze it for each of the districts in Guinea. To do this we will need to import district (administrative level 2) boundary layers from below. We will use the Humanitarian Data Exchange (HDX) site to retrieve subnational administrative boundaries for Guinea. Specifically, we will use the geoBoundaries-GIN-ADM2_simplified.geojson which can be accessed here and read them in directly using geopandas.

import geopandas as gpd

admin2_gdf = gpd.read_file(
    "https://raw.githubusercontent.com/wmgeolab/geoBoundaries/0f0b6f5fb638e7faf115f876da4e77d8f7fa319f/releaseData/gbOpen/GIN/ADM2/geoBoundaries-GIN-ADM2_simplified.geojson"
)
# check the CRS
print(admin2_gdf.crs)
EPSG:4326

Now we can use the bounds of the admin boundaries to clip the data to a box containing Guinea.

subset = da.rio.clip_box(*admin2_gdf.total_bounds)
# select the band of interest, as there is only one in this dataset we'll select the default
data_band = subset.sel(band="cog_default")
data_band
<xarray.DataArray 'stackstac-52df0ce77b6e6dbb5f28f680fe94f581' (time: 1,
                                                                y: 6104, x: 8289)> Size: 405MB
dask.array<getitem, shape=(1, 6104, 8289), dtype=float64, chunksize=(1, 1024, 1024), chunktype=numpy.ndarray>
Coordinates: (12/17)
  * time            (time) datetime64[ns] 8B NaT
    id              (time) <U19 76B 'AGB_map_2017v0m_COG'
    band            <U11 44B 'cog_default'
  * x               (x) float64 66kB -15.09 -15.09 -15.08 ... -7.642 -7.641
  * y               (y) float64 49kB 12.68 12.68 12.67 ... 7.196 7.195 7.194
    proj:bbox       object 8B {37.73103856358817, 51.86423292864056, -35.0540...
    ...              ...
    start_datetime  <U25 100B '2017-01-01T00:00:00+00:00'
    raster:bands    object 8B {'scale': 1, 'nodata': 'inf', 'offset': 0, 'sam...
    title           <U17 68B 'Default COG Layer'
    description     <U47 188B 'Cloud optimized default layer to display on map'
    epsg            int64 8B 4326
    spatial_ref     int64 8B 0
Attributes:
    spec:        RasterSpec(epsg=4326, bounds=(-18.274427824843425, -35.05405...
    resolution:  0.0008983152841195214
import hvplot.xarray

biomass = data_band.squeeze()
biomass

biomass.hvplot(
    x="x",
    y="y",
    coastline=True,
    rasterize=True,
    cmap="viridis",
    widget_location="bottom",
    frame_width=600,
)