From 7038cc74fa8d10d74d4bda11d668968eceb6cf34 Mon Sep 17 00:00:00 2001 From: Sandra Hoang Date: Thu, 27 Jul 2023 10:49:10 -0400 Subject: [PATCH] Ran black formatter --- docs/conf.py | 58 ++-- stac_ipyleaflet/constants.py | 4 +- stac_ipyleaflet/core.py | 270 ++++++++++-------- .../stac_discovery/catalogs/nasa_maap_stac.py | 4 +- stac_ipyleaflet/stac_discovery/requests.py | 3 +- stac_ipyleaflet/widgets/basemaps.py | 62 ++-- stac_ipyleaflet/widgets/draw.py | 47 +-- write_biomass_layers.py | 32 ++- 8 files changed, 254 insertions(+), 226 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 34e036e..3af2d9f 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -19,7 +19,8 @@ # import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) import stac_ipyleaflet @@ -31,22 +32,22 @@ # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] +extensions = ["sphinx.ext.autodoc", "sphinx.ext.viewcode"] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix(es) of source filenames. # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'stac ipyleaflet' +project = "stac ipyleaflet" copyright = "2023, Aimee Barciauskas" author = "Aimee Barciauskas" @@ -69,10 +70,10 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -83,7 +84,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'alabaster' +html_theme = "alabaster" # Theme options are theme-specific and customize the look and feel of a # theme further. For a list of options available for each theme, see the @@ -94,13 +95,13 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # -- Options for HTMLHelp output --------------------------------------- # Output file base name for HTML help builder. -htmlhelp_basename = 'stac_ipyleafletdoc' +htmlhelp_basename = "stac_ipyleafletdoc" # -- Options for LaTeX output ------------------------------------------ @@ -109,15 +110,12 @@ # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # # 'preamble': '', - # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -127,9 +125,13 @@ # (source start file, target name, title, author, documentclass # [howto, manual, or own class]). latex_documents = [ - (master_doc, 'stac_ipyleaflet.tex', - 'stac ipyleaflet Documentation', - 'Aimee Barciauskas', 'manual'), + ( + master_doc, + "stac_ipyleaflet.tex", + "stac ipyleaflet Documentation", + "Aimee Barciauskas", + "manual", + ), ] @@ -138,9 +140,7 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'stac_ipyleaflet', - 'stac ipyleaflet Documentation', - [author], 1) + (master_doc, "stac_ipyleaflet", "stac ipyleaflet Documentation", [author], 1) ] @@ -150,13 +150,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'stac_ipyleaflet', - 'stac ipyleaflet Documentation', - author, - 'stac_ipyleaflet', - 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "stac_ipyleaflet", + "stac ipyleaflet Documentation", + author, + "stac_ipyleaflet", + "One line description of project.", + "Miscellaneous", + ), ] - - - diff --git a/stac_ipyleaflet/constants.py b/stac_ipyleaflet/constants.py index b6028f5..b71ce01 100644 --- a/stac_ipyleaflet/constants.py +++ b/stac_ipyleaflet/constants.py @@ -1,4 +1,4 @@ -REQUEST_TIMEOUT = 3 # three second timeout +REQUEST_TIMEOUT = 3 # three second timeout RESCALE = "0,50" TITILER_ENDPOINT = "https://titiler.maap-project.org" -TITILER_STAC_ENDPOINT = "https://titiler-stac.maap-project.org" \ No newline at end of file +TITILER_STAC_ENDPOINT = "https://titiler-stac.maap-project.org" diff --git a/stac_ipyleaflet/core.py b/stac_ipyleaflet/core.py index 92e56d5..a77c4c8 100644 --- a/stac_ipyleaflet/core.py +++ b/stac_ipyleaflet/core.py @@ -19,11 +19,12 @@ from stac_ipyleaflet.widgets.basemaps import BasemapsWidget from stac_ipyleaflet.widgets.draw import DrawControlWidget + class StacIpyleaflet(Map): """ Stac ipyleaflet is an extension to ipyleaflet `Map`. """ - + raw_input = input draw_control: DrawControl @@ -46,13 +47,13 @@ def __init__(self, **kwargs): kwargs["layout"] = Layout(height="600px") if "scroll_wheel_zoom" not in kwargs: - kwargs["scroll_wheel_zoom"] = True + kwargs["scroll_wheel_zoom"] = True # Create map - super().__init__(**kwargs) - + super().__init__(**kwargs) + self.accent_color = "SteelBlue" - self.layers = BasemapsWidget.template(self) + self.layers = BasemapsWidget.template(self) self.buttons = {} self.selected_data = [] @@ -60,123 +61,147 @@ def __init__(self, **kwargs): self.draw_control_added = False self.aoi_coordinates = [] self.aoi_bbox = () - - gif_file = files('stac_ipyleaflet.data').joinpath('loading.gif') + + gif_file = files("stac_ipyleaflet.data").joinpath("loading.gif") with open(gif_file, "rb") as f: - gif_widget=Image( + gif_widget = Image( value=f.read(), - format='png', + format="png", width=200, height=200, ) - loading_widget=VBox() - loading_widget.children=[gif_widget] - self.loading_widget_layer = Popup(child=loading_widget, min_width=200, min_height=200) + loading_widget = VBox() + loading_widget.children = [gif_widget] + self.loading_widget_layer = Popup( + child=loading_widget, min_width=200, min_height=200 + ) - main_button_layout = Layout(width="120px", height="35px", border="1px solid #4682B4") - draw_btn = ToggleButton(description="Draw", icon="square-o", layout=main_button_layout) + main_button_layout = Layout( + width="120px", height="35px", border="1px solid #4682B4" + ) + draw_btn = ToggleButton( + description="Draw", icon="square-o", layout=main_button_layout + ) draw_btn.style.text_color = self.accent_color draw_btn.style.button_color = "transparent" draw_btn.tooltip = "Draw Area of Interest" - draw_btn.observe(self.toggle_draw_widget_display, type="change", names=["value"]) + draw_btn.observe( + self.toggle_draw_widget_display, type="change", names=["value"] + ) self.buttons["draw"] = draw_btn - layers_btn = ToggleButton(description="Layers", icon="map-o", layout=main_button_layout) + layers_btn = ToggleButton( + description="Layers", icon="map-o", layout=main_button_layout + ) layers_btn.style.text_color = self.accent_color layers_btn.style.button_color = "transparent" layers_btn.tooltip = "Open/Close Layers Menu" - layers_btn.observe(self.toggle_layers_widget_display, type="change", names=["value"]) + layers_btn.observe( + self.toggle_layers_widget_display, type="change", names=["value"] + ) self.buttons["layers"] = layers_btn """ histogram_btn = Button(description="Histogram", icon="bar-chart") histogram_btn.style.text_color = "white" histogram_btn.style.button_color = self.accent_color histogram_btn.on_click(self.create_histograms) """ - stac_btn = ToggleButton(description="STAC Data", icon="search", layout=main_button_layout) + stac_btn = ToggleButton( + description="STAC Data", icon="search", layout=main_button_layout + ) stac_btn.style.text_color = self.accent_color stac_btn.style.button_color = "white" stac_btn.tooltip = "Open/Close STAC Data Search" - stac_btn.observe(self.toggle_stac_widget_display, type="change", names=["value"]) - self.buttons["stac"] = stac_btn - - buttons_box_layout = Layout(display='flex', - flex_flow='row', - align_items='center', - justify_content='center', - width='100%', - height="50px") - buttons_box = HBox(children=[draw_btn, layers_btn, stac_btn],layout=buttons_box_layout) + stac_btn.observe( + self.toggle_stac_widget_display, type="change", names=["value"] + ) + self.buttons["stac"] = stac_btn + + buttons_box_layout = Layout( + display="flex", + flex_flow="row", + align_items="center", + justify_content="center", + width="100%", + height="50px", + ) + buttons_box = HBox( + children=[draw_btn, layers_btn, stac_btn], layout=buttons_box_layout + ) display(buttons_box) - + self.add_biomass_layers() self.add_custom_tools() self.draw_control = DrawControlWidget.template(self) return None - #logic to handle main menu toggle buttons + # logic to handle main menu toggle buttons def toggle_layers_widget_display(self, b): if b["new"]: - if self.layers_widget.layout.display == 'none': - self.layers_widget.layout.display = 'block' - self.stac_widget.layout.display = 'none' - self.aoi_widget.layout.display = 'none' + if self.layers_widget.layout.display == "none": + self.layers_widget.layout.display = "block" + self.stac_widget.layout.display = "none" + self.aoi_widget.layout.display = "none" self.buttons["stac"].value = False self.buttons["draw"].value = False if self.draw_control_added: self.remove(self.draw_control) self.draw_control_added = False if not b["new"]: - if self.layers_widget.layout.display == 'block': - self.layers_widget.layout.display = 'none' - - def toggle_stac_widget_display(self, b): + if self.layers_widget.layout.display == "block": + self.layers_widget.layout.display = "none" + + def toggle_stac_widget_display(self, b): if b["new"]: - if self.stac_widget.layout.display == 'none': - self.stac_widget.layout.display = 'block' - self.layers_widget.layout.display = 'none' - self.aoi_widget.layout.display = 'none' + if self.stac_widget.layout.display == "none": + self.stac_widget.layout.display = "block" + self.layers_widget.layout.display = "none" + self.aoi_widget.layout.display = "none" self.buttons["layers"].value = False self.buttons["draw"].value = False if self.draw_control_added: self.remove(self.draw_control) self.draw_control_added = False if not b["new"]: - if self.stac_widget.layout.display == 'block': - self.stac_widget.layout.display = 'none' - - def toggle_draw_widget_display(self, b): + if self.stac_widget.layout.display == "block": + self.stac_widget.layout.display = "none" + + def toggle_draw_widget_display(self, b): if b["new"]: - if self.aoi_widget.layout.display == 'none': - self.aoi_widget.layout.display = 'block' + if self.aoi_widget.layout.display == "none": + self.aoi_widget.layout.display = "block" self.add_control(self.draw_control) self.draw_control_added = True - self.stac_widget.layout.display = 'none' - self.layers_widget.layout.display = 'none' + self.stac_widget.layout.display = "none" + self.layers_widget.layout.display = "none" self.buttons["stac"].value = False self.buttons["layers"].value = False if not b["new"]: - if self.aoi_widget.layout.display == 'block': - self.aoi_widget.layout.display = 'none' + if self.aoi_widget.layout.display == "block": + self.aoi_widget.layout.display = "none" if self.draw_control_added: self.remove(self.draw_control) self.draw_control_added = False def create_aoi_widget(self): - aoi_widget = HBox(layout=Layout(width="300px", padding="0px 6px 2px 6px", margin="0px 2px 2px 2px")) - aoi_widget.layout.flex_flow="column" - aoi_widget.layout.min_width="300px" - aoi_widget.layout.max_height="360px" - aoi_widget.layout.overflow="auto" + aoi_widget = HBox( + layout=Layout( + width="300px", padding="0px 6px 2px 6px", margin="0px 2px 2px 2px" + ) + ) + aoi_widget.layout.flex_flow = "column" + aoi_widget.layout.min_width = "300px" + aoi_widget.layout.max_height = "360px" + aoi_widget.layout.overflow = "auto" aoi_widget_desc = HTML( - value="

Polygon

", + value="

Polygon

", ) aoi_html = HTML( value="Waiting for area of interest...", description="", - ) + ) aoi_clear_button = Button( description="Clear AOI Polygon", tooltip="Clear AOI Polygon", @@ -186,97 +211,97 @@ def create_aoi_widget(self): ) aoi_widget.children = [aoi_widget_desc, aoi_html, aoi_clear_button] - aoi_widget.layout.display ='none' + aoi_widget.layout.display = "none" return aoi_widget - + def create_layers_widget(self): - layers_widget = Box(style= { "max-width: 420px" }) - layers_widget.layout.flex_flow="column" - layers_widget.layout.max_height="360px" - layers_widget.layout.overflow="auto" + layers_widget = Box(style={"max-width: 420px"}) + layers_widget.layout.flex_flow = "column" + layers_widget.layout.max_height = "360px" + layers_widget.layout.overflow = "auto" - tab_headers = ['Biomass Layers', 'Basemaps'] + tab_headers = ["Biomass Layers", "Basemaps"] tab_children = [] tab_widget = Tab() out = Output() display(out) - - opacity_values = [i*10 for i in range(10+1)] # [0.001, 0.002, ...] - + opacity_values = [i * 10 for i in range(10 + 1)] # [0.001, 0.002, ...] + def handle_basemap_opacity_change(change): selected_bm = self.basemap_selection_dd.value for l in self.layers: if l.base: if l.name == selected_bm: - l.opacity = change['new']/100 + l.opacity = change["new"] / 100 def handle_layer_opacity_change(change): selected_layer = change.owner.description for l in self.layers: if l.name == selected_layer: - l.opacity = change['new'] + l.opacity = change["new"] - for tab in tab_headers: - tab_content = VBox() + for tab in tab_headers: + tab_content = VBox() listed_layers = [] - # sort layers by name property + # sort layers by name property layers_in_drawing_order = [l for l in self.layers] - layerlist_layers = sorted(layers_in_drawing_order, key=lambda x: x.name, reverse=False) - if tab == "Biomass Layers": - layers_hbox = [] - for layer in layerlist_layers: + layerlist_layers = sorted( + layers_in_drawing_order, key=lambda x: x.name, reverse=False + ) + if tab == "Biomass Layers": + layers_hbox = [] + for layer in layerlist_layers: # check if layer name is a basemap - if not layer.base: + if not layer.base: layer_checkbox = Checkbox( - value=layer.visible, - description=layer.name, - indent=False + value=layer.visible, description=layer.name, indent=False ) jslink((layer_checkbox, "value"), (layer, "visible")) - hbox = HBox( - [layer_checkbox] - ) + hbox = HBox([layer_checkbox]) layer_opacity_slider = SelectionSlider( value=1, - options=[("%g"%i, i/100) for i in opacity_values], + options=[("%g" % i, i / 100) for i in opacity_values], description=f"{layer.name}", continuous_update=False, - orientation='horizontal', - layout=Layout(margin="-12px 0 4px 0") + orientation="horizontal", + layout=Layout(margin="-12px 0 4px 0"), ) layer_opacity_slider.style.description_width = "0px" layer_opacity_slider.style.handle_color = self.accent_color - layer_opacity_slider.observe(handle_layer_opacity_change, names="value") + layer_opacity_slider.observe( + handle_layer_opacity_change, names="value" + ) layers_hbox.append(hbox) layers_hbox.append(layer_opacity_slider) listed_layers.append(layer.name) tab_content.children = [VBox(layers_hbox)] tab_children.append(tab_content) - elif tab == "Basemaps": + elif tab == "Basemaps": basemaps = [] - for layer in layerlist_layers: + for layer in layerlist_layers: # check if layer is a basemap if layer.base: basemaps.append((f"{layer.name}", f"{layer.name}")) - + def on_change(change): - if change['type'] == 'change' and change['name'] == 'value': + if change["type"] == "change" and change["name"] == "value": with out: out.clear_output() - #print("changed to %s" % change['new']) + # print("changed to %s" % change['new']) for l in self.layers: if l.base: - if l.name == change['new']: - l.opacity = basemap_opacity_slider.value/100 - l.visible = True + if l.name == change["new"]: + l.opacity = basemap_opacity_slider.value / 100 + l.visible = True else: l.visible = False return None - dropdown = Dropdown(options=basemaps, value="Open Street Map") - self.basemap_selection_dd = dropdown + + dropdown = Dropdown(options=basemaps, value="Open Street Map") + self.basemap_selection_dd = dropdown dropdown.observe(on_change) basemap_opacity_slider = IntSlider( @@ -284,17 +309,19 @@ def on_change(change): min=0, max=100, step=10, - description='% Opacity:', - #disabled=False, - style={'bar_color': 'maroon'}, + description="% Opacity:", + # disabled=False, + style={"bar_color": "maroon"}, continuous_update=False, - orientation='horizontal', + orientation="horizontal", readout=True, - readout_format='d' - ) + readout_format="d", + ) basemap_opacity_slider.style.handle_color = self.accent_color - basemap_opacity_slider.observe(handle_basemap_opacity_change, names="value") + basemap_opacity_slider.observe( + handle_basemap_opacity_change, names="value" + ) tab_content.children = [dropdown, basemap_opacity_slider] tab_children.append(tab_content) @@ -302,37 +329,44 @@ def on_change(change): tab_widget.titles = tab_headers print(tab_widget.box_style) layers_widget.children = [tab_widget] - layers_widget.layout.display ='none' + layers_widget.layout.display = "none" return layers_widget - def add_custom_tools(self): # Create custom map widgets self.layers_widget = self.create_layers_widget() self.stac_widget = StacDiscoveryWidget.template(self) - self.aoi_widget = self.create_aoi_widget() + self.aoi_widget = self.create_aoi_widget() layers_widget = VBox([self.layers_widget]) stac_widget = VBox([self.stac_widget]) aoi_widget = VBox([self.aoi_widget]) - layers_control = WidgetControl(widget=layers_widget, position="topright", id="layers_widget") - stack_control = WidgetControl(widget=stac_widget, position="topright", id="stac_widget") - aoi_control = WidgetControl(widget=aoi_widget, position="topright", id="aoi_widget") - + layers_control = WidgetControl( + widget=layers_widget, position="topright", id="layers_widget" + ) + stack_control = WidgetControl( + widget=stac_widget, position="topright", id="stac_widget" + ) + aoi_control = WidgetControl( + widget=aoi_widget, position="topright", id="aoi_widget" + ) + self.add(layers_control) self.add(stack_control) self.add(aoi_control) - def add_biomass_layers(self): - biomass_file = files('stac_ipyleaflet.data').joinpath('biomass-layers.csv') - with open(biomass_file, newline='') as f: + def add_biomass_layers(self): + biomass_file = files("stac_ipyleaflet.data").joinpath("biomass-layers.csv") + with open(biomass_file, newline="") as f: csv_reader = csv.reader(f) next(csv_reader, None) # skip the headers sorted_csv = sorted(csv_reader, key=lambda row: row[0], reverse=True) for row in sorted_csv: name, tile_url = row[0], row[1] - tile_layer = TileLayer(url=tile_url, attribution=name, name=name, visible=False) + tile_layer = TileLayer( + url=tile_url, attribution=name, name=name, visible=False + ) self.add_layer(tile_layer) def find_layer(self, name: str): @@ -509,7 +543,7 @@ def _part_read(src_path: str, *args, **kwargs) -> ImageData: self.remove_layer(self.loading_widget_layer) self.add_layer(histogram_layer) return None """ - + # generates warning/error popup """ def gen_popup_icon(self, msg): warning_msg = HTML() diff --git a/stac_ipyleaflet/stac_discovery/catalogs/nasa_maap_stac.py b/stac_ipyleaflet/stac_discovery/catalogs/nasa_maap_stac.py index d59ecea..1b530bc 100644 --- a/stac_ipyleaflet/stac_discovery/catalogs/nasa_maap_stac.py +++ b/stac_ipyleaflet/stac_discovery/catalogs/nasa_maap_stac.py @@ -78,9 +78,7 @@ print() df = pd.DataFrame(output_collections) df.sort_values(by=["id"], inplace=True) -df.drop(columns=["metadata"]).to_csv( - "nasa_maap_stac.tsv", index=False, sep="\t" -) +df.drop(columns=["metadata"]).to_csv("nasa_maap_stac.tsv", index=False, sep="\t") with open("nasa_maap_stac.json", "w") as f: json.dump(df.to_dict("records"), f, indent=4) diff --git a/stac_ipyleaflet/stac_discovery/requests.py b/stac_ipyleaflet/stac_discovery/requests.py index f9cecdc..05dacd4 100644 --- a/stac_ipyleaflet/stac_discovery/requests.py +++ b/stac_ipyleaflet/stac_discovery/requests.py @@ -2,6 +2,7 @@ import logging from stac_ipyleaflet.constants import REQUEST_TIMEOUT + def make_get_request(url, params=None, timeout=REQUEST_TIMEOUT): """GET Request wrapper to watch for and catch specific errors Args: @@ -17,4 +18,4 @@ def make_get_request(url, params=None, timeout=REQUEST_TIMEOUT): logging.error(f"timeout raised during get request") except requests.exceptions.RequestException as e: logging.error(e) - return None \ No newline at end of file + return None diff --git a/stac_ipyleaflet/widgets/basemaps.py b/stac_ipyleaflet/widgets/basemaps.py index 869f79c..eb8e64d 100644 --- a/stac_ipyleaflet/widgets/basemaps.py +++ b/stac_ipyleaflet/widgets/basemaps.py @@ -1,17 +1,15 @@ from ipyleaflet import basemaps, basemap_to_tiles, TileLayer from ipywidgets import Box -class BasemapsWidget(): + +class BasemapsWidget: def template(self, **kwargs) -> Box(): base_layers = [] - def make_base_layer (url=None, visible=False, name="", layer=""): + + def make_base_layer(url=None, visible=False, name="", layer=""): if url: layer = TileLayer( - url=url, - name=name, - base=True, - visible=False, - **kwargs + url=url, name=name, base=True, visible=False, **kwargs ) return layer else: @@ -19,55 +17,39 @@ def make_base_layer (url=None, visible=False, name="", layer=""): layer.base = True layer.visible = visible layer.name = name - return layer - + return layer + tile_layers = [ { "url": "https://mt1.google.com/vt/lyrs=p&x={x}&y={y}&z={z}", - "name": "Google Terrain" + "name": "Google Terrain", }, { "url": "http://services.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer/tile/{z}/{y}/{x}", - "name": "Esri Light Gray" + "name": "Esri Light Gray", }, ] - + for tl in tile_layers: tile_layer = make_base_layer(url=tl["url"], name=tl["name"]) base_layers.append(tile_layer) - + basemap_layers = [ - { - "layer": basemaps.Esri.WorldImagery, - "name": "Esri World Imagery" - }, - { - "layer": basemaps.Esri.NatGeoWorldMap, - "name": "Esri National Geographic" - }, - { - "layer": basemaps.OpenStreetMap.Mapnik, - "name": "Open Street Map" - }, - { - "layer": basemaps.OpenTopoMap, - "name": "Open Topo Map" - }, - { - "layer": basemaps.Stamen.Toner, - "name": "Black & White" - }, - { - "layer": basemaps.Strava.Water, - "name": "Water" - }, + {"layer": basemaps.Esri.WorldImagery, "name": "Esri World Imagery"}, + {"layer": basemaps.Esri.NatGeoWorldMap, "name": "Esri National Geographic"}, + {"layer": basemaps.OpenStreetMap.Mapnik, "name": "Open Street Map"}, + {"layer": basemaps.OpenTopoMap, "name": "Open Topo Map"}, + {"layer": basemaps.Stamen.Toner, "name": "Black & White"}, + {"layer": basemaps.Strava.Water, "name": "Water"}, ] - + for bm in basemap_layers: if bm["name"] == "Open Street Map": - bm_layer = make_base_layer(layer=bm["layer"], name=bm["name"], visible=True) + bm_layer = make_base_layer( + layer=bm["layer"], name=bm["name"], visible=True + ) else: bm_layer = make_base_layer(layer=bm["layer"], name=bm["name"]) base_layers.append(bm_layer) - + return base_layers diff --git a/stac_ipyleaflet/widgets/draw.py b/stac_ipyleaflet/widgets/draw.py index f90f148..7cad1a9 100644 --- a/stac_ipyleaflet/widgets/draw.py +++ b/stac_ipyleaflet/widgets/draw.py @@ -1,8 +1,9 @@ from ipyleaflet import DrawControl, GeoJSON from ipywidgets import Box, Output -class DrawControlWidget(): - def template(self, **kwargs) -> Box( style={"max_height: 200px"} ): + +class DrawControlWidget: + def template(self, **kwargs) -> Box(style={"max_height: 200px"}): main = self bbox_out = Output() @@ -10,25 +11,24 @@ def template(self, **kwargs) -> Box( style={"max_height: 200px"} ): draw_control = DrawControl( edit=False, remove=False, - circlemarker = {}, - polygon = {}, - polyline = {}, - ) + circlemarker={}, + polygon={}, + polyline={}, + ) aoi_coords = main.aoi_widget.children[1] - aoi_clear_button = main.aoi_widget.children[2] - - def handle_clear(self): + aoi_clear_button = main.aoi_widget.children[2] + + def handle_clear(self): draw_layer = main.find_layer("draw_layer") main.remove_layer(draw_layer) aoi_coords.value = "Waiting for area of interest..." aoi_clear_button.disabled = True - def handle_draw(self, action, geo_json, **kwargs): + def handle_draw(self, action, geo_json, **kwargs): main.aoi_coordinates = [] main.aoi_bbox = () - if action == "created": if geo_json["geometry"]: geojson_layer = GeoJSON( @@ -37,26 +37,33 @@ def handle_draw(self, action, geo_json, **kwargs): style={ "fillColor": "transparent", "color": "#333", - "weight": 3 - } + "weight": 3, + }, ) main.add_layer(geojson_layer) raw_coordinates = geo_json["geometry"]["coordinates"][0] + def bounding_box(points): x_coordinates, y_coordinates = zip(*points) - return (min(x_coordinates), min(y_coordinates), max(x_coordinates), max(y_coordinates)) + return ( + min(x_coordinates), + min(y_coordinates), + max(x_coordinates), + max(y_coordinates), + ) + bbox = bounding_box(raw_coordinates) main.aoi_coordinates = raw_coordinates main.aoi_bbox = bbox coords_list = [coord for coord in raw_coordinates] - coords = (",
".join(map(str, coords_list))) + coords = ",
".join(map(str, coords_list)) aoi_coords.value = f"

