RStoolbox icon indicating copy to clipboard operation
RStoolbox copied to clipboard

MTL file error

Open abenson-ut opened this issue 2 years ago • 2 comments

Hello,

I am trying to do some atmospheric corrections on Landsat 8 data in Rstudio. Following previous code that I have seen I have run this so far.

install.packages("raster") install.packages("rgdal") install.packages("ggplot2") install.packages("devtools") install.packages("sf")

Define the multiple mutiple packages in a vector

PkgToLoad <- c("raster", "rgdal", "ggplot2", "devtools", "sf")

Load the packages

lapply(PkgToLoad, library, character.only = TRUE)

library(devtools)

The package 'devtools' is important in order to be able to import packages directly from the Github repository

Had to update all packages before this code would work

install_github("bleutner/RStoolbox")

library("RStoolbox")

#perform the radiometric correction #Import meta-data and bands based on MTL file

readMeta("C:/Users/Allyson/University of Texas at El Paso/Microsoft forest SD project - General/ABP/PR_Trial/PuertoRicoL8USGS/LC08_L2SP_005047_20180616_20200831_02_T1_MTL.txt") #sep = '=', stringsAsFactors = F package = "RStoolbox")

-when I try to read the MTL file I get this error

Error in .rowNamesDF<-(x, value = value) : duplicate 'row.names' are not allowed In addition: Warning message: non-unique value when setting 'row.names': ‘QA_NA’

I attached the MTL text file. Can anyone give me input on how I can fix this?

LC08_L2SP_005047_20180616_20200831_02_T1_MTL.txt

abenson-ut avatar Jun 23 '22 18:06 abenson-ut

Try raw=TRUE, so it will read all info. x <- readMeta("LC08_L2SP_005047_20180616_20200831_02_T1_MTL.txt",raw = TRUE)

looks like readMeta() has no LEVEL2 product included when you go default with raw=FALSE: lines 81-84:

prodid  <- .getParFromAnyGroup("LANDSAT_PRODUCT_ID", "LEVEL1") 
level   <- .getParFromAnyGroup("PROCESSING_LEVEL", "LEVEL1") 
colNum  <- .getParFromAnyGroup("COLLECTION_NUMBER", "LEVEL1") 
colTier <- .getParFromAnyGroup("COLLECTION_CATEGORY", "LEVEL1") 

Then problem in line 100 bands <- regmatches(files, regexpr("(?<=[\\dQA]_)[^_]*(?=\\.TIF)|B6_VCID.*(?=\\.TIF)", files, perl = TRUE)) finds only: [1] "AEROSOL" "PIXEL" "RADSAT" while changing to: bands <- regmatches(files, regexpr("(?<=[\\dQA_])[^_]*(?=\\.TIF)|B6_VCID.*(?=\\.TIF)", files, perl = TRUE)) gives:

[1] "B1"      "B2"      "B3"      "B4"      "B5"      "B6"      "B7"      "B10"     "TRAD"    "URAD"    "DRAD"    "ATRAN"   "EMIS"    "EMSD"    "CDIST"   "AEROSOL" "QA"      "PIXEL"   "RADSAT" 

Next thing, In level 2, there is no ANGLE tifs, so the MTL's PRODUCT_CONTENTS is different than those in the test folder. So, line 104 returns all FALSE obviously.

@bleutner including LEVEL 2 would be great!:)

Btw. Landsat L2 SP is already atmospherically corrected (https://www.usgs.gov/landsat-missions/landsat-collection-2-surface-reflectance)

Rapsodia86 avatar Jun 27 '22 14:06 Rapsodia86

I also had a similar issue when using Landsat 9 data, as it is only distributed as a level 2 product

andrewmaclachlan avatar Jul 19 '22 15:07 andrewmaclachlan