Skip to content

Commit

Permalink
Merge branch 'update_sliders_1.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Nov 3, 2023
1 parent d34e7ca commit 9abf3f6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
58 changes: 40 additions & 18 deletions src/coastseg/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand Down Expand Up @@ -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
)
Expand Down
6 changes: 6 additions & 0 deletions src/coastseg/extracted_shoreline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", [])
Expand Down
4 changes: 2 additions & 2 deletions src/coastseg/map_UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):",
Expand Down Expand Up @@ -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):",
Expand Down
4 changes: 2 additions & 2 deletions src/coastseg/settings_UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):",
Expand Down Expand Up @@ -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):",
Expand Down

0 comments on commit 9abf3f6

Please sign in to comment.