Git Product home page Git Product logo

earthengine-jupyter's Introduction

earthengine-jupyter

NOTICE: This is an experimental project and is not an officially supported Google project. You are welcome to use it, but we do not guarantee stability.

Setup

try:
  import ee_jupyter
  print('ee_jupyter was already installed.')
except ModuleNotFoundError:
  print('ee_jupyter was not found. Installing now...')
  import os
  result = os.system('pip -q install earthengine-jupyter')

How to use

This lib contains a Map class that can be used to display an interactive map.

import ee
from ee_jupyter.core import authenticate_if_needed
from ee_jupyter.ipyleaflet import Map
from ee_jupyter.layout import MapWithInspector
import ipywidgets as widgets
authenticate_if_needed()
# Intialize the Earth Engine client library.
ee.Initialize()
map1 = Map(center=(37.5924, -122.09), zoom=8)
map1

Define an Earth Engine image layer, and add it to the interactive map.

img1 = ee.Image("LANDSAT/LC09/C02/T1_L2/LC09_044034_20220127")
visualization = {
    'bands': ['SR_B4', 'SR_B3', 'SR_B2'],
    'min': 0.2 / 0.0000275,
    'max': 0.4 / 0.0000275,
}
map1.addLayer(eeObject=img1, visParams=visualization, name='Landsat scene')

We can also create an inspector object and associate it with the previously created map.

from ee_jupyter.ipyleaflet import Inspector

inspector1 = Inspector(map_object=map1)
inspector1

Typically when you create a inspector object, you will want to display it with the map. The MapWithInpsector object adds a button that toggles the inspector functionality.

The map below shows a Sentinel-2 image covering Paris. Click on the inspector toggle button to open the inspector.

map_init_paris = {'center':(49.4, 2.3), 'zoom':8}
m = MapWithInspector(**map_init_paris)
image = ee.Image('COPERNICUS/S2_SR_HARMONIZED/20220604T104619_20220604T104620_T31UDQ')
m.map.addLayer(image, {'bands': ['B4', 'B3', 'B2'], 'max': 2500}, 'Landsat image')
m

Tip With Caption

Note that when viewed on GitHub Pages you can manipulate Jupyter widgets independently, but the widgets do not interact with each other. To experience the cross-widget interactivity, open up this notebook in a Jupyter environment.

Displaying a Map Image

If you want to display a static (non-interactive) image, you can do that as well. The embed=True parameter will allow the image to be saved within the notebook.

from IPython.display import Image


visualization['dimensions'] = 400  # maximum dimension for the image
url = img1.getThumbUrl(visualization)

Image(url=url, format='png', embed=True)

earthengine-jupyter's People

Contributors

tylere avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

earthengine-jupyter's Issues

Lazy loading of inspector tree exposes JSON briefly

When expanding a node for the first time, the JSON blob is briefly exposed before parsed to tree, and if long, extends the panel across the whole map.

image

The tree building and opening handler are a lot of code and maybe more complicated than needed. Is the lazy loading beneficial when there are 1000's of elements vs rendering the entire tree? A foundation for building the entire tree follows. It still needs to be tested against objects with 1000's of elements to see how fast it will render and respond. If it is performant, we should maybe consider using it, to simplify and avoid exposed JSON. If it is slow to render and not very responsive, we need to figure out how to not expose the JSON in the current implementation.

!pip install -q ipytree
from ipytree import Tree, Node
from google.colab import output
output.enable_custom_widget_manager()

def create_tree(data, name=None):
    if name is None:
        name = type(data).__name__
    node = Node(f'{name}: ({len(data)} elements)', show_icon=False, opened=False)
    if isinstance(data, dict):
        for key, value in data.items():
            if isinstance(value, (dict, list)):
                node.add_node(create_tree(value, key))
            else:
                child_node = Node(f'{key}: {value}', show_icon=False)
                node.add_node(child_node)
    elif isinstance(data, list):
        for index, item in enumerate(data):
            if isinstance(item, (dict, list)):
                node.add_node(create_tree(item, f'{index}'))
            else:
                child_node = Node(f'{index}: {item}', show_icon=False)
                node.add_node(child_node)
    return node

data = {
  "type": "Image",
  "bands": [
    {
      "id": "B1",
      "data_type": {
        "type": "PixelType",
        "precision": "float"
      },
      "dimensions": [
        9161,
        9161
      ],
      "crs": "EPSG:32628",
      "crs_transform": [
        30,
        0,
        341085,
        0,
        -30,
        8808015
      ]
    },
    {
      "id": "B2",
      "data_type": {
        "type": "PixelType",
        "precision": "float"
      },
      "dimensions": [
        9161,
        9161
      ],
      "crs": "EPSG:32628",
      "crs_transform": [
        30,
        0,
        341085,
        0,
        -30,
        8808015
      ]
    },
  ]
}

tree = Tree(animation=0)
tree.add_node(create_tree(data))
tree

task monitor

A widget to monitor the status of ee.Tasks would be a good fit for this package IMO. An implementation using ipywidget can be found here: TaskManager from ipygee. Would be happy to contribute if I find some free time (a bit difficult at the moment, but could happen in a near future)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.