sentinel-hub/sentinel2-cloud-detector

missing NaN values in CloudMaskRequest

mdoubko opened this issue · 10 comments

Dear all,

I have noticed that no data in mask and prob outputs of CloudMaskRequest are assigned 0 and 0.0007 value, respectively! Am I doing something wrong?

I have noticed this when using following WCS request over fields where a scenes border occurred (in particular in Haselsdorf, Austria on 21/8/2017:

wcs_bands_request = WcsRequest(data_folder=outdir,
resx='10m',
resy='10m',
layer='NDVI__NORMALIZED_DIFFERENCE_VEGETATION_INDEX_',
maxcc=1.0,
bbox=betsiboka_bbox,
time=timerange,
image_format=MimeType.TIFF_d32f,
custom_url_params={CustomUrlParam.SHOWLOGO: False, CustomUrlParam.ATMFILTER:"None", CustomUrlParam.EVALSCRIPT: bands_script},
instance_id=userID)
all_cloud_masks = CloudMaskRequest(ogc_request=wcs_bands_request, threshold=0.2)

thanks,
Marcela Doubkova

Dear Marcela,

could you please share the code snippet that reproduces the problem? Like above, but with the definition of the bbox and time_interval.

Thank you and best regards,

Anze

Hi Marcela,

please upgrade your s2cloudless package to the new version 1.1.0. In this latest version you can assign a cloud probability (or mask) value for non valid data pixels. By default it is set to 0 and False, respectively. But if you prefer, you can set it to np.nan or any other value. Example code snippet:

all_cloud_masks.get_probability_masks(non_valid_value=0)

This functionality is included in CloudMaskRequest.

The non valid value is specified in get_probability_masks and get_cloud_masks methods:

all_cloud_masks = CloudMaskRequest(ogc_request=wcs_bands_request, threshold=0.2)

all_cloud_masks.get_probability_masks(non_valid_value=0)
or
all_cloud_masks.get_cloud_masks(non_valid_value=False)

Thanks, nevertheless I am using cloudmaskrequest in iterative manner. My, hopefully last question, at least fo rnow, is how should I update following code?
THANSK!

all_cloud_masks = CloudMaskRequest(ogc_request=wcs_bands_request, threshold=0.2)

cloud_prob_mean = np.empty(len(dates_WCS), dtype=np.float32) index = 0

for prob, mask, data in all_cloud_masks:
cloud_prob_mean[index] = np.nanmean(prob)
index = index +1

Two options:


all_cloud_masks = CloudMaskRequest(ogc_request=wcs_bands_request, threshold=0.2)
cloud_prob_mean = np.empty(len(dates_WCS), dtype=np.float32)
index = 0
all_cloud_masks.get_probability_masks(non_valid_value=np.nan)

for prob, mask, data in all_cloud_masks:
cloud_prob_mean[index] = np.nanmean(prob)
index = index +1

Note: cloud probability maps are cached and hence calculated only once.


all_cloud_masks = CloudMaskRequest(ogc_request=wcs_bands_request, threshold=0.2)
cloud_probs = all_cloud_masks.get_probability_masks(non_valid_value=np.nan)
cloud_prob_mean = np.nanmean(cloud_probs, axis=(1,2))