Closed madhuksridhar closed 4 months ago
Fmask rasters for test S30 and L30 granules uploaded here
Description of bits in the Fmask QA layer is given in HLS user guide Table 9
One way to read Fmask raster and mask out cloud related pixels
def retrieve_permutations(f, repeat=0):
import itertools
perm= itertools.product(*[f.get(i, [0, 1]) for i in range(repeat)])
possible_bin=[] ## binary
possible_int = [] ## int
for i in list(perm):
my_bin = ''.join((str(v) for v in i))
my_bin.replace("'","")
possible_bin.append(my_bin)
possible_int.append(int(my_bin,2))
return possible_bin, possible_int
def get_cloud_mask(fmask_ds):
"""
See Table 9 in the HLS v2 user guide
https://lpdaac.usgs.gov/documents/1698/HLS_User_Guide_V2.pdf
"""
cloud_shadow_fixed = {4: [1]}
adj_cloud_fixed = {5: [1]}
cloud_fixed = {6: [1]}
cloud_shadow_ignore = retrieve_permutations(cloud_shadow_fixed, 8)
adj_cloud_ignore = retrieve_permutations(adj_cloud_fixed, 8)
cloud_ignore = retrieve_permutations(cloud_fixed, 8)
## take the integer output
fmask_ignore =np.concatenate([cloud_ignore[1], cloud_shadow_ignore[1], adj_cloud_ignore[1]])
mask = fmask_ds.isin(fmask_ignore)
# check unique clear values after masking
#clear = fmask_ds.where(~fmask_ds.isin(fmask_ignore))
#print("unique cloud fmask values :", np.unique(clear))
return mask
Fixed by #10
Description
Restrict VI calculations to pixels that meet the following conditions: