Skip to content

Commit

Permalink
Merge pull request #218 from kvos/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
kvos authored May 28, 2021
2 parents 380ca2a + 4b5ab52 commit 0520c4b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
26 changes: 22 additions & 4 deletions coastsat/SDS_classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,18 @@ def label_images(metadata,settings):
fn = SDS_tools.get_filenames(filenames[i],filepath, satname)
# read and preprocess image
im_ms, georef, cloud_mask, im_extra, im_QA, im_nodata = SDS_preprocess.preprocess_single(fn, satname, settings['cloud_mask_issue'])
# calculate cloud cover
cloud_cover = np.divide(sum(sum(cloud_mask.astype(int))),

# compute cloud_cover percentage (with no data pixels)
cloud_cover_combined = np.divide(sum(sum(cloud_mask.astype(int))),
(cloud_mask.shape[0]*cloud_mask.shape[1]))
if cloud_cover_combined > 0.99: # if 99% of cloudy pixels in image skip
continue

# remove no data pixels from the cloud mask (for example L7 bands of no data should not be accounted for)
cloud_mask_adv = np.logical_xor(cloud_mask, im_nodata)
# compute updated cloud cover percentage (without no data pixels)
cloud_cover = np.divide(sum(sum(cloud_mask_adv.astype(int))),
(sum(sum((~im_nodata).astype(int)))))
# skip image if cloud cover is above threshold
if cloud_cover > settings['cloud_thresh'] or cloud_cover == 1:
continue
Expand Down Expand Up @@ -559,9 +568,18 @@ def evaluate_classifier(classifier, metadata, settings):
# read and preprocess image
im_ms, georef, cloud_mask, im_extra, im_QA, im_nodata = SDS_preprocess.preprocess_single(fn, satname, settings['cloud_mask_issue'])
image_epsg = metadata[satname]['epsg'][i]
# calculate cloud cover
cloud_cover = np.divide(sum(sum(cloud_mask.astype(int))),

# compute cloud_cover percentage (with no data pixels)
cloud_cover_combined = np.divide(sum(sum(cloud_mask.astype(int))),
(cloud_mask.shape[0]*cloud_mask.shape[1]))
if cloud_cover_combined > 0.99: # if 99% of cloudy pixels in image skip
continue

# remove no data pixels from the cloud mask (for example L7 bands of no data should not be accounted for)
cloud_mask_adv = np.logical_xor(cloud_mask, im_nodata)
# compute updated cloud cover percentage (without no data pixels)
cloud_cover = np.divide(sum(sum(cloud_mask_adv.astype(int))),
(sum(sum((~im_nodata).astype(int)))))
# skip image if cloud cover is above threshold
if cloud_cover > settings['cloud_thresh']:
continue
Expand Down
25 changes: 21 additions & 4 deletions coastsat/SDS_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,9 +641,18 @@ def save_jpg(metadata, settings, **kwargs):
fn = SDS_tools.get_filenames(filenames[i],filepath, satname)
# read and preprocess image
im_ms, georef, cloud_mask, im_extra, im_QA, im_nodata = preprocess_single(fn, satname, settings['cloud_mask_issue'])
# calculate cloud cover
cloud_cover = np.divide(sum(sum(cloud_mask.astype(int))),

# compute cloud_cover percentage (with no data pixels)
cloud_cover_combined = np.divide(sum(sum(cloud_mask.astype(int))),
(cloud_mask.shape[0]*cloud_mask.shape[1]))
if cloud_cover_combined > 0.99: # if 99% of cloudy pixels in image skip
continue

# remove no data pixels from the cloud mask (for example L7 bands of no data should not be accounted for)
cloud_mask_adv = np.logical_xor(cloud_mask, im_nodata)
# compute updated cloud cover percentage (without no data pixels)
cloud_cover = np.divide(sum(sum(cloud_mask_adv.astype(int))),
(sum(sum((~im_nodata).astype(int)))))
# skip image if cloud cover is above threshold
if cloud_cover > cloud_thresh or cloud_cover == 1:
continue
Expand Down Expand Up @@ -733,9 +742,17 @@ def get_reference_sl(metadata, settings):
fn = SDS_tools.get_filenames(filenames[i],filepath, satname)
im_ms, georef, cloud_mask, im_extra, im_QA, im_nodata = preprocess_single(fn, satname, settings['cloud_mask_issue'])

# calculate cloud cover
cloud_cover = np.divide(sum(sum(cloud_mask.astype(int))),
# compute cloud_cover percentage (with no data pixels)
cloud_cover_combined = np.divide(sum(sum(cloud_mask.astype(int))),
(cloud_mask.shape[0]*cloud_mask.shape[1]))
if cloud_cover_combined > 0.99: # if 99% of cloudy pixels in image skip
continue

# remove no data pixels from the cloud mask (for example L7 bands of no data should not be accounted for)
cloud_mask_adv = np.logical_xor(cloud_mask, im_nodata)
# compute updated cloud cover percentage (without no data pixels)
cloud_cover = np.divide(sum(sum(cloud_mask_adv.astype(int))),
(sum(sum((~im_nodata).astype(int)))))

# skip image if cloud cover is above threshold
if cloud_cover > settings['cloud_thresh']:
Expand Down
2 changes: 1 addition & 1 deletion coastsat/SDS_shoreline.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def extract_shorelines(metadata, settings):
cloud_mask_adv = np.logical_xor(cloud_mask, im_nodata)
# compute updated cloud cover percentage (without no data pixels)
cloud_cover = np.divide(sum(sum(cloud_mask_adv.astype(int))),
(cloud_mask.shape[0]*cloud_mask.shape[1]))
(sum(sum((~im_nodata).astype(int)))))
# skip image if cloud cover is above user-defined threshold
if cloud_cover > settings['cloud_thresh']:
continue
Expand Down

0 comments on commit 0520c4b

Please sign in to comment.