Changing Reflectance Values in Python/Rasterio Modu

I’m needing some help. I’m attempting to use the Python modules rasterio and numpy to change the reflectance values. First I created a list of my bands, assigned variables, and then layer stacked the 4 bands. I need to do this again but I need to change the reflectance values by dividing all reflectance values by 10000 when you supply the individual bands’ arrays to the write function of the new layer stack. This is because surface reflectance values for the Sentinel 2 data are scaled by 10000. So, a value of 5000 in one of the bands (uint16 dtype) is actually a reflectance value of 0.5 (i.e. 5000/10000). My question is where exactly do I divide 10000 at? I’ve tried simply inserting “/10000” in the stacked.write lines. Ultimately, I keep coming up with either numpy.array issues or data types not matching other types. Below is the code for the original stack without modified values. Thank you so much in advance.

inlistB = [

b1 =, inlistB [0]), mode=‘r’)
b2 =, inlistB [1]), mode=‘r’)
b3 =, inlistB [2]), mode=‘r’)
b4 =, inlistB [3]), mode=‘r’)

stacked =
os.path.join(outdat, ‘stacked.tiff’), mode = ‘w’,
driver = ‘GTiff’,
height = b1.height,
width = b1.width,
count = len(inlistB),
dtype = b1.dtypes[0],
crs =,

stacked.write([0], 1)
stacked.write([0], 2)
stacked.write([0], 3)
stacked.write([0], 4)

stacked =, ‘stacked.tiff’), mode = ‘r’)

1 Like