Visualizing MapBiomas Datasets#
MapBiomas datasets are available as an EE asset as part of the awesome GEE community catelogue
See https://gee-community-catalog.org/projects/mapbiomas/ for source documentation
Copyright 2024 Ian Housman, Maria Olga Borja
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
try:
import geeViz.geeView as geeView
except:
!python -m pip install geeViz
import geeViz.geeView as geeView
# Module to help with class codes, names, colors and collapsing levels of MapBiomas data
import geeViz.examples.mapBiomasLookup as mbl
ee = geeView.ee
Map = geeView.Map
print('done')
Initializing GEE
Cached project id file path: C:\Users\ihousman\.config\earthengine\credentials.proj_id
Cached project id: lcms-292214
*** Earth Engine *** Share your feedback by taking our Annual Developer Satisfaction Survey: https://google.qualtrics.com/jfe/form/SV_0JLhFqfSY1uiEaW?source=Init
Successfully initialized
geeViz package folder: c:\Users\ihousman\AppData\Local\Programs\Python\Python311\Lib\site-packages\geeViz
done
Make a basic viewer#
Source information can be found here: https://gee-community-catalog.org/projects/mapbiomas
This example mosaics most available MapBiomas data
geeViz will automatically generate legends and query lookups using
"autoViz" : True
in the visualization paramsOnce the map loads, you can annimate the time series using the time lapse controls
Double-clicking on the map will show the values for the pixel you clicked on
# Datasets available here: https://gee-community-catalog.org/projects/mapbiomas/
Map.clearMap()
# Specify which years to show
years = list(range(1985, 2023 + 1))
# Specify projection to use for zonal summaries and map querying
# Be sure to leave one of scale or transform as None
crs = "EPSG:4326"
transform = None
scale = 30
# Choose which level to show (1-4)
# Only 1 and 2 work with on-the-fly Sankey charts
remap_level = 1
Map.setQueryCRS(crs)
if transform == None:
Map.setQueryScale(scale)
else:
Map.setQueryTransform(transform)
# Bring in land use land cover datasets and mosaic them
paths = [
"projects/mapbiomas-public/assets/bolivia/collection2/mapbiomas_bolivia_collection2_integration_v1", # 1985-2023
"projects/mapbiomas-public/assets/peru/collection2/mapbiomas_peru_collection2_integration_v1", # 1985-2022
"projects/mapbiomas-public/assets/colombia/collection1/mapbiomas_colombia_collection1_integration_v1", # 1985-2022
"projects/mapbiomas-public/assets/ecuador/collection1/mapbiomas_ecuador_collection1_integration_v1", # 1985-2022
"projects/mapbiomas-public/assets/venezuela/collection1/mapbiomas_venezuela_collection1_integration_v1", # 1985-2022
"projects/mapbiomas-public/assets/paraguay/collection1/mapbiomas_paraguay_collection1_integration_v1", # 1985-2022
"projects/mapbiomas-public/assets/brazil/lulc/collection9/mapbiomas_collection90_integration_v1", # 1985-2023
"projects/mapbiomas-raisg/public/collection5/mapbiomas_raisg_panamazonia_collection5_integration_v1", # 1985-2022
"projects/MapBiomas_Pampa/public/collection3/mapbiomas_uruguay_collection1_integration_v1", # 1985-2022
"projects/mapbiomas-public/assets/chile/collection1/mapbiomas_chile_collection1_integration_v1", # 2000-2022
"projects/mapbiomas-public/assets/argentina/collection1/mapbiomas_argentina_collection1_integration_v1", # 1998-2022
]
stack = ee.ImageCollection([ee.Image(p).byte() for p in paths]).toBands()
# View palettes source here:
# var palettes = require('users/mapbiomas/modules:Palettes.js');
out_band_name = "lulc"
# Bring in the names, values, and palette
remap_info = mbl.getLevelNRemap(remap_level, out_band_name)
# Function to convert a given band into a time-enabled image object
def setupLulc(yr):
img = stack.select([f".*_{yr}"]).reduce(ee.Reducer.firstNonNull()).remap(remap_info["remap_from"], remap_info["remap_to"]).rename([out_band_name]).set("system:time_start", ee.Date.fromYMD(yr, 6, 1).millis())
img = img.set(remap_info["viz_dict"])
return img
# Convert the image stack into an image collection
lulcC = ee.ImageCollection([setupLulc(yr) for yr in years])
# Add the collection to the map
Map.addLayer(lulcC, {"autoViz": True}, "MapBiomas LULC")
## Set up the map
Map.turnOnInspector()
Map.setCenter(-62.8, -3, 4)
Map.view()
Setting click query crs to: EPSG:4326
Setting click query scale to: 30
Adding layer: MapBiomas LULC
Starting webmap
Using default refresh token for geeView
Local web server at: http://localhost:8001/geeView/ already serving.
cwd a:\GEE\gee_py_modules_package\geeViz\examples
geeView URL: http://localhost:8001/geeView/?projectID=lcms-292214&accessToken=ya29.a0AeDClZBoV6RTt-kTHktaitp6cLCRopannvKr9B7F9QimHl9HpH7bQSlKU53sXETcKcw5F5qayQER5a-NS3bhiUocGlPCAoK0T4OH6kON4zdkFLv-ZFMB3-S0Hl34cOsGuljb25SUEJoSZ09ieUHPNmSPqKCvGV0V8dVSB4myMtwaCgYKATsSARESFQHGX2MiBg28W2WOQErk15VfYCK2tQ0178&accessTokenCreationTime=1732571109268
Calculating and Exporting Statistics¶#
geeViz streamlines calculating and exporting statistics
Once the map loads, you can use the
TOOLS
underArea Tools
to generate chartsCharts can be downloaded as a PNG and the underlying data can be downloaded as a CSV
Map.clearMapLayers()
Map.turnOffLayersWhenTimeLapseIsOn = False # Set this to False to avoid layers automatically turning off when a time lapse is turned on
Map.addLayer(lulcC, {'autoViz':True,'years':years,'canAreaChart':True,'areaChartParams':{'crs':crs,'scale':scale,'transform':transform}}, "MapBiomas LULC" )
# Add country boundaries as a layer to select with
countries = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level0")
Map.addSelectLayer(countries, {}, "Global Country Boundaries")
assetTerritories = ee.FeatureCollection("users/joaovsiqueira1/MAPBIOMAS/ti_uc")
Map.addSelectLayer(assetTerritories, {}, "MapBiomas Territories")
Map.turnOnAutoAreaCharting()
Map.view()
Adding layer: MapBiomas LULC
Adding layer: Global Country Boundaries
Adding layer: MapBiomas Territories
Starting webmap
Using default refresh token for geeView
Local web server at: http://localhost:8001/geeView/ already serving.
cwd a:\GEE\gee_py_modules_package\geeViz\examples
geeView URL: http://localhost:8001/geeView/?projectID=lcms-292214&accessToken=ya29.a0AcM612x6ne6BHe3XY7j9ocdXwWB_PEPsf231RSnHcDZIYEbXeST4S3SN-B8GrtpqX_fMLOLXcuM6IG2sj-nyV0WjKFU-eGMLcx25tS8NC42Z2KEGm_LkmlI-88hMcTSDCYVB1c1Qx5Rcy_1_fu8ZQpdTgS-2uRyaVIEER3BVqesaCgYKAVQSARESFQHGX2MiStNTxFwZi9bxifrWLjqNnQ0178
Create Sankey Charts#
You can also create Sankey charts and download transition matrices with geeViz
Once the map loads, you can use the
TOOLS
underArea Tools
to generate chartsYou can customize the years to include in the sankey charts under the
Area Tools Parameters
->Transition Charting Periods
Charts can be downloaded as a PNG and the underlying data can be downloaded as a CSV
Map.clearMapLayers()
# Only allow Sankey charts for levels <=2
sankey = True
if remap_level > 2:
sankey = False
Map.addTimeLapse(lulcC, {'autoViz':True,'years':years,'canAreaChart':True,'areaChartParams':{'line':True,'sankey':sankey,'crs':crs,'transform':transform,'scale':scale}}, 'MapBiomas LULC' )
countries = ee.FeatureCollection("FAO/GAUL_SIMPLIFIED_500m/2015/level0")
Map.addSelectLayer(countries, {}, "Global Country Boundaries")
assetTerritories = ee.FeatureCollection("users/joaovsiqueira1/MAPBIOMAS/ti_uc")
Map.addSelectLayer(assetTerritories, {}, "MapBiomas Territories")
Map.turnOnAutoAreaCharting()
Map.view()
Adding layer: MapBiomas LULC
Adding layer: Global Country Boundaries
Adding layer: MapBiomas Territories
Starting webmap
Using default refresh token for geeView
Local web server at: http://localhost:8001/geeView/ already serving.
cwd a:\GEE\gee_py_modules_package\geeViz\examples
geeView URL: http://localhost:8001/geeView/?projectID=lcms-292214&accessToken=ya29.a0AcM612zpiC1nWa7Q2n38SOHQdKW5xdZ5JiFJ1rtNUdM3a2YEw7zvXxMSLpW8loQT6dzHsY1sJZxYs30i5_Tlm2PZc860gyG8nfWsq-WtmVNYoeXqm6EJ0N3GDiKJBK2SZXrlhoWfODqskUCNduAdlfCTnGCUMii6JNcKAVg8U64aCgYKAQUSARESFQHGX2Mi23EXnCDVC9LkY4WTMHWm-Q0178