Skip to content

Commit

Permalink
updated v1.1.0
Browse files Browse the repository at this point in the history
- added recursive handling for folder object count

- fixed [Issue 18](#18) to handle featureview operations

- fixed issue with copy, move, asset size estimation and acl

- Added extra fields for geeadd search tool
  • Loading branch information
samapriya committed Mar 6, 2024
1 parent ca0c83f commit 8b4c04a
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 20 deletions.
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

#### v1.1.0
- added recursive handling for folder object count
- fixed [Issue 18](https://github.com/samapriya/gee_asset_manager_addon/issues/18) to handle featureview operations
- fixed issue with copy, move, asset size estimation and acl
- Added extra fields for geeadd search tool

#### v1.0.1
- Updated pending/ready tasks as they are called in tasklist
- Fixed task cancellation options
Expand Down
2 changes: 1 addition & 1 deletion geeadd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

__author__ = "Samapriya Roy"
__email__ = "samapriya.roy@gmail.com"
__version__ = "1.0.1"
__version__ = "1.1.0"
4 changes: 4 additions & 0 deletions geeadd/acl_changer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,16 @@ def fparse(path):
image_list.append(child["id"])
elif child["type"].lower() == "table":
table_list.append(child["id"])
elif child["type"].lower() == "feature_view":
table_list.append(child["id"])
elif ee.data.getAsset(path)["type"].lower() == "image":
image_list.append(path)
elif ee.data.getAsset(path)["type"].lower() == "image_collection":
collection_list.append(path)
elif ee.data.getAsset(path)["type"].lower() == "table":
table_list.append(path)
elif ee.data.getAsset(path)["type"].lower() == "feature_view":
table_list.append(path)
else:
print(ee.data.getAsset(path)["type"].lower())
return [collection_list, table_list, image_list, folder_list]
Expand Down
31 changes: 26 additions & 5 deletions geeadd/batch_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,16 @@
"""
__license__ = "Apache 2.0"
import ee
import os

import ee


def camel_case(s):
words = s.split()
temp = words
res = ' '.join(ele.title() for ele in temp)
return res
# Image copy
def image_copy(initial, replace_string, replaced_string, fpath):
if replace_string == replaced_string or replace_string == None:
Expand All @@ -38,16 +44,16 @@ def image_copy(initial, replace_string, replaced_string, fpath):


# Table copy
def table_copy(initial, replace_string, replaced_string, fpath):
def table_copy(initial, replace_string, replaced_string, fpath,ftype):
if replace_string == replaced_string or replace_string == None:
final = fpath
else:
final = initial.replace(replace_string, replaced_string)
try:
if ee.data.getAsset(final):
print("Table already copied: {}".format(final))
print(f"{camel_case(ftype)} already copied: {final}")
except Exception as e:
print("Copying table to {}".format(final))
print(f"Copying {camel_case(ftype)} to {final}")
try:
ee.data.copyAsset(initial, final)
except Exception as e:
Expand Down Expand Up @@ -166,9 +172,15 @@ def copy(path, fpath):
child["name"], replace_string, replaced_string, fpath
)
elif child["type"].lower() == "table":
ftype = "table"
table_copy(
child["name"], replace_string, replaced_string, fpath
)
elif child["type"].lower() == "feature_view":
ftype = "feature view"
table_copy(
child["name"], replace_string, replaced_string, fpath,ftype
)
print("")
elif ee.data.getAsset(path)["type"].lower() == "image":
path = ee.data.getAsset(path)["name"]
Expand Down Expand Up @@ -232,12 +244,21 @@ def copy(path, fpath):
print(e)
# collection_copy(path, replace_string, replaced_string, fpath)
elif ee.data.getAsset(path)["type"].lower() == "table":
ftype = "table"
path = ee.data.getAsset(path)["name"]
replace_string = None
replaced_string = ee.data.getAsset(
"/".join(fpath.split("/")[:-1]) + "/"
)["name"]
table_copy(path, replace_string, replaced_string, fpath,ftype)
elif ee.data.getAsset(path)["type"].lower() == "feature_view":
ftype = "feature view"
path = ee.data.getAsset(path)["name"]
replace_string = None
replaced_string = ee.data.getAsset(
"/".join(fpath.split("/")[:-1]) + "/"
)["name"]
table_copy(path, replace_string, replaced_string, fpath)
table_copy(path, replace_string, replaced_string, fpath,ftype)
except Exception as e:
print(e)

Expand Down
36 changes: 29 additions & 7 deletions geeadd/batch_mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,19 @@
"""
__license__ = "Apache 2.0"
import ee
import os

import ee


def camel_case(s):
words = s.split()
temp = words
res = ' '.join(ele.title() for ele in temp)
return res

# Image copy
def image_move(initial, replace_string, replaced_string, fpath):
def image_move(initial, replace_string, replaced_string, fpath,ftype):
ee.Initialize()
if replace_string == replaced_string or replace_string == None:
final = fpath
Expand All @@ -41,17 +48,17 @@ def image_move(initial, replace_string, replaced_string, fpath):


# Table copy
def table_move(initial, replace_string, replaced_string, fpath):
def table_move(initial, replace_string, replaced_string, fpath,ftype):
ee.Initialize()
if replace_string == replaced_string or replace_string == None:
final = fpath
else:
final = initial.replace(replace_string, replaced_string)
try:
if ee.data.getAsset(final):
print("Table already moved: {}".format(final))
except Exception:
print("Moving table to {}".format(final))
print(f"{camel_case(ftype)} already moved: {final}")
except Exception as e:
print(f"Moving {camel_case(ftype)} to {final}")
try:
ee.data.renameAsset(initial, final)
except Exception as e:
Expand Down Expand Up @@ -170,9 +177,15 @@ def mover(path, fpath):
child["name"], replace_string, replaced_string, fpath
)
elif child["type"].lower() == "table":
ftype = "table"
table_move(
child["name"], replace_string, replaced_string, fpath
)
elif child["type"].lower() == "feature_view":
ftype = "feature view"
table_move(
child["name"], replace_string, replaced_string, fpath,ftype
)
print("")
elif ee.data.getAsset(path)["type"].lower() == "image":
path = ee.data.getAsset(path)["name"]
Expand Down Expand Up @@ -235,12 +248,21 @@ def mover(path, fpath):
except Exception as e:
print(e)
elif ee.data.getAsset(path)["type"].lower() == "table":
ftype = "table"
path = ee.data.getAsset(path)["name"]
replace_string = None
replaced_string = ee.data.getAsset(
"/".join(fpath.split("/")[:-1]) + "/"
)["name"]
table_move(path, replace_string, replaced_string, fpath,ftype)
elif ee.data.getAsset(path)["type"].lower() == "feature_view":
ftype = "feature view"
path = ee.data.getAsset(path)["name"]
replace_string = None
replaced_string = ee.data.getAsset(
"/".join(fpath.split("/")[:-1]) + "/"
)["name"]
table_move(path, replace_string, replaced_string, fpath)
table_move(path, replace_string, replaced_string, fpath,ftype)
except Exception as e:
print(e)
print("Initial path {} not found".format(path))
24 changes: 18 additions & 6 deletions geeadd/geeadd.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def tasks(state,id):
print(f"Tasks Failed: {st.count('FAILED')}")
print(f"Tasks Cancelled: {st.count('CANCELLED') + st.count('CANCELLING')}")


def assetsize(asset):
"""
Print the size and item count of an Earth Engine asset.
Expand All @@ -350,17 +349,23 @@ def assetsize(asset):

header = asset_info["type"]

if header in ["IMAGE_COLLECTION", "IMAGE", "TABLE"]:
if header in ["IMAGE_COLLECTION", "IMAGE", "TABLE","FEATURE_VIEW"]:
if header == "IMAGE_COLLECTION":
collc = ee.ImageCollection(asset)
size = sum(collc.aggregate_array("system:asset_size").getInfo())
item_count = collc.size().getInfo()
elif header == "IMAGE":
collc = ee.ImageCollection.fromImages([ee.Image(asset)])
size = sum(collc.aggregate_array("system:asset_size").getInfo())
item_count = 1
elif header == "TABLE":
collc = ee.FeatureCollection(asset)
size = float(collc.get("system:asset_size").getInfo())
item_count = collc.size().getInfo()
item_count = collc.size().getInfo()
elif header == "FEATURE_VIEW":
collc = ee.data.getAsset(asset)
size = float(collc['sizeBytes'])
item_count = collc['featureCount']
print(f"\n{asset} ===> {humansize(size)}")
print(f"Total number of items in {header.title()}: {item_count}")

Expand All @@ -369,8 +374,7 @@ def assetsize(asset):
"ascii"
)
size = humansize(float(out.split()[0]))

num = subprocess.check_output(f"earthengine ls {asset}", shell=True).decode(
num = subprocess.check_output(f"earthengine ls -r {asset}", shell=True).decode(
"ascii"
)
num = [
Expand All @@ -380,7 +384,7 @@ def assetsize(asset):
]

print(f"\n{asset} ===> {size}")
print(f"Total number of items in folder: {len(num)}")
print(f"Total number of items including all folders: {len(num)}")


def search(mname, source):
Expand All @@ -406,6 +410,8 @@ def search(mname, source):
"title": rows["title"],
"ee_id_snippet": rows["id"],
"provider": rows["provider"],
"tags": rows["tags"],
"license": rows["license"],
"sample_code": rows["sample_code"],
}

Expand All @@ -426,6 +432,8 @@ def search(mname, source):
"title": rows["title"],
"ee_id_snippet": rows["id"],
"provider": rows["provider"],
"tags": rows["tags"],
"license": rows["license"],
"sample_code": rows["sample_code"],
}
gee_bundle.append(item)
Expand All @@ -445,6 +453,8 @@ def search(mname, source):
"title": rows["title"],
"ee_id_snippet": rows["id"],
"provider": rows["provider"],
"tags": rows["tags"],
"license": rows["license"],
"sample_code": rows["sample_code"],
}
gee_bundle.append(item)
Expand All @@ -464,6 +474,8 @@ def search(mname, source):
"title": rows["title"],
"ee_id_snippet": rows["id"],
"provider": rows["provider"],
"tags": rows["tags"],
"license": rows["license"],
"sample_code": rows["sample_code"],
}
gee_bundle.append(item)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="geeadd",
version="1.0.1",
version="1.1.0",
packages=["geeadd"],
data_files=[("", ["LICENSE"])],
url="https://github.com/samapriya/gee_asset_manager_addon",
Expand Down

0 comments on commit 8b4c04a

Please sign in to comment.