Skip to content

Commit

Permalink
finish testing filtering out cloudy images and update printed msg whe…
Browse files Browse the repository at this point in the history
…n image is filtered out
  • Loading branch information
2320sharon committed Apr 17, 2024
1 parent 5320553 commit b303b74
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/coastsat/SDS_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,7 @@ def retrieve_images(

fn = [filepath_ms,filepath_swir,filepath_QA]

# Removes images whose cloud cover and no data coverage exceeds the threshold
skip_image=SDS_preprocess.filter_images_by_cloud_cover_nodata(fn,satname, cloud_mask_issue,max_cloud_no_data_cover,cloud_threshold, do_cloud_mask=True, s2cloudless_prob=60)

# if the images was filtered out, skip the image being saved as a jpg
Expand Down
10 changes: 2 additions & 8 deletions src/coastsat/SDS_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def filter_images_by_cloud_cover_nodata(fn, satname, cloud_mask_issue, max_cloud
if max_cloud_no_data_cover is None and max_cloud_cover is None:
# nothing was filtered return False
return False
print(f"max_cloud_no_data_cover: {max_cloud_no_data_cover}, max_cloud_cover: {max_cloud_cover}")
(
im_ms,
georef,
Expand Down Expand Up @@ -115,9 +114,8 @@ def remove_files_above_threshold(filepaths: list[str], prc: float, threshold: in
Returns:
bool: True if files were removed, False otherwise.
"""
print(f"prc: {prc}, threshold: {threshold} {msg}")
if prc > threshold:
print(f"skipping image {os.path.basename(filepaths[0])} {msg} {prc*100:.2f}%")
print(f"skipping image '{os.path.basename(filepaths[0])}' {msg} {prc*100:.2f}% exceeds threshold of {threshold*100:.2f}%")
# delete files that exceed the cloud cover threshold
for file in filepaths:
os.remove(file)
Expand Down Expand Up @@ -283,7 +281,7 @@ def pad_edges(im_swir: np.ndarray, im_nodata: np.ndarray) -> np.ndarray:
if right_pad > 0:
im_nodata[:, -right_pad:] = True

# Apply this padding to your masks or other arrays as needed
# Apply this padding to your masks
im_nodata[:top_pad, :] = True
im_nodata[:, :left_pad] = True
return im_nodata
Expand Down Expand Up @@ -570,10 +568,6 @@ def get_zero_pixels(im_ms: np.ndarray, shape: tuple) -> np.ndarray:
im_zeros = np.ones(shape).astype(bool)
for k in [1, 3, 4]: # loop through the Green, NIR and SWIR bands
im_zeros = np.logical_and(np.isin(im_ms[:, :, k], 0), im_zeros)
# modify the logic to add ANY pixel with 0 intensity in ANY of the Green, NIR and SWIR bands to the im_zeros mask
# im_zeros = np.zeros(shape).astype(bool)
# for k in [1, 3, 4]: # loop through the Green, NIR and SWIR bands
# im_zeros = np.logical_or(np.isin(im_ms[:, :, k], 0), im_zeros)
return im_zeros


Expand Down

0 comments on commit b303b74

Please sign in to comment.