I am using the following code to mask the clouds from Landsat image using QA band. I am facing the strange issue as you can see I have 2 print statements in my code which prints the fill_value of landsat_pre and landsat_pre_cl_free respectively. If I run the code with both the print statement i get the output as landsat_pre_cl_free 999999 and landsat_pre_cl_free 16959. Where as if I remove the first print statement then I get landsat_pre_cl_free 999999. I am unable to understand why the fill value of landsat_pre_cl_free is getting changed because of removing the first print statement. I am using the following packages with conda

rasterio                  1.0.25           py36h238e834_0    conda-forge
numpy                     1.17.2           py36h6b0580a_0    conda-forge


import earthpy.mask as em
import numpy as np
import numpy.ma as ma
import rasterio as rio

all_masked_values = [2800, 2804, 2808, 2812, 6896, 6900, 6904, 6908] 

landsat_qa_path = 'BQA.TIF'

with rio.open(path_landsat_pre_st) as landsat_pre_src:
    landsat_pre = landsat_pre_src.read(masked=True)

print("landsat_pre", landsat_pre.fill_value)

with rio.open(landsat_qa_path) as landsat_pre_cl:
    landsat_qa = landsat_pre_cl.read()

landsat_pre_cl_free = em.mask_pixels(
    landsat_pre, landsat_qa, vals=all_masked_values)

print("landsat_pre_cl_free", landsat_pre_cl_free.fill_value)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.