{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/120_javascript.ipynb)\n", "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/geemap-binder)\n", "\n", "**Calling functions in Earth Engine JavaScript libraries from Python**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the following line to enable tab-completion for JavaScript libraries." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%config IPCompleter.use_jedi = False" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import libraries" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import ee\n", "import geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "geemap.ee_initialize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use the [Open Earth Engine Library (OEEL)](https://www.open-geocomputing.org/OpenEarthEngineLibrary/#)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "oeel = geemap.requireJS()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ic = ee.ImageCollection(\"COPERNICUS/S2_SR\")\n", "\n", "icSize = (\n", " oeel.Algorithms.Sentinel2.cloudfree(maxCloud=20, S2Collection=ic)\n", " .filterDate('2020-01-01', '2020-01-02')\n", " .size()\n", ")\n", "print('Cloud free imagery: ', icSize.getInfo())" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use an Earth Engine JavaScript library from a HTTP URL." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = 'https://github.com/gee-community/geemap/blob/master/examples/javascripts/grid.js'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib = geemap.requireJS(url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib.availability" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "grid = lib.generateGrid(-180, -50, 180, 50, 10, 10, 0, 0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.addLayer(grid, {}, 'Grid')\n", "Map" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use a local Earth Engine JavaScript library." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib = geemap.requireJS('grid.js', Map)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib.availability" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib.grid_test()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use an Earth Engine JavaScript from an Earth Engine repo." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib = geemap.requireJS('users/gena/packages:grid')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "lib.availability" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "grid = lib.generateGrid(-180, -50, 180, 50, 10, 10, 0, 0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Map = geemap.Map()\n", "Map.addLayer(grid, {}, 'Grid')\n", "Map" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }