125 example code
Using Earth engine examples
- ee datasets seem to come from https://code.earthengine.google.com/scripts/load
- When logged into gee, this link returns a f.json. It contains all code examples from the docs, including the datasets.
- community datasets can be accessed using git from https://earthengine.googlesource.com
- which in many cases can be translated into python code
- this should make it feasible to use the code examples directly into geemap
Uncomment the following line to install geemap if needed.
In [ ]:
Copied!
# !pip install -U geemap
# !pip install -U geemap
In [ ]:
Copied!
import ee
import geemap
import json
import ee
import geemap
import json
Manually download f.json¶
Explore json contents¶
Change file download location. Also added f.json to repo.
In [ ]:
Copied!
url = 'https://github.com/gee-community/geemap/blob/master/geemap/data/gee_f.json'
geemap.download_file(url)
url = 'https://github.com/gee-community/geemap/blob/master/geemap/data/gee_f.json'
geemap.download_file(url)
In [ ]:
Copied!
with open('gee_f.json', encoding="utf-8") as f:
functions = json.load(f)
functions.keys()
with open('gee_f.json', encoding="utf-8") as f:
functions = json.load(f)
functions.keys()
In [ ]:
Copied!
[(x['name'], len(x['contents'])) for x in functions['examples']]
[(x['name'], len(x['contents'])) for x in functions['examples']]
Details¶
In [ ]:
Copied!
details = [
(dataset['name'], dataset['code'])
for x in functions['examples']
for dataset in x['contents']
if x['name'] == 'Datasets'
]
details[0]
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¶
In [ ]:
Copied!
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]
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]
In [ ]:
Copied!
len(details), len(results_convert)
len(details), len(results_convert)
Except for 2 cases, converts ran without error.
In [ ]:
Copied!
len([x for x in results_convert if x])
len([x for x in results_convert if x])
Verify availability¶
In [ ]:
Copied!
from geemap import datasets
len(datasets.get_ee_stac_list())
from geemap import datasets
len(datasets.get_ee_stac_list())
In [ ]:
Copied!
known_datasets = set(name.replace('/', '_') for name in datasets.get_ee_stac_list())
known_code = set(name for name, _ in details)
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¶
In [ ]:
Copied!
len(known_code & known_datasets)
len(known_code & known_datasets)
Sometimes there is a 2 example available for a dataset, mostly FeatureViews.
In [ ]:
Copied!
excess = known_code - known_datasets
excess = known_code - known_datasets
In [ ]:
Copied!
len(excess)
len(excess)
In [ ]:
Copied!
excess_no_featureview = set(x.replace('_FeatureView', '') for x in known_code)
len(excess_no_featureview - known_datasets)
excess_no_featureview = set(x.replace('_FeatureView', '') for x in known_code)
len(excess_no_featureview - known_datasets)
Leftovers
In [ ]:
Copied!
(excess_no_featureview - known_datasets)
(excess_no_featureview - known_datasets)
Datasets without examples¶
In [ ]:
Copied!
missing_code = known_datasets - known_code
len(missing_code)
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
In [ ]:
Copied!
missing_code
missing_code
In [ ]:
Copied!
from geemap import common
[x['title'] for x in common.search_ee_data('LANDSAT L1T')][:5]
from geemap import common
[x['title'] for x in common.search_ee_data('LANDSAT L1T')][:5]
In [ ]:
Copied!
[(x['uid'], x['title']) for x in common.search_ee_data('MODIS MYD')][:5]
[(x['uid'], x['title']) for x in common.search_ee_data('MODIS MYD')][:5]
Last update:
2023-04-06
Created: 2022-08-11
Created: 2022-08-11