hugging-face-toy / etc /extras.py
Jonathan Marokhovsky
Created an extras file to keep track of the demo code I used while playing around with the Carbon Calculator
8e97c4e
raw
history blame
No virus
1.25 kB
"""
This is code I played around with in the code section of:
https://huggingface.co/spaces/boettiger-lab/leafmap
"""
from pystac_client import Client
from shapely.geometry import box
import shapely
import json
# DELETE BELOW, just making a quick script to add to the carbon Calculator
irrecoverable = (
"https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif"
)
vulnerable = "https://data.source.coop/cboettig/carbon/cogs/vulnerable_c_total_2018.tif"
m = leafmap.Map(center=[41, -69], zoom=5)
# COPY BELOW
m.add_cog_layer(
irrecoverable,
palette="greys",
name="doomed",
transparent_bg=True,
opacity=0.5,
zoom_to_layer=False,
)
m.add_cog_layer(
vulnerable,
palette="oranges",
name="at_risk",
transparent_bg=True,
opacity=0.5,
zoom_to_layer=False,
)
aoi_box = box(
-70.74295109234716, 41.01426426532743, -69.46303157927986, 42.0218426094371
)
bbox = aoi_box.bounds
api_url = "https://earth-search.aws.element84.com/v1"
client = Client.open(api_url)
search_results = client.search(
collections=["sentinel-2-l2a"],
bbox=bbox,
sortby=["-properties.datetime"],
max_items=4,
)
items = search_results.item_collection()
m.add_geojson(items.to_dict())