Tips on Chap7 data preprocessing
hope-data-science opened this issue · 1 comments
Currently I'm learning this tutorial on my own, and I find that in 7.7.2, it takes a long time to resample such big data. Therefore I suggest we do the clipping in 7.7.3 first, and then resample. This may save some time. Will problem arise in it? Thanks.
My codes:
library(pacman)
p_load(sp,raster,rgeos,rgdal,rasterVis,raster,fs,sf,tidyverse)
# read data
manchester_boundary <- st_read("data/manchester_boundary_download/Manchester_boundary.shp")
listlandsat <- dir("data/LC08_L1TP_203023_20190513_20190521_01_T1",
pattern = "[B123456790].TIF",full.names = T) %>% stack()
#check they have the same Coordinate Reference System (CRS)
crs(manchester_boundary)
crs(listlandsat)
# get only Manchester
lsatmask <- listlandsat %>%
# now crop our temp data to the extent
crop(.,manchester_boundary)%>%
mask(., manchester_boundary)
# handle 8th band
b8list = dir("data/LC08_L1TP_203023_20190513_20190521_01_T1",
pattern = "[B8].TIF",full.names = T) %>%
raster()
## ngb is a nearest neighbour sampling method
b8correct <- b8list%>%
# now crop our temp data to the extent
crop(.,manchester_boundary)%>%
mask(., manchester_boundary)%>%
resample(., lsatmask$LC08_L1TP_203023_20190513_20190521_01_T1_B1,
method = "ngb")
lsatmask <- lsatmask %>%
addLayer(., b8correct)
raster::compareRaster(listlandsat$LC08_L1TP_203023_20190513_20190521_01_T1_B1,
listlandsat$LC08_L1TP_203023_20190513_20190521_01_T1_B8)
# add mask to the filenames within the raster stack
names(lsatmask) <- names(lsatmask)%>%
str_c(.,
"mask",
sep="_")
Thank you for your contribution. I've learned a lot from this course.
Thanks the the idea. This would work to speed the processing up, but resampling is changing the resolution of data or in this case making sure our band8 aligns with the rest of the raster. The issue with this is that if you clip and then resample the cells that might influence any chances could have been clipped and so influence the resampling. So, yes it is possible to do this, but it might slightly alter the result.