Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTL file error #84

Open
abenson-ut opened this issue Jun 23, 2022 · 2 comments
Open

MTL file error #84

abenson-ut opened this issue Jun 23, 2022 · 2 comments

Comments

@abenson-ut
Copy link

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

@Rapsodia86
Copy link

Rapsodia86 commented Jun 27, 2022

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)

@andrewmaclachlan
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants