Skip to content

Commit

Permalink
#6 plot reference shoreline in detection images
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Nov 10, 2023
1 parent ae22e32 commit de6b0ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/coastsat/SDS_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,11 @@ def retrieve_images(
) as f:
for key in metadict.keys():
f.write("%s\t%s\n" % (key, metadict[key]))

if im_fn.get("ms", "unknown") != "unknown":
logger.info(
f"Successfully downloaded image id {im_meta.get('id','unknown')} as {im_fn.get('ms')}"
)
except Exception as e:
logger.error(
f"Could not save metasdata for {im_meta.get('id','unknown')} that failed.\n{e}"
Expand Down Expand Up @@ -1513,7 +1518,7 @@ def filter_S2_collection(im_list):
return im_list
else:
idx_max = np.argmax([np.sum(utm_zones == _) for _ in np.unique(utm_zones)])
utm_zone_selected = np.unique(utm_zones)[idx_max]
utm_zone_selected = np.unique(utm_zones)[idx_max]
# find the images that were acquired at the same time but have different utm zones
idx_all = np.arange(0, len(im_list), 1)
idx_covered = np.ones(len(im_list)).astype(bool)
Expand Down
24 changes: 23 additions & 1 deletion src/coastsat/SDS_shoreline.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ def extract_shorelines(
settings,
date,
satname,
im_ref_buffer,
)
# if the user decides to skip the image, continue and do not save the mapped shoreline
if skip_image:
Expand Down Expand Up @@ -877,7 +878,16 @@ def process_shoreline(contours, cloud_mask, im_nodata, georef, image_epsg, setti


def show_detection(
im_ms, cloud_mask, im_labels, shoreline, image_epsg, georef, settings, date, satname
im_ms,
cloud_mask,
im_labels,
shoreline,
image_epsg,
georef,
settings,
date,
satname,
im_ref_buffer=None,
):
"""
Shows the detected shoreline to the user for visual quality control.
Expand Down Expand Up @@ -998,8 +1008,18 @@ def show_detection(
ax1.axis("off")
ax1.set_title(sitename, fontweight="bold", fontsize=16)

# color map for the reference shoreline buffer
masked_cmap = plt.cm.get_cmap("Greys")
# masked_cmap.set_bad(color="gray", alpha=0)
# Create a masked array where False values are masked
masked_array = None
if im_ref_buffer is not None:
masked_array = np.ma.masked_where(im_ref_buffer == False, im_ref_buffer)

# create image 2 (classification)
ax2.imshow(im_class)
if masked_array is not None:
ax2.imshow(masked_array, cmap=masked_cmap, alpha=0.37)
ax2.plot(sl_pix[:, 0], sl_pix[:, 1], "k.", markersize=3)
ax2.axis("off")
orange_patch = mpatches.Patch(color=colours[0, :], label="sand")
Expand All @@ -1015,6 +1035,8 @@ def show_detection(

# create image 3 (MNDWI)
ax3.imshow(im_mwi, cmap="bwr")
if masked_array is not None:
ax3.imshow(masked_array, cmap=masked_cmap, alpha=0.37)
ax3.plot(sl_pix[:, 0], sl_pix[:, 1], "k.", markersize=3)
ax3.axis("off")
ax3.set_title(satname, fontweight="bold", fontsize=16)
Expand Down

0 comments on commit de6b0ba

Please sign in to comment.