我正在使用包rhdf5构建一个具有特定地理域气候数据的大型h5。
域在空间中的维数为48x47 (lonxlat)。气候变量(降水、温度.)组织在一个由2256行(48*47=2256)和248个列组成的矩阵中(每天观察8次,为期31天)。
为了满足目标模型的需求,我需要将h5数据集构造为(time,lon,lat) (248,48,47)。为此,我将观测矩阵转换为c维数组(48,47,248) (lon,lat,time),然后使用命令'aperm‘来切换维数的顺序。
但是,当我在h5文件中写入数据集时,会收到以下消息:“不支持写入这种类型的数据”。
在这里,我使用的代码:
# load package from bioconductor
require(rhdf5)
setwd("path/to/file")
lon <-read.csv("lon_h5.csv", header=FALSE)
lon <-as.matrix(lon) #matrix 48x47
lat <-read.csv("lat_h5.csv", header=FALSE)
lat<-as.matrix(lat) #matrix 48x47
h5createFile("file.h5")
h5createDataset("file.h5", "lon",c(48,47), storage.mode = "double")
h5createDataset("file.h5", "lat",c(48,47), storage.mode = "double")
h5write(lon, file="file.h5", name="lon")
h5write(lat, file="file.h5", name="lat")
tmp <-read.csv(file="temperature.csv", header=TRUE)
tmp = array(tmp,dim=c(48,47,248)) # it loops the 48 longitude points first, then the 47 latitude points, then 248 time steps
tmp = aperm(a=tmp,perm=c(3,1,2)) # switch the order of the dimensions, putting time first, then longitude, then latitude
h5createDataset("file.h5", "tmp",c(248,48,47), storage.mode = "double")
h5write(tmp, file="file.h5", name="tmp")
'Writing of this type of data not supported.'这个数组有559488个元素(48*47*248),所以它不应该是一个维度问题。
当我写一个矩阵时,没有任何问题,例如对于lon和lat矩阵。有人知道包rhdf5是否有数组问题吗?
谢谢
更新:很明显,这个问题与数组的“列表”存储模式有关,而这个存储模式没有在rhdf5包中实现。
有人建议我改变tmp的存储模式。
storage.mode(tmp)="double" 但是这是行不通的( storage.mode(tmp) = "double“:(list)对象中的错误不能被强制输入'double')。我试过了
tmp<-as.numeric(unlist(tmp))但这将使我的数组的维数从559488元素更改为1262204908 (!)元素。其他建议?谢谢
发布于 2015-02-05 21:49:26
如果有人对这个问题的解决感兴趣,可以在这里找到:
https://stackoverflow.com/questions/28304761
复制相似问题