diff --git a/src/coastseg/common.py b/src/coastseg/common.py index 387c2d8f..0639f9ec 100644 --- a/src/coastseg/common.py +++ b/src/coastseg/common.py @@ -1208,24 +1208,21 @@ def download_url(url: str, save_path: str, filename: str = None, chunk_size: int content_length = r.headers.get("Content-Length") if content_length: total_length = int(content_length) + with open(save_path, "wb") as fd: + with tqdm( + total=total_length, + unit="B", + unit_scale=True, + unit_divisor=1024, + desc=f"Downloading {filename}", + initial=0, + ascii=True, + ) as pbar: + for chunk in r.iter_content(chunk_size=chunk_size): + fd.write(chunk) + pbar.update(len(chunk)) else: - print( - "Content length not found in response headers. Downloading without progress bar." - ) - total_length = None - with open(save_path, "wb") as fd: - with tqdm( - total=total_length, - unit="B", - unit_scale=True, - unit_divisor=1024, - desc=f"Downloading {filename}", - initial=0, - ascii=True, - ) as pbar: - for chunk in r.iter_content(chunk_size=chunk_size): - fd.write(chunk) - pbar.update(len(chunk)) + logger.warning("Content length not found in response headers") def get_center_point(coords: list) -> tuple: @@ -1241,6 +1238,31 @@ def get_center_point(coords: list) -> tuple: return center_x, center_y +def convert_linestrings_to_multipoints(gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame: + """ + Convert LineString geometries in a GeoDataFrame to MultiPoint geometries. + Args: + - gdf (gpd.GeoDataFrame): The input GeoDataFrame. + Returns: + - gpd.GeoDataFrame: A new GeoDataFrame with MultiPoint geometries. If the input GeoDataFrame + already contains MultiPoints, the original GeoDataFrame is returned. + """ + + # Check if the gdf already contains MultiPoints + if any(gdf.geometry.type == "MultiPoint"): + return gdf + + def linestring_to_multipoint(linestring): + if isinstance(linestring, LineString): + return MultiPoint(linestring.coords) + return linestring + + # Convert each LineString to a MultiPoint + gdf["geometry"] = gdf["geometry"].apply(linestring_to_multipoint) + + return gdf + + def get_epsg_from_geometry(geometry: "shapely.geometry.polygon.Polygon") -> int: """Uses geometry of shapely rectangle in crs 4326 to return the most accurate utm code as a string of format 'epsg:utm_code' @@ -1645,7 +1667,7 @@ def save_extracted_shorelines( geomtype="lines", ) - # Save extracted shorelines as a GeoJSON file + # Save extracted shorelines to GeoJSON files extracted_shorelines.to_file( save_path, "extracted_shorelines_lines.geojson", extracted_shorelines_gdf_lines ) diff --git a/src/coastseg/extracted_shoreline.py b/src/coastseg/extracted_shoreline.py index f733f365..2b478ddc 100644 --- a/src/coastseg/extracted_shoreline.py +++ b/src/coastseg/extracted_shoreline.py @@ -285,6 +285,12 @@ def combine_satellite_data(satellite_data: dict) -> dict: # Fill the satellite_data dict for satname, sat_data in satellite_data.items(): + satellite_data[satname].setdefault("dates", []) + satellite_data[satname].setdefault("geoaccuracy", []) + satellite_data[satname].setdefault("shorelines", []) + satellite_data[satname].setdefault("cloud_cover", []) + satellite_data[satname].setdefault("filename", []) + satellite_data[satname].setdefault("idx", []) satellite_data[satname].setdefault("dates", []) satellite_data[satname].setdefault("geoaccuracy", []) satellite_data[satname].setdefault("shorelines", []) diff --git a/src/coastseg/map_UI.py b/src/coastseg/map_UI.py index 00ed9978..e8776fd7 100644 --- a/src/coastseg/map_UI.py +++ b/src/coastseg/map_UI.py @@ -612,7 +612,7 @@ def get_beach_area_slider(self): self.beach_area_slider = ipywidgets.IntSlider( value=1000, - min=10, + min=5, max=10000, step=10, description="min_beach_area (sqm):", @@ -741,7 +741,7 @@ def get_min_length_sl_slider(self): self.min_length_sl_slider = ipywidgets.IntSlider( value=500, - min=50, + min=5, max=1000, step=1, description="min_length_sl (m):", diff --git a/src/coastseg/settings_UI.py b/src/coastseg/settings_UI.py index 988ddffb..b026f719 100644 --- a/src/coastseg/settings_UI.py +++ b/src/coastseg/settings_UI.py @@ -168,7 +168,7 @@ def get_beach_area_slider(self): self.beach_area_slider = ipywidgets.IntSlider( value=4500, - min=100, + min=5, max=10000, step=10, description="min_beach_area (sqm):", @@ -233,7 +233,7 @@ def get_cloud_slider(self): self.cloud_slider = ipywidgets.IntSlider( value=300, - min=100, + min=0, max=1000, step=1, description="dist_clouds (m):",