import ee
import geemap.core as geemap13 Subcriterion B1
Using python and Earth Engine
This document shows an example calculation of criterion B using data assets and functions available on Earth Engine (EE) from a notebook running Python.
13.1 Import python modules
13.2 Initialize EE session
myproject='ee-jrferrerparis'ee.Authenticate()
ee.Initialize(project=myproject)13.3 Earth Engine assets
Here we will use three assets, two of them are available in Earth Engine’s data catalog:
gfc=ee.Image('UMD/hansen/global_forest_change_2024_v1_12')
countries=ee.FeatureCollection('USDOS/LSIB_SIMPLE/2017')The third asset has been uploaded from (FerrerParis20025?) into my personal project
macrogroups=ee.Image('projects/{}/assets/IVC_NS_v7_270m_cea'.format(myproject))13.4 Prepare the data
First we need to select the target macrogroup, in this case the raster value is the ID, so value 563 returns the potential distribution of M563:
MG563 = macrogroups.eq(563);Then we define a region of interest, in this case we know this macrogroup is present in three countries: Colombia, Venezuela, and Trinidad and Tobago:
region = countries.filter(
ee.Filter.inList('country_na', ['Colombia','Venezuela', 'Trinidad & Tobago'])
)Then we need to get the latest tree cover extent that best approximate the current distribution of forest areas within the macrogroup otential distribution. We use the band treecover2000 with values greater than 10%, substract the pixels from the loss band and add the pixels from the gain band. Finally we apply the mask for the potential distribution of our target macrogroup.
MF563_dist = (
gfc
.select(['treecover2000'])
.gt(10)
.subtract(gfc.select(['loss']))
.add(gfc.select(['gain']))
.mask(MG563)
)13.5 Calculate Extent of Occurrence
params = {'scale': 30, 'maxPixels':1e10}res_km2 = (params['scale']*params['scale'])/1e6EOO = MF563_dist.updateMask(1).reduceToVectors(
scale= 1000,
geometry= region,
geometryType= 'polygon',
).geometry().convexHull(maxError=1);EOO.area().divide(1e6).format('%.2f')- 1267297.06
13.6 Visualise results
This code is useful to visualise the layers in jupyter notebooks.
Visualisation currently not working with quarto or Visual Studio Code
m = geemap.Map()
m.centerObject(EOO)
m.add_layer(
MF563_dist,
{'min': 1, 'max': 3, 'palette': ['0000FF', '00FF00', 'FF0000']},
'raster',
)display_image = ee.Image(0).updateMask(0).paint(EOO, '000000', 3)
m.add_layer(display_image, {'palette': '000000'}, 'vectors')
m