Coordinates:

{coords}

BBox:

{bbox}" self.clear() aoi_clear_button.disabled = False aoi_clear_button.on_click(handle_clear) - + return - + def value_changed(change): print("CHANGE", change) @@ -68,10 +75,10 @@ def value_changed(change): "shapeOptions": { "fillColor": "transparent", "color": "#333", - "fillOpacity": 1.0 + "fillOpacity": 1.0, }, - "repeatMode": False + "repeatMode": False, } draw_control.output = bbox_out - + return draw_control diff --git a/write_biomass_layers.py b/write_biomass_layers.py index 86b93e7..b878a9f 100644 --- a/write_biomass_layers.py +++ b/write_biomass_layers.py @@ -3,8 +3,9 @@ import json import os + def write_biomass_layers(): - data_dir = 'biomass-dashboard-datasets/datasets/' + data_dir = "biomass-dashboard-datasets/datasets/" files = os.listdir(data_dir) biomass_file = os.path.join( @@ -12,23 +13,28 @@ def write_biomass_layers(): "data", "biomass-layers.csv", ) - with open(biomass_file, 'w', newline='') as csv_file: - fieldnames = ['Layer Name', 'Tiles URL'] + with open(biomass_file, "w", newline="") as csv_file: + fieldnames = ["Layer Name", "Tiles URL"] writer = csv.DictWriter(csv_file, fieldnames=fieldnames) writer.writeheader() for filename in files: - with open(f"{data_dir}{filename}", 'r') as file_obj: + with open(f"{data_dir}{filename}", "r") as file_obj: data = json.loads(file_obj.read()) - if data['source'].get('tiles'): - tile_url = data['source']['tiles'][0] - tile_url = tile_url.replace('&color_formula=gamma r {gamma}', '') - tile_url = tile_url.replace('{titiler_server_url}', 'https://titiler.maap-project.org') + if data["source"].get("tiles"): + tile_url = data["source"]["tiles"][0] + tile_url = tile_url.replace("&color_formula=gamma r {gamma}", "") + tile_url = tile_url.replace( + "{titiler_server_url}", "https://titiler.maap-project.org" + ) file_obj.close() - writer.writerow({ - fieldnames[0]: data['id'].capitalize().replace('_', ' '), - fieldnames[1]: tile_url}) + writer.writerow( + { + fieldnames[0]: data["id"].capitalize().replace("_", " "), + fieldnames[1]: tile_url, + } + ) csv_file.close() -if __name__ == '__main__': - write_biomass_layers() +if __name__ == "__main__": + write_biomass_layers()