rhdfsrasternetcdfhdf

Extracting a variable from multiple hdf files


I have these 3 files here. Trying to stack them and extract a variable called "OzoneTropColumn". I am able to extract data for single file but unable to extract for multiple files.

library(raster)
library(ncdf4)
list_col1 <- list.files("E:/TES", pattern = "*.hdf", full.names = TRUE) 
ncin1 <- raster::stack(list_col1, varname = "Data Fields/OzoneTropColumn", ncdf=TRUE)

Any help would be much appreciated.

Thank you


Solution

  • I don't know if this really works since I am no expert in raster or importing hdf files. But this code did load the three files in R for me but still gave some warnings:-

    library(raster)
    library(ncdf4)
    list_col1 <- as.list(list.files("E:/TES", pattern = "*.hdf",
                                    full.names = TRUE))
    ncin1 <- raster::stack(list_col1,
                           varname = "Data Fields/OzoneTropColumn",
                           ncdf=TRUE)
    
    [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named Data Fields/phony_dim_1 BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
    [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named Data Fields/phony_dim_0 BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
    [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named Data Fields/phony_dim_1 BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
    [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named Data Fields/phony_dim_0 BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
    [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named Data Fields/phony_dim_1 BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
    [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named Data Fields/phony_dim_0 BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
    [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named Data Fields/phony_dim_1 BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
    [1] "vobjtovarid4: **** WARNING **** I was asked to get a varid for dimension named Data Fields/phony_dim_0 BUT this dimension HAS NO DIMVAR! Code will probably fail at this point"
    

    But does shows me that it has read the 3 files

    ncin1[[1]]
    class      : RasterLayer 
    dimensions : 83, 90, 7470  (nrow, ncol, ncell)
    resolution : 1, 1  (x, y)
    extent     : 0.5, 90.5, 0.5, 83.5  (xmin, xmax, ymin, ymax)
    crs        : NA 
    source     : /home/shawn/Downloads/TES/TES-Aura_L3-O3-M2004m09_F01_12.hdf 
    names      : Data.Fields.OzoneTropColumn.1 
    zvar       : Data Fields/OzoneTropColumn
    
    ncin1[[2]]
    class      : RasterLayer 
    dimensions : 83, 90, 7470  (nrow, ncol, ncell)
    resolution : 1, 1  (x, y)
    extent     : 0.5, 90.5, 0.5, 83.5  (xmin, xmax, ymin, ymax)
    crs        : NA 
    source     : /home/shawn/Downloads/TES/TES-Aura_L3-O3-M2004m10_F01_12.hdf 
    names      : Data.Fields.OzoneTropColumn.2 
    zvar       : Data Fields/OzoneTropColumn
    
    ncin1[[3]]
    class      : RasterLayer 
    dimensions : 83, 90, 7470  (nrow, ncol, ncell)
    resolution : 1, 1  (x, y)
    extent     : 0.5, 90.5, 0.5, 83.5  (xmin, xmax, ymin, ymax)
    crs        : NA 
    source     : /home/shawn/Downloads/TES/TES-Aura_L3-O3-M2004m11_F01_12.hdf 
    names      : Data.Fields.OzoneTropColumn.3 
    zvar       : Data Fields/OzoneTropColumn