Skip to content

Commit

Permalink
fix error with ring around S2 img
Browse files Browse the repository at this point in the history
  • Loading branch information
2320sharon committed Jan 9, 2024
1 parent 57ffd83 commit 5457b8e
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/coastsat/SDS_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,13 @@ def get_zero_pixels(im_ms: np.ndarray, shape: tuple) -> np.ndarray:
considered to be a zero pixel only if all of these three bands have a zero value for that pixel.
"""
# Identify identify pixels with 0 intensity in the Green, NIR and SWIR bands
im_zeros = np.ones(shape).astype(bool)
# im_zeros = np.ones(shape).astype(bool) # old code @todo remove this line if the new code works
# 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_and(np.isin(im_ms[:, :, k], 0), im_zeros)
im_zeros = np.logical_or(np.isin(im_ms[:, :, k], 0), im_zeros)
return im_zeros


Expand Down Expand Up @@ -550,7 +554,8 @@ def preprocess_single(
im_nodata = np.logical_or(im_zeros, im_nodata)
if "merged" in fn_ms:
im_nodata = morphology.dilation(im_nodata, morphology.square(5))

# update cloud mask with all the nodata pixels
cloud_mask = np.logical_or(cloud_mask, im_nodata)
else:
# compute cloud mask using QA60 band
cloud_mask_QA60 = create_cloud_mask(
Expand All @@ -567,10 +572,10 @@ def preprocess_single(
im_zeros = get_zero_pixels(im_ms, cloud_mask.shape)
# add zeros to im nodata
im_nodata = np.logical_or(im_zeros, im_nodata)
# update cloud mask with all the nodata pixels
cloud_mask = np.logical_or(cloud_mask, im_nodata)
if "merged" in fn_ms:
im_nodata = morphology.dilation(im_nodata, morphology.square(5))
# update cloud mask with all the nodata pixels
cloud_mask = np.logical_or(cloud_mask, im_nodata)

# no extra image
im_extra = []
Expand Down

0 comments on commit 5457b8e

Please sign in to comment.