Package: dynamic-world
dynamic-world 🛰️Wrapper package aroundGoogle's Dynamic World App[^1], to easily monitor forests and calculate their co2 storage on a near-real time.[^1]: This dataset is produced for the Dynamic World Project by Google in partnership with National Geographic Society and the World Resources Institute.Installpipinstalldynamic-worldAn external C library is required as well:GDAL. TheDockerfilealready has GDAl installed. If working locally, an easy way to install it is by runningconda install -c conda-forge gdalGoogle Earth Engine authenticationThis package runs computation on Earth Engine and needs to be authenticated beforehand. See theauthenticationfrom a Jupyter notebook, or alternatively using aprivate keycreating aservice account.UsageGiven a Forest (defined as a directory with some configuration files, see bellow), this package retrieves statistics and images of it.
SeeJupyter tutorialfor a usage example.ForestsEach forest (or "proyect") is defined inside a directory with a given name and 2 files:A forest_config.yml (name is mandatory) which looks like this:# Name of the forest/proyectname:Sample# Locations of the geojson filegeojson:'./sample.geojson'# Co2 factor: how many tons of CO2 are stored on average per hectareco2_factor:{'trees':591.85,'grass':6,'bare':6,'crops':11.5,'flooded_vegetation':6,'other':0,'factor_pixel':100,# Indicates how many pixels are (on average) inside a hectare}# Date in which the reforestation started, in format YYYY-mm-ddstart_date:'2022-01-01'A valid geojson filesee(named as defined in forest_config.yml) that defines the areaInternally, forests are stored as a ForestConfig instance (see dynamic_world.configurations for more details).Available calculationsGiven a forest and a pair of dates, we download the forest's landcover image, landcover statistics and total CO2 calculation. In other words, we mean the amount of CO2 (measured in tons) that a forest stores (and therefore is not released into the atmosphere if it was burned :D)The forest image is stored as aCloud Optimized Geotifffile. The expression used for the file-name is the following:f"{forest.name.replace(' ','_')}_{start_date}_{end_date}.cog.tif"Forreductionswe use the Mode (polling). If a very large time interval is specified, recent changes in the forest will be masked by old pixel values. It is encouraged to use the smallest possible time intervals (at least a week is required or there may not be data). However, depending on some factors (such as the amount of clouds), specifying a small time interval may result in many NA (see mrv.calculations documentation for further info on how NA are treated when calculating the co2 factor).Development notesWe encourage developers to open the repository usingVSCode remote container functionality.SecretsTo run the tests, you will need only one secret, which is Earth Engine'sservice accountbase64-encoded:SERVICE_ACCOUNT=<very-long-string>The following snippet can be used to base64-encode theservice_account.jsonfile:python <<HEREDOCimport base64with open('service_account.json', 'rb') as file:file = file.read()base64_encoded_data = base64.b64encode(file)base64_message = base64_encoded_data.decode('utf-8')print(base64_message)HEREDOCHow to run tests locally# In the root directory of the proyectpytest# Run coveragepytest--covmrv--cov-branch--cov-reportterm-missing--disable-warningsHow to run tests in docker# Build test dockerdockerbuild--tagdw--fileDockerfile--targetdev.# Run lint and testsdockerrundw/bin/bash-c"flake8 && pytest"