%pip uninstall -yq earthaccess
%pip install -q git+https://github.com/nsidc/earthaccess.git@explore
import earthaccess
import ipyleaflet
from ipywidgets import Dropdown
from shapely.geometry.polygon import orient
from shapely.geometry import Polygon
= earthaccess.login() auth
# ArcticDEM
# note that we need to use the same projection for the image service layer and the map.
= ipyleaflet.Map(
m1 =(90, 0),
center=4,
zoom=ipyleaflet.basemaps.Esri.ArcticOceanBase,
basemap=ipyleaflet.projections.EPSG5936.ESRIBasemap,
crs
)# add arctic ocean reference basemap
= ipyleaflet.basemap_to_tiles(ipyleaflet.basemaps.Esri.ArcticOceanReference)
tl1
m1.add(tl1)
# create a widget control for the raster function
= [
raster_functions "Aspect Map",
"Contour 25",
"Hillshade Elevation Tinted",
"Hillshade Gray",
"Height Ellipsoidal",
"Height Orthometric",
"Slope Map"]
= Dropdown(
raster_dropdown1 =raster_functions[3],
value=raster_functions,
options="Raster:",
description
)
# add image service layer with ArcticDEM
= 'https://elevation2.arcgis.com/arcgis/rest/services/Polar/ArcticDEM/ImageServer'
url = {"rasterFunction": raster_dropdown1.value}
rendering_rule = ipyleaflet.ImageService(
image_layer ="CustomBaseLayer",
name=url,
urlformat='jpgpng', rendering_rule=rendering_rule,
='Esri, PGC, UMN, NSF, NGA, DigitalGlobe',
attribution=ipyleaflet.projections.EPSG5936.ESRIBasemap)
crs
m1.add(image_layer)
# add control for raster function
= ipyleaflet.WidgetControl(widget=raster_dropdown1, position="topright")
dropdown_control
m1.add(dropdown_control)
# set the rendering rule
def set_raster_function(sender):
= {"rasterFunction": raster_dropdown1.value}
image_layer.rendering_rule # force redrawing of map by removing and adding layer
m1.remove(image_layer)
m1.add(image_layer)
# watch raster function widget for changes
raster_dropdown1.observe(set_raster_function)
# polygon = [(-83.837578, 45.82529), (-80.167794, 45.82529), (-80.167794, 46.021921), (-83.837578, 46.021921), (-83.837578, 45.82529)]
= [(-139.59, 59.53), (-138.80, 59.90), (-137.15, 59.45),(-137.30, 58.78),(-138.64, 59.18),(-139.59, 59.53)]
coords = list(orient(Polygon(coords)).exterior.coords)
polygon
if 'sw' in vars():
if len(sw.roi) > 0:
= sw.roi
polygon else:
= earthaccess.SearchWidget(map=m1)
sw
= {
params "concept_id" : ["C2596864127-NSIDC_CPRD", "C2076090826-LPCLOUD", "C2237824918-ORNL_CLOUD"],
"temporal": ("2020-01", "2023-09"),
# "cloud_cover": (0, 20),
"polygon": polygon
}= earthaccess.search_data(**params)
results = sw.explore(results, roi={"polygon": polygon})
m # explore will inject its own controls so we add the base layer dropdown back
try:
map.add(dropdown_control)
sw.except Exception:
pass
m