from IPython.display import display as iDisplay
import ipywidgets as widgets
from pystac_client import Client
import json
# This class is a proxy to visualize STAC responses nicely in Jupyter
# To show the actual list or dict in Jupyter, use repr() or print()
[docs]class VisualList(list):
def __init__(self, data: list):
list.__init__(self, data)
def _repr_html_(self):
# Construct HTML, but load Vue Components source files only if the
# openEO HTML tag is not yet defined
return """
<script>
if (!window.customElements || !window.customElements.get('openeo-items')) {{
var el = document.createElement('script');
el.src = "https://cdn.jsdelivr.net/npm/@openeo/vue-components@2/assets/openeo.min.js";
document.head.appendChild(el);
}}
</script>
<openeo-items>
<script type="application/json">{props}</script>
</openeo-items>
""".format(
props=json.dumps({'items': [i.to_dict() for i in self], 'show-map': True})
)
[docs]class STAC_Query_UI(widgets.VBox):
def __init__(self, stac_api: str, headers: dict = None, **kwargs):
super().__init__(**kwargs)
self.client = Client.open(stac_api, headers=headers)
self.query_results = None
collection_ids = [c.id for c in self.client.get_all_collections()]
self.collections_w = widgets.SelectMultiple(
options=collection_ids,
description="Collection(s):",
disabled=False,
layout={
"width": "95%",
},
)
self.limit_w = widgets.BoundedIntText(
value=10,
min=0,
max=1000,
step=1,
description="Limit:",
disabled=False,
layout={
"width": "95%",
},
)
self.ids_w = widgets.Textarea(
placeholder="Comma delimited list of IDs",
description="ID(s):",
disabled=False,
layout={
"width": "95%",
},
)
self.bbox_w = widgets.Text(
placeholder="Comma delimited list of bounds (order: W, S, E, N)",
description="BBox:",
disabled=False,
layout={
"width": "95%",
},
)
self.start_date_w = widgets.DatePicker(description="Start Date", disabled=False)
self.end_date_w = widgets.DatePicker(description="End Date", disabled=False)
self.show_query_w = widgets.Checkbox(
value=False,
description="Print query",
disabled=False,
indent=False,
)
self.query_btn_w = widgets.Button(
description="Run Query",
disabled=False,
button_style="",
tooltip="Run Query",
icon="check",
)
self.response_text = widgets.Output()
self.query_btn_w.on_click(self.click_button)
common_widgets = widgets.VBox([self.collections_w, self.limit_w, self.ids_w])
spatial_widgets = widgets.VBox([self.bbox_w])
temporal_widgets = widgets.VBox([self.start_date_w, self.end_date_w])
children = [common_widgets, spatial_widgets, temporal_widgets]
tab = widgets.Tab()
tab.children = children
titles = ["Common", "Spatial", "Temporal"]
for i in range(len(titles)):
tab.set_title(i, str(titles[i]))
self.children = [tab, self.show_query_w, self.query_btn_w, self.response_text]
[docs] def display(self):
iDisplay(self)