<jupyter_start><jupyter_text>Interactive Maps for Google Earth Engine Python API This notebook is a showcase of a new feature of `geetools`, and it is still under active development on https://github.com/gee-community/gee_tools. There are 2 options: 1. maptool Based on https://github.com/mccarthyryanc/folium_gee but improved in order to 'emulate' the behavior of Map in the Code Editor.  Pros:1. This module can be use to generate html for other purposes like webapps, etc2. Can change zoom with mouse scroll Cons:1. When using this module you have to complete the Map (addLayer, etc), and at the end use `Map.show()` to show the map. Can't add more layers afterwards.2. Takes a long time to show the map 2. ipymap Based on https://github.com/gee-community/ee-jupyter-contrib/blob/master/examples/getting-started/display-interactive-map.ipynb Pros and cons are the opposite to `maptool` *(I'll try to keep this notebook up to date)*  Make imports<jupyter_code>import ee
ee.Initialize()<jupyter_output><empty_output><jupyter_text>Get an image<jupyter_code>col = ee.ImageCollection('COPERNICUS/S2')
site = ee.Geometry.Point([-72, -42])
col = col.filterBounds(site).filterMetadata('CLOUD_COVERAGE_ASSESSMENT', 'less_than', 40)
i = ee.Image(col.first())
igeom = i.geometry()<jupyter_output><empty_output><jupyter_text>define visualization parameters (dict)<jupyter_code>visParam = {'bands':['B8', 'B11', 'B4'], 'min':0, 'max':5000}<jupyter_output><empty_output><jupyter_text>define inspection `addLayer` has a parameter called `inspect` that defines de content for a pop up, which is a dict with the following keys:1. data: eeObject from where to get the data2. reducer: can be 'first', 'mean', 'media' and 'sum'3. scale: scale to use in the reduction. If not provided, it uses the nominalScale for the image's first band<jupyter_code>inspect = {'data':i, 'reducer':'mean'}<jupyter_output><empty_output><jupyter_text>Plot the image into an interactive Map using `maptool` (Folium)<jupyter_code>from geetools.ui import maptool
Map = maptool.Map()

Map.addLayer(i, visParam, 'Sentinel 2 Patagonia')
Map.centerObject(i)

Map.addLayer(igeom, name='Image boundries', inspect=inspect)

Map.show()<jupyter_output><empty_output><jupyter_text>Plot the image into an interactive Map using `ipymap` (ipyleaflet) This Map has extra features:1. Inspector2. Tasks3. Assets At the moment, the only one working is the inspector  First plot an empty Map (you can add stuff here too)<jupyter_code>from geetools import ui
Map2 = ui.Map()

# you can do also:
# from geetools.ui import ipymap
# Map2 = ipymap.Map()
Map2.show()<jupyter_output><empty_output><jupyter_text>addLayer<jupyter_code>Map2.addLayer(i, visParam, 'Sentinel 2 Patagonia')
Map2.addLayer(i, {'bands':['B8'], 'min':0, 'max':5000}, 'just B8')<jupyter_output><empty_output><jupyter_text>Center an Image<jupyter_code>Map2.centerObject(i)<jupyter_output><empty_output><jupyter_text>addLayer Geometry<jupyter_code>Map2.addLayer(igeom, name='Image boundries')<jupyter_output><empty_output><jupyter_text>Center a Geometry<jupyter_code>Map2.centerObject(igeom)<jupyter_output><empty_output><jupyter_text>Get Map Center<jupyter_code>center = Map2.getCenter()
center.getInfo()<jupyter_output><empty_output><jupyter_text>Get Map Bounds<jupyter_code>bounds = Map2.getBounds()
bounds.getInfo()<jupyter_output><empty_output><jupyter_text>Remove a layer<jupyter_code>Map2.removeLayer('Sentinel 2 Patagonia')<jupyter_output><empty_output><jupyter_text>TABS You can add a custom Tab with a custom handler. The handler is a function with 4 main parameters:- **type:** the interaction type. Can be 'click', 'mouseover', etc- **coordinates:** the coordinates where the interaction has taken place. If you have used ipyleaflet before, take in consideraton that coordinates are inverted (to match GEE format): [longitud, latitude]- **widget:** The widget inside the Tab. Defaults to an empty HTML widget- **map:** the Map instance. You can apply any of its methods, or get any of its properties<jupyter_code>print(Map2.addTab.__doc__)
def test_handler(**change):    
    # PARAMS
    ty = change['type']
    coords = change['coordinates']
    wid = change['widget']
    themap = change['map']
        
    if ty == 'click':  # If interaction was a click
        # Loading message before sending a request to EE
        wid.value = 'Loading...'
        # Map's bounds
        bounds = themap.getBounds().getInfo()['coordinates']
        # Change Widget Value
        wid.value = "You have clicked on {} and map's bounds are {}".format(coords, bounds)

Map2.addTab('TestTAB', test_handler)
print("Check out the Map!")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11461011139674379, 'fraction_numerical': 0.011353898886032563, 'mean_word_length': 5.8360175695461205, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 57, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '14', 'dir': 'jupyter-structured-clean-dedup', 'id': '173503', 'license': 'MIT', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1512, 'n_words': 462, 'path': 'notebooks/.ipynb_checkpoints/map_visualization-checkpoint.ipynb', 'repo_name': 'bworstell/gee_tools', 'size': '4668'}