I tried raster stacking using the below code.I tried to read pixel values at a particular coordinate and few values are coming as zero where as when I tried reading the value before stacking there is some pixel value at that particular coordinate. I don't understand why my raster stacking is causing the issue.

from rasterio import plot
import os
import earthpy.spatial as es

    def image_stack(path, dest_file):
        band_fnames = os.listdir(path)
        band_paths = [path + fname for fname in band_fnames]
        arr, arr_meta = es.stack(band_paths, dest_file)
        return len(band_fnames)
  • what is es? it gives me some errors. Could you please add the imports as well?
    – Muser
    Commented Aug 18, 2020 at 9:11
  • I have added the import statements to the code Commented Aug 18, 2020 at 9:25
  • 1
    listdir will also list directories in path, you have only valid files in path?
    – Bera
    Commented Aug 18, 2020 at 9:32
  • 1
    Yes I have only the required files in the path mentioned. Commented Aug 18, 2020 at 10:00

1 Answer 1


The issue is with the band count of the resultant stack, I have updated it's count and now the pixel values are non-zero .

  • Thanks for providing an answer. Could you please provide the code you used to solve the issue?
    – Aaron
    Commented Sep 20, 2020 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.