modCloudMask: Create cloud masks for MODIS images

Description Usage Arguments Details Value Examples

View source: R/modCloudMask.R

Description

modCloudMask creates cloud masks derived from the State Quality Assurance (State QA) band.

Usage

1
modCloudMask(src, AppRoot, out.name, overwrite = FALSE, ...)

Arguments

src

the path to the folder with the MODIS with state_1km images.

AppRoot

the directory where cloud masks are saved.

out.name

the name of the folder that stores the outputs. If the arguemnt is not defined the folder will be named as "CloudMask".

overwrite

logical argument. If TRUE, overwrites the existing images with the same name.

...

arguments for nested functions.

  • dates a vector of dates being considered for creating cloud masks. This argument is optional.

Details

This function, interprets the State Quality Assurance (State QA) band to create cloud masks. The NA and 1 values of the mask represent cloudy and clear-sky pixels pixels respectively.

Value

this function does not return anything. It saves the cloud masks (CLD) as GTiff files in the AppRoot directory.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Not run: 
# load a spatial polygon object of Navarre
data(ex.navarre)
wdir <- file.path(tempdir(),"Path_for_downloading_folder")
print(wdir)

# search and download images from MODIS between
# 01-01-2018 and 03-01-2018 for the region of Navarre
modDownSearch(product = "MOD09GA",
            startDate = as.Date("01-01-2017", "%d-%m-%Y"),
            endDate = as.Date("03-01-2017", "%d-%m-%Y"),
            username = "username",
            password = "password",
            AppRoot = wdir,
            extract.tif = TRUE,
            collection = 6,
            extent = ex.navarre)
            
# assign src1 as the output folder for modMosaic
wdir.mod <- file.path(wdir, "Modis")
wdir.mod.tiles <- file.path(wdir.mod, "MOD09GA")
wdir.mod.tif <- file.path(wdir.mod.tiles, "tif")
# mosaic the MODIS images
modMosaic(wdir.mod.tif, # the input folder 
          AppRoot = wdir.mod.tiles, # the output folder 
          out.name = "Navarre", # creates Navarre folder in AppRoot
          gutils = TRUE,
          extent = ex.navarre)


wdir.mod.navarre <- file.path(wdir.mod.tiles, "Navarre")
# generate the cloud masks      
modCloudMask(src = wdir.mod.navarre,
             AppRoot = wdir.mod.tiles,
             overwrite = TRUE)
             
files.mod.cld <- file.path(wdir.mod.tiles,"CloudMask")
img.mod.cld <- stack(list.files(files.mod.cld, full.names=TRUE, pattern="CLD"))

# select b01
img.mod.navarre <- stack(list.files(wdir.mod.navarre, 
                                    full.names=TRUE, 
                                    recursive = TRUE, 
                                    pattern="b01_1"))

# project to 500m
img.mod.cld.500 <- projectRaster(img.mod.cld,img.mod.navarre)

# plot the cloud free b01 layer
spplot(img.mod.navarre*img.mod.cld.500)

## End(Not run)

RGISTools documentation built on July 2, 2020, 3:58 a.m.