geeViz.assetManagerLib

Helpful functions for managing GEE assets

geeViz.assetManagerLib includes functions for copying, deleting, uploading, changing permissions, and more.

Functions

assetsize(asset)

Prints the size of a GEE asset.

base(in_path)

Gets the filename without extension.

batchCopy(fromFolder, toFolder[, outType])

Copies all assets from one folder to another in GEE.

batchDelete(Collection[, type])

Deletes all assets in a collection.

batchUpdateAcl(folder[, writers, ...])

Updates the ACL for all assets under a given folder in GEE.

check_dir(in_path)

Ensures the directory exists.

check_end(in_path[, add])

Ensures a trailing character is in the path.

copyByName(fromFolder, toFolder, nameIdentifier)

Copies assets from one folder to another based on a name identifier.

countTasks([break_running_ready])

Counts the number of tasks.

create_asset(asset_path[, asset_type, recursive])

Creates an asset in GEE.

create_image_collection(full_path_to_collection)

Creates an image collection in GEE.

deleteByName(Collection, nameIdentifier[, type])

Deletes assets in a collection based on a name identifier.

ee_asset_exists(path)

Checks if a GEE asset exists.

getDate(year, month, day)

Gets a date in ISO format.

humansize(nbytes)

Converts a file size in bytes to a human-readable format.

ingestFromGCSImagesAsBands(gcsURIs, assetPath)

Ingests multiple images from Google Cloud Storage as bands of a single GEE image.

ingestImageFromGCS(gcsURIs, assetPath[, ...])

Ingests an image from Google Cloud Storage to GEE.

is_leap_year(year)

Determines if a year is a leap year.

julian_to_calendar(julian_date, year)

Converts a Julian date to a calendar date.

limitTasks(taskLimit)

Limits the number of tasks running.

listAssets(folder)

Lists assets within a given asset folder or image collection.

moveImages(images, toFolder[, delete_original])

Moves images to a new folder, optionally deleting the originals.

now([Format])

Gets the current readable date/time.

setDate(assetPath, year, month, day)

Sets the date for an asset.

updateACL(assetName[, writers, ...])

Updates the Access Control List (ACL) for a given GEE asset.

uploadTifToGCS(tif, gcsBucket[, overwrite])

Uploads a single TIFF file to Google Cloud Storage.

uploadToGEEAssetImagesAsBands(tif_dict, ...)

Uploads images to GCS and manifests them as bands of a single GEE image.

uploadToGEEImageAsset(localTif, gcsBucket, ...)

Uploads an image to GEE as an asset.

upload_to_gcs(image_dir, gs_bucket[, ...])

Uploads files to Google Cloud Storage.

upload_to_gee(image_dir, gs_bucket, asset_dir)

Uploads images to Google Earth Engine.

verify_path(path)

Verifies the validity of a path.

walkFolders(folder[, images])

Walks down folders and gets all images.

walkFoldersTables(folder[, tables])

Walks down folders and gets all tables.

year_month_day_to_seconds(year_month_day)

Converts a date to seconds since epoch.

geeViz.assetManagerLib.updateACL(assetName, writers=[], all_users_can_read=True, readers=[])[source]

Updates the Access Control List (ACL) for a given GEE asset.

Parameters:
  • assetName (str) – The name of the GEE asset.

  • writers (list, optional) – List of users with write access. Defaults to an empty list.

  • all_users_can_read (bool, optional) – Whether all users can read the asset. Defaults to True.

  • readers (list, optional) – List of users with read access. Defaults to an empty list.

Returns:

None

Example

>>> updateACL('users/youruser/yourasset', writers=['user1'], all_users_can_read=False, readers=['user2'])
geeViz.assetManagerLib.listAssets(folder: str) list[str][source]

Lists assets within a given asset folder or image collection.

Parameters:

folder (str) – The path to the asset folder or image collection.

Returns:

A list of asset IDs within the specified folder.

Return type:

list[str]

Example

>>> listAssets('users/youruser/yourfolder')
geeViz.assetManagerLib.batchUpdateAcl(folder, writers=[], all_users_can_read=True, readers=[])[source]

Updates the ACL for all assets under a given folder in GEE.

Parameters:
  • folder (str) – The path to the folder in GEE.

  • writers (list, optional) – List of users with write access. Defaults to an empty list.

  • all_users_can_read (bool, optional) – Whether all users can read the assets. Defaults to True.

  • readers (list, optional) – List of users with read access. Defaults to an empty list.

Returns:

None

Example

>>> batchUpdateAcl('users/youruser/yourfolder', writers=['user1'], all_users_can_read=False)
geeViz.assetManagerLib.batchCopy(fromFolder, toFolder, outType='imageCollection')[source]

Copies all assets from one folder to another in GEE.

Parameters:
  • fromFolder (str) – The source folder path.

  • toFolder (str) – The destination folder path.

  • outType (str, optional) – The type of assets to copy (‘imageCollection’ or ‘tables’). Defaults to ‘imageCollection’.

Returns:

None

Example

>>> batchCopy('users/youruser/source', 'users/youruser/dest')
geeViz.assetManagerLib.copyByName(fromFolder, toFolder, nameIdentifier, outType='imageCollection')[source]

Copies assets from one folder to another based on a name identifier.

Parameters:
  • fromFolder (str) – The source folder path.

  • toFolder (str) – The destination folder path.

  • nameIdentifier (str) – A substring to identify assets to copy.

  • outType (str, optional) – The type of assets to copy (‘imageCollection’ or ‘tables’). Defaults to ‘imageCollection’.

Returns:

None

Example

>>> copyByName('users/youruser/source', 'users/youruser/dest', '2020')
geeViz.assetManagerLib.moveImages(images, toFolder, delete_original=False)[source]

Moves images to a new folder, optionally deleting the originals.

Parameters:
  • images (list) – List of image paths to move.

  • toFolder (str) – The destination folder path.

  • delete_original (bool, optional) – Whether to delete the original images. Defaults to False.

Returns:

None

Example

>>> moveImages(['users/youruser/img1', 'users/youruser/img2'], 'users/youruser/dest', delete_original=True)
geeViz.assetManagerLib.batchDelete(Collection, type='imageCollection')[source]

Deletes all assets in a collection.

Parameters:
  • Collection (str) – The path to the collection.

  • type (str, optional) – The type of assets to delete (‘imageCollection’ or ‘tables’). Defaults to ‘imageCollection’.

Returns:

None

Example

>>> batchDelete('users/youruser/collection')
geeViz.assetManagerLib.deleteByName(Collection, nameIdentifier, type='imageCollection')[source]

Deletes assets in a collection based on a name identifier.

Parameters:
  • Collection (str) – The path to the collection.

  • nameIdentifier (str) – A substring to identify assets to delete.

  • type (str, optional) – The type of assets to delete (‘imageCollection’ or ‘tables’). Defaults to ‘imageCollection’.

Returns:

None

Example

>>> deleteByName('users/youruser/collection', '2020')
geeViz.assetManagerLib.humansize(nbytes)[source]

Converts a file size in bytes to a human-readable format.

Parameters:

nbytes (int) – The size in bytes.

Returns:

The human-readable file size.

Return type:

str

Example

>>> humansize(1048576)
'1 MB'
geeViz.assetManagerLib.assetsize(asset)[source]

Prints the size of a GEE asset.

Parameters:

asset (str) – The path to the GEE asset.

Returns:

None

Example

>>> assetsize('users/youruser/yourasset')
geeViz.assetManagerLib.upload_to_gcs(image_dir, gs_bucket, image_extension='.tif', copy_or_sync='copy', overwrite=False)[source]

Uploads files to Google Cloud Storage.

Parameters:
  • image_dir (str) – The directory containing the images to upload.

  • gs_bucket (str) – The GCS bucket to upload to.

  • image_extension (str, optional) – The file extension of the images. Defaults to ‘.tif’.

  • copy_or_sync (str, optional) – Whether to copy or sync files (‘copy’ or ‘sync’). Defaults to ‘copy’.

  • overwrite (bool, optional) – Whether to overwrite existing files. Defaults to False.

Returns:

None

Example

>>> upload_to_gcs('/tmp/images/', 'gs://mybucket')
geeViz.assetManagerLib.uploadTifToGCS(tif, gcsBucket, overwrite=False)[source]

Uploads a single TIFF file to Google Cloud Storage.

Parameters:
  • tif (str) – The path to the TIFF file.

  • gcsBucket (str) – The GCS bucket to upload to.

  • overwrite (bool, optional) – Whether to overwrite existing files. Defaults to False.

Returns:

None

Example

>>> uploadTifToGCS('/tmp/image.tif', 'gs://mybucket')
geeViz.assetManagerLib.upload_to_gee(image_dir, gs_bucket, asset_dir, image_extension='.tif', resample_method='MEAN', band_names=[], property_list=[])[source]

Uploads images to Google Earth Engine.

Parameters:
  • image_dir (str) – The directory containing the images to upload.

  • gs_bucket (str) – The GCS bucket to upload to.

  • asset_dir (str) – The GEE asset directory.

  • image_extension (str, optional) – The file extension of the images. Defaults to ‘.tif’.

  • resample_method (str, optional) – The resampling method. Defaults to ‘MEAN’.

  • band_names (list, optional) – List of band names. Defaults to an empty list.

  • property_list (list, optional) – List of properties for the images. Defaults to an empty list.

