geetools.Asset
#
An Asset management class mimicking the pathlib.Path
class behaviour.
Package Contents#
Classes#
An Asset management class mimicking the |
- class geetools.Asset.Asset(*args)[source]#
An Asset management class mimicking the
pathlib.Path
class behaviour.Initialize the Asset class.
Note
An asset cannot be an absolute path like in a normal filesystem and thus any trailing “/” will be removed.
- property name[source]#
Return the asset name.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.name
- property owner[source]#
Return the asset owner (project name).
This method is only parsing the asset path and is not checking asset existence.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.owner
- property parent[source]#
Return the direct parent directory.
It can go further up than the root folder if the asset is not absolute.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.parent
- property parents[source]#
Return the parent directories from the root folder.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.parents
- property parts[source]#
Return the asset parts of the path.
We will show all the parts from the root to the asset name. Remember that projects/user/assets is not part of the asset name but is part of the path.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.parts
- property st_size[source]#
Return the byte size of the file.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.st_size
- property type: str[source]#
Return the asset type.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.type
- Return type:
str
- __eq__(other)[source]#
Override the equal operator to compare the asset with other paths.
- Parameters:
other (object) –
- Return type:
bool
- __ge__(other)[source]#
Override the greater than or equal operator to compare the asset with other paths.
- Parameters:
other (geetools.types.pathlike) –
- Return type:
bool
- __gt__(other)[source]#
Override the greater than operator to compare the asset with other paths.
- Parameters:
other (geetools.types.pathlike) –
- Return type:
bool
- __idiv__(other)[source]#
Override the in-place division operator to join the asset with other paths.
- Parameters:
other (geetools.types.pathlike) –
- Return type:
- __le__(other)[source]#
Override the less than or equal operator to compare the asset with other paths.
- Parameters:
other (geetools.types.pathlike) –
- Return type:
bool
- __lt__(other)[source]#
Override the less than operator to compare the asset with other paths.
- Parameters:
other (geetools.types.pathlike) –
- Return type:
bool
- __ne__(other)[source]#
Override the not equal operator to compare the asset with other paths.
- Parameters:
other (object) –
- Return type:
bool
- __truediv__(other)[source]#
Override the division operator to join the asset with other paths.
- Parameters:
other (geetools.types.pathlike) –
- Return type:
- as_posix()[source]#
Return the asset id as a posix path.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.as_posix() # equivalent to str(asset)
- Return type:
str
- as_uri()[source]#
Return the asset id as a uri.
The uri can be directly copy/pasted to your browser to see the asset in the GEE code editor.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.as_uri()
- Return type:
str
- copy(new_asset, overwrite=False)[source]#
Copy the asset to a target destination.
Copy this asset (any type) to the given target, and return a new
Asset
instance pointing to target. If target exists and overwrite is False the method will raise an error. Else it will silently delete the existing asset. If the asset is a folder the whole content will be moved as well.- Parameters:
new_asset (Asset) – The destination asset.
overwrite (bool) – If True, overwrite the destination asset if it exists. Defaults to False.
- Returns:
The new asset instance.
- Return type:
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") new_asset = ee.Asset("projects/ee-geetools/assets/folder/new_image") asset.copy(new_asset, overwrite=False)
- delete()[source]#
Alias for unlink.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.delete()
- exists(raised=False)[source]#
Return True if the asset exists and/or the user has access to it.
- Parameters:
raised (bool) – If True, raise an exception if the asset does not exist. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.exists()
- expanduser()[source]#
Return a new path with expanded ~ constructs.
If one don’t want to write the path with the complete project name, the method will build it for you.
Examples
asset = ee.Asset("~/assets/folder/image") asset.expanduser()
- Return type:
- glob(pattern)[source]#
Return a list of assets matching the pattern.
- Parameters:
pattern (str) – The pattern to match with the asset name.
- Return type:
list
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder") asset.glob("image_*")
- classmethod home()[source]#
Return the root asset folder of the used cloud project.
- Returns:
The root asset folder.
- Return type:
Examples
ee.Asset.home()
- is_absolute(raised=False)[source]#
Return True if the asset is absolute.
An absolute asset path starts with “projects” and contains “assets” at the 3rd position. We don’t check if the project name exist in this method, simply the sctructure of the path.
- Parameters:
raised (bool) – If True, raise an exception if the asset is not absolute. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.is_absolute()
- is_feature_collection(raised=False)[source]#
Return
True
if the asset is a feature collection.- Parameters:
raised (bool) – If True, raise an exception if the asset is not a feature collection. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/feature_collection") asset.is_feature_collection()
- is_folder(raised=False)[source]#
Return
True
if the asset is a folder.- Parameters:
raised (bool) – If True, raise an exception if the asset is not a folder. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder") asset.is_folder()
- is_image(raised=False)[source]#
Return
True
if the asset is an image.- Parameters:
raised (bool) – If True, raise an exception if the asset is not an image. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.is_image()
- is_image_collection(raised=False)[source]#
Return
True
if the asset is an image collection.- Parameters:
raised (bool) – If True, raise an exception if the asset is not an image collection. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image_collection") asset.is_image_collection()
- is_project(raised=False)[source]#
Return
True
if the asset is a project.As project path are not assets, we cannot check their existence. We only check the path structure.
- Parameters:
raised (bool) – If True, raise an exception if the asset is not a project. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets") asset.is_project()
- is_relative_to(other)[source]#
Return True if the asset is relative to another asset.
- Parameters:
other (geetools.types.pathlike) – The other asset to compare with.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.is_relative_to("projects/ee-geetools/assets")
- is_type(asset_type, raised=False)[source]#
Return
True
if the asset is of the specified type.- Parameters:
asset_type (str) – The asset type to check for.
raised – If True, raise an exception if the asset is not corresponding to the type. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.is_type("IMAGE")
- is_user_project(raised=False)[source]#
Check if the current asset is in the same project as the user.
- Parameters:
raised (bool) – If True, raise an exception if the asset is not in the same project. Defaults to False.
- Return type:
bool
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.is_user_project()
- iterdir(recursive=False)[source]#
Get the list of children of a folder.
- Parameters:
recursive (bool) – If True, get all the children recursively. Defaults to False.
- Return type:
list
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder") asset.iterdir(recursive=True)
- joinpath(*args)[source]#
Join the asset with other paths.
- Parameters:
*args – The other paths to join with the asset.
- Return type:
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.joinpath("other", "path")
- match(*patterns)[source]#
Return True if the asset matches the patterns.
patterns: The patterns to match with the asset name.
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") asset.match("**/image")
- Return type:
bool
- mkdir(parents=False, exist_ok=False)[source]#
Create a folder asset from the Asset path.
- Parameters:
parents – If True, create all the parents of the folder. Defaults to False.
exist_ok – If True, do not raise an error if the folder already exists. Defaults to False.
- Return type:
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder") asset.mkdir(parents=True, exist_ok=True)
- move(new_asset, overwrite=False)[source]#
Move the asset to a target destination.
Move this asset (any type) to the given target, and return a new
Asset
instance pointing to target. If target exists and overwrite is False the method will raise an error. Else it will silently delete the existing file. If the asset is a folder the whole content will be moved as well. The initial content is removed after the move.- Parameters:
new_asset (Asset) – The destination asset.
overwrite (bool) – If True, overwrite the destination asset if it exists. Defaults to False.
- Returns:
The new asset instance.
- Return type:
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder/image") new_asset = ee.Asset("projects/ee-geetools/assets/folder/new_image") asset.move(new_asset, overwrite=False)
- rglob(pattern)[source]#
Return a list of assets matching the pattern recursively.
- Parameters:
pattern (str) – The pattern to match with the asset name.
- Return type:
list
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder") asset.rglob("image_*")
- rmdir(recursive=False, dry_run=None)[source]#
Remove the asset folder.
This method will delete a folder asset and all its childrend. by default it is not recursive and will raise an error if the folder is not empty. By setting the recursive argument to True, the method will delete all the children and the folder asset. To avoid deleting important assets by accident the method is set to dry_run by default.
- Parameters:
recursive (bool) – If True, delete all the children and the folder asset. Defaults to False.
dry_run (Optional[bool]) – If True, do not delete the asset simply pass them to the output list. Defaults to True.
- Returns:
The list of deleted assets.
- Return type:
list
Examples
asset = ee.Asset("projects/ee-geetools/assets/folder") asset.rmdir(recursive=True)