Search code examples
rsentinel2

Read Sentinel-2 bands into R retrieves high values


When I directly read into R the jp2 band files I get unusual high values compared to when I read the files in SNAP (version 9). To read the bands into R I use terra package (you can also use raster package) and the values range from 0 to 18000 more or less. I was wondering if SNAP is doing some conversion that I am not aware of to show values that range from 0 to 0.15 more or less.

> r_10
class       : SpatRaster 
dimensions  : 10980, 10980, 4  (nrow, ncol, nlyr)
resolution  : 10, 10  (x, y)
extent      : 499980, 609780, 6690240, 6800040  (xmin, xmax, ymin, ymax)
coord. ref. : WGS 84 / UTM zone 32N (EPSG:32632) 
sources     : T32VNN_20181018T105031_B02_10m.jp2  
              T32VNN_20181018T105031_B03_10m.jp2  
              T32VNN_20181018T105031_B04_10m.jp2  
              ... and 1 more source(s)
names       : B02_10m_m10_2018, B03_10m_m10_2018, B04_10m_m10_2018, B08_10m_m10_2018 
min values  :                0,                0,                0,                0 
max values  :            18815,            17880,            17023,            15608 
> 

I have tried to export the bands from SNAP into TIF to see if it is a problem of format but it takes forever. I was hoping that there is a convesion factor to show the actual values that I need for my analysis.


Solution

  • SNAP applies a scaling factor of 1.0E4 so that values can be stored more efficiently as integers. You will need to either divide the values by this scaling factor in R, or else use the scaled units to benefit from more efficient integer arithmetic. See https://step.esa.int/docs/tutorials/Exporting%20data%20from%20SNAP.pdf for more details