Home > Back-end >  How to create a quality mask to mask multiple values in a MODIS LST raster
How to create a quality mask to mask multiple values in a MODIS LST raster

Time:12-16

I work with a land surfase temperature (LST) raster from the MODIS-terra satellite ->(raster1).

Each raster has an associated raster with quality flags for each pixel -> (qa1)

Doing freq(qa1) I get the values of the flags:

     value  count
[1,]     2   8482
[2,]     3  32563
[3,]    17     29
[4,]    21     45
[5,]    65 199897
[6,]    81   1076
[7,]   129      7
[8,]   145   1235
[9,]    NA 148615

I want to create a quality mask that keeps only the values: 0, 17 and 65. I did the following:

maskqa1[is.na(qa1)] <-0                  #to assign the value 0 to the NA of raster qa1
maskqa1[maskqa1 == 2 | maskqa1 == 3]<-NA #to mask pixels with flag 2 and 3
maskqa1[maskqa1 > 17]<-NA                #to mask pixels with flags greater than 17

With the last line I mask the flag 65. Surely there is a way to indicate to assign NA value to the flags between 17 and 65, that I don't know.

Later on I will work with rasters with other flags and I would like to know options to improve my filtering possibilities.

CodePudding user response:

Possibly the simplest approach would be to use the "not in" operator ! %in% to set all the values different from 0, 17 and 65 to NA.

im[!im %in% c(0, 17, 65)] <- NA
  • Related