rsatellite-imagelandsat

Radiometric corrections with R


I am trying to convert Landsat 8 files to reflectance via R / RStoolbox

I am using a script with the following code:

metaData  <- readMeta("LC08_L1TP_183033_20210623_20210630_02_T1_MTL.txt")
lsat <- stackMeta("LC08_L1TP_183033_20210623_20210630_02_T1_MTL.txt")
lsat_sref <- radCor(lsat, metaData, method = "dos")

I've got this error :

Error in CRS(paste0(c("+proj=", "+zone=", "+units=m +datum="), pars, collapse = " ")) :
  No spaces permitted in PROJ4 argument-value pairs: +proj= +zone= +units=m +datum=

Can you try to help me please ?


Solution

  • The problem is with your second line of code. You need to change it as follows and it should work:

    lsat <- stackMeta(metaData)

    Please find below a little reprex to show you how it works:

    REPREX

    library(RStoolbox)
    
    mtlFile  <- system.file("external/landsat/LT52240631988227CUB02_MTL.txt", package="RStoolbox")
    metaData <- readMeta(mtlFile)
    lsat <- stackMeta(metaData)
    lsat_sref <- radCor(lsat, metaData, method = "dos")
    
    lsat_sref
    #> class      : RasterStack 
    #> dimensions : 310, 287, 88970, 7  (nrow, ncol, ncell, nlayers)
    #> resolution : 30, 30  (x, y)
    #> extent     : 619395, 628005, -419505, -410205  (xmin, xmax, ymin, ymax)
    #> crs        : +proj=utm +zone=22 +datum=WGS84 +units=m +no_defs 
    #> names      :       B1_sre,       B2_sre,       B3_sre,       B4_sre,       B5_sre,        B6_bt,       B7_sre 
    #> min values :   0.01327889,   0.00000000,   0.00000000,   0.00000000,   0.00000000, 293.37508120,   0.00000000 
    #> max values :    0.2028536,    0.1935375,    0.2243498,    0.4356817,    0.3393489,  299.8284592,    0.2617160
    

    Created on 2021-10-12 by the reprex package (v2.0.1)

    Edit

    Output of summary()

    summary(metaData)
    #> Scene:      LT52240631988227CUB02 
    #> Satellite:  LANDSAT5 
    #> Sensor:     TM 
    #> Date:       1988-08-14 
    #> Path/Row:   224/63 
    #> Projection: +proj=utm +zone=22 +datum=WGS84 +units=m +no_defs
    #> 
    #> Data:
    #>                              FILES QUANTITY CATEGORY
    #> B1_dn LT52240631988227CUB02_B1.TIF       dn    image
    #> B2_dn LT52240631988227CUB02_B2.TIF       dn    image
    #> B3_dn LT52240631988227CUB02_B3.TIF       dn    image
    #> B4_dn LT52240631988227CUB02_B4.TIF       dn    image
    #> B5_dn LT52240631988227CUB02_B5.TIF       dn    image
    #> B6_dn LT52240631988227CUB02_B6.TIF       dn    image
    #> B7_dn LT52240631988227CUB02_B7.TIF       dn    image
    #> 
    #> Available calibration parameters (gain and offset):
    #>  dn -> radiance (toa)
    #>  dn -> brightness temperature (toa)
    

    Created on 2021-10-12 by the reprex package (v2.0.1)

    Edit 2

    I think I found your problem. When downloading from the site https://earthexplorer.usgs.gov/ you normally get, in addition to the .mtl metadata file, a total of 12 radiometric bands (i.e. B1-B11, and a "dedicated assessment quality band"-i.e. Bqa). All these files must be in the same folder and you must not delete any of them (some of them are used for radiometric corrections). In other words, the package RSToolbox is expecting these different files.

    If you do this, everything should work.

    Here is an example (not a reprex) from a landsat 8 image that I downloaded and all the code works:

    library(RStoolbox)
    metaData <- readMeta("DATA_09/Landsat8/Landsat8_RAW/LC08_L1TP_016030_20160927_20170220_01_T1_MTL.txt")
    
    # NB : Please, note the presence of all the bands (B1-B11 + Band qa):
    
    summary(metaData)
    #> Scene:      LC80160302016271LGN01 
    #> Satellite:  LANDSAT8 
    #> Sensor:     OLI_TIRS 
    #> Date:       2016-09-27 
    #> Path/Row:   16/30 
    #> Projection: +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs
    
    #> Data:
    #>                                                   FILES QUANTITY CATEGORY
    #> B1_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B1.TIF       dn    image
    #> B2_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B2.TIF       dn    image
    #> B3_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B3.TIF       dn    image
    #> B4_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B4.TIF       dn    image
    #> B5_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B5.TIF       dn    image
    #> B6_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B6.TIF       dn    image
    #> B7_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B7.TIF       dn    image
    #> B9_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B9.TIF       dn    image
    #> B10_dn LC08_L1TP_016030_20160927_20170220_01_T1_B10.TIF       dn    image
    #> B11_dn LC08_L1TP_016030_20160927_20170220_01_T1_B11.TIF       dn    image
    #> B8_dn   LC08_L1TP_016030_20160927_20170220_01_T1_B8.TIF       dn      pan
    #> QA_dn  LC08_L1TP_016030_20160927_20170220_01_T1_BQA.TIF       dn       qa
    #>
    #> Available calibration parameters (gain and offset):
    #>  dn -> radiance (toa)
    #>  dn -> reflectance (toa)
    #>  dn -> brightness temperature (toa)
    
    lsat <- stackMeta(metaData)
    lsat
    #> class      : RasterStack 
    #> dimensions : 504, 541, 272664, 10  (nrow, ncol, ncell, nlayers)
    #> resolution : 30, 30  (x, y)
    #> extent     : 318195, 334425, 4737735, 4752855  (xmin, xmax, ymin, ymax)
    #> crs        : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs 
    #> names      : B1_dn, B2_dn, B3_dn, B4_dn, B5_dn, B6_dn, B7_dn, B9_dn, B10_dn, #> B11_dn 
    #> min values :  8492,  7617,  6777,  6026,  5290,  5185,  5142,  4995,  22328,  #> 20666 
    #> max values : 19081, 19935, 21595, 22716, 27590, 38013, 39165,  5105,  30111,  #> 27137 
    
    
    lsat_sref <- radCor(lsat, metaData, method = "dos")
    lsat_sref
    #> class      : RasterStack 
    #> dimensions : 504, 541, 272664, 10  (nrow, ncol, ncell, nlayers)
    #> resolution : 30, 30  (x, y)
    #> extent     : 318195, 334425, 4737735, 4752855  (xmin, xmax, ymin, ymax)
    #> crs        : +proj=utm +zone=18 +datum=WGS84 +units=m +no_defs 
    #> names      :       B1_sre,       B2_sre,       B3_sre,       B4_sre,        B5_sre,       B6_sre,       B7_sre,       B9_sre,       B10_bt,       B11_bt 
    #> min values : 1.078127e-01, 7.822588e-02, 5.389152e-02, 3.082883e-02, 8.681202e-03, 5.291948e-03, 3.968224e-03, 0.000000e+00, 2.847589e+02, 2.830717e+02 
    #> max values : 4.347280e-01, 4.464235e-01, 5.032560e-01, 5.323340e-01, 6.762622e-01, 9.449113e-01, 9.547490e-01, 3.183901e-03, 3.039071e+02, 3.018956e+02