39 inspector tool
Uncomment the following line to install leafmap if needed.
In [1]:
Copied!
# !pip install leafmap
# !pip install leafmap
In [2]:
Copied!
import leafmap
import leafmap
Create an interactive map.
In [3]:
Copied!
m = leafmap.Map()
m = leafmap.Map()
Add Cloud Optimized GeoTIFF (COG) from Planetary Computer.
In [4]:
Copied!
collection = "landsat-8-c2-l2"
item = "LC08_L2SP_047027_20201204_02_T1"
collection = "landsat-8-c2-l2"
item = "LC08_L2SP_047027_20201204_02_T1"
In [5]:
Copied!
m.add_stac_layer(
collection=collection,
item=item,
assets="SR_B7,SR_B5,SR_B4",
name="Landsat Band-754",
)
m.add_stac_layer(
collection=collection,
item=item,
assets="SR_B7,SR_B5,SR_B4",
name="Landsat Band-754",
)
--------------------------------------------------------------------------- error Traceback (most recent call last) File ~/.local/lib/python3.9/site-packages/urllib3/response.py:401, in HTTPResponse._decode(self, data, decode_content, flush_decoder) 400 if self._decoder: --> 401 data = self._decoder.decompress(data) 402 except self.DECODER_ERROR_CLASSES as e: error: BrotliDecoderDecompressStream failed while processing the stream During handling of the above exception, another exception occurred: DecodeError Traceback (most recent call last) File ~/.local/lib/python3.9/site-packages/requests/models.py:760, in Response.iter_content.<locals>.generate() 759 try: --> 760 for chunk in self.raw.stream(chunk_size, decode_content=True): 761 yield chunk File ~/.local/lib/python3.9/site-packages/urllib3/response.py:572, in HTTPResponse.stream(self, amt, decode_content) 571 if self.chunked and self.supports_chunked_reads(): --> 572 for line in self.read_chunked(amt, decode_content=decode_content): 573 yield line File ~/.local/lib/python3.9/site-packages/urllib3/response.py:768, in HTTPResponse.read_chunked(self, amt, decode_content) 767 chunk = self._handle_chunk(amt) --> 768 decoded = self._decode( 769 chunk, decode_content=decode_content, flush_decoder=False 770 ) 771 if decoded: File ~/.local/lib/python3.9/site-packages/urllib3/response.py:404, in HTTPResponse._decode(self, data, decode_content, flush_decoder) 403 content_encoding = self.headers.get("content-encoding", "").lower() --> 404 raise DecodeError( 405 "Received response with content-encoding: %s, but " 406 "failed to decode it." % content_encoding, 407 e, 408 ) 409 if flush_decoder: DecodeError: ('Received response with content-encoding: br, but failed to decode it.', error('BrotliDecoderDecompressStream failed while processing the stream')) During handling of the above exception, another exception occurred: ContentDecodingError Traceback (most recent call last) Input In [5], in <cell line: 1>() ----> 1 m.add_stac_layer( 2 collection=collection, 3 item=item, 4 assets="SR_B7,SR_B5,SR_B4", 5 name="Landsat Band-754", 6 ) File ~/.local/lib/python3.9/site-packages/leafmap/foliumap.py:825, in Map.add_stac_layer(self, url, collection, item, assets, bands, titiler_endpoint, name, attribution, opacity, shown, **kwargs) 797 def add_stac_layer( 798 self, 799 url=None, (...) 809 **kwargs, 810 ): 811 """Adds a STAC TileLayer to the map. 812 813 Args: (...) 823 shown (bool, optional): A flag indicating whether the layer should be on by default. Defaults to True. 824 """ --> 825 tile_url = stac_tile( 826 url, collection, item, assets, bands, titiler_endpoint, **kwargs 827 ) 828 bounds = stac_bounds(url, collection, item, titiler_endpoint) 829 self.add_tile_layer( 830 url=tile_url, 831 name=name, (...) 834 shown=shown, 835 ) File ~/.local/lib/python3.9/site-packages/leafmap/common.py:1387, in stac_tile(url, collection, item, assets, bands, titiler_endpoint, **kwargs) 1359 # if ("expression" in kwargs) and ("rescale" not in kwargs): 1360 # stats = stac_stats( 1361 # collection=collection, (...) 1378 # "rescale" 1379 # ] = f"{stats[0]['percentile_2']},{stats[0]['percentile_98']}" 1381 if ( 1382 (assets is not None) 1383 and ("asset_expression" not in kwargs) 1384 and ("expression" not in kwargs) 1385 and ("rescale" not in kwargs) 1386 ): -> 1387 stats = stac_stats( 1388 collection=collection, 1389 item=item, 1390 assets=assets, 1391 titiler_endpoint=titiler_endpoint, 1392 ) 1393 if 'detail' not in stats: 1395 percentile_2 = min( 1396 [stats[s][list(stats[s].keys())[0]]["percentile_2"] for s in stats] 1397 ) File ~/.local/lib/python3.9/site-packages/leafmap/common.py:1556, in stac_stats(url, collection, item, assets, titiler_endpoint, **kwargs) 1554 r = requests.get(f"{titiler_endpoint}/stac/statistics", params=kwargs).json() 1555 else: -> 1556 r = requests.get( 1557 titiler_endpoint.url_for_stac_statistics(), params=kwargs 1558 ).json() 1560 return r File ~/.local/lib/python3.9/site-packages/requests/api.py:75, in get(url, params, **kwargs) 64 def get(url, params=None, **kwargs): 65 r"""Sends a GET request. 66 67 :param url: URL for the new :class:`Request` object. (...) 72 :rtype: requests.Response 73 """ ---> 75 return request('get', url, params=params, **kwargs) File ~/.local/lib/python3.9/site-packages/requests/api.py:61, in request(method, url, **kwargs) 57 # By using the 'with' statement we are sure the session is closed, thus we 58 # avoid leaving sockets open which can trigger a ResourceWarning in some 59 # cases, and look like a memory leak in others. 60 with sessions.Session() as session: ---> 61 return session.request(method=method, url=url, **kwargs) File ~/.local/lib/python3.9/site-packages/requests/sessions.py:529, in Session.request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json) 524 send_kwargs = { 525 'timeout': timeout, 526 'allow_redirects': allow_redirects, 527 } 528 send_kwargs.update(settings) --> 529 resp = self.send(prep, **send_kwargs) 531 return resp File ~/.local/lib/python3.9/site-packages/requests/sessions.py:687, in Session.send(self, request, **kwargs) 684 pass 686 if not stream: --> 687 r.content 689 return r File ~/.local/lib/python3.9/site-packages/requests/models.py:838, in Response.content(self) 836 self._content = None 837 else: --> 838 self._content = b''.join(self.iter_content(CONTENT_CHUNK_SIZE)) or b'' 840 self._content_consumed = True 841 # don't need to release the connection; that's been handled by urllib3 842 # since we exhausted the data. File ~/.local/lib/python3.9/site-packages/requests/models.py:765, in Response.iter_content.<locals>.generate() 763 raise ChunkedEncodingError(e) 764 except DecodeError as e: --> 765 raise ContentDecodingError(e) 766 except ReadTimeoutError as e: 767 raise ConnectionError(e) ContentDecodingError: ('Received response with content-encoding: br, but failed to decode it.', error('BrotliDecoderDecompressStream failed while processing the stream'))
In [6]:
Copied!
m.add_stac_layer(
collection=collection,
item=item,
assets="SR_B5,SR_B4,SR_B3",
name="Landsat Band-543",
)
m.add_stac_layer(
collection=collection,
item=item,
assets="SR_B5,SR_B4,SR_B3",
name="Landsat Band-543",
)
In [7]:
Copied!
m
m
Out[7]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Last update:
2022-03-14