Manage Assets as Path objects#

github colab

Set up environment#

Install all the required libs if necessary and perform the import statements upstream.

[ ]:
# uncomment if installation of libs is necessary
# !pip install earthengine-api geetools
[ ]:
import ee
import geetools #noqa: F401
[ ]:
# uncomment if authetication to GEE is needed
# ee.Authenticate()
[ ]:
# uncomment if initialization is required
# ee.Initialize()

The Asset object#

In Google Earth Engine API, users are working with Assets. An asset is a filelike object that englobes a wide variety of types: IMAGE, IMAGE_COLLECTION, FOLDER, TABLE, FEATURE_COLLECTION, etc.

They are identified by a unique ID, which is a string that looks like this: projects/username/assets/foo. They can be modified using the ee.data module. This module has been proven complicated when dealing with basic file manipulation operation such as listing, moving, copying, etc.

geetools provides a simple way to manage assets using the Asset object. This object is a subclass of the pathlib.Path object, which is a powerful way to manage file paths in Python. Most of the methods and properties are overwritten to work with the Google Earth Engine API.

[ ]:
# let's create a folder asset from the root folder
folder = ee.Asset("~/test_folder/subfolder").expanduser()

then many operations can be performed on it

[ ]:
# create the actual asset object
folder.mkdir(parents=True)
[ ]:
# see the parents of the asset
folder.parents

To get more informations on the Asset object, it’s properties and methods, you can refer to our API documentation.