Returns:

None

Example

>>> upload_to_gee('/tmp/images/', 'gs://mybucket', 'users/youruser/yourcollection')
geeViz.assetManagerLib.check_end(in_path, add='/')[source]

Ensures a trailing character is in the path.

Parameters:
  • in_path (str) – The input path.

  • add (str, optional) – The character to add. Defaults to ‘/’.

Returns:

The modified path.

Return type:

str

Example

>>> check_end('users/youruser/collection')
'users/youruser/collection/'
geeViz.assetManagerLib.base(in_path)[source]

Gets the filename without extension.

Parameters:

in_path (str) – The input path.

Returns:

The filename without extension.

Return type:

str

Example

>>> base('/tmp/image.tif')
'image'
geeViz.assetManagerLib.walkFolders(folder, images=[])[source]

Walks down folders and gets all images.

Parameters:
  • folder (str) – The folder path.

  • images (list, optional) – List of images. Defaults to an empty list.

Returns:

List of image paths.

Return type:

list

Example

>>> walkFolders('users/youruser/collection')
geeViz.assetManagerLib.walkFoldersTables(folder, tables=[])[source]

Walks down folders and gets all tables.

Parameters:
  • folder (str) – The folder path.

  • tables (list, optional) – List of tables. Defaults to an empty list.

Returns:

List of table paths.

Return type:

list

Example

>>> walkFoldersTables('users/youruser/collection')
geeViz.assetManagerLib.check_dir(in_path)[source]

Ensures the directory exists.

Parameters:

in_path (str) – The directory path.

Returns:

None

Example

>>> check_dir('/tmp/mydir')
geeViz.assetManagerLib.year_month_day_to_seconds(year_month_day)[source]

Converts a date to seconds since epoch.

Parameters:

year_month_day (list) – List containing year, month, and day.

Returns:

Seconds since epoch.

Return type:

int

Example

>>> year_month_day_to_seconds([2020, 1, 1])
geeViz.assetManagerLib.limitTasks(taskLimit)[source]

Limits the number of tasks running.

Parameters:

taskLimit (int) – The maximum number of tasks.

Returns:

None

Example

>>> limitTasks(10)
geeViz.assetManagerLib.countTasks(break_running_ready=False)[source]

Counts the number of tasks.

Parameters:

break_running_ready (bool, optional) – Whether to break running and ready tasks. Defaults to False.

Returns:

Total tasks or tuple of running and ready tasks.

Return type:

int or tuple

Example

>>> countTasks()
>>> countTasks(True)
geeViz.assetManagerLib.ee_asset_exists(path)[source]

Checks if a GEE asset exists.

Parameters:

path (str) – The asset path.

Returns:

True if the asset exists, False otherwise.

Return type:

bool

Example

>>> ee_asset_exists('users/youruser/yourasset')
geeViz.assetManagerLib.create_image_collection(full_path_to_collection, properties=None)[source]

Creates an image collection in GEE.

Parameters:
  • full_path_to_collection (str) – The full path to the collection.

  • properties (dict, optional) – Properties for the collection. Defaults to None.

Returns:

None

Example

>>> create_image_collection('users/youruser/newcollection')
geeViz.assetManagerLib.create_asset(asset_path, asset_type='Folder', recursive=True)[source]

Creates an asset in GEE.

Parameters:
  • asset_path (str) – The asset path.

  • asset_type (str, optional) – The type of asset. Defaults to ee.data.ASSET_TYPE_FOLDER.

  • recursive (bool, optional) – Whether to create nested folders. Defaults to True.

Returns:

None

Example

>>> create_asset('users/youruser/newfolder')
geeViz.assetManagerLib.verify_path(path)[source]

Verifies the validity of a path.

Parameters:

path (str) – The path to verify.

Returns:

None

Example

>>> verify_path('users/youruser/collection')
geeViz.assetManagerLib.is_leap_year(year)[source]

Determines if a year is a leap year.

Parameters:

year (int) – The year.

Returns:

True if the year is a leap year, False otherwise.

Return type:

bool

Example

>>> is_leap_year(2020)
True
geeViz.assetManagerLib.now(Format='%b %d %Y %H:%M:%S %a')[source]

Gets the current readable date/time.

Parameters:

Format (str, optional) – The format of the date/time. Defaults to ‘%b %d %Y %H:%M:%S %a’.

Returns:

The current date/time.

Return type:

str

Example

>>> now()
geeViz.assetManagerLib.julian_to_calendar(julian_date, year)[source]

Converts a Julian date to a calendar date.

Parameters:
  • julian_date (int) – The Julian date.

  • year (int) – The year.

