Skip to content

Instantly share code, notes, and snippets.

@giswqs
Created May 25, 2020 18:44
Show Gist options
  • Save giswqs/2b06098ac01ba6882c1037d9b07955b8 to your computer and use it in GitHub Desktop.
Save giswqs/2b06098ac01ba6882c1037d9b07955b8 to your computer and use it in GitHub Desktop.
convert GEE JavaScripts to Jupyter notebooks
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import os\nfrom geemap.conversion import *\n\n# Change js_dir to your directory contained GEE JavaScripts\njs_dir = '/home/qiusheng/Downloads/javascripts/'\n\n# Convert all Earth Engine JavaScripts in a folder recursively to Python scripts.\njs_to_python_dir(in_dir=js_dir, out_dir=js_dir, use_qgis=True)\nprint(\"Python scripts saved at: {}\".format(js_dir))",
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": "Converting Earth Engine JavaScripts to Python scripts...\n\nProcessing 1/5: /home/qiusheng/Downloads/javascripts/ModisQaBands.js\nProcessing 2/5: /home/qiusheng/Downloads/javascripts/FromName.js\nProcessing 3/5: /home/qiusheng/Downloads/javascripts/NormalizedDifference.js\nProcessing 4/5: /home/qiusheng/Downloads/javascripts/QualityMosaic.js\nProcessing 5/5: /home/qiusheng/Downloads/javascripts/ClippedComposite.js\nPython scripts saved at: /home/qiusheng/Downloads/javascripts/\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "# Convert all Earth Engine Python scripts in a folder recursively to Jupyter notebooks.\nnb_template = get_nb_template() # Get the notebook template from the package folder.\npy_to_ipynb_dir(js_dir, nb_template)\n\n# Execute all Jupyter notebooks in a folder recursively and save the output cells.\nexecute_notebook_dir(in_dir=js_dir)",
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"text": "Converting Earth Engine Python scripts to Jupyter notebooks ...\n\nProcessing 1/5: /home/qiusheng/Downloads/javascripts/ModisQaBands_qgis.py\n\nProcessing 2/5: /home/qiusheng/Downloads/javascripts/QualityMosaic_qgis.py\n\nProcessing 3/5: /home/qiusheng/Downloads/javascripts/FromName_qgis.py\n\nProcessing 4/5: /home/qiusheng/Downloads/javascripts/NormalizedDifference_qgis.py\n\nProcessing 5/5: /home/qiusheng/Downloads/javascripts/ClippedComposite_qgis.py\n\nExecuting Earth Engine Jupyter notebooks ...\n\nProcessing 1/5: /home/qiusheng/Downloads/javascripts/NormalizedDifference.ipynb ...\n\nProcessing 2/5: /home/qiusheng/Downloads/javascripts/FromName.ipynb ...\n\nProcessing 3/5: /home/qiusheng/Downloads/javascripts/QualityMosaic.ipynb ...\n\nProcessing 4/5: /home/qiusheng/Downloads/javascripts/ClippedComposite.ipynb ...\n\nProcessing 5/5: /home/qiusheng/Downloads/javascripts/ModisQaBands.ipynb ...\n\n",
"name": "stdout"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": true,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Table of Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": true
},
"language_info": {
"name": "python",
"version": "3.8.2",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "",
"data": {
"description": "convert GEE JavaScripts to Jupyter notebooks",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment