# %pip install -U leafmap from leafmap import leafmap catalogs = { "Element84 Earth Search": "https://earth-search.aws.element84.com/v1", "Microsoft Planetary Computer": "https://planetarycomputer.microsoft.com/api/stac/v1", } m = leafmap.Map(center=[37.7452, -122.4108], zoom=12, catalog_source=catalogs) m.add("stac") m # m.stac_item url = "https://earth-search.aws.element84.com/v1/" collection = "sentinel-2-l2a" time_range = "2023-04-01/2023-07-31" bbox = [-122.491, 37.7208, -122.411, 37.7786] search = leafmap.stac_search( url=url, max_items=5, collections=[collection], bbox=bbox, datetime=time_range, query={"eo:cloud_cover": {"lt": 10}}, get_collection=True, ) # search search = leafmap.stac_search( url=url, max_items=5, collections=[collection], bbox=bbox, datetime=time_range, query={"eo:cloud_cover": {"lt": 10}}, get_assets=True, ) # search name, item = next(iter(search.items())) name item search = leafmap.stac_search( url=url, max_items=5, collections=[collection], bbox=bbox, datetime=time_range, query={"eo:cloud_cover": {"lt": 10}}, get_links=True, ) search url = search[0] bands = leafmap.stac_bands(url) bands[:10] m = leafmap.Map() m.add_stac_layer(url, bands=["nir", "red", "green"], name="Sentinel-2") m if m.user_roi is not None: roi = m.user_roi_bounds() else: roi = [-122.5315, 37.6882, -122.3523, 37.8166] bands = ["nir", "red", "green"] item["nir"] array = leafmap.read_raster(item["nir"], window=roi, coord_crs="epsg:4326") array.shape sources = [item["nir"], item["red"], item["green"]] array = leafmap.read_rasters(sources, window=roi, coord_crs="epsg:4326") array.shape leafmap.numpy_to_cog( array, "s2.tif", bounds=roi, profile=item["nir"], coord_crs="epsg:4326" ) m = leafmap.Map() m.add_raster("s2.tif", band=[1, 2, 3], vmin=0, vmax=4000, layer_name="Subset") m