Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Add colab and layout helper functions
Browse files Browse the repository at this point in the history
Fixes #18
  • Loading branch information
tylere committed Oct 2, 2022
1 parent bef5a78 commit 9d9ffc7
Show file tree
Hide file tree
Showing 15 changed files with 164,255 additions and 1,354 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@

<!-- do not remove -->

## 0.0.4

### New Features

- Inspector: display scrollbar when exceeding maximum height or width ([#11](https://github.com/tylere/earthengine-jupyter/issues/11))

- Inspector: Simplify the object display by using OrderedDict ([#10](https://github.com/tylere/earthengine-jupyter/issues/10))
- The object folder's display logic currently hardcodes the keys that it expects to display. It could be better to order the keys that are returned by ee.Object.getInfo().

- Map: Display crosshairs when cursor is over the map ([#9](https://github.com/tylere/earthengine-jupyter/issues/9))

- Provide map view details in the Inspector's Point folder ([#5](https://github.com/tylere/earthengine-jupyter/issues/5))
- For example:
```
Point
Longitude: -101.440234375
​ Latitude: 41.62751361509059
​ Zoom Level: 4
​​ Scale (approx. m/px): 9783.93962050256
```

- Inspector: return "No unmasked pixels at clicked point." for layers with fully masked bands ([#2](https://github.com/tylere/earthengine-jupyter/issues/2))

- Inspector: disable Pixels & Objects folders if there are non map layers ([#1](https://github.com/tylere/earthengine-jupyter/issues/1))
- Similar to the Code Editor, only display the Pixels and Objects folders if the map has layers



## 0.0.3


Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ except ModuleNotFoundError:
result = os.system('pip -q install earthengine-jupyter')
```

ee_jupyter was already installed.
Make sure that the earthengine-jupyter package is installed...

## How to use

This lib contains a
[`Map`](https://googlestaging.github.io/earthengine-jupyter/ipyleaflet.html#map)
class that can be used to display an interactive map.
This lib contains a `Map` class that can be used to display an
interactive map.

``` python
import ee
Expand Down
2 changes: 1 addition & 1 deletion ee_jupyter/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.3"
__version__ = "0.0.4"
9 changes: 7 additions & 2 deletions ee_jupyter/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
'doc_host': 'https://googlestaging.github.io',
'git_url': 'https://github.com/googlestaging/earthengine-jupyter',
'lib_path': 'ee_jupyter'},
'syms': { 'ee_jupyter.core': {'ee_jupyter.core.authenticate_if_needed': ('core.html#authenticate_if_needed', 'ee_jupyter/core.py')},
'syms': { 'ee_jupyter.colab': { 'ee_jupyter.colab.set_colab_output_cell_height': ( 'colab.html#set_colab_output_cell_height',
'ee_jupyter/colab.py')},
'ee_jupyter.core': {'ee_jupyter.core.authenticate_if_needed': ('core.html#authenticate_if_needed', 'ee_jupyter/core.py')},
'ee_jupyter.ipyleaflet': { 'ee_jupyter.ipyleaflet.Inspector': ('ipyleaflet.html#inspector', 'ee_jupyter/ipyleaflet.py'),
'ee_jupyter.ipyleaflet.Inspector.__init__': ( 'ipyleaflet.html#inspector.__init__',
'ee_jupyter/ipyleaflet.py'),
Expand All @@ -28,4 +30,7 @@
'ee_jupyter.ipyleaflet.Map.addLayer': ('ipyleaflet.html#map.addlayer', 'ee_jupyter/ipyleaflet.py'),
'ee_jupyter.ipyleaflet.TileLayerEE': ('ipyleaflet.html#tilelayeree', 'ee_jupyter/ipyleaflet.py'),
'ee_jupyter.ipyleaflet.TileLayerEE.__init__': ( 'ipyleaflet.html#tilelayeree.__init__',
'ee_jupyter/ipyleaflet.py')}}}
'ee_jupyter/ipyleaflet.py')},
'ee_jupyter.layout': { 'ee_jupyter.layout.MapInspectorHBox': ('panel.html#mapinspectorhbox', 'ee_jupyter/layout.py'),
'ee_jupyter.layout.MapInspectorHBox.__init__': ( 'panel.html#mapinspectorhbox.__init__',
'ee_jupyter/layout.py')}}}
14 changes: 14 additions & 0 deletions ee_jupyter/colab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_colab.ipynb.

# %% auto 0
__all__ = ['set_colab_output_cell_height']

# %% ../nbs/00_colab.ipynb 3
def set_colab_output_cell_height(max_height):
"""Sets the maximum height for the current notebook cell's output."""
import google

from IPython.display import Javascript
from string import Template
s = Template('google.colab.output.setIframeHeight(0, true, {maxHeight: $height})')
display(Javascript(s.substitute(height=max_height)))
22 changes: 11 additions & 11 deletions ee_jupyter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

# %% ../nbs/00_core.ipynb 5
def authenticate_if_needed():
"""Authenticate Earth Engine, if credentials do not exist.
* Authenticate, if needed."""
import ee
import os
if os.path.exists(ee.oauth.get_credentials_path()):
print('\N{check mark} Authentication credentials were found.')
else:
ee.Authenticate()
"""Authenticate Earth Engine, if credentials do not exist.
* Authenticate, if needed."""

import ee
import os

if os.path.exists(ee.oauth.get_credentials_path()):
print('\N{check mark} Authentication credentials were found.')
else:
ee.Authenticate()
8 changes: 4 additions & 4 deletions ee_jupyter/ipyleaflet.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_ipyleaflet.ipynb.
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_ipyleaflet.ipynb.

# %% auto 0
__all__ = ['DEFAULT_MAP_HEIGHT', 'SCALE_LEVEL_0', 'TileLayerEE', 'Map', 'Inspector']

# %% ../nbs/00_ipyleaflet.ipynb 4
# %% ../nbs/01_ipyleaflet.ipynb 4
import ee
import ipyleaflet
import ipytree
import ipywidgets as widgets
import traitlets

# %% ../nbs/00_ipyleaflet.ipynb 6
# %% ../nbs/01_ipyleaflet.ipynb 6
DEFAULT_MAP_HEIGHT = '400px'

class TileLayerEE(ipyleaflet.TileLayer):
Expand Down Expand Up @@ -80,7 +80,7 @@ def get_tile_layer_url(ee_image_object):
)
self.add_layer(TileLayerEE(ee_object=eeObject, url=tile_url, name=name, visible=shown))

# %% ../nbs/00_ipyleaflet.ipynb 14
# %% ../nbs/01_ipyleaflet.ipynb 14
# Map scale at Level 0 in meters/pixel
SCALE_LEVEL_0 = 156543.03392

Expand Down
30 changes: 30 additions & 0 deletions ee_jupyter/layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_panel.ipynb.

# %% auto 0
__all__ = ['MapInspectorHBox']

# %% ../nbs/02_panel.ipynb 4
from .ipyleaflet import Map
from .ipyleaflet import Inspector
import ipywidgets
from traitlets import Unicode

# %% ../nbs/02_panel.ipynb 6
class MapInspectorHBox(ipywidgets.HBox):
"""A panel that includes a map and Inspector widget."""

def __init__(self,
map_obj=None,
**kwargs):
if map_obj is None:
kwargs['height'] = '300px'
map_obj = Map(**kwargs)
inspector_obj = Inspector(map_obj)
self.map = map_obj
self.inspector = inspector_obj

if 'children' not in kwargs:
kwargs['children'] = []
kwargs['children'].insert(0, self.map)
kwargs['children'].insert(1, self.inspector)
super().__init__(**kwargs)
Binary file added index_files/figure-gfm/cell-10-output-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 92 additions & 0 deletions nbs/00_colab.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "05d86507-c00c-4f70-96a5-e47b56eb54e7",
"metadata": {},
"outputs": [],
"source": [
"#|hide\n",
"# Copyright 2022 Google LLC\n",
"#\n",
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
"# you may not use this file except in compliance with the License.\n",
"# You may obtain a copy of the License at\n",
"# \n",
"# https://www.apache.org/licenses/LICENSE-2.0\n",
"# \n",
"# Unless required by applicable law or agreed to in writing, software\n",
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
"# See the License for the specific language governing permissions and\n",
"# limitations under the License."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5427930d-da44-425f-adac-6a9a2ca769e5",
"metadata": {},
"outputs": [],
"source": [
"#| default_exp colab"
]
},
{
"cell_type": "markdown",
"id": "85662442-f26a-400f-9656-005d342855de",
"metadata": {},
"source": [
"# Colab module\n",
"\n",
"> Tools specific to working within a Colab environment."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e682b176-cf69-4cf2-9d4c-d2acc18f93b3",
"metadata": {},
"outputs": [],
"source": [
"#|export\n",
"def set_colab_output_cell_height(max_height):\n",
" \"\"\"Sets the maximum height for the current notebook cell's output.\"\"\"\n",
" import google\n",
" \n",
" from IPython.display import Javascript\n",
" from string import Template\n",
" s = Template('google.colab.output.setIframeHeight(0, true, {maxHeight: $height})')\n",
" display(Javascript(s.substitute(height=max_height)))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e6cb06b8-a5ee-4f12-bab6-a292581be7de",
"metadata": {},
"outputs": [],
"source": [
"#|eval: false\n",
"set_output_cell_height(max_height=200)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
22 changes: 11 additions & 11 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,17 @@
"source": [
"#|export\n",
"def authenticate_if_needed():\n",
" \"\"\"Authenticate Earth Engine, if credentials do not exist.\n",
" \n",
" * Authenticate, if needed.\"\"\"\n",
" \n",
" import ee\n",
" import os\n",
" \n",
" if os.path.exists(ee.oauth.get_credentials_path()):\n",
" print('\\N{check mark} Authentication credentials were found.')\n",
" else:\n",
" ee.Authenticate()"
" \"\"\"Authenticate Earth Engine, if credentials do not exist.\n",
"\n",
" * Authenticate, if needed.\"\"\"\n",
"\n",
" import ee\n",
" import os\n",
"\n",
" if os.path.exists(ee.oauth.get_credentials_path()):\n",
" print('\\N{check mark} Authentication credentials were found.')\n",
" else:\n",
" ee.Authenticate()"
]
},
{
Expand Down
Loading

0 comments on commit 9d9ffc7

Please sign in to comment.