Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
giswqs
GitHub Repository: giswqs/geemap
Path: blob/master/docs/notebooks/125_example_code.ipynb
2313 views
Kernel: Python 3

Open in Colab

Using Earth engine examples

Uncomment the following line to install geemap if needed.

# !pip install -U geemap
import ee import geemap import json

Explore json contents

Change file download location. Also added f.json to repo.

url = "https://github.com/gee-community/geemap/blob/master/geemap/data/gee_f.json" geemap.download_file(url)
with open("gee_f.json", encoding="utf-8") as f: functions = json.load(f) functions.keys()
[(x["name"], len(x["contents"])) for x in functions["examples"]]

Details

details = [ (dataset["name"], dataset["code"]) for x in functions["examples"] for dataset in x["contents"] if x["name"] == "Datasets" ] details[0]

Convert js to py

def get_py(js): try: return geemap.js_snippet_to_py( js, add_new_cell=False, import_ee=False, import_geemap=False, show_map=False ) except: return None results_convert = [get_py(js) for _, js in details]
len(details), len(results_convert)

Except for 2 cases, converts ran without error.

len([x for x in results_convert if x])

Verify availability

from geemap import datasets len(datasets.get_ee_stac_list())
known_datasets = set(name.replace("/", "_") for name in datasets.get_ee_stac_list()) known_code = set(name for name, _ in details)

Only some have exact matches

len(known_code & known_datasets)

Sometimes there is a 2 example available for a dataset, mostly FeatureViews.

excess = known_code - known_datasets
len(excess)
excess_no_featureview = set(x.replace("_FeatureView", "") for x in known_code) len(excess_no_featureview - known_datasets)

Leftovers

(excess_no_featureview - known_datasets)

Datasets without examples

missing_code = known_datasets - known_code len(missing_code)

These are also missing in gee itself (logically as these load from f.json).

Deprecated stuff afaik, s.a. Landsat LT1

missing_code
from geemap import common [x["title"] for x in common.search_ee_data("LANDSAT L1T")][:5]
[(x["uid"], x["title"]) for x in common.search_ee_data("MODIS MYD")][:5]