Error when loading HDF files into R -
i trying use hdf data of chlorophyll levels in r, have package rhdf5
installed , running yet when try , load hdf data in lines of errors.
here code using
library("rhdf5") library(maps) june_data<-h5ls('./data/june chloro level.hdf') june_data
the error produces is
hdf5-diag: error detected in hdf5 (1.8.7) thread 0: #000: h5f.c line 1522 in h5fopen(): unable open file major: file accessability minor: unable open file #001: h5f.c line 1313 in h5f_open(): unable read superblock major: file accessability minor: read failed #002: h5fsuper.c line 334 in h5f_super_read(): unable find file signature major: file accessability minor: not hdf5 file #003: h5fsuper.c line 155 in h5f_locate_signature(): unable find valid file signature major: low-level i/o minor: unable initialize object hdf5: unable open file error in h5checktypeoropenloc(file, readonly = true) : error in h5checktypeoropenloc(). file './data/june chloro level.hdf' not valid hdf5 file.
i have looked through google , have found other people problem no idea how fix it.
i'm not sure if you've solved problem yet or figured out if files hdf4 or hdf? having similar problems , downloaded hdfview here check whether files hdf4 or 5.
they hdf4 , found easy solution working hdf4 files in r without having mess recompiling gdal or similar using gdal_translate
gdalutils
package. code used hdf files work:
library(gdalutils) # provides detailed data on hdf4 files takes ages gdalinfo("mod17a3h.a2000001.h21v09.006.2015141183401.hdf") # tells me subdatasets within hdf4 modis files , makes them list sds <- get_subdatasets("mod17a3h.a2000001.h21v09.006.2015141183401.hdf") sds [1] "hdf4_eos:eos_grid:mod17a3h.a2000001.h21v09.006.2015141183401.hdf:mod_grid_mod17a3h:npp_500m" [2] "hdf4_eos:eos_grid:mod17a3h.a2000001.h21v09.006.2015141183401.hdf:mod_grid_mod17a3h:npp_qc_500m" # i'm interested in first subdataset , can use gdal_translate convert .tif gdal_translate(sds[1], dst_dataset = "npp2000.tif") # load , plot new .tif rast <- raster("npp2000.tif") plot(rast) # if have lots of files can make loop files <- dir(pattern = ".hdf") files [1] "mod17a3h.a2000001.h21v09.006.2015141183401.hdf" "mod17a3h.a2001001.h21v09.006.2015148124025.hdf" [3] "mod17a3h.a2002001.h21v09.006.2015153182349.hdf" "mod17a3h.a2003001.h21v09.006.2015166203852.hdf" [5] "mod17a3h.a2004001.h21v09.006.2015099031743.hdf" "mod17a3h.a2005001.h21v09.006.2015113012334.hdf" [7] "mod17a3h.a2006001.h21v09.006.2015125163852.hdf" "mod17a3h.a2007001.h21v09.006.2015169164508.hdf" [9] "mod17a3h.a2008001.h21v09.006.2015186104744.hdf" "mod17a3h.a2009001.h21v09.006.2015198113503.hdf" [11] "mod17a3h.a2010001.h21v09.006.2015216071137.hdf" "mod17a3h.a2011001.h21v09.006.2015230092603.hdf" [13] "mod17a3h.a2012001.h21v09.006.2015254070417.hdf" "mod17a3h.a2013001.h21v09.006.2015272075433.hdf" [15] "mod17a3h.a2014001.h21v09.006.2015295062210.hdf" filename <- substr(files,11,14) filename <- paste0("npp", filename, ".tif") filename [1] "npp2000.tif" "npp2001.tif" "npp2002.tif" "npp2003.tif" "npp2004.tif" "npp2005.tif" "npp2006.tif" "npp2007.tif" "npp2008.tif" [10] "npp2009.tif" "npp2010.tif" "npp2011.tif" "npp2012.tif" "npp2013.tif" "npp2014.tif" <- 1 (i in 1:15){ sds <- get_subdatasets(files[i]) gdal_translate(sds[1], dst_dataset = filename[i]) }
it doesn't read them r there's no way manipulate them before converting them worth finding smallest geographic extent possible hdf files you're not waiting ages.
for data (assuming hdf4) looks change filename , select subset want , should work you. original post answer here:
Comments
Post a Comment