你可以用terra
.
library(terra)
f <- "MOD10A1.A2015364.h25v06.006.2016182181418.hdf"
你可以做
x <- rast(f)
names(x)
#[1] "MOD_Grid_Snow_500m:NDSI_Snow_Cover" "MOD_Grid_Snow_500m:NDSI_Snow_Cover_Basic_QA"
#[3] "MOD_Grid_Snow_500m:NDSI_Snow_Cover_Algorithm_Flags_QA" "MOD_Grid_Snow_500m:NDSI"
#[5] "MOD_Grid_Snow_500m:Snow_Albedo_Daily_Tile" "MOD_Grid_Snow_500m:orbit_pnt"
#[7] "MOD_Grid_Snow_500m:granule_pnt"
并使用第一层
ndsisc <- x[[1]]
ndsisc
#class : SpatRaster
#dimensions : 2400, 2400, 1 (nrow, ncol, nlyr)
#resolution : 463.3127, 463.3127 (x, y)
#extent : 7783654, 8895604, 2223901, 3335852 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs
#source : MOD10A1.A2015364.h25v06.006.2016182181418.hdf:MOD_Grid_Snow_500m:NDSI_Snow_Cover
#names : MOD_Grid_Snow_500m:NDSI_Snow_Cover
或者确认文件的子数据集结构
s <- sds(f)
s
#class : SpatDataSet
#subdatasets : 7
#dimensions : 2400, 2400 (nrow, ncol)
#nlyr : 1, 1, 1, 1, 1, 1, 1
#resolution : 463.3127, 463.3127 (x, y)
#extent : 7783654, 8895604, 2223901, 3335852 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs
#source(s) : MOD10A1.A2015364.h25v06.006.2016182181418.hdf
#names : NDSI_Snow_Cover, NDSI_Snow_Cover_Basic_QA, NDSI_Snow_Cover_Algorithm_Flags_QA, NDSI, Snow_Albedo_Daily_Tile, orbit_pnt, granule_pnt
names(s)
#[1] "NDSI_Snow_Cover" "NDSI_Snow_Cover_Basic_QA" "NDSI_Snow_Cover_Algorithm_Flags_QA"
#[4] "NDSI" "Snow_Albedo_Daily_Tile" "orbit_pnt"
[7] "granule_pnt"
并使用第一个子数据集
ndsisc <- s[1]
ndsisc
#class : SpatRaster
#dimensions : 2400, 2400, 1 (nrow, ncol, nlyr)
#resolution : 463.3127, 463.3127 (x, y)
#extent : 7783654, 8895604, 2223901, 3335852 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs
#source : MOD10A1.A2015364.h25v06.006.2016182181418.hdf:MOD_Grid_Snow_500m:NDSI_Snow_Cover
#names : NDSI snow cover from best observation of the day
现在用freq
(或unique
)检查值
fq <- freq(ndsisc)
tail(fq)
# layer value count
#[84,] 1 92 28
#[85,] 1 93 15
#[86,] 1 94 3
#[87,] 1 201 33636
#[88,] 1 237 37178
#[89,] 1 250 807785
正如您断言的那样,有低于 100 和高于 200 的值,但不是介于两者之间。
下一步可能是
nd <- clamp(ndsisc, 0, 100, values=FALSE)
nd
#class : SpatRaster
#dimensions : 2400, 2400, 1 (nrow, ncol, nlyr)
#resolution : 463.3127, 463.3127 (x, y)
#extent : 7783654, 8895604, 2223901, 3335852 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs
#source : memory
#names : NDSI snow cover from best observation of the day
#min values : 0
#max values : 94
也许您不小心使用了“Snow_Albedo_Daily_Tile”子数据集?
albedo <- s[5]
albedo
#class : SpatRaster
#dimensions : 2400, 2400, 1 (nrow, ncol, nlyr)
#resolution : 463.3127, 463.3127 (x, y)
#extent : 7783654, 8895604, 2223901, 3335852 (xmin, xmax, ymin, ymax)
#coord. ref. : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs
#source : MOD10A1.A2015364.h25v06.006.2016182181418.hdf:MOD_Grid_Snow_500m:Snow_Albedo_Daily_Tile
#names : Snow albedo of the corresponding snow cover observation
那个值在 100 到 200 之间。但这是否出乎意料?
as.vector(unique(albedo))
#[1] 0 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
#[32] 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#[63] 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 88 91 92 93 94 95
#[94] 100 101 125 137 150 251 253