Returns:

List containing year, month, and day.

Return type:

list

Example

>>> julian_to_calendar(32, 2020)
[2020, 2, 1]
geeViz.assetManagerLib.getDate(year, month, day)[source]

Gets a date in ISO format.

Parameters:
  • year (int) – The year.

  • month (int) – The month.

  • day (int) – The day.

Returns:

The date in ISO format.

Return type:

str

Example

>>> getDate(2020, 1, 1)
'2020-01-01T00:00:00Z'
geeViz.assetManagerLib.setDate(assetPath, year, month, day)[source]

Sets the date for an asset.

Parameters:
  • assetPath (str) – The asset path.

  • year (int) – The year.

  • month (int) – The month.

  • day (int) – The day.

Returns:

None

Example

>>> setDate('users/youruser/yourasset', 2020, 1, 1)
geeViz.assetManagerLib.ingestImageFromGCS(gcsURIs, assetPath, overwrite=False, bandNames=None, properties=None, pyramidingPolicy=None, noDataValues=None)[source]

Ingests an image from Google Cloud Storage to GEE.

Parameters:
  • gcsURIs (list) – List of GCS URIs.

  • assetPath (str) – The asset path in GEE.

  • overwrite (bool, optional) – Whether to overwrite existing assets. Defaults to False.

  • bandNames (list, optional) – List of band names. Defaults to None.

  • properties (dict, optional) – Properties for the asset. Defaults to None.

  • pyramidingPolicy (list, optional) – Pyramiding policy for the bands. Defaults to None.

  • noDataValues (list, optional) – No data values for the bands. Defaults to None.

Returns:

None

Example

>>> ingestImageFromGCS(['gs://mybucket/image.tif'], 'users/youruser/yourasset')
geeViz.assetManagerLib.ingestFromGCSImagesAsBands(gcsURIs, assetPath, overwrite=False, properties=None)[source]

Ingests multiple images from Google Cloud Storage as bands of a single GEE image.

Parameters:
  • gcsURIs (list) – List of GCS URIs or dictionaries with band information.

  • assetPath (str) – The asset path in GEE.

  • overwrite (bool, optional) – Whether to overwrite existing assets. Defaults to False.

  • properties (dict, optional) – Properties for the asset. Defaults to None.

Returns:

None

Example

>>> ingestFromGCSImagesAsBands([{'gcsURI': 'gs://mybucket/band1.tif', 'bandName': 'B1'}], 'users/youruser/yourasset')
geeViz.assetManagerLib.uploadToGEEImageAsset(localTif, gcsBucket, assetPath, overwrite=False, bandNames=None, properties=None, pyramidingPolicy=None, noDataValues=None, parallel_threshold='150M', gsutil_path='C:/Program Files (x86)/Google/Cloud SDK/google-cloud-sdk/bin/gsutil.cmd')[source]

Uploads an image to GEE as an asset.

Parameters:
  • localTif (str) – Path to the local TIFF file.

  • gcsBucket (str) – The GCS bucket to upload to.

  • assetPath (str) – The asset path in GEE.

  • overwrite (bool, optional) – Whether to overwrite existing assets. Defaults to False.

  • bandNames (list, optional) – List of band names. Defaults to None.

  • properties (dict, optional) – Properties for the asset. Defaults to None.

  • pyramidingPolicy (list, optional) – Pyramiding policy for the bands. Defaults to None.

  • noDataValues (list, optional) – No data values for the bands. Defaults to None.

  • parallel_threshold (str, optional) – Threshold for parallel uploads. Defaults to ‘150M’.

  • gsutil_path (str, optional) – Path to the gsutil command. Defaults to a default path.

Returns:

None

Example

>>> uploadToGEEImageAsset('/tmp/image.tif', 'gs://mybucket', 'users/youruser/yourasset')
geeViz.assetManagerLib.uploadToGEEAssetImagesAsBands(tif_dict, gcsBucket, assetPath, overwrite=False, properties=None)[source]

Uploads images to GCS and manifests them as bands of a single GEE image.

Parameters:
  • tif_dict (dict) – Dictionary of TIFF files and their properties.

  • gcsBucket (str) – The GCS bucket to upload to.

  • assetPath (str) – The asset path in GEE.

  • overwrite (bool, optional) – Whether to overwrite existing assets. Defaults to False.

  • properties (dict, optional) – Properties for the asset. Defaults to None.

Returns:

None

Example

>>> tif_dict = {'/tmp/band1.tif': {'bandName': 'B1'}, '/tmp/band2.tif': {'bandName': 'B2'}}
>>> uploadToGEEAssetImagesAsBands(tif_dict, 'gs://mybucket', 'users/youruser/yourasset')